From a8e3591a0f8957bbebfd4503ab2d13199066b975 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Tue, 8 Dec 2009 01:02:46 +0000 Subject: [PATCH] CSPACE-610: Sample code to delete vocabularies and vocabulary items now guarded by a flag. --- .../vocabulary/client/sample/Sample.java | 110 +++++++++++------- 1 file changed, 66 insertions(+), 44 deletions(-) diff --git a/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java b/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java index b93872ec1..f55a4a203 100644 --- a/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java +++ b/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java @@ -50,8 +50,8 @@ import org.slf4j.LoggerFactory; * VocabularyServiceTest, carries out tests against a * deployed and running Vocabulary Service. * - * $LastChangedRevision: 753 $ - * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class Sample { private static final Logger logger = @@ -435,47 +435,49 @@ public class Sample { } public static void main(String[] args) { - + + // Configure logging. BasicConfigurator.configure(); - logger.info("VocabularyBaseImport starting..."); - Sample vbi = new Sample(); + logger.info("VocabularyBaseImport starting..."); - logger.info("Deleting all vocabulary items and vocabularies ..."); + Sample vbi = new Sample(); + VocabulariesCommonList vocabularies; + List vocabIds; + String details = ""; - // For each vocabulary ... + // Optionally delete all vocabularies and vocabulary items. - VocabulariesCommonList vocabularies = vbi.readVocabularies(); - List vocabIds = vbi.readVocabularyIds(vocabularies); - for (String vocabId : vocabIds) { - // Delete vocabulary items for this vocabulary. - logger.info("Deleting vocabulary items ..."); - vbi.deleteAllItemsForVocab(vocabId); - // Delete vocabularies. - logger.info("Deleting vocabulary ..."); - vbi.deleteVocabulary(vocabId); - } + boolean ENABLE_DELETE_ALL = false; + if (ENABLE_DELETE_ALL) { - // Read vocabularies after deletion. - logger.info("Reading vocabularies after deletion ..."); + logger.info("Deleting all vocabulary items and vocabularies ..."); - String details = ""; + // For each vocabulary ... + vocabularies = vbi.readVocabularies(); + vocabIds = vbi.readVocabularyIds(vocabularies); + for (String vocabId : vocabIds) { + logger.info("Deleting all vocabulary items for vocabulary ..."); + vbi.deleteAllItemsForVocab(vocabId); + logger.info("Deleting vocabulary ..."); + vbi.deleteVocabulary(vocabId); + } - vocabularies = vbi.readVocabularies(); - details = vbi.displayAllVocabularies(vocabularies); - logger.info(details); + logger.info("Reading vocabularies after deletion ..."); + vocabularies = vbi.readVocabularies(); + details = vbi.displayAllVocabularies(vocabularies); + logger.info(details); - logger.info("Reading items in each vocabulary after deletion ..."); + logger.info("Reading items in each vocabulary after deletion ..."); + vocabIds = vbi.readVocabularyIds(vocabularies); + for (String vocabId : vocabIds) { + VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId); + details = vbi.displayAllVocabularyItems(items); + logger.info(details); + } - // Read items in each vocabulary. - vocabIds = vbi.readVocabularyIds(vocabularies); - for (String vocabId : vocabIds) { - VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId); - details = vbi.displayAllVocabularyItems(items); - logger.info(details); } - // Create new vocabularies, each populated with vocabulary items. final String acquisitionMethodsVocabName = "Acquisition Methods"; @@ -494,7 +496,7 @@ public class Sample { "Ethnography","Herpetology","Media and Performance Art", "Paintings and Sculpture","Paleobotany","Photographs", "Prints and Drawings"); - + vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues); vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues); vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues); @@ -502,23 +504,43 @@ public class Sample { logger.info("VocabularyBaseImport complete."); - logger.info("Reading newly-created vocabularies ..."); - - // Read vocabularies after import. + logger.info("Reading vocabularies and items ..."); + // Get a list of vocabularies. vocabularies = vbi.readVocabularies(); - details = vbi.displayAllVocabularies(vocabularies); - logger.info(details); + // For each vocabulary ... + for (VocabulariesCommonList.VocabularyListItem + vocabulary : vocabularies.getVocabularyListItem()) { + // Get its display name. + logger.info(vocabulary.getDisplayName()); + // Get a list of the vocabulary items in this vocabulary. + VocabularyitemsCommonList items = + vbi.readItemsInVocab(vocabulary.getCsid()); + // For each vocabulary item ... + for (VocabularyitemsCommonList.VocabularyitemListItem + item : items.getVocabularyitemListItem()) { + // Get its display name. + logger.info(" " + item.getDisplayName()); + } + } - logger.info("Reading items in each vocabulary ..."); + // Sample alternate methods of reading all vocabularies and + // vocabulary items separately. + boolean RUN_ADDITIONAL_SAMPLES = false; + if (RUN_ADDITIONAL_SAMPLES) { - // Read items in each vocabulary after import. - vocabIds = vbi.readVocabularyIds(vocabularies); - for (String vocabId : vocabIds) { - VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId); - details = vbi.displayAllVocabularyItems(items); + logger.info("Reading all vocabularies ..."); + details = vbi.displayAllVocabularies(vocabularies); logger.info(details); + + logger.info("Reading all vocabulary items ..."); + vocabIds = vbi.readVocabularyIds(vocabularies); + for (String vocabId : vocabIds) { + VocabularyitemsCommonList items = vbi.readItemsInVocab(vocabId); + details = vbi.displayAllVocabularyItems(items); + logger.info(details); + } + } - } -- 2.47.3