Skip to content

Commit

Permalink
Merge pull request 'task: migrate to new vocabulary server' (#11) fro…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Jul 30, 2024
2 parents ba90adb + 1d275a0 commit 6f381de
Showing 1 changed file with 44 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -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.helper.ExtendedVocabularyRecord;
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 {
Expand Down Expand Up @@ -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<String> multiselectSelectedValues = new ArrayList<>();
private List<String> defaultSelectedValues = new ArrayList<>();
Expand Down Expand Up @@ -133,50 +136,38 @@ 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<VocabRecord> 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;
}
}
}
}
}
selectValues = vocabularyAPI.vocabularyRecords().getRecordMainValues(vocabulary.getId());
} else {
List<StringPair> 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<VocabRecord> 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<FieldDefinition> 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;
}

selectValues = vocabularyAPI.vocabularyRecords()
.getRecordMainValues(vocabularyAPI.vocabularyRecords()
.list(vocabulary.getId())
.search(searchField.get().getId() + ":" + searchFieldValue));
}
}

Expand Down

0 comments on commit 6f381de

Please sign in to comment.