Skip to content

Commit

Permalink
fix: missing metadata gui drop-down bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Nov 14, 2024
1 parent bf18e50 commit 97e9484
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Data
@RequiredArgsConstructor
public class MetadataConfiguredField {
public class MetadataEditionConfiguredField {

// metadata, property or person
@NonNull
Expand Down Expand Up @@ -67,22 +67,22 @@ public class MetadataConfiguredField {
private boolean repeatable;
private boolean deletable;

private List<MetadataField> metadataFields = new ArrayList<>();
private List<MetadataEditionField> metadataFields = new ArrayList<>();

private boolean onlyEmptyReadOnlyFields;

public void addMetadataField(MetadataField mf) {
public void addMetadataField(MetadataEditionField mf) {
this.metadataFields.add(mf);
}

public void deleteMetadataField(MetadataField mf) {
public void deleteMetadataField(MetadataEditionField mf) {
this.metadataFields.remove(mf);
}

public boolean isShowField() {
// show only filled read only fields
if ("textReadonly".equals(this.type) || "textareaReadonly".equals(this.type) || !this.onlyEmptyReadOnlyFields) {
for (MetadataField mf : this.metadataFields) {
for (MetadataEditionField mf : this.metadataFields) {
if (mf.getPerson() != null) {
Person p = mf.getPerson();
if (StringUtils.isNotBlank(p.getLastname()) || StringUtils.isNotBlank(p.getFirstname())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import javax.faces.model.SelectItem;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;
import org.goobi.beans.Processproperty;

Expand All @@ -13,30 +16,38 @@

@Data
@RequiredArgsConstructor
public class MetadataField {
public class MetadataEditionField {

// holds the actual object
private Metadata metadata;
private Person person;
private Processproperty property;

@NonNull
private MetadataConfiguredField configuredField;
@ToString.Exclude
private MetadataEditionConfiguredField configuredField;

public void setVocabularyValue(String value) {
if (StringUtils.isNotBlank(value)) {
for (SelectItem item : configuredField.getVocabularyList()) {
if (value.equals(item.getValue())) {
if (metadata != null) {
metadata.setValue(item.getLabel());
metadata.setAuthorityFile(configuredField.getVocabularyName(), configuredField.getVocabularyUrl(),
configuredField.getVocabularyUrl() + "/" + value);
// TODO: Write correct authority information here
// metadata.setAuthorityFile(configuredField.getVocabularyName(), configuredField.getVocabularyUrl(),
// configuredField.getVocabularyUrl() + "/" + value);
} else if (property != null) {
property.setWert(item.getLabel());
}
break;
}
}
} else {
if (metadata != null) {
metadata.setValue(null);
} else if (property != null) {
property.setWert(null);
}
}
}

Expand Down Expand Up @@ -79,5 +90,4 @@ public String getValue() {
public String getHelpText() {
return configuredField.getHelpText();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public class MetadataEditionPlugin implements IStepPluginVersion2 {
private Integer imageIndex = null;

@Getter
private transient List<MetadataConfiguredField> metadataFieldList = new ArrayList<>();
private transient List<MetadataEditionConfiguredField> metadataFieldList = new ArrayList<>();

@Getter
@Setter
private transient MetadataField currentField;
private transient MetadataEditionField currentField;

@Getter
@Setter
Expand Down Expand Up @@ -189,7 +189,7 @@ public class MetadataEditionPlugin implements IStepPluginVersion2 {
@Getter
private boolean displayDownloadButton = false;

private transient List<MetadataField> deleteList = new ArrayList<>();
private transient List<MetadataEditionField> deleteList = new ArrayList<>();

@Getter
@Setter
Expand All @@ -198,7 +198,7 @@ public class MetadataEditionPlugin implements IStepPluginVersion2 {
private String newField;

@Getter
private transient MetadataConfiguredField selectedField;
private transient MetadataEditionConfiguredField selectedField;

@Getter
@Setter
Expand Down Expand Up @@ -400,7 +400,7 @@ private void initDisplayFields(SubnodeConfiguration config) {
vocabularyRecords = Collections.emptyList();
}

MetadataConfiguredField metadataField = new MetadataConfiguredField(source, name, fieldType, label, required, helpText, searchable);
MetadataEditionConfiguredField metadataField = new MetadataEditionConfiguredField(source, name, fieldType, label, required, helpText, searchable);
metadataField.setStructType(structType);
metadataField.setDefaultValue(defaultValue);
metadataField.setValidationRegex(validationRegex);
Expand All @@ -416,13 +416,14 @@ private void initDisplayFields(SubnodeConfiguration config) {
this.metadataFieldList.add(metadataField);
}

for (MetadataConfiguredField cf : this.metadataFieldList) {
List<MetadataEditionConfiguredField> brokenConfiguredFields = new ArrayList<>(this.metadataFieldList.size());
for (MetadataEditionConfiguredField cf : this.metadataFieldList) {
boolean found = false;
if ("property".contains(cf.getSource())) {
for (Processproperty prop : properties) {
if (prop.getTitel().equals(cf.getName())) {
found = true;
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setProperty(prop);
if (StringUtils.isBlank(prop.getWert())) {
prop.setWert(cf.getDefaultValue());
Expand All @@ -440,7 +441,7 @@ private void initDisplayFields(SubnodeConfiguration config) {
property.setType(PropertyType.STRING);
property.setWert(cf.getDefaultValue());
this.process.getEigenschaften().add(property);
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setProperty(property);
property.setWert(cf.getDefaultValue());
cf.addMetadataField(mf);
Expand All @@ -461,7 +462,7 @@ private void initDisplayFields(SubnodeConfiguration config) {
if (StringUtils.isBlank(md.getValue())) {
md.setValue(cf.getDefaultValue());
}
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setMetadata(md);
cf.addMetadataField(mf);
}
Expand All @@ -476,7 +477,7 @@ private void initDisplayFields(SubnodeConfiguration config) {
} else {
this.logical.addMetadata(md);
}
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setMetadata(md);
cf.addMetadataField(mf);
} catch (MetadataTypeNotAllowedException e) {
Expand All @@ -497,7 +498,7 @@ private void initDisplayFields(SubnodeConfiguration config) {
for (Person p : personList) {
if (p.getType().getName().equals(cf.getName())) {
found = true;
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setPerson(p);
cf.addMetadataField(mf);
}
Expand All @@ -511,16 +512,25 @@ private void initDisplayFields(SubnodeConfiguration config) {
} else {
this.logical.addPerson(person);
}
MetadataField mf = new MetadataField(cf);
MetadataEditionField mf = new MetadataEditionField(cf);
mf.setPerson(person);
cf.addMetadataField(mf);
} catch (MetadataTypeNotAllowedException e) {
log.error(e);
}
}
}

if (cf.getMetadataFields().isEmpty()) {
brokenConfiguredFields.add(cf);
String message = "The configured field \"" + cf.getLabel() + "\" contains no valid metadata fields, it will be removed! Please check your configuration!";
log.error(message);
Helper.setFehlerMeldung(message);
}
}

brokenConfiguredFields.forEach(cf -> this.metadataFieldList.remove(cf));

//* Allow the search of other processes inside of Goobi to find items with the same NLI identifier and which have a specific workflow progress
//* Allow to duplicate metadata from a searched Goobi process into the current process

Expand Down Expand Up @@ -709,10 +719,10 @@ private void removeMetadata(String metadataType, DocStruct docstruct) {
public void saveAllChanges() {

boolean totalValid = true;
for (MetadataConfiguredField mf : this.metadataFieldList) {
for (MetadataEditionConfiguredField mf : this.metadataFieldList) {
if (mf.getRequired().booleanValue()) {
boolean fieldValid = false;
for (MetadataField metadataField : mf.getMetadataFields()) {
for (MetadataEditionField metadataField : mf.getMetadataFields()) {
if (StringUtils.isNotBlank(metadataField.getValue())) {
fieldValid = true;
}
Expand All @@ -723,7 +733,7 @@ public void saveAllChanges() {
}

} else if (StringUtils.isNotBlank(mf.getValidationRegex())) {
for (MetadataField metadataField : mf.getMetadataFields()) {
for (MetadataEditionField metadataField : mf.getMetadataFields()) {
if (!metadataField.getValue().matches(mf.getValidationRegex())) {
Helper.setFehlerMeldung(mf.getLabel() + ": " + mf.getValidationErrorText(), "");
totalValid = false;
Expand All @@ -736,7 +746,7 @@ public void saveAllChanges() {
return;
}

for (MetadataField mf : this.deleteList) {
for (MetadataEditionField mf : this.deleteList) {
if ("property".contains(mf.getConfiguredField().getSource())) {
Processproperty pp = mf.getProperty();
this.process.getEigenschaften().remove(pp);
Expand All @@ -757,8 +767,8 @@ public void saveAllChanges() {
}

// save properties
for (MetadataConfiguredField cf : this.metadataFieldList) {
for (MetadataField mf : cf.getMetadataFields()) {
for (MetadataEditionConfiguredField cf : this.metadataFieldList) {
for (MetadataEditionField mf : cf.getMetadataFields()) {
if (mf.getProperty() != null) {
PropertyManager.saveProcessProperty(mf.getProperty());
}
Expand Down Expand Up @@ -994,9 +1004,9 @@ private String getVocabularyBaseName() {

// unused
public void addField() {
MetadataConfiguredField field = this.currentField.getConfiguredField();
MetadataEditionConfiguredField field = this.currentField.getConfiguredField();
if (field != null) {
MetadataField metadataField = new MetadataField(this.currentField.getConfiguredField());
MetadataEditionField metadataField = new MetadataEditionField(this.currentField.getConfiguredField());
field.addMetadataField(metadataField);

if ("property".contains(field.getSource())) {
Expand Down Expand Up @@ -1040,7 +1050,7 @@ public void addField() {

public void deleteField() {
if (this.currentField != null) {
for (MetadataConfiguredField cf : this.metadataFieldList) {
for (MetadataEditionConfiguredField cf : this.metadataFieldList) {
if (cf.getSource().equals(this.currentField.getConfiguredField().getSource())) {
cf.getMetadataFields().remove(this.currentField);
}
Expand All @@ -1052,7 +1062,7 @@ public void deleteField() {

public List<SelectItem> getPossibleFields() {
List<SelectItem> answer = new ArrayList<>();
for (MetadataConfiguredField cf : this.metadataFieldList) {
for (MetadataEditionConfiguredField cf : this.metadataFieldList) {
if ((cf.isRepeatable() || cf.getMetadataFields().isEmpty())
&& (!"textReadonly".equals(cf.getType()) && !"textareaReadonly".equals(cf.getType()))) {
answer.add(new SelectItem(cf.getName(), cf.getLabel()));
Expand All @@ -1064,7 +1074,7 @@ public List<SelectItem> getPossibleFields() {
public void addMetadataField() {
this.displayMetadataAddPopup = false;

MetadataField mf = new MetadataField(this.selectedField);
MetadataEditionField mf = new MetadataEditionField(this.selectedField);
this.selectedField.addMetadataField(mf);
switch (this.selectedField.getSource()) {
case "property":
Expand Down Expand Up @@ -1138,7 +1148,7 @@ public String getNewField() {

public void setNewField(String newField) {
if (this.newField == null || !this.newField.equals(newField)) {
for (MetadataConfiguredField cf : this.metadataFieldList) {
for (MetadataEditionConfiguredField cf : this.metadataFieldList) {
if (cf.getName().equals(newField)) {
this.selectedField = cf;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@
</h:selectOneMenu>
</ui:fragment>


<ui:fragment rendered="#{configuredField.type == 'vocabularyList'}">
<h:selectOneMenu
styleClass="form-select"
Expand Down

0 comments on commit 97e9484

Please sign in to comment.