From d35a7249963f1d2a123ee298c8a3ee8e675ddbd4 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:11:41 +0100 Subject: [PATCH 1/7] Correct naming: rulesetManagementInterface -> rulesetManagement --- .../forms/createprocess/CreateProcessForm.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java index b7b7187169d..6efe6c3f444 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java @@ -69,7 +69,7 @@ public class CreateProcessForm extends BaseForm implements RulesetSetupInterface private final SearchTab searchTab = new SearchTab(this); private final TitleRecordLinkTab titleRecordLinkTab = new TitleRecordLinkTab(this); - private RulesetManagementInterface rulesetManagementInterface; + private RulesetManagementInterface rulesetManagement; private List priorityList = ServiceManager.getUserService().getCurrentMetadataLanguage(); private String acquisitionStage = "create"; private Project project; @@ -87,7 +87,7 @@ public class CreateProcessForm extends BaseForm implements RulesetSetupInterface */ @Override public RulesetManagementInterface getRuleset() { - return rulesetManagementInterface; + return rulesetManagement; } /** @@ -102,14 +102,14 @@ public void updateRulesetAndDocType(Ruleset ruleset) throws RulesetNotFoundExcep private void setRulesetManagementInterface(Ruleset ruleset) throws RulesetNotFoundException { try { - this.rulesetManagementInterface = ServiceManager.getRulesetService().openRuleset(ruleset); + this.rulesetManagement = ServiceManager.getRulesetService().openRuleset(ruleset); } catch (IOException e) { logger.error(e.getLocalizedMessage()); } } private List getAllRulesetDivisions() { - List allDocTypes = rulesetManagementInterface + List allDocTypes = rulesetManagement .getStructuralElements(priorityList).entrySet() .stream().map(entry -> new SelectItem(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); @@ -460,7 +460,7 @@ private void processChildren() { // set parent relations between main process and its imported child processes! try { ImportService.processProcessChildren(getMainProcess(), this.childProcesses, template, - rulesetManagementInterface, acquisitionStage, priorityList); + rulesetManagement, acquisitionStage, priorityList); } catch (DataException | InvalidMetadataValueException | NoSuchMetadataFieldException | ProcessGenerationException | IOException | RulesetNotFoundException e) { Helper.setErrorMessage("Unable to attach child documents to process: " + e.getMessage()); @@ -489,7 +489,7 @@ private void processAncestors() throws ProcessGenerationException { ImportService.updateTasks(process); } else if (Objects.nonNull(tempProcess.getMetadataNodes())) { try { - ImportService.processTempProcess(tempProcess, template, rulesetManagementInterface, + ImportService.processTempProcess(tempProcess, template, rulesetManagement, acquisitionStage, priorityList); } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { throw new ProcessGenerationException("Error creating process hierarchy: invalid metadata found!"); From 4c4536a3c456f65856feb21d6839741ff314cfc6 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:14:27 +0100 Subject: [PATCH 2/7] Correct naming: rulesetManagementInterface -> rulesetManagement --- .../forms/createprocess/CreateProcessForm.java | 8 ++++---- .../forms/createprocess/ImportDialog.java | 2 +- .../forms/createprocess/ProcessDataTab.java | 2 +- .../createprocess/ProcessMetadataTab.java | 2 +- .../dataeditor/AddDocStrucTypeDialog.java | 18 +++++++++--------- .../forms/dataeditor/AddMediaUnitDialog.java | 4 ++-- .../dataeditor/ChangeDocStrucTypeDialog.java | 6 +++--- .../forms/dataeditor/DataEditorForm.java | 2 +- .../forms/dataeditor/GalleryPanel.java | 2 +- .../forms/dataeditor/MetadataPanel.java | 6 +++--- .../forms/dataeditor/StructurePanel.java | 12 ++++++------ .../interfaces/RulesetSetupInterface.java | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java index 6efe6c3f444..6df5ca180a5 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java @@ -83,10 +83,10 @@ public class CreateProcessForm extends BaseForm implements RulesetSetupInterface /** * Returns the ruleset management to access the ruleset. * - * @return the ruleset + * @return the ruleset management */ @Override - public RulesetManagementInterface getRuleset() { + public RulesetManagementInterface getRulesetManagement() { return rulesetManagement; } @@ -96,11 +96,11 @@ public RulesetManagementInterface getRuleset() { * @throws RulesetNotFoundException thrown if ruleset could not be found */ public void updateRulesetAndDocType(Ruleset ruleset) throws RulesetNotFoundException { - setRulesetManagementInterface(ruleset); + setRulesetManagement(ruleset); processDataTab.setAllDocTypes(getAllRulesetDivisions()); } - private void setRulesetManagementInterface(Ruleset ruleset) throws RulesetNotFoundException { + private void setRulesetManagement(Ruleset ruleset) throws RulesetNotFoundException { try { this.rulesetManagement = ServiceManager.getRulesetService().openRuleset(ruleset); } catch (IOException e) { diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ImportDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ImportDialog.java index edbbdfeb1c6..67ab7cac384 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ImportDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ImportDialog.java @@ -227,7 +227,7 @@ public void getRecordHierarchy() { // import ancestors LinkedList processes = ServiceManager.getImportService().importProcessHierarchy( this.currentRecordId, opac, projectId, templateId, this.importDepth, - this.createProcessForm.getRuleset().getFunctionalKeys( + this.createProcessForm.getRulesetManagement().getFunctionalKeys( FunctionalMetadata.HIGHERLEVEL_IDENTIFIER)); this.createProcessForm.setProcesses(processes); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDataTab.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDataTab.java index 90a344649b9..fe1d34cf6b6 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDataTab.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessDataTab.java @@ -191,7 +191,7 @@ public void generateProcessTitleAndTiffHeader() { List processDetails = this.createProcessForm.getProcessMetadataTab().getProcessDetailsElements(); Process process = this.createProcessForm.getMainProcess(); try { - StructuralElementViewInterface docTypeView = createProcessForm.getRuleset().getStructuralElementView( + StructuralElementViewInterface docTypeView = createProcessForm.getRulesetManagement().getStructuralElementView( docType, createProcessForm.getAcquisitionStage(), createProcessForm.getPriorityList()); String processTitle = docTypeView.getProcessTitle().orElse(""); if (processTitle.isEmpty()) { diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessMetadataTab.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessMetadataTab.java index 6dbde57ae55..01399e10ec8 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessMetadataTab.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/ProcessMetadataTab.java @@ -38,7 +38,7 @@ public ProcessMetadataTab(CreateProcessForm createProcessForm) { * which its Metadata are wanted to be shown */ public ProcessFieldedMetadata initializeProcessDetails(IncludedStructuralElement structure) { - return ImportService.initializeProcessDetails(structure, this.createProcessForm.getRuleset(), + return ImportService.initializeProcessDetails(structure, this.createProcessForm.getRulesetManagement(), this.createProcessForm.getAcquisitionStage(), this.createProcessForm.getPriorityList()); } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddDocStrucTypeDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddDocStrucTypeDialog.java index 67883471510..cf42b3cd458 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddDocStrucTypeDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddDocStrucTypeDialog.java @@ -437,7 +437,7 @@ public void prepareDocStructTypes() { private void prepareDocStructAddTypeSelectionItemsForChildren() { docStructAddTypeSelectionItemsForChildren = new ArrayList<>(); - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( dataEditor.getSelectedStructure().orElseThrow(IllegalStateException::new).getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); for (Entry entry : divisionView.getAllowedSubstructuralElements().entrySet()) { @@ -448,11 +448,11 @@ private void prepareDocStructAddTypeSelectionItemsForChildren() { private void prepareDocStructAddTypeSelectionItemsForParent() { docStructAddTypeSelectionItemsForParent = new ArrayList<>(); if (!parents.isEmpty()) { - StructuralElementViewInterface parentDivisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface parentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView( parents.getLast().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); for (Entry entry : parentDivisionView.getAllowedSubstructuralElements().entrySet()) { String newParent = entry.getKey(); - StructuralElementViewInterface newParentDivisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface newParentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView( newParent, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); if (newParentDivisionView.getAllowedSubstructuralElements().containsKey( dataEditor.getSelectedStructure().orElseThrow(IllegalStateException::new).getType())) { @@ -465,7 +465,7 @@ private void prepareDocStructAddTypeSelectionItemsForParent() { private void prepareDocStructAddTypeSelectionItemsForSiblings() { docStructAddTypeSelectionItemsForSiblings = new ArrayList<>(); if (!parents.isEmpty()) { - StructuralElementViewInterface parentDivisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface parentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView( parents.getLast().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); for (Entry entry : parentDivisionView.getAllowedSubstructuralElements().entrySet()) { docStructAddTypeSelectionItemsForSiblings.add(new SelectItem(entry.getKey(), entry.getValue())); @@ -508,7 +508,7 @@ public void prepareSelectAddableMetadataTypesItems(boolean currentElement, List< if (Objects.nonNull(selectedMetadataTreeNode) && Objects.nonNull(selectedMetadataTreeNode.getData())) { existingMetadata = Metadata.mapToKey(((ProcessFieldedMetadata) selectedMetadataTreeNode.getData()).getMetadata()); - ComplexMetadataViewInterface metadataView = dataEditor.getRuleset().getMetadataView( + ComplexMetadataViewInterface metadataView = dataEditor.getRulesetManagement().getMetadataView( ((ProcessFieldedMetadata) selectedMetadataTreeNode.getData()).getMetadataID(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); addableMetadata = metadataView.getAddableMetadata(existingMetadata, Collections.emptyList()); @@ -518,7 +518,7 @@ public void prepareSelectAddableMetadataTypesItems(boolean currentElement, List< addableMetadata = structure.getAddableMetadata(existingMetadata, Collections.emptyList()); } else { - structure = dataEditor.getRuleset() + structure = dataEditor.getRulesetManagement() .getStructuralElementView(docStructAddTypeSelectionSelectedItem, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); addableMetadata = structure.getAddableMetadata(existingMetadata, @@ -575,7 +575,7 @@ private Map getExistingMetadataRows(List metadataTre private StructuralElementViewInterface getStructuralElementView() { Optional selectedStructure = dataEditor.getSelectedStructure(); if (selectedStructure.isPresent()) { - return dataEditor.getRuleset() + return dataEditor.getRulesetManagement() .getStructuralElementView( selectedStructure.get().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); @@ -587,7 +587,7 @@ private StructuralElementViewInterface getStructuralElementView() { if (structureTreeNode.getDataObject() instanceof View) { View view = (View) structureTreeNode.getDataObject(); if (Objects.nonNull(view.getMediaUnit())) { - return dataEditor.getRuleset().getStructuralElementView(view.getMediaUnit().getType(), + return dataEditor.getRulesetManagement().getStructuralElementView(view.getMediaUnit().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); } } @@ -770,7 +770,7 @@ public void addLinkButtonClick() { */ public String getCurrentStructureLabel() { if (dataEditor.getSelectedStructure().isPresent()) { - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( dataEditor.getSelectedStructure().get().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); return divisionView.getLabel(); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddMediaUnitDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddMediaUnitDialog.java index 10ff76beaa0..ae0caeb7b79 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddMediaUnitDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/AddMediaUnitDialog.java @@ -104,7 +104,7 @@ public void preparePossibleTypes() { if (InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT.equals(selectedPosition) || InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT.equals(selectedPosition)) { - divisionView = dataEditor.getRuleset().getStructuralElementView( + divisionView = dataEditor.getRulesetManagement().getStructuralElementView( selectedMediaUnit.orElseThrow(IllegalStateException::new).getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList() @@ -116,7 +116,7 @@ public void preparePossibleTypes() { selectedMediaUnit.get(), dataEditor.getWorkpiece().getMediaUnit()); if (!parents.isEmpty()) { - divisionView = dataEditor.getRuleset().getStructuralElementView( + divisionView = dataEditor.getRulesetManagement().getStructuralElementView( parents.getLast().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/ChangeDocStrucTypeDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/ChangeDocStrucTypeDialog.java index 1b5119e7762..1d8608de384 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/ChangeDocStrucTypeDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/ChangeDocStrucTypeDialog.java @@ -131,7 +131,7 @@ private Map getAllowedChildTypesFromIncludedStructuralParentElem IncludedStructuralElement rootElement = dataEditor.getWorkpiece().getRootElement(); if (rootElement.equals(includedStructuralElement)) { if (Objects.isNull(dataEditor.getProcess().getParent())) { - return dataEditor.getRuleset().getStructuralElements(dataEditor.getPriorityList()); + return dataEditor.getRulesetManagement().getStructuralElements(dataEditor.getPriorityList()); } else { return getAllowedChildTypesFromParentalProcess(); } @@ -159,7 +159,7 @@ private Map getAllowedChildTypesFromParentalProcess() throws IOE } private Map getAllowedSubstructuralElements(String parentType) { - StructuralElementViewInterface parentView = dataEditor.getRuleset().getStructuralElementView(parentType, + StructuralElementViewInterface parentView = dataEditor.getRulesetManagement().getStructuralElementView(parentType, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); return parentView.getAllowedSubstructuralElements(); } @@ -176,7 +176,7 @@ private void restrictTypesToChildElements( for (Iterator> possibleTypesIterator = possibleTypes.entrySet() .iterator(); possibleTypesIterator.hasNext();) { String typeToCheck = possibleTypesIterator.next().getKey(); - StructuralElementViewInterface viewOnTypeToCheck = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface viewOnTypeToCheck = dataEditor.getRulesetManagement().getStructuralElementView( typeToCheck, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); if (!viewOnTypeToCheck.getAllowedSubstructuralElements().keySet().containsAll(childTypes)) { possibleTypesIterator.remove(); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java index 87a1b12130f..597846f2d5a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java @@ -521,7 +521,7 @@ public String getProcessTitle() { } @Override - public RulesetManagementInterface getRuleset() { + public RulesetManagementInterface getRulesetManagement() { return ruleset; } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/GalleryPanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/GalleryPanel.java index eaa43fa7800..d7307b2efb1 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/GalleryPanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/GalleryPanel.java @@ -188,7 +188,7 @@ List getPriorityList() { } RulesetManagementInterface getRuleset() { - return dataEditor.getRuleset(); + return dataEditor.getRulesetManagement(); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java index ac93c93c322..bc206adc638 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java @@ -126,7 +126,7 @@ public void setSelectedMetadataTreeNode(TreeNode selectedMetadataTreeNode) { void showLogical(Optional optionalStructure) { if (optionalStructure.isPresent()) { - StructuralElementViewInterface divisionView = dataEditorForm.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditorForm.getRulesetManagement().getStructuralElementView( optionalStructure.get().getType(), dataEditorForm.getAcquisitionStage(), dataEditorForm.getPriorityList()); logicalMetadataTable = new ProcessFieldedMetadata(optionalStructure.get(), divisionView); dataEditorForm.getAddDocStrucTypeDialog().prepareSelectAddableMetadataTypesItems(true, @@ -139,7 +139,7 @@ void showLogical(Optional optionalStructure) { void showPageInLogical(MediaUnit mediaUnit) { if (Objects.nonNull(mediaUnit)) { - StructuralElementViewInterface divisionView = dataEditorForm.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditorForm.getRulesetManagement().getStructuralElementView( mediaUnit.getType(), dataEditorForm.getAcquisitionStage(), dataEditorForm.getPriorityList()); logicalMetadataTable = new ProcessFieldedMetadata(mediaUnit, divisionView); dataEditorForm.getAddDocStrucTypeDialog().prepareSelectAddableMetadataTypesItems(true, @@ -152,7 +152,7 @@ void showPageInLogical(MediaUnit mediaUnit) { void showPhysical(Optional optionalMediaUnit) { if (optionalMediaUnit.isPresent() && Objects.nonNull(optionalMediaUnit.get().getType())) { - StructuralElementViewInterface divisionView = dataEditorForm.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditorForm.getRulesetManagement().getStructuralElementView( optionalMediaUnit.get().getType(), dataEditorForm.getAcquisitionStage(), dataEditorForm.getPriorityList()); physicalMetadataTable = new ProcessFieldedMetadata(optionalMediaUnit.get(), divisionView); dataEditorForm.getAddDocStrucTypeDialog().prepareSelectAddableMetadataTypesItems(true); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/StructurePanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/StructurePanel.java index bf2460f099f..24c9d75833f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/StructurePanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/StructurePanel.java @@ -451,7 +451,7 @@ private DefaultTreeNode buildStructureTree() { private Collection buildStructureTreeRecursively(IncludedStructuralElement structure, TreeNode result) { StructureTreeNode node; if (Objects.isNull(structure.getLink())) { - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( structure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); node = new StructureTreeNode(divisionView.getLabel(), divisionView.isUndefined() && Objects.nonNull(structure.getType()), false, structure); @@ -462,7 +462,7 @@ private Collection buildStructureTreeRecursively(IncludedStructuralElement String type = ServiceManager.getProcessService().getBaseType(child.getId()); if (child.getId() == ServiceManager.getProcessService() .processIdFromUri(structure.getLink().getUri())) { - StructuralElementViewInterface view = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface view = dataEditor.getRulesetManagement().getStructuralElementView( type, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); node = new StructureTreeNode(view.getLabel(), view.isUndefined(), true, structure); } @@ -563,7 +563,7 @@ private String buildViewLabel(View view) { * @return the generated node so that you can add children to it */ private DefaultTreeNode addTreeNode(String type, boolean linked, Object dataObject, DefaultTreeNode parent) { - StructuralElementViewInterface structuralElementView = dataEditor.getRuleset().getStructuralElementView(type, + StructuralElementViewInterface structuralElementView = dataEditor.getRulesetManagement().getStructuralElementView(type, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); return addTreeNode(structuralElementView.getLabel(), structuralElementView.isUndefined(), linked, dataObject, parent); @@ -676,7 +676,7 @@ private DefaultTreeNode buildMediaTree(MediaUnit mediaRoot) { } private void buildMediaTreeRecursively(MediaUnit mediaUnit, DefaultTreeNode parentTreeNode) { - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( mediaUnit.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); DefaultTreeNode treeNode = addTreeNode(Objects.equals(mediaUnit.getType(), MediaUnit.TYPE_PAGE) ? divisionView.getLabel().concat(" " + mediaUnit.getOrderlabel()) : divisionView.getLabel(), @@ -1196,7 +1196,7 @@ private void checkLogicalDragDrop(StructureTreeNode dragNode, StructureTreeNode IncludedStructuralElement dragStructure = (IncludedStructuralElement) dragNode.getDataObject(); IncludedStructuralElement dropStructure = (IncludedStructuralElement) dropNode.getDataObject(); - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( dropStructure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); LinkedList dragParents; @@ -1232,7 +1232,7 @@ private void checkPhysicalDragDrop(StructureTreeNode dragNode, StructureTreeNode MediaUnit dragUnit = (MediaUnit) dragNode.getDataObject(); MediaUnit dropUnit = (MediaUnit) dropNode.getDataObject(); - StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView( + StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( dropUnit.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); LinkedList dragParents; diff --git a/Kitodo/src/main/java/org/kitodo/production/interfaces/RulesetSetupInterface.java b/Kitodo/src/main/java/org/kitodo/production/interfaces/RulesetSetupInterface.java index 3073c9c54a6..785bc485454 100644 --- a/Kitodo/src/main/java/org/kitodo/production/interfaces/RulesetSetupInterface.java +++ b/Kitodo/src/main/java/org/kitodo/production/interfaces/RulesetSetupInterface.java @@ -27,7 +27,7 @@ public interface RulesetSetupInterface { * * @return the ruleset */ - RulesetManagementInterface getRuleset(); + RulesetManagementInterface getRulesetManagement(); /** * Returns the current acquisition stage to adapt the displaying of fields From 3888813a6876e3f7707660a7d8b43dc4373e5f84 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:34:58 +0100 Subject: [PATCH 3/7] Simplify creation of RulesetNotFoundException --- .../exceptions/RulesetNotFoundException.java | 15 +++++++++------ .../production/services/data/RulesetService.java | 6 +----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java b/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java index 9e67e72c8a6..942ada5e913 100644 --- a/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java +++ b/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java @@ -11,15 +11,18 @@ package org.kitodo.exceptions; +import java.util.Arrays; + +import org.kitodo.production.helper.Helper; + public class RulesetNotFoundException extends Exception { /** - * Constructor with given exception message. + * Creates a new ruleset not found exception. * - * @param exceptionMessage - * as String + * @param missingFile + * name of missing ruleset file */ - public RulesetNotFoundException(String exceptionMessage) { - super(exceptionMessage); + public RulesetNotFoundException(String missingFile) { + super(Helper.getTranslation("rulesetNotFound", Arrays.asList(missingFile))); } - } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java index 34b566a3a16..4018163bf48 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java @@ -15,7 +15,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -42,7 +41,6 @@ import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.dto.ClientDTO; import org.kitodo.production.dto.RulesetDTO; -import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyPrefsHelper; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.base.ClientSearchService; @@ -238,9 +236,7 @@ private RulesetManagementInterface openRulesetFile(String fileName) throws IOExc try { ruleset.load(new File(Paths.get(ConfigCore.getParameter(ParameterCore.DIR_RULESETS), fileName).toString())); } catch (FileNotFoundException e) { - List param = new ArrayList<>(); - param.add(fileName); - throw new RulesetNotFoundException(Helper.getTranslation("rulesetNotFound", param)); + throw new RulesetNotFoundException(fileName); } if (logger.isTraceEnabled()) { From 9e71e93bfd036b8c7d9dd679c461e54a6f09b8e0 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:45:32 +0100 Subject: [PATCH 4/7] Make RulesetNotFoundException a FileNotFoundException This simplifies exception handling a lot --- .../exceptions/RulesetNotFoundException.java | 3 ++- .../production/forms/ProcessListBaseView.java | 5 ++--- .../forms/createprocess/CreateProcessForm.java | 15 ++++++++------- .../createprocess/TitleRecordLinkTab.java | 5 ++--- .../forms/dataeditor/DataEditorForm.java | 5 ++--- .../GeneratesNewspaperProcessesThread.java | 3 +-- .../helper/tasks/NewspaperMigrationTask.java | 5 ++--- .../migration/NewspaperProcessesMigrator.java | 9 ++++----- .../process/NewspaperProcessesGenerator.java | 18 ++++++++---------- .../services/data/ImportService.java | 11 +++++------ .../services/data/ProcessService.java | 7 ++----- .../services/data/RulesetService.java | 4 ++-- 12 files changed, 40 insertions(+), 50 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java b/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java index 942ada5e913..c3c95fe9031 100644 --- a/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java +++ b/Kitodo/src/main/java/org/kitodo/exceptions/RulesetNotFoundException.java @@ -11,11 +11,12 @@ package org.kitodo.exceptions; +import java.io.FileNotFoundException; import java.util.Arrays; import org.kitodo.production.helper.Helper; -public class RulesetNotFoundException extends Exception { +public class RulesetNotFoundException extends FileNotFoundException { /** * Creates a new ruleset not found exception. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessListBaseView.java b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessListBaseView.java index dbc184256bd..82b253c8bb0 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessListBaseView.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessListBaseView.java @@ -29,7 +29,6 @@ import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.export.ExportDms; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.enums.ChartMode; @@ -316,7 +315,7 @@ private void exportDMSForProcesses(List processes) { public boolean createProcessesWithCalendar(ProcessDTO processDTO) { try { return ProcessService.canCreateProcessWithCalendar(processDTO); - } catch (IOException | DAOException | RulesetNotFoundException e) { + } catch (IOException | DAOException e) { Helper.setErrorMessage(ERROR_READING, new Object[] {ObjectType.PROCESS.getTranslationSingular() }, logger, e); } @@ -333,7 +332,7 @@ public boolean createProcessesWithCalendar(ProcessDTO processDTO) { public boolean createProcessAsChildPossible(ProcessDTO processDTO) { try { return ProcessService.canCreateChildProcess(processDTO); - } catch (IOException | DAOException | RulesetNotFoundException e) { + } catch (IOException | DAOException e) { Helper.setErrorMessage(ERROR_READING, new Object[] {ObjectType.PROCESS.getTranslationSingular() }, logger, e); } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java index 6df5ca180a5..0f6fd1db548 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java @@ -294,14 +294,14 @@ public String createNewProcess() { } catch (DataException e) { Helper.setErrorMessage("errorSaving", new Object[] {ObjectType.PROCESS.getTranslationSingular() }, logger, e); - } catch (IOException | ProcessGenerationException e) { - logger.error(e.getLocalizedMessage()); } catch (RulesetNotFoundException e) { String rulesetFile = "Process list is empty"; if (!this.processes.isEmpty() && Objects.nonNull(getMainProcess().getRuleset())) { rulesetFile = getMainProcess().getRuleset().getFile(); } Helper.setErrorMessage("rulesetNotFound", new Object[] {rulesetFile }, logger, e); + } catch (IOException | ProcessGenerationException e) { + logger.error(e.getLocalizedMessage(), e); } return this.stayOnCurrentPage; } @@ -370,7 +370,7 @@ public void prepareProcess(int templateId, int projectId, String referringView, } } - } catch (ProcessGenerationException | RulesetNotFoundException | DataException | DAOException | IOException e) { + } catch (ProcessGenerationException | DataException | DAOException | IOException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } } @@ -379,7 +379,7 @@ public void prepareProcess(int templateId, int projectId, String referringView, * Create process hierarchy. */ private void createProcessHierarchy() - throws DataException, ProcessGenerationException, IOException, RulesetNotFoundException { + throws DataException, ProcessGenerationException, IOException { // discard all processes in hierarchy except the first if parent process in // title record link tab is selected! if (this.processes.size() > 1 && Objects.nonNull(this.titleRecordLinkTab.getTitleRecordProcess()) @@ -462,7 +462,7 @@ private void processChildren() { ImportService.processProcessChildren(getMainProcess(), this.childProcesses, template, rulesetManagement, acquisitionStage, priorityList); } catch (DataException | InvalidMetadataValueException | NoSuchMetadataFieldException - | ProcessGenerationException | IOException | RulesetNotFoundException e) { + | ProcessGenerationException | IOException e) { Helper.setErrorMessage("Unable to attach child documents to process: " + e.getMessage()); } } @@ -493,10 +493,11 @@ private void processAncestors() throws ProcessGenerationException { acquisitionStage, priorityList); } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { throw new ProcessGenerationException("Error creating process hierarchy: invalid metadata found!"); + } catch (RulesetNotFoundException e) { + throw new ProcessGenerationException( + "Ruleset not found:" + tempProcess.getProcess().getRuleset().getTitle()); } catch (IOException e) { throw new ProcessGenerationException("Error reading Ruleset: " + tempProcess.getProcess().getRuleset().getTitle()); - } catch (RulesetNotFoundException e) { - throw new ProcessGenerationException("Ruleset not found:" + tempProcess.getProcess().getRuleset().getTitle()); } } } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java index 047fd3777bc..0e050e634f7 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java @@ -36,7 +36,6 @@ import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.helper.Helper; import org.kitodo.production.metadata.MetadataEditor; @@ -126,7 +125,7 @@ public void chooseParentProcess() { try { titleRecordProcess = ServiceManager.getProcessService().getById(Integer.valueOf(chosenParentProcess)); createInsertionPositionSelectionTree(); - } catch (DAOException | DataException | IOException | RulesetNotFoundException e) { + } catch (DAOException | DataException | IOException e) { Helper.setErrorMessage("errorLoadingOne", new Object[] {possibleParentProcesses.parallelStream() .filter(selectItem -> selectItem.getValue().equals(chosenParentProcess)).findAny() @@ -142,7 +141,7 @@ public void chooseParentProcess() { * @throws IOException * if the METS file cannot be read */ - public void createInsertionPositionSelectionTree() throws DAOException, DataException, IOException, RulesetNotFoundException { + public void createInsertionPositionSelectionTree() throws DAOException, DataException, IOException { if (Objects.isNull(titleRecordProcess)) { return; } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java index 597846f2d5a..8094bdc9615 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java @@ -52,7 +52,6 @@ import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.exceptions.InvalidMetadataValueException; import org.kitodo.exceptions.NoSuchMetadataFieldException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.forms.createprocess.ProcessDetail; import org.kitodo.production.helper.Helper; import org.kitodo.production.interfaces.RulesetSetupInterface; @@ -228,7 +227,7 @@ public String open(String processID, String referringView) { selectedMedia = new LinkedList<>(); init(); MetadataLock.setLocked(process.getId(), user); - } catch (IOException | DAOException | InvalidImagesException | NoSuchElementException | RulesetNotFoundException e) { + } catch (IOException | DAOException | InvalidImagesException | NoSuchElementException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); return referringView; } @@ -252,7 +251,7 @@ private void openMetsFile() throws IOException, InvalidImagesException { ServiceManager.getFileService().searchForMedia(process, workpiece); } - private RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException, RulesetNotFoundException { + private RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException { final long begin = System.nanoTime(); String metadataLanguage = user.getMetadataLanguage(); priorityList = LanguageRange.parse(metadataLanguage.isEmpty() ? "en" : metadataLanguage); diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/tasks/GeneratesNewspaperProcessesThread.java b/Kitodo/src/main/java/org/kitodo/production/helper/tasks/GeneratesNewspaperProcessesThread.java index 13c33fe0e8a..1d239f6f28f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/tasks/GeneratesNewspaperProcessesThread.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/tasks/GeneratesNewspaperProcessesThread.java @@ -21,7 +21,6 @@ import org.kitodo.exceptions.CommandException; import org.kitodo.exceptions.DoctypeMissingException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.model.bibliography.course.Course; import org.kitodo.production.process.NewspaperProcessesGenerator; @@ -85,7 +84,7 @@ public void run() { } super.setProgress(100); } catch (ConfigurationException | DAOException | DataException | DoctypeMissingException | IOException - | ProcessGenerationException | RulesetNotFoundException | CommandException e) { + | ProcessGenerationException | CommandException e) { setException(e); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/tasks/NewspaperMigrationTask.java b/Kitodo/src/main/java/org/kitodo/production/helper/tasks/NewspaperMigrationTask.java index 7909a97f574..a0aa6338755 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/tasks/NewspaperMigrationTask.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/tasks/NewspaperMigrationTask.java @@ -19,7 +19,6 @@ import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.CommandException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.dto.BatchDTO; import org.kitodo.production.migration.NewspaperProcessesMigrator; @@ -124,7 +123,7 @@ private int getNumberOfSteps() { * ruleset */ private void next() throws DAOException, IOException, ProcessGenerationException, DataException, - ConfigurationException, RulesetNotFoundException, CommandException { + ConfigurationException, CommandException { switch (part) { case CONVERT_PROCESSES: { super.setWorkDetail(migrator.getProcessTitle(step)); @@ -165,7 +164,7 @@ public void run() { } setProgress(100); } catch (ConfigurationException | DAOException | IOException | ProcessGenerationException | DataException - | RulesetNotFoundException | CommandException e) { + | CommandException e) { setException(e); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java index f743a3aaba5..6cfd90f0920 100644 --- a/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java +++ b/Kitodo/src/main/java/org/kitodo/production/migration/NewspaperProcessesMigrator.java @@ -44,7 +44,6 @@ import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.CommandException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.dto.BatchDTO; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.helper.tasks.NewspaperMigrationTask; @@ -278,7 +277,7 @@ public static void initializeMigration(Integer batchId) throws DataException { * the ID of the newspaper division in the ruleset */ private void initializeMigrator(Process process, String newspaperIncludedStructalElementDivision) - throws IOException, ConfigurationException, RulesetNotFoundException { + throws IOException, ConfigurationException { title = process.getTitle().replaceFirst(INDIVIDUAL_PART, ""); logger.trace("Newspaper is: {}", title); @@ -312,7 +311,7 @@ private void initializeMigrator(Process process, String newspaperIncludedStructa * index of process to convert in the processes transfer object * list passed to the constructor—not the process ID */ - public void convertProcess(int index) throws DAOException, IOException, ConfigurationException, RulesetNotFoundException { + public void convertProcess(int index) throws DAOException, IOException, ConfigurationException { final long begin = System.nanoTime(); Integer processId = transferredProcess.get(index).getId(); Process process = processService.getById(processId); @@ -548,7 +547,7 @@ private static String getCompletedDate(IncludedStructuralElement includedStructu * An error has occurred in the disk drive. */ public void createOverallProcess() throws ProcessGenerationException, IOException, DataException, DAOException, - CommandException, RulesetNotFoundException { + CommandException { final long begin = System.nanoTime(); logger.info("Creating overall process {}...", title); @@ -583,7 +582,7 @@ public void createOverallProcess() throws ProcessGenerationException, IOExceptio * if a process cannot be load from the database */ public void createNextYearProcess() throws ProcessGenerationException, IOException, DataException, DAOException, - CommandException, RulesetNotFoundException { + CommandException { final long begin = System.nanoTime(); Entry yearToCreate = yearsIterator.next(); String yearTitle = getYearTitle(yearToCreate.getKey()); diff --git a/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java b/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java index da609de743c..9bf04822f76 100644 --- a/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java +++ b/Kitodo/src/main/java/org/kitodo/production/process/NewspaperProcessesGenerator.java @@ -55,7 +55,6 @@ import org.kitodo.exceptions.CommandException; import org.kitodo.exceptions.DoctypeMissingException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.production.forms.createprocess.ProcessFieldedMetadata; import org.kitodo.production.metadata.MetadataEditor; import org.kitodo.production.model.bibliography.course.Course; @@ -289,7 +288,7 @@ public int getNumberOfSteps() { * but its value cannot be evaluated to an integer */ public void nextStep() throws ConfigurationException, DAOException, DataException, IOException, - ProcessGenerationException, DoctypeMissingException, RulesetNotFoundException, CommandException { + ProcessGenerationException, DoctypeMissingException, CommandException { if (currentStep == 0) { initialize(); @@ -310,7 +309,7 @@ public void nextStep() throws ConfigurationException, DAOException, DataExceptio * if something goes wrong when reading or writing one of the * affected files */ - private void initialize() throws ConfigurationException, IOException, DoctypeMissingException, RulesetNotFoundException { + private void initialize() throws ConfigurationException, IOException, DoctypeMissingException { final long begin = System.nanoTime(); overallMetadataFileUri = processService.getMetadataFileUri(overallProcess); @@ -345,7 +344,7 @@ private void initialize() throws ConfigurationException, IOException, DoctypeMis * if something goes wrong when reading or writing one of the * affected files */ - private void initializeRulesetFields(String newspaperType) throws ConfigurationException, IOException, RulesetNotFoundException { + private void initializeRulesetFields(String newspaperType) throws ConfigurationException, IOException { RulesetManagementInterface ruleset = rulesetService.openRuleset(overallProcess.getRuleset()); StructuralElementViewInterface newspaperView = ruleset.getStructuralElementView(newspaperType, acquisitionStage, ENGLISH); StructuralElementViewInterface yearDivisionView = nextSubView(ruleset, newspaperView, acquisitionStage); @@ -498,7 +497,7 @@ private static Map getMetadataEntries(Collection metad } private void createProcess(int index) throws DAOException, DataException, IOException, ProcessGenerationException, - CommandException, RulesetNotFoundException { + CommandException { final long begin = System.nanoTime(); List individualIssuesForProcess = processesToCreate.get(index); @@ -642,8 +641,7 @@ private String dateMark(String scheme, LocalDate date) { } private void prepareTheAppropriateYearProcess(String yearMark, Map genericFields) - throws DAOException, DataException, ProcessGenerationException, IOException, CommandException, - RulesetNotFoundException { + throws DAOException, DataException, ProcessGenerationException, IOException, CommandException { if (yearMark.equals(currentYear)) { return; @@ -655,7 +653,7 @@ private void prepareTheAppropriateYearProcess(String yearMark, Map genericFields) - throws ProcessGenerationException, DataException, IOException, CommandException, RulesetNotFoundException { + throws ProcessGenerationException, DataException, IOException, CommandException { final long begin = System.nanoTime(); generateProcess(overallProcess.getTemplate().getId(), overallProcess.getProject().getId()); @@ -781,7 +779,7 @@ private IncludedStructuralElement getOrCreateIncludedStructuralElement( return createdChild; } - private void finish() throws DataException, IOException, RulesetNotFoundException { + private void finish() throws DataException, IOException { final long begin = System.nanoTime(); saveAndCloseCurrentYearProcess(); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index 03684f52023..5911a15d595 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java @@ -78,7 +78,6 @@ import org.kitodo.exceptions.NoSuchMetadataFieldException; import org.kitodo.exceptions.ParameterNotFoundException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.exceptions.UnsupportedFormatException; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.forms.createprocess.ProcessBooleanMetadata; @@ -956,7 +955,7 @@ public static void processProcessChildren(Process mainProcess, LinkedList priorityList) throws DataException, InvalidMetadataValueException, NoSuchMetadataFieldException, - ProcessGenerationException, IOException, RulesetNotFoundException { + ProcessGenerationException, IOException { for (TempProcess tempProcess : childProcesses) { if (Objects.isNull(tempProcess) || Objects.isNull(tempProcess.getProcess())) { logger.error("Child process " + (childProcesses.indexOf(tempProcess) + 1) + " is null => Skip!"); @@ -1057,8 +1056,8 @@ public static void updateTasks(Process process) { public static void processTempProcess(TempProcess tempProcess, Template template, RulesetManagementInterface managementInterface, String acquisitionStage, List priorityList) - throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException, IOException, - RulesetNotFoundException { + throws InvalidMetadataValueException, NoSuchMetadataFieldException, ProcessGenerationException, + IOException { List processDetails = transformToProcessDetails(tempProcess, managementInterface, acquisitionStage, priorityList); String docType = tempProcess.getWorkpiece().getRootElement().getType(); @@ -1075,7 +1074,7 @@ public static void processTempProcess(TempProcess tempProcess, Template template * @param process the process to check. * @param docType the doctype to check in the ruleset. */ - public static void checkTasks(Process process, String docType) throws IOException, RulesetNotFoundException { + public static void checkTasks(Process process, String docType) throws IOException { // remove tasks from process, if doctype is configured not to use a workflow Collection divisionsWithNoWorkflow = ServiceManager.getRulesetService() .openRuleset(process.getRuleset()).getDivisionsWithNoWorkflow(); @@ -1114,7 +1113,7 @@ public Process importProcess(String ppn, int projectId, int templateId, String s ServiceManager.getMetsService().save(tempProcess.getWorkpiece(), out); } catch (DAOException | IOException | ProcessGenerationException | XPathExpressionException | ParserConfigurationException | NoRecordFoundException | UnsupportedFormatException - | URISyntaxException | SAXException | RulesetNotFoundException | InvalidMetadataValueException + | URISyntaxException | SAXException | InvalidMetadataValueException | NoSuchMetadataFieldException | DataException | CommandException e) { throw new ImportException( Helper.getTranslation("errorImporting", Arrays.asList(Helper.getTranslation("process"), ppn))); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java index 8a1d5e74658..3252d2864cc 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java @@ -120,7 +120,6 @@ import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.exceptions.ProcessGenerationException; -import org.kitodo.exceptions.RulesetNotFoundException; import org.kitodo.export.ExportMets; import org.kitodo.production.dto.BatchDTO; import org.kitodo.production.dto.ProcessDTO; @@ -2515,10 +2514,9 @@ public String getLastProcessingEnd(ProcessDTO processDTO) { * @return whether child processes for the given ProcessDTO can be created via the calendar or not * @throws DAOException if process could not be loaded from database * @throws IOException if ruleset file could not be read - * @throws RulesetNotFoundException if ruleset file could not be read */ public static boolean canCreateProcessWithCalendar(ProcessDTO processDTO) - throws DAOException, IOException, RulesetNotFoundException { + throws DAOException, IOException { Collection functionalDivisions; if (Objects.isNull(processDTO.getRuleset())) { return false; @@ -2542,10 +2540,9 @@ public static boolean canCreateProcessWithCalendar(ProcessDTO processDTO) * @return whether child processes for the given ProcessDTO can be created via the calendar or not * @throws DAOException if process could not be loaded from database * @throws IOException if ruleset file could not be read - * @throws RulesetNotFoundException if ruleset file could not be read */ public static boolean canCreateChildProcess(ProcessDTO processDTO) throws DAOException, - IOException, RulesetNotFoundException { + IOException { Collection functionalDivisions; if (Objects.isNull(processDTO.getRuleset())) { return false; diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java index 4018163bf48..17f9a67d687 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java @@ -226,11 +226,11 @@ private QueryBuilder getRulesetsForCurrentUserQuery() { * database object that references the ruleset * @return a Ruleset Management in which the ruleset has been loaded */ - public RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException, RulesetNotFoundException { + public RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException { return openRulesetFile(ruleset.getFile()); } - private RulesetManagementInterface openRulesetFile(String fileName) throws IOException, RulesetNotFoundException { + private RulesetManagementInterface openRulesetFile(String fileName) throws IOException { final long begin = System.nanoTime(); RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); try { From fcab08da1317ade9a8ac8461f0f198298f6f8eba Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:56:28 +0100 Subject: [PATCH 5/7] Simplify code, remove unnecessary delegate function --- .../production/services/data/RulesetService.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java index 17f9a67d687..33fa76bf0e9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/RulesetService.java @@ -11,7 +11,6 @@ package org.kitodo.production.services.data; -import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Paths; @@ -227,14 +226,12 @@ private QueryBuilder getRulesetsForCurrentUserQuery() { * @return a Ruleset Management in which the ruleset has been loaded */ public RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException { - return openRulesetFile(ruleset.getFile()); - } - - private RulesetManagementInterface openRulesetFile(String fileName) throws IOException { final long begin = System.nanoTime(); - RulesetManagementInterface ruleset = ServiceManager.getRulesetManagementService().getRulesetManagement(); + RulesetManagementInterface rulesetManagement = ServiceManager.getRulesetManagementService() + .getRulesetManagement(); + String fileName = ruleset.getFile(); try { - ruleset.load(new File(Paths.get(ConfigCore.getParameter(ParameterCore.DIR_RULESETS), fileName).toString())); + rulesetManagement.load(Paths.get(ConfigCore.getParameter(ParameterCore.DIR_RULESETS), fileName).toFile()); } catch (FileNotFoundException e) { throw new RulesetNotFoundException(fileName); } @@ -242,6 +239,6 @@ private RulesetManagementInterface openRulesetFile(String fileName) throws IOExc if (logger.isTraceEnabled()) { logger.trace("Reading ruleset took {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - begin)); } - return ruleset; + return rulesetManagement; } } From cb20c7870cab9a1958ce6c0d60da5ef1e3b2db90 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 14:59:19 +0100 Subject: [PATCH 6/7] Remove strangely extractey sub-method The method did unrelated initializations and more than its name suggested. Tracking the time is not necessary here either because the ruleset service already does. --- .../forms/dataeditor/DataEditorForm.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java index 8094bdc9615..cbef67690fe 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/DataEditorForm.java @@ -46,7 +46,6 @@ import org.kitodo.api.validation.State; import org.kitodo.api.validation.ValidationResult; import org.kitodo.data.database.beans.Process; -import org.kitodo.data.database.beans.Ruleset; import org.kitodo.data.database.beans.User; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.exceptions.InvalidImagesException; @@ -218,7 +217,9 @@ public String open(String processID, String referringView) { return referringView; } - ruleset = openRuleset(process.getRuleset()); + String metadataLanguage = user.getMetadataLanguage(); + priorityList = LanguageRange.parse(metadataLanguage.isEmpty() ? "en" : metadataLanguage); + ruleset = ServiceManager.getRulesetService().openRuleset(process.getRuleset()); openMetsFile(); if (!workpiece.getId().equals(process.getId().toString())) { Helper.setErrorMessage("metadataConfusion", new Object[] {process.getId(), workpiece.getId() }); @@ -251,17 +252,6 @@ private void openMetsFile() throws IOException, InvalidImagesException { ServiceManager.getFileService().searchForMedia(process, workpiece); } - private RulesetManagementInterface openRuleset(Ruleset ruleset) throws IOException { - final long begin = System.nanoTime(); - String metadataLanguage = user.getMetadataLanguage(); - priorityList = LanguageRange.parse(metadataLanguage.isEmpty() ? "en" : metadataLanguage); - RulesetManagementInterface openRuleset = ServiceManager.getRulesetService().openRuleset(ruleset); - if (logger.isTraceEnabled()) { - logger.trace("Reading ruleset took {} ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - begin)); - } - return openRuleset; - } - private void init() { final long begin = System.nanoTime(); From 3c38870c53c8941a275bf1dc87b870181d27d70e Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Tue, 5 Jan 2021 15:01:07 +0100 Subject: [PATCH 7/7] Remove unlucky catching of exception which caused follow-up error --- .../createprocess/CreateProcessForm.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java index 0f6fd1db548..75294bf9bbf 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CreateProcessForm.java @@ -92,22 +92,17 @@ public RulesetManagementInterface getRulesetManagement() { /** * Update ruleset and docType. - * @param ruleset as Ruleset - * @throws RulesetNotFoundException thrown if ruleset could not be found + * + * @param ruleset + * as Ruleset + * @throws IOException + * thrown if ruleset could not be read */ - public void updateRulesetAndDocType(Ruleset ruleset) throws RulesetNotFoundException { - setRulesetManagement(ruleset); + public void updateRulesetAndDocType(Ruleset ruleset) throws IOException { + rulesetManagement = ServiceManager.getRulesetService().openRuleset(ruleset); processDataTab.setAllDocTypes(getAllRulesetDivisions()); } - private void setRulesetManagement(Ruleset ruleset) throws RulesetNotFoundException { - try { - this.rulesetManagement = ServiceManager.getRulesetService().openRuleset(ruleset); - } catch (IOException e) { - logger.error(e.getLocalizedMessage()); - } - } - private List getAllRulesetDivisions() { List allDocTypes = rulesetManagement .getStructuralElements(priorityList).entrySet()