Skip to content

Commit

Permalink
Make use of centralized String constants
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Feb 3, 2025
1 parent 8f9d1fc commit 40691d2
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class StringConstants {

public static final String KITODO = "kitodo";

public static final String COMMA_DELIMITER = ", ";
public static final String SEMICOLON_DELIMITER = "; ";
public static final String EDIT_FORM_SAVE = "editForm:save";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.dataeditor;

import static org.kitodo.constants.StringConstants.KITODO;

import com.sun.xml.bind.marshaller.NamespacePrefixMapper;

/**
Expand All @@ -26,7 +28,6 @@ public class MetsKitodoNamespacePrefixMapper extends NamespacePrefixMapper {
private static final String XLINK_PREFIX = "xlink";
private static final String XLINK_URI = "http://www.w3.org/1999/xlink";

private static final String KITODO_PREFIX = "kitodo";
private static final String KITODO_URI = "http://meta.kitodo.org/v1/";

@Override
Expand All @@ -36,7 +37,7 @@ public String getPreferredPrefix(String namespaceUri, String suggestion, boolean
} else if (XLINK_URI.equals(namespaceUri)) {
return XLINK_PREFIX;
} else if (KITODO_URI.equals(namespaceUri)) {
return KITODO_PREFIX;
return KITODO;
}
return suggestion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.dataeditor;

import static org.kitodo.constants.StringConstants.KITODO;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
Expand All @@ -24,7 +26,7 @@ public void shouldReturnPrefix() {
String preferredMetsPrefix = mapper.getPreferredPrefix("http://www.loc.gov/METS/", null, true);
String preferredXlinkPrefix = mapper.getPreferredPrefix("http://www.w3.org/1999/xlink", null, true);
String notExistingPrefix = mapper.getPreferredPrefix("http://not.existing", "return this", true);
assertEquals("kitodo", preferredKitodoPrefix, "Prefix mapper return the wrong prefix for kitodo uri");
assertEquals(KITODO, preferredKitodoPrefix, "Prefix mapper return the wrong prefix for kitodo uri");
assertEquals("mets", preferredMetsPrefix, "Prefix mapper return the wrong prefix for mets uri");
assertEquals("xlink", preferredXlinkPrefix, "Prefix mapper return the wrong prefix for xlink uri");
assertEquals("return this", notExistingPrefix, "Prefix mapper return the wrong prefix for not existing uri");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

package org.kitodo.dataeditor.ruleset;

import static org.kitodo.constants.StringConstants.CREATE;
import static org.kitodo.constants.StringConstants.EDIT;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.contains;
Expand Down Expand Up @@ -1101,7 +1104,7 @@ public void testReimportOfMetadataModesCreate() throws Exception {
imported.add(newMetadataEntry("metadataToKeepExceptInEditing", "value not to replace")); // 0
imported.add(newMetadataEntry("metadataThatIsNew", "new value")); // 1

int numAdded = underTest.updateMetadata("division", metadata, "create", imported);
int numAdded = underTest.updateMetadata("division", metadata, CREATE, imported);
assertEquals(5, numAdded);

List<Metadata> defaultReplace = metadata.stream()
Expand Down Expand Up @@ -1163,7 +1166,7 @@ public void testReimportOfMetadataModesEdit() throws Exception {
imported.add(newMetadataEntry("metadataToAddDuringCreationAndKeepLater", "value not to replace")); // 0
imported.add(newMetadataEntry("metadataToKeepExceptInEditing", "replaced value")); // -1

int numAdded = underTest.updateMetadata("division", metadata, "edit", imported);
int numAdded = underTest.updateMetadata("division", metadata, EDIT, imported);
assertEquals(-1, numAdded);

List<Metadata> keepLater = metadata.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.dataformat.access;

import static org.kitodo.constants.StringConstants.KITODO;

import java.math.BigInteger;
import java.net.URI;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -58,7 +60,7 @@ public class DivXmlElementAccess extends LogicalDivision {
* The qualified name of the Kitodo metadata format, needed to assemble the
* metadata entries in METS using JAXB.
*/
private static final QName KITODO_QNAME = new QName("http://meta.kitodo.org/v1/", "kitodo");
private static final QName KITODO_QNAME = new QName("http://meta.kitodo.org/v1/", KITODO);

/**
* Some magic numbers that are used in the METS XML file representation of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.data.elasticsearch;

import static org.kitodo.constants.StringConstants.KITODO;

import javax.persistence.Table;

import org.kitodo.config.ConfigMain;
Expand All @@ -31,7 +33,7 @@ public abstract class Index {
*/
public Index(Class<?> beanClass) {
Table table = beanClass.getAnnotation(Table.class);
this.index = ConfigMain.getParameter("elasticsearch.index", "kitodo");
this.index = ConfigMain.getParameter("elasticsearch.index", KITODO);
this.setType(table.name());
}

Expand All @@ -42,7 +44,7 @@ public Index(Class<?> beanClass) {
* as String
*/
public Index(String type) {
this.index = ConfigMain.getParameter("elasticsearch.index", "kitodo");
this.index = ConfigMain.getParameter("elasticsearch.index", KITODO);
this.setType(type);
}

Expand Down
4 changes: 3 additions & 1 deletion Kitodo/src/main/java/org/kitodo/config/ConfigProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.config;

import static org.kitodo.constants.StringConstants.KITODO;

import de.unigoettingen.sub.search.opac.ConfigOpac;

import java.io.IOException;
Expand Down Expand Up @@ -142,7 +144,7 @@ public String getOpacCatalog() {
* @return tif definition as String
*/
public String getTifDefinition() throws DoctypeMissingException {
return getParamString("tifheader." + getDocType(), "kitodo");
return getParamString("tifheader." + getDocType(), KITODO);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.forms.createprocess;

import static org.kitodo.constants.StringConstants.CREATE;

import java.io.IOException;
import java.net.URI;
import java.text.MessageFormat;
Expand Down Expand Up @@ -92,7 +94,6 @@ public class CreateProcessForm extends BaseForm implements MetadataTreeTableInte

private RulesetManagementInterface rulesetManagement;
private final List<Locale.LanguageRange> priorityList;
private final String acquisitionStage = "create";
private Project project;
private Template template;
private LinkedList<TempProcess> processes = new LinkedList<>();
Expand Down Expand Up @@ -174,7 +175,7 @@ private List<SelectItem> getAllRulesetDivisions() {
*/
@Override
public String getAcquisitionStage() {
return acquisitionStage;
return CREATE;
}

/**
Expand Down Expand Up @@ -419,7 +420,7 @@ private String parentTypeIfForbidden() throws IOException {
} else {
String parentType = logicalDivision.getType();
StructuralElementViewInterface divisionView = rulesetManagement.getStructuralElementView(parentType,
acquisitionStage, priorityList);
CREATE, priorityList);
if (divisionView.getAllowedSubstructuralElements().containsKey(processDataTab.getDocType())) {
return null;
} else {
Expand Down Expand Up @@ -595,8 +596,8 @@ private void saveChildProcessLinks() throws IOException, DataException {
private void processChildren() {
// set parent relations between main process and its imported child processes!
try {
ImportService.processProcessChildren(getMainProcess(), childProcesses, rulesetManagement,
acquisitionStage, priorityList);
ImportService.processProcessChildren(getMainProcess(), childProcesses, rulesetManagement, CREATE,
priorityList);
} catch (DataException | InvalidMetadataValueException | NoSuchMetadataFieldException
| ProcessGenerationException | IOException e) {
Helper.setErrorMessage("Unable to attach child documents to process: " + e.getMessage());
Expand All @@ -620,7 +621,7 @@ private void processAncestors() throws ProcessGenerationException {
private void processTempProcess(TempProcess tempProcess) throws ProcessGenerationException {
try {
tempProcess.getProcessMetadata().preserve();
ImportService.processTempProcess(tempProcess, rulesetManagement, acquisitionStage, priorityList, null);
ImportService.processTempProcess(tempProcess, rulesetManagement, CREATE, priorityList, null);
} catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) {
throw new ProcessGenerationException("Error creating process hierarchy: invalid metadata found!");
} catch (RulesetNotFoundException e) {
Expand All @@ -637,11 +638,11 @@ private void saveProcessHierarchyMetadata() {
if (this.processes.indexOf(tempProcess) == 0) {
tempProcess.getProcessMetadata().preserve();
}
ProcessHelper.saveTempProcessMetadata(tempProcess, rulesetManagement, acquisitionStage, priorityList);
ProcessHelper.saveTempProcessMetadata(tempProcess, rulesetManagement, CREATE, priorityList);
}
// save child processes meta.xml files
for (TempProcess tempProcess : this.childProcesses) {
ProcessHelper.saveTempProcessMetadata(tempProcess, rulesetManagement, acquisitionStage, priorityList);
ProcessHelper.saveTempProcessMetadata(tempProcess, rulesetManagement, CREATE, priorityList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.forms.createprocess;

import static org.kitodo.constants.StringConstants.CREATE;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -32,7 +34,6 @@
import org.kitodo.production.helper.ProcessHelper;
import org.kitodo.production.helper.TempProcess;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.services.data.ImportService;
import org.omnifaces.util.Ajax;
import org.primefaces.PrimeFaces;

Expand Down Expand Up @@ -85,11 +86,10 @@ void attachToExistingParentAndGenerateAtstslIfNotExist(TempProcess tempProcess)

if (StringUtils.isBlank(tempProcess.getAtstsl())) {
if (Objects.nonNull(parentTempProcess)) {
ProcessHelper.generateAtstslFields(tempProcess, Collections.singletonList(parentTempProcess),
ImportService.ACQUISITION_STAGE_CREATE, true);
ProcessHelper.generateAtstslFields(tempProcess, Collections.singletonList(parentTempProcess), CREATE,
true);
} else {
ProcessHelper.generateAtstslFields(tempProcess, null,
ImportService.ACQUISITION_STAGE_CREATE, true);
ProcessHelper.generateAtstslFields(tempProcess, null, CREATE, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.forms.createprocess;

import static org.kitodo.constants.StringConstants.CREATE;

import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -146,7 +148,7 @@ public int addMetadataIfNotExists(Collection<Metadata> potentialMetadataItems)
throws InvalidMetadataValueException, NoSuchMetadataFieldException {

preserve();
int count = rulesetService.updateMetadata(division.getType(), metadata, "create", potentialMetadataItems);
int count = rulesetService.updateMetadata(division.getType(), metadata, CREATE, potentialMetadataItems);
buildTreeNodeAndCreateMetadataTable();
return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.forms.dataeditor;

import static org.kitodo.constants.StringConstants.EDIT;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -84,12 +86,6 @@ public class DataEditorForm implements MetadataTreeTableInterface, RulesetSetupI

private static final Logger logger = LogManager.getLogger(DataEditorForm.class);

/**
* A filter on the rule set depending on the workflow step. So far this is
* not configurable anywhere and is therefore on “edit”.
*/
private final String acquisitionStage;

/**
* Backing bean for the add doc struc type dialog.
*/
Expand Down Expand Up @@ -248,7 +244,6 @@ public DataEditorForm() {
this.changeDocStrucTypeDialog = new ChangeDocStrucTypeDialog(this);
this.editPagesDialog = new EditPagesDialog(this);
this.uploadFileDialog = new UploadFileDialog(this);
acquisitionStage = "edit";
}

/**
Expand Down Expand Up @@ -644,7 +639,7 @@ public void deletePhysicalDivision() {

@Override
public String getAcquisitionStage() {
return acquisitionStage;
return EDIT;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.forms.massimport;

import static org.kitodo.constants.StringConstants.CREATE;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -34,7 +36,6 @@ public class AddMetadataDialog {
private RulesetManagementInterface rulesetManagement;
private final List<Locale.LanguageRange> priorityList = ServiceManager.getUserService()
.getCurrentMetadataLanguage();
private final String acquisitionStage = "create";
private List<StructuralElementViewInterface> allRulesetDivisions = new ArrayList<>();

AddMetadataDialog(MassImportForm massImportForm) {
Expand Down Expand Up @@ -71,7 +72,7 @@ public void setRulesetManagement(RulesetManagementInterface rulesetManagement) {
/**
* Returns the list of selectable metadata types.
*
* @return the map of metadata types
* @return the list of metadata types
*/
public List<ProcessDetail> getAllMetadataTypes() {
if (Objects.isNull(metadataTypes)) {
Expand All @@ -96,7 +97,7 @@ public void prepareMetadataTypes() {

private List<StructuralElementViewInterface> getDivisions() {
return rulesetManagement.getStructuralElements(priorityList).keySet().stream()
.map(key -> rulesetManagement.getStructuralElementView(key, acquisitionStage, priorityList))
.map(key -> rulesetManagement.getStructuralElementView(key, CREATE, priorityList))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.helper.metadata.legacytypeimplementations;

import static org.kitodo.constants.StringConstants.EDIT;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -77,7 +79,7 @@ public class LegacyLogicalDocStructHelper implements LegacyDocStructHelperInterf
this.priorityList = priorityList;
this.parent = parent;
String type = logicalDivision.getType();
this.divisionView = ruleset.getStructuralElementView(Objects.nonNull(type) ? type : "", "edit", priorityList);
this.divisionView = ruleset.getStructuralElementView(Objects.nonNull(type) ? type : "", EDIT, priorityList);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.kitodo.production.helper.metadata.legacytypeimplementations;

import static org.kitodo.constants.StringConstants.EDIT;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -95,7 +97,7 @@ public LegacyMetadataTypeHelper getMetadataTypeByName(String identifier) {
logger.catching(Level.TRACE, e);
priorityList = LanguageRange.parse("en");
}
StructuralElementViewInterface divisionView = ruleset.getStructuralElementView("", "edit",
StructuralElementViewInterface divisionView = ruleset.getStructuralElementView("", EDIT,
priorityList);
List<MetadataViewWithValuesInterface> entryViews = divisionView
.getSortedVisibleMetadata(Collections.emptyList(), Arrays.asList(identifier));
Expand Down
Loading

0 comments on commit 40691d2

Please sign in to comment.