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 4e9436b2cd2..680c7084812 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 @@ -560,7 +560,8 @@ private DefaultTreeNode buildStructureTree() { addParentLinksRecursive(dataEditor.getProcess(), invisibleRootNode); List processIds = getAllLinkedProcessIds(structure); Map processTypeMap = processIds.isEmpty() ? Collections.emptyMap() : fetchProcessTypes(processIds); - buildStructureTreeRecursively(structure, invisibleRootNode, processTypeMap); + Map viewCache = new HashMap<>(); + buildStructureTreeRecursively(structure, invisibleRootNode, processTypeMap, viewCache); return invisibleRootNode; } @@ -603,18 +604,20 @@ private String buildPageRangeFromLogicalDivision(LogicalDivision structure) { * @param structure the logical division * @return the StructureTreeNode instance */ - private StructureTreeNode buildStructureTreeNode(LogicalDivision structure, Map idTypeMap) { + private StructureTreeNode buildStructureTreeNode(LogicalDivision structure, Map idTypeMap, + Map viewCache) { StructureTreeNode node; if (Objects.isNull(structure.getLink())) { - StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView( - structure.getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()); + StructuralElementViewInterface divisionView = viewCache.computeIfAbsent(structure.getType(), key -> + dataEditor.getRulesetManagement().getStructuralElementView( + key, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList()) + ); String label = divisionView.getLabel(); String pageRange = buildPageRangeFromLogicalDivision(structure); boolean undefined = divisionView.isUndefined() && Objects.nonNull(structure.getType()); node = new StructureTreeNode(label, pageRange, undefined, false, structure); } else { node = new StructureTreeNode(structure.getLink().getUri().toString(), null, true, true, structure); - Map viewCache = new HashMap<>(); for (Process child : dataEditor.getCurrentChildren()) { if (child.getId() == ServiceManager.getProcessService().processIdFromUri(structure.getLink().getUri())) { String type = idTypeMap.get(child.getId()); @@ -640,8 +643,8 @@ private StructureTreeNode buildStructureTreeNode(LogicalDivision structure, Map * @return a collection of views that contains all views of the full sub-tree */ private Collection buildStructureTreeRecursively(LogicalDivision structure, TreeNode result, Map processTypeMap) { - StructureTreeNode node = buildStructureTreeNode(structure, processTypeMap); + String> processTypeMap, Map viewCache) { + StructureTreeNode node = buildStructureTreeNode(structure, processTypeMap, viewCache); /* * Creating the tree node by handing over the parent node automatically * appends it to the parent as a child. That’s the logic of the JSF @@ -655,7 +658,7 @@ private Collection buildStructureTreeRecursively(LogicalDivision structure Set viewsShowingOnAChild = new HashSet<>(); if (!this.logicalStructureTreeContainsMedia()) { for (LogicalDivision child : structure.getChildren()) { - viewsShowingOnAChild.addAll(buildStructureTreeRecursively(child, parent, processTypeMap)); + viewsShowingOnAChild.addAll(buildStructureTreeRecursively(child, parent, processTypeMap, viewCache)); } } else { // iterate through children and views ordered by the ORDER attribute @@ -663,7 +666,8 @@ private Collection buildStructureTreeRecursively(LogicalDivision structure for (Pair pair : merged) { if (Objects.nonNull(pair.getRight())) { // add child and their views - viewsShowingOnAChild.addAll(buildStructureTreeRecursively(pair.getRight(), parent, processTypeMap)); + viewsShowingOnAChild.addAll(buildStructureTreeRecursively(pair.getRight(), parent, + processTypeMap, viewCache)); } else if (!viewsShowingOnAChild.contains(pair.getLeft())) { // add views of current logical division as leaf nodes DefaultTreeNode viewNode = addTreeNode(buildViewLabel(pair.getLeft()), false, false, pair.getLeft(), parent); diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java index 52e698c3f18..76326b54068 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/dataeditor/StructurePanelTest.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import org.kitodo.DummyRulesetManagement; +import org.kitodo.api.dataeditor.rulesetmanagement.StructuralElementViewInterface; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.mets.LinkedMetsResource; import org.kitodo.data.database.beans.Process; @@ -51,13 +52,14 @@ public void testBuildStructureTreeRecursively() throws Exception { link.setUri(URI.create("database://?process.id=42")); structure.setLink(link); Map processTypeMap = new HashMap<>(); + Map viewCache = new HashMap<>(); processTypeMap.put(ServiceManager.getProcessService().processIdFromUri(link.getUri()), "Monograph"); TreeNode result = new DefaultTreeNode(); Method buildStructureTreeRecursively = StructurePanel.class.getDeclaredMethod("buildStructureTreeRecursively", - LogicalDivision.class, TreeNode.class, Map.class); + LogicalDivision.class, TreeNode.class, Map.class, Map.class); buildStructureTreeRecursively.setAccessible(true); - buildStructureTreeRecursively.invoke(underTest, structure, result, processTypeMap); + buildStructureTreeRecursively.invoke(underTest, structure, result, processTypeMap, viewCache); assertTrue(((StructureTreeNode) result.getChildren().get(0).getData()).isLinked()); }