From 3190b51a412746e2bdbab3974e44071cb419754f Mon Sep 17 00:00:00 2001 From: Dominick Leppich Date: Tue, 14 May 2024 12:05:37 +0200 Subject: [PATCH 1/3] task: migrate to new vocabulary server --- .../goobi/plugins/aeon/AeonProperty.java | 103 +++++++++--------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java index dd41dad..5babb7e 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java @@ -1,23 +1,24 @@ package de.intranda.goobi.plugins.aeon; +import de.intranda.goobi.plugins.AeonProcessCreationWorkflowPlugin; +import de.sub.goobi.helper.Helper; +import io.goobi.vocabulary.exchange.FieldDefinition; +import io.goobi.vocabulary.exchange.Vocabulary; +import io.goobi.vocabulary.exchange.VocabularySchema; +import io.goobi.workflow.api.vocabulary.VocabularyAPIManager; +import io.goobi.workflow.api.vocabulary.jsfwrapper.JSFVocabularyRecord; +import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.lang.StringUtils; + import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.configuration.HierarchicalConfiguration; -import org.apache.commons.lang.StringUtils; -import org.goobi.production.cli.helper.StringPair; -import org.goobi.vocabulary.Field; -import org.goobi.vocabulary.VocabRecord; -import org.goobi.vocabulary.Vocabulary; - -import de.intranda.goobi.plugins.AeonProcessCreationWorkflowPlugin; -import de.sub.goobi.persistence.managers.VocabularyManager; -import lombok.Data; +import java.util.Optional; +import java.util.stream.Collectors; @Data public class AeonProperty { @@ -59,6 +60,8 @@ public class AeonProperty { private AeonProcessCreationWorkflowPlugin plugin; + private VocabularyAPIManager vocabularyAPI = VocabularyAPIManager.getInstance(); + /** contains the list of selected values in multiselect */ private List multiselectSelectedValues = new ArrayList<>(); private List defaultSelectedValues = new ArrayList<>(); @@ -133,50 +136,44 @@ public AeonProperty(HierarchicalConfiguration config, AeonProcessCreationWorkflo } private void initializeVocabulary() { - + Vocabulary vocabulary = vocabularyAPI.vocabularies().findByName(vocabularyName); if (vocabularyField == null || vocabularyField.isEmpty()) { - Vocabulary currentVocabulary = VocabularyManager.getVocabularyByTitle(vocabularyName); - - if (currentVocabulary != null) { - VocabularyManager.getAllRecords(currentVocabulary); - List recordList = currentVocabulary.getRecords(); - Collections.sort(recordList); - selectValues = new ArrayList<>(recordList.size()); - if (currentVocabulary != null && currentVocabulary.getId() != null) { - for (VocabRecord vr : recordList) { - for (Field f : vr.getFields()) { - if (f.getDefinition().isMainEntry()) { - selectValues.add(f.getValue()); - break; - } - } - } - } - } + List recordList = vocabularyAPI.vocabularyRecords().list(vocabulary.getId(), Optional.of(1000), Optional.empty()).getContent(); + selectValues = recordList.stream() + .map(JSFVocabularyRecord::getMainValue) + .collect(Collectors.toList()); } else { - List vocabularySearchFields = new ArrayList<>(); - for (String fieldname : vocabularyField) { - String[] parts = fieldname.trim().split("="); - if (parts.length > 1) { - String fieldName = parts[0]; - String value = parts[1]; - StringPair sp = new StringPair(fieldName, value); - vocabularySearchFields.add(sp); - } + if (vocabularyField.size() > 1) { + Helper.setFehlerMeldung("vocabularyList with multiple fields is not supported right now"); + return; } - List records = VocabularyManager.findRecords(vocabularyName, vocabularySearchFields); - if (records != null && records.size() > 0) { - Collections.sort(records); - selectValues = new ArrayList<>(records.size()); - for (VocabRecord vr : records) { - for (Field f : vr.getFields()) { - if (f.getDefinition().isMainEntry()) { - selectValues.add(f.getValue()); - break; - } - } - } + + String[] parts = vocabularyField.get(0).trim().split("="); + if (parts.length != 2) { + Helper.setFehlerMeldung("Wrong field format"); + return; + } + + String searchFieldName = parts[0]; + String searchFieldValue = parts[1]; + + VocabularySchema schema = vocabularyAPI.vocabularySchemas().get(vocabulary.getSchemaId()); + Optional searchField = schema.getDefinitions().stream() + .filter(d -> d.getName().equals(searchFieldName)) + .findFirst(); + + if (searchField.isEmpty()) { + Helper.setFehlerMeldung("Field " + searchFieldName + " not found in vocabulary " + vocabulary.getName()); + return; } + + // Assume there are not than 1000 hits, otherwise it is not useful anyway.. + List recordList = vocabularyAPI.vocabularyRecords() + .search(vocabulary.getId(), searchField.get().getId() + ":" + searchFieldValue) + .getContent(); + selectValues = recordList.stream() + .map(JSFVocabularyRecord::getMainValue) + .collect(Collectors.toList()); } } From 98ddaeccc99cb75cbea6aa5a76a5c54226ee6629 Mon Sep 17 00:00:00 2001 From: Dominick Leppich Date: Wed, 22 May 2024 08:00:01 +0200 Subject: [PATCH 2/3] fix: use all record retrieval api --- .../main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java index 5babb7e..1b9eb1f 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java @@ -138,7 +138,7 @@ public AeonProperty(HierarchicalConfiguration config, AeonProcessCreationWorkflo private void initializeVocabulary() { Vocabulary vocabulary = vocabularyAPI.vocabularies().findByName(vocabularyName); if (vocabularyField == null || vocabularyField.isEmpty()) { - List recordList = vocabularyAPI.vocabularyRecords().list(vocabulary.getId(), Optional.of(1000), Optional.empty()).getContent(); + List recordList = vocabularyAPI.vocabularyRecords().all(vocabulary.getId()); selectValues = recordList.stream() .map(JSFVocabularyRecord::getMainValue) .collect(Collectors.toList()); From 1d275a01f25bdf48a894e40e81ab880dfcc6a9cc Mon Sep 17 00:00:00 2001 From: Dominick Leppich Date: Tue, 30 Jul 2024 09:25:42 +0200 Subject: [PATCH 3/3] fix: adapt to vocabulary core API changes --- .../goobi/plugins/aeon/AeonProperty.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java index 1b9eb1f..adaf659 100644 --- a/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java +++ b/module-base/src/main/java/de/intranda/goobi/plugins/aeon/AeonProperty.java @@ -6,7 +6,7 @@ import io.goobi.vocabulary.exchange.Vocabulary; import io.goobi.vocabulary.exchange.VocabularySchema; import io.goobi.workflow.api.vocabulary.VocabularyAPIManager; -import io.goobi.workflow.api.vocabulary.jsfwrapper.JSFVocabularyRecord; +import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabularyRecord; import lombok.Data; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.configuration.HierarchicalConfiguration; @@ -138,10 +138,7 @@ public AeonProperty(HierarchicalConfiguration config, AeonProcessCreationWorkflo private void initializeVocabulary() { Vocabulary vocabulary = vocabularyAPI.vocabularies().findByName(vocabularyName); if (vocabularyField == null || vocabularyField.isEmpty()) { - List recordList = vocabularyAPI.vocabularyRecords().all(vocabulary.getId()); - selectValues = recordList.stream() - .map(JSFVocabularyRecord::getMainValue) - .collect(Collectors.toList()); + selectValues = vocabularyAPI.vocabularyRecords().getRecordMainValues(vocabulary.getId()); } else { if (vocabularyField.size() > 1) { Helper.setFehlerMeldung("vocabularyList with multiple fields is not supported right now"); @@ -166,14 +163,11 @@ private void initializeVocabulary() { Helper.setFehlerMeldung("Field " + searchFieldName + " not found in vocabulary " + vocabulary.getName()); return; } - - // Assume there are not than 1000 hits, otherwise it is not useful anyway.. - List recordList = vocabularyAPI.vocabularyRecords() - .search(vocabulary.getId(), searchField.get().getId() + ":" + searchFieldValue) - .getContent(); - selectValues = recordList.stream() - .map(JSFVocabularyRecord::getMainValue) - .collect(Collectors.toList()); + + selectValues = vocabularyAPI.vocabularyRecords() + .getRecordMainValues(vocabularyAPI.vocabularyRecords() + .list(vocabulary.getId()) + .search(searchField.get().getId() + ":" + searchFieldValue)); } }