Skip to content

Commit

Permalink
Refactor business logic to helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Jan 24, 2024
1 parent c1baf8a commit 1525512
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -66,26 +62,13 @@ public Map<LogicalDivision, MediaPartial> getMediaPartialDivisions() {
mediaSelection = dataEditor.getGalleryPanel().getLastSelection();
Map<LogicalDivision, MediaPartial> 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<LogicalDivision, MediaPartial> mediaViewDivisions,
List<LogicalDivision> logicalDivisions, Map<MediaVariant, URI> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<LogicalDivision, MediaPartial> mediaPartialDivisions,
List<LogicalDivision> logicalDivisions, Map<MediaVariant, URI> 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);
}
}

}

0 comments on commit 1525512

Please sign in to comment.