From 1ea605e9d8ecfb4da77583e83b273f784f390632 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Mon, 13 Nov 2023 13:13:33 +0100 Subject: [PATCH] Fix that physical divisions of audio and video files have the type "track" instead of "page" --- .../org/kitodo/api/dataformat/Workpiece.java | 11 ++- .../main/java/org/kitodo/utils/MediaUtil.java | 94 +++++++++++++++++++ .../java/org/kitodo/utils/MediaUtilTest.java | 52 ++++++++++ .../entities/PhysicalStructMapType.java | 14 +-- .../dataeditor/MetsKitodoWrapperTest.java | 33 ++++++- .../dataeditor/AddDocStrucTypeDialog.java | 2 +- .../forms/dataeditor/EditPagesDialog.java | 4 +- .../forms/dataeditor/GalleryPanel.java | 35 ++++++- .../forms/dataeditor/PaginationPanel.java | 10 +- .../forms/dataeditor/StructurePanel.java | 2 +- .../forms/dataeditor/UploadFileDialog.java | 13 +-- .../production/services/file/FileService.java | 21 +++-- .../src/main/resources/kitodo_fileFormats.xml | 18 ++++ .../main/webapp/pages/metadataEditor.xhtml | 8 +- 14 files changed, 264 insertions(+), 53 deletions(-) create mode 100644 Kitodo-API/src/main/java/org/kitodo/utils/MediaUtil.java create mode 100644 Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java diff --git a/Kitodo-API/src/main/java/org/kitodo/api/dataformat/Workpiece.java b/Kitodo-API/src/main/java/org/kitodo/api/dataformat/Workpiece.java index 797a06a59ed..e97377163f3 100644 --- a/Kitodo-API/src/main/java/org/kitodo/api/dataformat/Workpiece.java +++ b/Kitodo-API/src/main/java/org/kitodo/api/dataformat/Workpiece.java @@ -12,7 +12,7 @@ package org.kitodo.api.dataformat; import java.util.ArrayList; -import java.util.Collections; +import java.util.Arrays; import java.util.Comparator; import java.util.GregorianCalendar; import java.util.List; @@ -180,15 +180,16 @@ public List getAllLogicalDivisions() { /** * Returns all child physical divisions of the physical division of the workpiece with - * type "page" sorted by their {@code order} as a flat list. The root media + * type "page" or "track" sorted by their {@code order} as a flat list. The root media * unit is not contained. The list isn’t backed by the physical divisions, which * means that insertions and deletions in the list would not change the * physical divisions. Therefore, a list that cannot be modified is returned. * - * @return all physical divisions with type "page", sorted by their {@code order} + * @return all physical divisions with type "page" or "track", sorted by their {@code order} */ - public List getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted() { - return getAllPhysicalDivisionChildrenFilteredByTypes(Collections.singletonList(PhysicalDivision.TYPE_PAGE)); + public List getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack() { + return getAllPhysicalDivisionChildrenFilteredByTypes( + Arrays.asList(PhysicalDivision.TYPE_PAGE, PhysicalDivision.TYPE_TRACK)); } /** diff --git a/Kitodo-API/src/main/java/org/kitodo/utils/MediaUtil.java b/Kitodo-API/src/main/java/org/kitodo/utils/MediaUtil.java new file mode 100644 index 00000000000..1b98d1ba10b --- /dev/null +++ b/Kitodo-API/src/main/java/org/kitodo/utils/MediaUtil.java @@ -0,0 +1,94 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.utils; + +import java.util.Objects; + +import org.kitodo.api.dataformat.PhysicalDivision; + +public class MediaUtil { + + public static final String MIME_TYPE_AUDIO_PREFIX = "audio"; + public static final String MIME_TYPE_IMAGE_PREFIX = "image"; + public static final String MIME_TYPE_VIDEO_PREFIX = "video"; + + /** + * Private constructor to hide the implicit public one. + */ + private MediaUtil() { + + } + + /** + * Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or + * {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. + * + * @param mimeType + * The mime type to check + * @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} or + * {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. + */ + public static boolean isAudioOrVideo(String mimeType) { + return isAudio(mimeType) || isVideo(mimeType); + } + + /** + * Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX}. + * + * @param mimeType + * The mime type to check + * @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_AUDIO_PREFIX} + */ + public static boolean isAudio(String mimeType) { + return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_AUDIO_PREFIX); + } + + /** + * Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX}. + * + * @param mimeType + * The mime type to check + * @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_IMAGE_PREFIX} + */ + public static boolean isImage(String mimeType) { + return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_IMAGE_PREFIX); + } + + /** + * Check if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX}. + * + * @param mimeType + * The mime type to check + * @return True if mime type starts with {@link org.kitodo.utils.MediaUtil#MIME_TYPE_VIDEO_PREFIX} + */ + public static boolean isVideo(String mimeType) { + return Objects.nonNull(mimeType) && mimeType.startsWith(MIME_TYPE_VIDEO_PREFIX); + } + + /** + * Get the type of {@link org.kitodo.api.dataformat.PhysicalDivision} by mime type. + * + * @param mimeType + * The mime type to get the physical division type for + * @return The type of the {@link org.kitodo.api.dataformat.PhysicalDivision} + */ + public static String getPhysicalDivisionTypeOfMimeType(String mimeType) { + if (isImage(mimeType)) { + return PhysicalDivision.TYPE_PAGE; + } + if (isAudioOrVideo(mimeType)) { + return PhysicalDivision.TYPE_TRACK; + } + return PhysicalDivision.TYPE_OTHER; + } + +} diff --git a/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java b/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java new file mode 100644 index 00000000000..d106a76074c --- /dev/null +++ b/Kitodo-API/src/test/java/org/kitodo/utils/MediaUtilTest.java @@ -0,0 +1,52 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * This file is part of the Kitodo project. + * + * It is licensed under GNU General Public License version 3 or later. + * + * For the full copyright and license information, please read the + * GPL3-License.txt file that was distributed with this source code. + */ + +package org.kitodo.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.kitodo.api.dataformat.PhysicalDivision; + +public class MediaUtilTest { + + /** + * Test detection of mime type. + */ + @Test + public void testMimeTypeDetection() { + assertTrue(MediaUtil.isAudio("audio/mp3")); + assertFalse(MediaUtil.isVideo("image/jpeg")); + + assertTrue(MediaUtil.isImage("image/jpeg")); + assertFalse(MediaUtil.isImage("video/mp4")); + + assertTrue(MediaUtil.isVideo("video/mp4")); + assertFalse(MediaUtil.isVideo("image/jpeg")); + + assertTrue(MediaUtil.isAudioOrVideo("audio/mp3")); + assertTrue(MediaUtil.isAudioOrVideo("video/mp4")); + assertFalse(MediaUtil.isAudioOrVideo("image/jpeg")); + } + + /** + * Test getting the type of the {@link org.kitodo.api.dataformat.PhysicalDivision}. + */ + @Test + public void testGettingPhysicalDivisionTypeByMimeType() { + assertEquals(PhysicalDivision.TYPE_PAGE, MediaUtil.getPhysicalDivisionTypeOfMimeType("image/jpeg")); + assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("audio/mp3")); + assertEquals(PhysicalDivision.TYPE_TRACK, MediaUtil.getPhysicalDivisionTypeOfMimeType("video/mp4")); + assertEquals(PhysicalDivision.TYPE_OTHER, MediaUtil.getPhysicalDivisionTypeOfMimeType("application/pdf")); + } +} diff --git a/Kitodo-DataEditor/src/main/java/org/kitodo/dataeditor/entities/PhysicalStructMapType.java b/Kitodo-DataEditor/src/main/java/org/kitodo/dataeditor/entities/PhysicalStructMapType.java index 1471cd4249b..6ff19803f04 100644 --- a/Kitodo-DataEditor/src/main/java/org/kitodo/dataeditor/entities/PhysicalStructMapType.java +++ b/Kitodo-DataEditor/src/main/java/org/kitodo/dataeditor/entities/PhysicalStructMapType.java @@ -17,13 +17,13 @@ import java.util.NoSuchElementException; import java.util.Objects; -import org.kitodo.api.dataformat.PhysicalDivision; import org.kitodo.config.KitodoConfig; import org.kitodo.config.enums.ParameterDataEditor; import org.kitodo.dataeditor.MetsKitodoObjectFactory; import org.kitodo.dataformat.metskitodo.DivType; import org.kitodo.dataformat.metskitodo.FileType; import org.kitodo.dataformat.metskitodo.StructMapType; +import org.kitodo.utils.MediaUtil; public class PhysicalStructMapType extends StructMapType { @@ -63,7 +63,7 @@ private List getDivTypesByFileTypes(List fileTypes) { div.setID("PHYS_" + String.format("%04d", counter)); div.setORDER(BigInteger.valueOf(counter)); div.setORDERLABEL(KitodoConfig.getParameter(ParameterDataEditor.METS_EDITOR_DEFAULT_PAGINATION)); - div.setTYPE(getPhysicalDivTypeByFileType(file)); + div.setTYPE(MediaUtil.getPhysicalDivisionTypeOfMimeType(file.getMIMETYPE())); DivType.Fptr divTypeFptr = objectFactory.createDivTypeFptr(); divTypeFptr.setFILEID(file); div.getFptr().add(divTypeFptr); @@ -75,16 +75,6 @@ private List getDivTypesByFileTypes(List fileTypes) { return divTypes; } - private String getPhysicalDivTypeByFileType(FileType file) { - if (file.getMIMETYPE().contains("image")) { - return PhysicalDivision.TYPE_PAGE; - } - if (file.getMIMETYPE().contains("audio")) { - return PhysicalDivision.TYPE_TRACK; - } - return PhysicalDivision.TYPE_OTHER; - } - private DivType getDivById(String id) { for (DivType div : this.getDiv().getDiv()) { if (Objects.equals(div.getID(),id)) { diff --git a/Kitodo-DataEditor/src/test/java/org/kitodo/dataeditor/MetsKitodoWrapperTest.java b/Kitodo-DataEditor/src/test/java/org/kitodo/dataeditor/MetsKitodoWrapperTest.java index 42ab75b63ab..ae38813dee3 100644 --- a/Kitodo-DataEditor/src/test/java/org/kitodo/dataeditor/MetsKitodoWrapperTest.java +++ b/Kitodo-DataEditor/src/test/java/org/kitodo/dataeditor/MetsKitodoWrapperTest.java @@ -36,6 +36,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.kitodo.api.dataformat.PhysicalDivision; import org.kitodo.dataeditor.enums.FileLocationType; import org.kitodo.dataeditor.enums.PositionOfNewDiv; import org.kitodo.dataformat.metskitodo.DivType; @@ -202,22 +203,22 @@ public void shouldReadGoobiMetadataGroup() } @Test - public void shouldInsertFileGroup() throws IOException, DatatypeConfigurationException { + public void shouldInsertFileGroup() throws DatatypeConfigurationException, IOException { Path path = Paths.get("images"); int numberOfFiles = 5; List mediaFiles = new ArrayList<>(); for (int i = 1; i <= numberOfFiles; i++) { mediaFiles.add( - new MediaFile(Paths.get(path + "/0000" + i + ".tif").toUri(), FileLocationType.URL, "image/tiff")); + new MediaFile(Paths.get(path + "/0000" + i + ".tif").toUri(), FileLocationType.URL, "image/tiff")); } MetsKitodoWrapper metsKitodoWrapper = new MetsKitodoWrapper("Manuscript"); metsKitodoWrapper.insertMediaFiles(mediaFiles); Assert.assertEquals("Wrong number of divs in physical structMap", numberOfFiles, - metsKitodoWrapper.getPhysicalStructMap().getDiv().getDiv().size()); - Assert.assertEquals("Wrong number of fils in fileSec", numberOfFiles, - metsKitodoWrapper.getMets().getFileSec().getFileGrp().get(0).getFile().size()); + metsKitodoWrapper.getPhysicalStructMap().getDiv().getDiv().size()); + Assert.assertEquals("Wrong number of files in fileSec", numberOfFiles, + metsKitodoWrapper.getMets().getFileSec().getFileGrp().get(0).getFile().size()); DivType divType = metsKitodoWrapper.getPhysicalStructMap().getDiv().getDiv().get(1); @@ -231,6 +232,28 @@ public void shouldInsertFileGroup() throws IOException, DatatypeConfigurationExc } + + @Test + public void testPhysicalDivisionType() throws IOException, DatatypeConfigurationException { + List mediaFiles = new ArrayList<>(); + mediaFiles.add(new MediaFile(Paths.get("image/jpeg/0001.jpeg").toUri(), FileLocationType.URL, "image/jpeg")); + mediaFiles.add(new MediaFile(Paths.get("audio/mpeg/0002.jpeg").toUri(), FileLocationType.URL, "audio/mpeg")); + mediaFiles.add(new MediaFile(Paths.get("video/mp4/0003.jpeg").toUri(), FileLocationType.URL, "video/mp4")); + + MetsKitodoWrapper metsKitodoWrapper = new MetsKitodoWrapper("MultiMedia"); + metsKitodoWrapper.insertMediaFiles(mediaFiles); + + Assert.assertEquals("Wrong number of divs in physical structMap", 3, + metsKitodoWrapper.getPhysicalStructMap().getDiv().getDiv().size()); + Assert.assertEquals("Wrong number of files in fileSec", 3, + metsKitodoWrapper.getMets().getFileSec().getFileGrp().get(0).getFile().size()); + + List divTypes = metsKitodoWrapper.getPhysicalStructMap().getDiv().getDiv(); + Assert.assertEquals(PhysicalDivision.TYPE_PAGE, divTypes.get(0).getTYPE()); + Assert.assertEquals(PhysicalDivision.TYPE_TRACK, divTypes.get(1).getTYPE()); + Assert.assertEquals(PhysicalDivision.TYPE_TRACK, divTypes.get(2).getTYPE()); + } + @Rule public ExpectedException expectedException = ExpectedException.none(); 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 17eaf77760a..1b0db56b099 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 @@ -553,7 +553,7 @@ public void prepareAddableMetadataForStructure(boolean currentElement) { } private void prepareSelectPageOnAddNodeItems() { - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); selectPageOnAddNodeItems = new ArrayList<>(physicalDivisions.size()); for (int i = 0; i < physicalDivisions.size(); i++) { View view = View.of(physicalDivisions.get(i)); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/EditPagesDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/EditPagesDialog.java index 4f35efcdeae..901c17d0a06 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/EditPagesDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/EditPagesDialog.java @@ -206,7 +206,7 @@ List getViewsToAdd(int firstPage, int lastPage) { private List getViewsToAdd(List pages) { return pages.parallelStream() - .map(dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted()::get) + .map(dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack()::get) .map(MetadataEditor::getFirstViewForPhysicalDivision) .collect(Collectors.toList()); } @@ -232,7 +232,7 @@ void prepare() { paginationSubSelectionItems = new ArrayList<>(); paginationSelectionItems = new ArrayList<>(); - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); int capacity = (int) Math.ceil(physicalDivisions.size() / .75); Set assigneds = new HashSet<>(capacity); Set unassigneds = new HashSet<>(capacity); 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 9818611bfb6..289eb50b96d 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 @@ -50,6 +50,7 @@ import org.kitodo.production.model.Subfolder; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.file.FileService; +import org.kitodo.utils.MediaUtil; import org.primefaces.PrimeFaces; /** @@ -349,7 +350,7 @@ void show() { Process process = dataEditor.getProcess(); Project project = process.getProject(); List physicalDivisions = dataEditor.getWorkpiece() - .getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + .getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); mediaContentTypeVariants.clear(); mediaContentTypePreviewFolder.clear(); @@ -393,7 +394,7 @@ private void initMediaContentType(List physicalDivisions, Fold */ private void updateMedia() { List physicalDivisions = dataEditor.getWorkpiece() - .getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + .getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); medias = new ArrayList<>(physicalDivisions.size()); dataEditor.getMediaProvider().resetMediaResolverForProcess(dataEditor.getProcess().getId()); for (PhysicalDivision physicalDivision : physicalDivisions) { @@ -799,7 +800,7 @@ public boolean isSelected(GalleryMediaContent galleryMediaContent, GalleryStripe private void selectMedia(String physicalDivisionOrder, String stripeIndex, String selectionType) { PhysicalDivision selectedPhysicalDivision = null; for (PhysicalDivision physicalDivision : this.dataEditor.getWorkpiece() - .getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted()) { + .getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack()) { if (Objects.equals(physicalDivision.getOrder(), Integer.parseInt(physicalDivisionOrder))) { selectedPhysicalDivision = physicalDivision; break; @@ -976,4 +977,32 @@ public int getSeveralAssignmentsIndex(GalleryMediaContent galleryMediaContent) { public String getCachingUUID() { return cachingUUID; } + + /** + * Check if media view has mime type prefix. + * + * @param mimeTypePrefix + * The mime type prefix + * @return True if media view has mime type prefix + */ + public boolean hasMediaViewMimeTypePrefix(String mimeTypePrefix) { + Pair lastSelection = getLastSelection(); + if (Objects.nonNull(lastSelection)) { + GalleryMediaContent galleryMediaContent = getGalleryMediaContent(lastSelection.getKey()); + if (Objects.nonNull(galleryMediaContent)) { + String mediaViewMimeType = galleryMediaContent.getMediaViewMimeType(); + switch (mimeTypePrefix) { + case MediaUtil.MIME_TYPE_AUDIO_PREFIX: + return MediaUtil.isAudio(mediaViewMimeType); + case MediaUtil.MIME_TYPE_VIDEO_PREFIX: + return MediaUtil.isVideo(mediaViewMimeType); + case MediaUtil.MIME_TYPE_IMAGE_PREFIX: + return MediaUtil.isImage(mediaViewMimeType); + default: + } + } + } + return false; + } + } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/PaginationPanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/PaginationPanel.java index 252f1a4851f..b0169169d02 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/PaginationPanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/PaginationPanel.java @@ -84,7 +84,7 @@ public void updateMediaReferences() { Helper.setWarnMessage(e.getMessage()); } dataEditor.setMediaUpdated(mediaReferencesChanged); - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); for (int i = 1; i < physicalDivisions.size(); i++) { PhysicalDivision physicalDivision = physicalDivisions.get(i - 1); physicalDivision.setOrder(i); @@ -112,7 +112,7 @@ public List getPaginationSelectionSelectedItems() { * selected items to set */ public void setPaginationSelectionSelectedItems(List selectedItems) { - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); if (!selectedItems.isEmpty()) { int lastItemIndex = selectedItems.get(selectedItems.size() - 1); if (this.paginationSelectionSelectedItems.isEmpty() @@ -266,7 +266,7 @@ public void setFictitiousCheckboxChecked(boolean fictitiousCheckboxChecked) { } private void preparePaginationSelectionItems() { - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); paginationSelectionItems = new ArrayList<>(physicalDivisions.size()); for (int i = 0; i < physicalDivisions.size(); i++) { View view = View.of(physicalDivisions.get(i)); @@ -280,7 +280,7 @@ private void preparePaginationSelectionItems() { */ public void preparePaginationSelectionSelectedItems() { paginationSelectionSelectedItems = new ArrayList<>(); - List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); for (Pair selectedElement : dataEditor.getSelectedMedia()) { for (int i = 0; i < physicalDivisions.size(); i++) { PhysicalDivision physicalDivision = physicalDivisions.get(i); @@ -342,7 +342,7 @@ public void startPaginationClick() { paginationStartValue, fictitiousCheckboxChecked, pageSeparators.get(0).getSeparatorString()); Paginator paginator = new Paginator(initializer); List physicalDivisions = dataEditor.getWorkpiece() - .getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + .getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); if (selectPaginationScopeSelectedItem) { for (int i = paginationSelectionSelectedItems.get(0); i < physicalDivisions.size(); i++) { physicalDivisions.get(i).setOrderlabel(paginator.next()); 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 d5bcbb5e67c..558751b89b7 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 @@ -239,7 +239,7 @@ void deleteSelectedPhysicalDivision() { } } int i = 1; - for (PhysicalDivision physicalDivision : dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted()) { + for (PhysicalDivision physicalDivision : dataEditor.getWorkpiece().getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack()) { physicalDivision.setOrder(i); i++; } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java index 47a409d223a..b269b1ec2b1 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java @@ -55,6 +55,7 @@ import org.kitodo.production.services.file.SubfolderFactoryService; import org.kitodo.production.services.image.ImageGenerator; import org.kitodo.production.thread.TaskImageGeneratorThread; +import org.kitodo.utils.MediaUtil; import org.primefaces.PrimeFaces; import org.primefaces.event.FileUploadEvent; import org.primefaces.model.TreeNode; @@ -213,16 +214,6 @@ private MediaVariant getMediaVariant() { return mediaVariant; } - private String getPhysicalDivType() { - if (mimeType.contains("image")) { - return PhysicalDivision.TYPE_PAGE; - } - if (mimeType.contains("audio")) { - return PhysicalDivision.TYPE_TRACK; - } - return PhysicalDivision.TYPE_OTHER; - } - private boolean setUpFolders() { VariableReplacer variableReplacer = new VariableReplacer(null, dataEditor.getProcess(), null); sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); @@ -336,7 +327,7 @@ public void prepare() { public void uploadMedia(FileUploadEvent event) { if (event.getFile() != null) { - PhysicalDivision physicalDivision = MetadataEditor.addPhysicalDivision(getPhysicalDivType(), + PhysicalDivision physicalDivision = MetadataEditor.addPhysicalDivision(MediaUtil.getPhysicalDivisionTypeOfMimeType(mimeType), dataEditor.getWorkpiece(), dataEditor.getWorkpiece().getPhysicalStructure(), InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT); uploadFileUri = new File(sourceFolderURI.getPath().concat(event.getFile().getFileName())).toURI(); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java b/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java index b258f24d26f..476a5dde7ef 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/file/FileService.java @@ -70,6 +70,7 @@ import org.kitodo.production.services.command.CommandService; import org.kitodo.production.services.data.RulesetService; import org.kitodo.serviceloader.KitodoServiceLoader; +import org.kitodo.utils.MediaUtil; public class FileService { @@ -1113,7 +1114,7 @@ public boolean searchForMedia(Process process, Workpiece workpiece) } addNewURIsToExistingPhysicalDivisions(currentMedia, - workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(), canonicals); + workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(), canonicals); Map> mediaToAdd = new TreeMap<>(currentMedia); List mediaToRemove = new LinkedList<>(canonicals); @@ -1162,7 +1163,7 @@ private List getCanonicalFileNamePartsAndSanitizeAbsoluteURIs(Workpiece if (!baseUriString.endsWith("/")) { baseUriString = baseUriString.concat("/"); } - for (PhysicalDivision physicalDivision : workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted()) { + for (PhysicalDivision physicalDivision : workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack()) { String unitCanonical = ""; for (Entry entry : physicalDivision.getMediaFiles().entrySet()) { Subfolder subfolder = subfolders.get(entry.getKey().getUse()); @@ -1211,7 +1212,7 @@ private void addNewURIsToExistingPhysicalDivisions(Map mediaToRemove, Workpiece workpiece, Collection subfolders) { - List pages = workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List pages = workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); for (String removal : mediaToRemove) { if (StringUtils.isNotBlank(removal)) { for (PhysicalDivision page : pages) { @@ -1233,7 +1234,7 @@ private void removeMissingMediaFromWorkpiece(List mediaToRemove, Workpie } if (!mediaToRemove.isEmpty()) { int i = 1; - for (PhysicalDivision division : workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted()) { + for (PhysicalDivision division : workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack()) { division.setOrder(i); i++; } @@ -1311,6 +1312,13 @@ private PhysicalDivision createPhysicalDivision(Map data) { for (Entry entry : data.entrySet()) { Folder folder = entry.getKey().getFolder(); MediaVariant mediaVariant = createMediaVariant(folder); + + // overwrite physical division type if mime type is audio or video + if (!PhysicalDivision.TYPE_TRACK.equals(physicalDivision.getType()) && MediaUtil.isAudioOrVideo( + mediaVariant.getMimeType())) { + physicalDivision.setType(PhysicalDivision.TYPE_TRACK); + } + physicalDivision.getMediaFiles().put(mediaVariant, entry.getValue()); } return physicalDivision; @@ -1331,7 +1339,8 @@ private MediaVariant createMediaVariant(Folder folder) { */ public void renumberPhysicalDivisions(Workpiece workpiece, boolean sortByOrder) { int order = 1; - for (PhysicalDivision physicalDivision : sortByOrder ? workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted() + for (PhysicalDivision physicalDivision : sortByOrder + ? workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack() : workpiece.getPhysicalStructure().getAllChildren()) { physicalDivision.setOrder(order++); } @@ -1343,7 +1352,7 @@ public void renumberPhysicalDivisions(Workpiece workpiece, boolean sortByOrder) * intermediate places are marked uncounted. */ private void repaginatePhysicalDivisions(Workpiece workpiece) { - List physicalDivisions = workpiece.getAllPhysicalDivisionChildrenFilteredByTypePageAndSorted(); + List physicalDivisions = workpiece.getAllPhysicalDivisionChildrenSortedFilteredByPageAndTrack(); int first = 0; String value; switch (ConfigCore.getParameter(ParameterCore.METS_EDITOR_DEFAULT_PAGINATION)) { diff --git a/Kitodo/src/main/resources/kitodo_fileFormats.xml b/Kitodo/src/main/resources/kitodo_fileFormats.xml index bc376cada58..5305a3608a6 100644 --- a/Kitodo/src/main/resources/kitodo_fileFormats.xml +++ b/Kitodo/src/main/resources/kitodo_fileFormats.xml @@ -70,4 +70,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/Kitodo/src/main/webapp/pages/metadataEditor.xhtml b/Kitodo/src/main/webapp/pages/metadataEditor.xhtml index 9caf467410b..aba0e1236af 100644 --- a/Kitodo/src/main/webapp/pages/metadataEditor.xhtml +++ b/Kitodo/src/main/webapp/pages/metadataEditor.xhtml @@ -207,11 +207,15 @@ +