From 15255129527c4700681c95a610cb9df321526ffc Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 24 Jan 2024 15:10:24 +0100 Subject: [PATCH] Refactor business logic to helper class --- .../forms/dataeditor/MediaPartialsPanel.java | 25 +++-------------- .../helper/metadata/MediaPartialHelper.java | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MediaPartialsPanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MediaPartialsPanel.java index 7a675ea1ad3..0973192542f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MediaPartialsPanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MediaPartialsPanel.java @@ -14,8 +14,9 @@ import static org.kitodo.production.helper.metadata.MediaPartialHelper.calculateExtentAndSortMediaPartials; import static org.kitodo.production.helper.metadata.MediaPartialHelper.convertFormattedTimeToMilliseconds; +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; import java.io.Serializable; -import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; @@ -24,17 +25,12 @@ import java.util.Objects; import java.util.stream.Collectors; -import javax.faces.context.FacesContext; -import javax.faces.model.SelectItem; - import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.kitodo.api.dataeditor.rulesetmanagement.FunctionalDivision; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.MediaPartial; -import org.kitodo.api.dataformat.MediaVariant; import org.kitodo.api.dataformat.PhysicalDivision; -import org.kitodo.api.dataformat.View; import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.metadata.MediaPartialHelper; import org.kitodo.production.services.dataeditor.DataEditorService; @@ -66,26 +62,13 @@ public Map getMediaPartialDivisions() { mediaSelection = dataEditor.getGalleryPanel().getLastSelection(); Map mediaPartialDivisions = new LinkedHashMap<>(); if (Objects.nonNull(mediaSelection)) { - addMediaPartialDivisions(mediaPartialDivisions, mediaSelection.getKey().getLogicalDivisions(), + MediaPartialHelper.addMediaPartialDivisions(mediaPartialDivisions, + mediaSelection.getKey().getLogicalDivisions(), mediaSelection.getLeft().getMediaFiles()); } return mediaPartialDivisions; } - private static void addMediaPartialDivisions(Map mediaViewDivisions, - List logicalDivisions, Map mediaFiles) { - for (LogicalDivision logicalDivision : logicalDivisions) { - for (View view : logicalDivision.getViews()) { - if (PhysicalDivision.TYPE_TRACK.equals( - view.getPhysicalDivision().getType()) && view.getPhysicalDivision() - .hasMediaPartial() && view.getPhysicalDivision().getMediaFiles().equals(mediaFiles)) { - mediaViewDivisions.put(logicalDivision, view.getPhysicalDivision().getMediaPartial()); - } - } - addMediaPartialDivisions(mediaViewDivisions, logicalDivision.getChildren(), mediaFiles); - } - } - /** * Validate the duration of the media. * diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/metadata/MediaPartialHelper.java b/Kitodo/src/main/java/org/kitodo/production/helper/metadata/MediaPartialHelper.java index 1896f84d8a3..a5ebfde54cc 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/metadata/MediaPartialHelper.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/metadata/MediaPartialHelper.java @@ -11,16 +11,20 @@ package org.kitodo.production.helper.metadata; +import java.net.URI; import java.time.Duration; import java.time.LocalTime; import java.util.List; import java.util.ListIterator; +import java.util.Map; import java.util.Objects; import java.util.regex.Pattern; import org.apache.commons.lang3.tuple.Pair; import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.MediaPartial; +import org.kitodo.api.dataformat.MediaVariant;. + import org.kitodo.api.dataformat.PhysicalDivision; import org.kitodo.api.dataformat.View; import org.kitodo.api.dataformat.Workpiece; @@ -145,4 +149,28 @@ public static void addMediaPartialToMediaSelection(String type, String title, St mediaSelection.getValue().getChildren().add(logicalDivision); } + /** + * Add a media partial division to the media partial divisions map. + * + * @param mediaPartialDivisions + * The media partial divisions + * @param logicalDivisions + * The logical divisions of current selection + * @param mediaFiles + * The media files of current selection + */ + public static void addMediaPartialDivisions(Map mediaPartialDivisions, + List logicalDivisions, Map mediaFiles) { + for (LogicalDivision logicalDivision : logicalDivisions) { + for (View view : logicalDivision.getViews()) { + if (PhysicalDivision.TYPE_TRACK.equals( + view.getPhysicalDivision().getType()) && view.getPhysicalDivision() + .hasMediaPartial() && view.getPhysicalDivision().getMediaFiles().equals(mediaFiles)) { + mediaPartialDivisions.put(logicalDivision, view.getPhysicalDivision().getMediaPartial()); + } + } + addMediaPartialDivisions(mediaPartialDivisions, logicalDivision.getChildren(), mediaFiles); + } + } + }