]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-610: Sample code to delete vocabularies and vocabulary items now guarded by...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 8 Dec 2009 01:02:46 +0000 (01:02 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 8 Dec 2009 01:02:46 +0000 (01:02 +0000)
services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java

index b93872ec1bcd07edd6a26cce8bdd3e7a450491dd..f55a4a203a1ed0aa3708fd5c8b95dd14491e4b78 100644 (file)
@@ -50,8 +50,8 @@ import org.slf4j.LoggerFactory;
  * VocabularyServiceTest, carries out tests against a\r
  * deployed and running Vocabulary Service.\r
  *\r
- * $LastChangedRevision: 753 $\r
- * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $\r
+ * $LastChangedRevision$\r
+ * $LastChangedDate$\r
  */\r
 public class Sample {\r
     private static final Logger logger =\r
@@ -435,47 +435,49 @@ public class Sample {
     }\r
 \r
        public static void main(String[] args) {\r
-               \r
+\r
+        // Configure logging.\r
                BasicConfigurator.configure();\r
-               logger.info("VocabularyBaseImport starting...");\r
 \r
-               Sample vbi = new Sample();\r
+        logger.info("VocabularyBaseImport starting...");\r
 \r
-        logger.info("Deleting all vocabulary items and vocabularies ...");\r
+               Sample vbi = new Sample();\r
+        VocabulariesCommonList vocabularies;\r
+        List<String> vocabIds;\r
+        String details = "";\r
 \r
-        // For each vocabulary ...\r
+        // Optionally delete all vocabularies and vocabulary items.\r
 \r
-        VocabulariesCommonList vocabularies = vbi.readVocabularies();\r
-        List<String> vocabIds = vbi.readVocabularyIds(vocabularies);\r
-        for (String vocabId : vocabIds) {\r
-            // Delete vocabulary items for this vocabulary.\r
-            logger.info("Deleting vocabulary items ...");\r
-            vbi.deleteAllItemsForVocab(vocabId);\r
-            // Delete vocabularies.\r
-            logger.info("Deleting vocabulary ...");\r
-            vbi.deleteVocabulary(vocabId);\r
-        }\r
+        boolean ENABLE_DELETE_ALL = false;\r
+        if (ENABLE_DELETE_ALL) {\r
 \r
-        // Read vocabularies after deletion.\r
-        logger.info("Reading vocabularies after deletion ...");\r
+            logger.info("Deleting all vocabulary items and vocabularies ...");\r
 \r
-        String details = "";\r
+            // For each vocabulary ...\r
+            vocabularies = vbi.readVocabularies();\r
+            vocabIds = vbi.readVocabularyIds(vocabularies);\r
+            for (String vocabId : vocabIds) {\r
+                logger.info("Deleting all vocabulary items for vocabulary ...");\r
+                vbi.deleteAllItemsForVocab(vocabId);\r
+                logger.info("Deleting vocabulary ...");\r
+                vbi.deleteVocabulary(vocabId);\r
+            }\r
 \r
-        vocabularies = vbi.readVocabularies();\r
-        details = vbi.displayAllVocabularies(vocabularies);\r
-        logger.info(details);\r
+            logger.info("Reading vocabularies after deletion ...");\r
+            vocabularies = vbi.readVocabularies();\r
+            details = vbi.displayAllVocabularies(vocabularies);\r
+            logger.info(details);\r
 \r
-        logger.info("Reading items in each vocabulary after deletion ...");\r
+            logger.info("Reading items in each vocabulary after deletion ...");\r
+            vocabIds = vbi.readVocabularyIds(vocabularies);\r
+            for (String vocabId : vocabIds) {\r
+                VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId);\r
+                details = vbi.displayAllVocabularyItems(items);\r
+                logger.info(details);\r
+            }\r
 \r
-        // Read items in each vocabulary.\r
-        vocabIds = vbi.readVocabularyIds(vocabularies);\r
-        for (String vocabId : vocabIds) {\r
-            VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId);\r
-            details = vbi.displayAllVocabularyItems(items);\r
-            logger.info(details);\r
         }\r
 \r
-\r
         // Create new vocabularies, each populated with vocabulary items.\r
 \r
                final String acquisitionMethodsVocabName = "Acquisition Methods";\r
@@ -494,7 +496,7 @@ public class Sample {
                                                                        "Ethnography","Herpetology","Media and Performance Art",\r
                                                                        "Paintings and Sculpture","Paleobotany","Photographs",\r
                                                                        "Prints and Drawings");\r
-\r
+        \r
                vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues);\r
                vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues);\r
                vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues);\r
@@ -502,23 +504,43 @@ public class Sample {
 \r
                logger.info("VocabularyBaseImport complete.");\r
 \r
-        logger.info("Reading newly-created vocabularies ...");\r
-\r
-        // Read vocabularies after import.\r
+        logger.info("Reading vocabularies and items ...");\r
+        // Get a list of vocabularies.\r
         vocabularies = vbi.readVocabularies();\r
-        details = vbi.displayAllVocabularies(vocabularies);\r
-        logger.info(details);\r
+        // For each vocabulary ...\r
+        for (VocabulariesCommonList.VocabularyListItem\r
+            vocabulary : vocabularies.getVocabularyListItem()) {\r
+            // Get its display name.\r
+            logger.info(vocabulary.getDisplayName());\r
+            // Get a list of the vocabulary items in this vocabulary.\r
+            VocabularyitemsCommonList items =\r
+                vbi.readItemsInVocab(vocabulary.getCsid());\r
+            // For each vocabulary item ...\r
+            for (VocabularyitemsCommonList.VocabularyitemListItem\r
+                item : items.getVocabularyitemListItem()) {\r
+                // Get its display name.\r
+                logger.info(" " + item.getDisplayName());\r
+            }\r
+        }\r
 \r
-        logger.info("Reading items in each vocabulary ...");\r
+        // Sample alternate methods of reading all vocabularies and\r
+        // vocabulary items separately.\r
+        boolean RUN_ADDITIONAL_SAMPLES = false;\r
+        if (RUN_ADDITIONAL_SAMPLES) {\r
 \r
-        // Read items in each vocabulary after import.\r
-        vocabIds = vbi.readVocabularyIds(vocabularies);\r
-        for (String vocabId : vocabIds) {\r
-            VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId);\r
-            details = vbi.displayAllVocabularyItems(items);\r
+            logger.info("Reading all vocabularies ...");\r
+            details = vbi.displayAllVocabularies(vocabularies);\r
             logger.info(details);\r
+\r
+            logger.info("Reading all vocabulary items ...");\r
+            vocabIds = vbi.readVocabularyIds(vocabularies);\r
+            for (String vocabId : vocabIds) {\r
+                VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId);\r
+                details = vbi.displayAllVocabularyItems(items);\r
+                logger.info(details);\r
+            }\r
+\r
         }\r
-        \r
 \r
        }\r
 \r