From bc0836a37732ef14d2fe808c5bfbe2d9060d0fd7 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Fri, 4 Jun 2021 09:31:58 +0200 Subject: [PATCH 01/16] Add migration file for upload and delete media authorities --- ...uthorities_for_upload_and_delete_media.sql | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql new file mode 100644 index 00000000000..11c663451e3 --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql @@ -0,0 +1,28 @@ +-- +-- (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. +-- + +-- Insert authorities for upload and delete media in metadata editor. + +INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_globalAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_clientAssignable'); + +INSERT IGNORE INTO authority (title) VALUES ('deleteMedia_globalAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('deleteMedia_clientAssignable'); + +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_globalAssignable'; +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_clientAssignable'; + +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'deleteMedia_globalAssignable'; +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'deleteMedia_clientAssignable'; From 1b276d000e8a503a23c535500bd0ed048e594474 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Mon, 21 Jun 2021 12:41:50 +0200 Subject: [PATCH 02/16] Rename the migration file after rebasing --- ...ql => V2_107__Add_authorities_for_upload_and_delete_media.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Kitodo-DataManagement/src/main/resources/db/migration/{V2_106__Add_authorities_for_upload_and_delete_media.sql => V2_107__Add_authorities_for_upload_and_delete_media.sql} (100%) diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_107__Add_authorities_for_upload_and_delete_media.sql similarity index 100% rename from Kitodo-DataManagement/src/main/resources/db/migration/V2_106__Add_authorities_for_upload_and_delete_media.sql rename to Kitodo-DataManagement/src/main/resources/db/migration/V2_107__Add_authorities_for_upload_and_delete_media.sql From 3a0e0e4cd3b4cbffe7aa0afd382a2f41c201fa85 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Thu, 11 Mar 2021 22:06:16 +0100 Subject: [PATCH 03/16] Add new function 'Upload files' in metadateditor --- .../forms/dataeditor/DataEditorForm.java | 11 + .../forms/dataeditor/UploadFileDialog.java | 236 ++++++++++++++++++ .../webapp/WEB-INF/resources/css/kitodo.css | 9 + .../metadataEditor/dialogs/uploadFile.xhtml | 73 ++++++ .../metadataEditor/logicalStructure.xhtml | 8 + .../main/webapp/pages/metadataEditor.xhtml | 1 + 6 files changed, 338 insertions(+) create mode 100644 Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java create mode 100644 Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml 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 d2048938948..fe96b22d85b 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 @@ -96,6 +96,7 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable { */ private final EditPagesDialog editPagesDialog; + private final UploadFileDialog uploadFileDialog ; /** * Backing bean for the gallery panel. */ @@ -192,6 +193,7 @@ public DataEditorForm() { this.addPhysicalDivisionDialog = new AddPhysicalDivisionDialog(this); this.changeDocStrucTypeDialog = new ChangeDocStrucTypeDialog(this); this.editPagesDialog = new EditPagesDialog(this); + this.uploadFileDialog = new UploadFileDialog(this); acquisitionStage = "edit"; } @@ -848,4 +850,13 @@ public void saveDataEditorSetting() { templateTaskId); } } + + /** + * Get uploadFileDialog. + * + * @return value of uploadFileDialog + */ + public UploadFileDialog getUploadFileDialog() { + return uploadFileDialog; + } } 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 new file mode 100644 index 00000000000..33e627cda81 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/UploadFileDialog.java @@ -0,0 +1,236 @@ +/* + * (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.production.forms.dataeditor; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.faces.model.SelectItem; + +import org.apache.commons.io.IOUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.api.dataformat.MediaUnit; +import org.kitodo.api.dataformat.MediaVariant; +import org.kitodo.data.database.beans.Folder; +import org.kitodo.exceptions.InvalidImagesException; +import org.kitodo.production.enums.GenerationMode; +import org.kitodo.production.helper.Helper; +import org.kitodo.production.helper.tasks.TaskManager; +import org.kitodo.production.metadata.InsertionPosition; +import org.kitodo.production.metadata.MetadataEditor; +import org.kitodo.production.model.Subfolder; +import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.file.SubfolderFactoryService; +import org.kitodo.production.services.image.ImageGenerator; +import org.kitodo.production.thread.TaskImageGeneratorThread; +import org.primefaces.event.FileUploadEvent; +import org.primefaces.model.UploadedFile; + +public class UploadFileDialog { + private static final Logger logger = LogManager.getLogger(UploadFileDialog.class); + + private final DataEditorForm dataEditor; + private UploadedFile file; + private String mimeType; + private String fileType; + private String use; + private URI sourceFolderURI; + private List possiblePositions; + private InsertionPosition selectedPosition = InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT; + private Folder sourceFolder; + private List contentFolders = new ArrayList<>(); + private MediaVariant mediaVariant; + + /** + * Constructor. + * + * @param dataEditor Instance of DataEditorForm where this instance of UploadFileDialog was created. + */ + UploadFileDialog(DataEditorForm dataEditor) { + this.dataEditor = dataEditor; + } + + public void prepare() { + sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); + contentFolders.add(dataEditor.getProcess().getProject().getMediaView()); + contentFolders.add(dataEditor.getProcess().getProject().getPreview()); + + + mimeType = sourceFolder.getMimeType(); + use = sourceFolder.getFileGroup(); + + mediaVariant = getMediaVariant(); + fileType = mimeType.substring(mimeType.indexOf("/") + 1); + sourceFolderURI = URI.create(sourceFolder.getUrlStructure().replace("$(meta.CatalogIDDigital)", + String.valueOf(dataEditor.getProcess().getId()))); + preparePossiblePositions(); + } + + private void preparePossiblePositions() { + possiblePositions = new ArrayList<>(); + possiblePositions.add(new SelectItem(InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.asFirstChildOfCurrentElement"))); + possiblePositions.add(new SelectItem(InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.asLastChildOfCurrentElement"))); + } + + /** + * Get fileType. + * + * @return value of fileType + */ + public String getFileType() { + return fileType; + } + + /** + * Set fileType. + * + * @param fileType as java.lang.String + */ + public void setFileType(String fileType) { + this.fileType = fileType; + } + + /** + * Get file. + * + * @return value of file + */ + public UploadedFile getFile() { + return file; + } + + /** + * Set file. + * + * @param file as org.primefaces.model.UploadedFile + */ + public void setFile(UploadedFile file) { + this.file = file; + } + + /** + * Get possiblePositions. + * + * @return value of possiblePositions + */ + public List getPossiblePositions() { + return possiblePositions; + } + + /** + * Set possiblePositions. + * + * @param possiblePositions as java.util.List + */ + public void setPossiblePositions(List possiblePositions) { + this.possiblePositions = possiblePositions; + } + + /** + * Get selectedPosition. + * + * @return value of selectedPosition + */ + public InsertionPosition getSelectedPosition() { + return selectedPosition; + } + + /** + * Set selectedPosition. + * + * @param selectedPosition as org.kitodo.production.metadata.InsertionPosition + */ + public void setSelectedPosition(InsertionPosition selectedPosition) { + this.selectedPosition = selectedPosition; + } + + private MediaVariant getMediaVariant() { + MediaVariant mediaVariant = new MediaVariant(); + mediaVariant.setMimeType(mimeType); + mediaVariant.setUse(use); + return mediaVariant; + } + + private String getPhysicalDivType() { + if (mimeType.contains("image")) { + return MediaUnit.TYPE_PAGE; + } + if (mimeType.contains("audio")) { + return MediaUnit.TYPE_TRACK; + } + return MediaUnit.TYPE_OTHER; + } + + private void generateNewUploadedImages() { + if (Objects.isNull(sourceFolder)) { + Helper.setErrorMessage("noSourceFolderConfiguredInProject"); + return; + } + if (Objects.isNull(contentFolders)) { + Helper.setErrorMessage("noImageFolderConfiguredInProject"); + return; + } + Subfolder generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); + if (generatorSource.listContents().isEmpty()) { + Helper.setErrorMessage("emptySourceFolder"); + } else { + List outputs = SubfolderFactoryService.createAll(dataEditor.getProcess(), contentFolders); + ImageGenerator imageGenerator = new ImageGenerator(generatorSource, GenerationMode.MISSING, outputs); + TaskManager.addTask(new TaskImageGeneratorThread(dataEditor.getProcess().getTitle(), imageGenerator)); + } + } + + public void refresh() throws InvalidImagesException { + dataEditor.refreshStructurePanel(); + dataEditor.getPaginationPanel().show(); + ServiceManager.getFileService().searchForMedia(dataEditor.getProcess(), dataEditor.getWorkpiece()); + dataEditor.getGalleryPanel().show(); + } + + public void uploadFiles(FileUploadEvent event) { + if (event.getFile() != null) { + //create MediaUnit and edit workpiece + MediaUnit mediaUnit = MetadataEditor.addMediaUnit(getPhysicalDivType(), dataEditor.getWorkpiece(), + dataEditor.getWorkpiece().getMediaUnit(), InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT); + + URI fileUri = sourceFolderURI.resolve(event.getFile().getFileName()); + mediaUnit.getMediaFiles().put(mediaVariant, fileUri); + switch (selectedPosition) { + case FIRST_CHILD_OF_CURRENT_ELEMENT: + this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add(0, + MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + break; + case LAST_CHILD_OF_CURRENT_ELEMENT: + this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add( + MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + break; + default: + throw new IllegalArgumentException("Position of new div element is not supported"); + + } + //upload file in sourceFolder + try (OutputStream outputStream = ServiceManager.getFileService().write(fileUri)) { + IOUtils.copy(event.getFile().getInputstream(), outputStream); + } catch (IOException e) { + Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); + } + } + generateNewUploadedImages(); + } +} diff --git a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css index b1a7edbcc9c..a71ded4507e 100644 --- a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css +++ b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css @@ -1748,6 +1748,15 @@ form#metadata div label, height: calc(var(--default-double-size) * 3); } +#uploadFileDialog { + padding: 10px; +} + +#uploadFileDialogForm { + height: 100%; + overflow-y: scroll; +} + #metadataAccordion\:metadata .ui-treetable-indent, #metadataAccordion\:metadata .ui-treetable-toggler { float: left; diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml new file mode 100644 index 00000000000..ed20fcc23ed --- /dev/null +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml @@ -0,0 +1,73 @@ + + + + + + + +

#{msgs.fileUpload}

+
+ + + + + +
+
+ +
+
+ + +
+
+
+
+
+
diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml index 28c509b6c1c..fa1174b0ff3 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml @@ -136,6 +136,14 @@ metadataAccordion:logicalMetadataWrapperPanel @(.structureElementDataList) imagePreviewForm:mediaContextMenu"/> + + From 82ad28f09dd62f62c8b77c1d3908c3c6c6a5a491 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Fri, 19 Mar 2021 00:08:17 +0100 Subject: [PATCH 04/16] Add 'Upload media' authority --- ...2_103__Add_Authoriies_for_upload_media.sql | 20 +++++++++++++++++++ .../controller/SecurityAccessController.java | 10 ++++++++++ .../security/SecurityAccessService.java | 10 ++++++++++ .../resources/messages/messages_de.properties | 1 + .../resources/messages/messages_en.properties | 1 + .../metadataEditor/logicalStructure.xhtml | 3 ++- 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql new file mode 100644 index 00000000000..1574a811b6b --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql @@ -0,0 +1,20 @@ +-- +-- (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. +-- + +-- Insert authorities for upload media in metadataeditor. + +INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_globalAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_clientAssignable'); + +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_globalAssignable'; +INSERT IGNORE INTO role_x_authority (role_id, authority_id) +SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_clientAssignable'; diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index a931a75dc4f..b37293721a6 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -431,6 +431,16 @@ public boolean hasAuthorityToUnassignTasks() { return securityAccessService.hasAuthorityToUnassignTasks(); } + + /** + * Check if the current user has the authority to upload media in metadataeditor. + * + * @return true if the current user has the authority to to upload media in metadataeditor + */ + public boolean hasAuthorityToUploadMedia() { + return securityAccessService.hasAuthorityToUploadMedia(); + } + /** * Check if the current user has the authority to edit the role. * diff --git a/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java b/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java index a694194be88..655cd8f0225 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java @@ -446,6 +446,16 @@ public boolean hasAuthorityToUnassignTasks() { return hasAuthorityGlobalOrForClient("unassignTasks"); } + + /** + * Check if the current user has the authority to upload media in metadataeditor. + * + * @return true if the current user has the authority to to upload media in metadataeditor + */ + public boolean hasAuthorityToUploadMedia() { + return hasAuthorityGlobalOrForClient("uploadMedia"); + } + /** * Checks if the current user has the authority to edit the role. * diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 8ebfa1e1fbc..9378888986a 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -1012,6 +1012,7 @@ updateType=Art der Aktualisierung upload=Images hochladen uploadFile=Datei hochladen uploadImport=Dateiupload-Import +uploadMedia=Medien hochladen uriMalformed=Der URI hat ein falsches Format. url=URL useExistingWorkflow=Bestehenden Workflow verwenden diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 605177bf8d5..ad4200d85e3 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -1028,6 +1028,7 @@ updateType=Update type upload=Upload images uploadFile=upload file uploadImport=file upload import +uploadMedia=Upload media uriMalformed=The URI is malformed. url=URL useExistingWorkflow=Use existing workflow diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml index fa1174b0ff3..83bfdf6b57f 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/logicalStructure.xhtml @@ -138,10 +138,11 @@ imagePreviewForm:mediaContextMenu"/> Date: Fri, 19 Mar 2021 00:13:22 +0100 Subject: [PATCH 05/16] Code impovement --- ..._104__Add_Authoriies_for_upload_media.sql} | 0 .../forms/dataeditor/UploadFileDialog.java | 246 ++++++++++++++---- .../resources/messages/messages_de.properties | 4 +- .../resources/messages/messages_en.properties | 4 +- .../webapp/WEB-INF/resources/css/kitodo.css | 29 ++- .../metadataEditor/dialogs/uploadFile.xhtml | 62 +++-- .../includes/metadataEditor/gallery.xhtml | 18 ++ .../metadataEditor/logicalStructure.xhtml | 2 +- 8 files changed, 284 insertions(+), 81 deletions(-) rename Kitodo-DataManagement/src/main/resources/db/migration/{V2_103__Add_Authoriies_for_upload_media.sql => V2_104__Add_Authoriies_for_upload_media.sql} (100%) diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql similarity index 100% rename from Kitodo-DataManagement/src/main/resources/db/migration/V2_103__Add_Authoriies_for_upload_media.sql rename to Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql 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 33e627cda81..73d89b1611d 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 @@ -14,21 +14,31 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import javax.faces.model.SelectItem; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.kitodo.api.dataformat.IncludedStructuralElement; import org.kitodo.api.dataformat.MediaUnit; import org.kitodo.api.dataformat.MediaVariant; +import org.kitodo.api.dataformat.View; +import org.kitodo.config.ConfigCore; import org.kitodo.data.database.beans.Folder; import org.kitodo.exceptions.InvalidImagesException; +import org.kitodo.exceptions.NoSuchMetadataFieldException; import org.kitodo.production.enums.GenerationMode; import org.kitodo.production.helper.Helper; +import org.kitodo.production.helper.tasks.EmptyTask; import org.kitodo.production.helper.tasks.TaskManager; import org.kitodo.production.metadata.InsertionPosition; import org.kitodo.production.metadata.MetadataEditor; @@ -37,7 +47,9 @@ import org.kitodo.production.services.file.SubfolderFactoryService; import org.kitodo.production.services.image.ImageGenerator; import org.kitodo.production.thread.TaskImageGeneratorThread; +import org.primefaces.PrimeFaces; import org.primefaces.event.FileUploadEvent; +import org.primefaces.model.TreeNode; import org.primefaces.model.UploadedFile; public class UploadFileDialog { @@ -46,14 +58,22 @@ public class UploadFileDialog { private final DataEditorForm dataEditor; private UploadedFile file; private String mimeType; - private String fileType; + private String fileExtension; private String use; private URI sourceFolderURI; - private List possiblePositions; - private InsertionPosition selectedPosition = InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT; + private List possiblePositions = new ArrayList<>(); + private InsertionPosition selectedPosition; private Folder sourceFolder; private List contentFolders = new ArrayList<>(); private MediaVariant mediaVariant; + private int indexSelectedMedia; + private IncludedStructuralElement parent; + private MediaUnit mediaUnit; + private URI uploadFileUri; + private Subfolder generatorSource; + private List> selectedMedia = new LinkedList<>(); + private Integer progress; + private List generateMediaTasks = new ArrayList<>(); /** * Constructor. @@ -64,46 +84,22 @@ public class UploadFileDialog { this.dataEditor = dataEditor; } - public void prepare() { - sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); - contentFolders.add(dataEditor.getProcess().getProject().getMediaView()); - contentFolders.add(dataEditor.getProcess().getProject().getPreview()); - - - mimeType = sourceFolder.getMimeType(); - use = sourceFolder.getFileGroup(); - - mediaVariant = getMediaVariant(); - fileType = mimeType.substring(mimeType.indexOf("/") + 1); - sourceFolderURI = URI.create(sourceFolder.getUrlStructure().replace("$(meta.CatalogIDDigital)", - String.valueOf(dataEditor.getProcess().getId()))); - preparePossiblePositions(); - } - - private void preparePossiblePositions() { - possiblePositions = new ArrayList<>(); - possiblePositions.add(new SelectItem(InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT, - Helper.getTranslation("dataEditor.position.asFirstChildOfCurrentElement"))); - possiblePositions.add(new SelectItem(InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT, - Helper.getTranslation("dataEditor.position.asLastChildOfCurrentElement"))); - } - /** - * Get fileType. + * Get fileExtension. * - * @return value of fileType + * @return value of fileExtension */ - public String getFileType() { - return fileType; + public String getFileExtension() { + return fileExtension; } /** - * Set fileType. + * Set fileExtension. * - * @param fileType as java.lang.String + * @param fileExtension as java.lang.String */ - public void setFileType(String fileType) { - this.fileType = fileType; + public void setFileExtension(String fileExtension) { + this.fileExtension = fileExtension; } /** @@ -136,7 +132,7 @@ public List getPossiblePositions() { /** * Set possiblePositions. * - * @param possiblePositions as java.util.List + * @param possiblePositions as java.util.List of SelectItem */ public void setPossiblePositions(List possiblePositions) { this.possiblePositions = possiblePositions; @@ -160,6 +156,38 @@ public void setSelectedPosition(InsertionPosition selectedPosition) { this.selectedPosition = selectedPosition; } + /** + * Get progress. + * + * @return value of progress + */ + public int getProgress() { + progress = updateProgress(); + return progress; + } + + /** + * Set progress. + * + * @param progress as int + */ + public void setProgress(Integer progress) { + this.progress = progress; + } + + private Integer updateProgress() { + if (!generateMediaTasks.isEmpty() && progress != 100) { + return generateMediaTasks.stream().mapToInt(w -> w.getProgress()).sum() / generateMediaTasks.size(); + } else { + return progress; + } + } + + public void resetProgress() { + progress = 0; + generateMediaTasks.clear(); + } + private MediaVariant getMediaVariant() { MediaVariant mediaVariant = new MediaVariant(); mediaVariant.setMimeType(mimeType); @@ -177,60 +205,164 @@ private String getPhysicalDivType() { return MediaUnit.TYPE_OTHER; } - private void generateNewUploadedImages() { - if (Objects.isNull(sourceFolder)) { + /** + * Prepare popup dialog. + */ + public void prepare() { + progress = 0; + generateMediaTasks = new ArrayList<>(); + selectedMedia = new LinkedList<>(); + sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); + sourceFolderURI = Paths.get(ConfigCore.getKitodoDataDirectory(), + ServiceManager.getProcessService().getProcessDataDirectory(dataEditor.getProcess()).getPath(), + sourceFolder.getRelativePath()).toUri(); + if (Objects.isNull(sourceFolder) && ServiceManager.getFileService().fileExist(sourceFolderURI)) { Helper.setErrorMessage("noSourceFolderConfiguredInProject"); return; } + generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); + mimeType = sourceFolder.getMimeType(); + use = sourceFolder.getFileGroup(); + mediaVariant = getMediaVariant(); + fileExtension = generatorSource.getFileFormat().getExtension(false); + contentFolders.add(dataEditor.getProcess().getProject().getMediaView()); + contentFolders.add(dataEditor.getProcess().getProject().getPreview()); if (Objects.isNull(contentFolders)) { Helper.setErrorMessage("noImageFolderConfiguredInProject"); - return; } - Subfolder generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); + preparePossiblePositions(); + initPosition(); + } + + private void initPosition() { + TreeNode selectedLogicalNode = dataEditor.getStructurePanel().getSelectedLogicalNode(); + if (Objects.nonNull(selectedLogicalNode) + && selectedLogicalNode.getData() instanceof StructureTreeNode) { + StructureTreeNode structureTreeNode = (StructureTreeNode) selectedLogicalNode.getData(); + if (structureTreeNode.getDataObject() instanceof View) { + if (Objects.nonNull(selectedLogicalNode.getParent()) + && selectedLogicalNode.getParent().getData() instanceof StructureTreeNode + && Objects.nonNull(((StructureTreeNode) selectedLogicalNode.getParent().getData()).getDataObject()) + && ((StructureTreeNode) selectedLogicalNode.getParent().getData()).getDataObject() + instanceof IncludedStructuralElement) { + parent = + (IncludedStructuralElement) ((StructureTreeNode) selectedLogicalNode.getParent().getData()).getDataObject(); + indexSelectedMedia = parent.getViews().indexOf(structureTreeNode.getDataObject()); + + } + } else if (structureTreeNode.getDataObject() instanceof IncludedStructuralElement) { + parent = (IncludedStructuralElement) structureTreeNode.getDataObject(); + } + } + } + + private void preparePossiblePositions() { + possiblePositions = new ArrayList<>(); + TreeNode selectedLogicalNode = dataEditor.getStructurePanel().getSelectedLogicalNode(); + if (Objects.nonNull(selectedLogicalNode) + && selectedLogicalNode.getData() instanceof StructureTreeNode) { + StructureTreeNode structureTreeNode = (StructureTreeNode) selectedLogicalNode.getData(); + if (structureTreeNode.getDataObject() instanceof View) { + possiblePositions.add(new SelectItem(InsertionPosition.BEFORE_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.beforeCurrentElement"))); + possiblePositions.add(new SelectItem(InsertionPosition.AFTER_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.afterCurrentElement"))); + } else { + possiblePositions.add(new SelectItem(InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.asFirstChildOfCurrentElement"))); + possiblePositions.add(new SelectItem(InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT, + Helper.getTranslation("dataEditor.position.asLastChildOfCurrentElement"))); + } + } + } + + private void generateNewUploadedImages() { + List outputs = SubfolderFactoryService.createAll(dataEditor.getProcess(), contentFolders); + ImageGenerator imageGenerator; if (generatorSource.listContents().isEmpty()) { - Helper.setErrorMessage("emptySourceFolder"); + imageGenerator = new ImageGenerator(generatorSource, GenerationMode.ALL, outputs); } else { - List outputs = SubfolderFactoryService.createAll(dataEditor.getProcess(), contentFolders); - ImageGenerator imageGenerator = new ImageGenerator(generatorSource, GenerationMode.MISSING, outputs); - TaskManager.addTask(new TaskImageGeneratorThread(dataEditor.getProcess().getTitle(), imageGenerator)); + imageGenerator = new ImageGenerator(generatorSource, GenerationMode.MISSING, outputs); } + EmptyTask emptyTask = new TaskImageGeneratorThread(dataEditor.getProcess().getTitle(), imageGenerator); + TaskManager.addTask(emptyTask); + generateMediaTasks.add(emptyTask); } - public void refresh() throws InvalidImagesException { - dataEditor.refreshStructurePanel(); - dataEditor.getPaginationPanel().show(); - ServiceManager.getFileService().searchForMedia(dataEditor.getProcess(), dataEditor.getWorkpiece()); - dataEditor.getGalleryPanel().show(); + /** + * Refresh the metadataeditor after uploading media. + */ + public void refresh() throws InvalidImagesException, NoSuchMetadataFieldException { + if (uploadFileUri != null && ServiceManager.getFileService().fileExist(uploadFileUri)) { + ServiceManager.getFileService().searchForMedia(dataEditor.getProcess(), dataEditor.getWorkpiece()); + dataEditor.getSelectedMedia().clear(); + dataEditor.getSelectedMedia().addAll(selectedMedia); + dataEditor.getStructurePanel().show(); + dataEditor.getStructurePanel().preserve(); + dataEditor.refreshStructurePanel(); + dataEditor.getGalleryPanel().show(); + //update selection with the last uploaded file + dataEditor.getStructurePanel().updateLogicalNodeSelection( + dataEditor.getGalleryPanel().getGalleryMediaContent(mediaUnit), parent); + StructureTreeNode structureTreeNode = new StructureTreeNode(mediaUnit.getLabel(), false, false, + MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + dataEditor.switchStructure(structureTreeNode, false); + dataEditor.getPaginationPanel().show(); + uploadFileUri = null; + } } - public void uploadFiles(FileUploadEvent event) { + /** + * Upload media. + * @param event as FileUploadEvent + */ + public void uploadMedia(FileUploadEvent event) { if (event.getFile() != null) { //create MediaUnit and edit workpiece - MediaUnit mediaUnit = MetadataEditor.addMediaUnit(getPhysicalDivType(), dataEditor.getWorkpiece(), + mediaUnit = MetadataEditor.addMediaUnit(getPhysicalDivType(), dataEditor.getWorkpiece(), dataEditor.getWorkpiece().getMediaUnit(), InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT); - - URI fileUri = sourceFolderURI.resolve(event.getFile().getFileName()); - mediaUnit.getMediaFiles().put(mediaVariant, fileUri); + uploadFileUri = sourceFolderURI.resolve(event.getFile().getFileName()); + //TODO: Find a better way to avoid overwriting an existing file + if (ServiceManager.getFileService().fileExist(uploadFileUri)) { + String newFileName = ServiceManager.getFileService().getFileName(uploadFileUri) + + "_" + Helper.generateRandomString(3) + "." + fileExtension; + uploadFileUri = sourceFolderURI.resolve(newFileName); + } + mediaUnit.getMediaFiles().put(mediaVariant, uploadFileUri); switch (selectedPosition) { case FIRST_CHILD_OF_CURRENT_ELEMENT: this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add(0, MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + selectedMedia.add(new ImmutablePair<>(mediaUnit,this.dataEditor.getStructurePanel().getSelectedStructure().get())); break; case LAST_CHILD_OF_CURRENT_ELEMENT: this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add( MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + selectedMedia.add(new ImmutablePair<>(mediaUnit,this.dataEditor.getStructurePanel().getSelectedStructure().get())); + break; + case AFTER_CURRENT_ELEMENT: + parent.getViews().add(indexSelectedMedia + 1, + MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + selectedMedia.add(new ImmutablePair<>(mediaUnit,parent)); + break; + case BEFORE_CURRENT_ELEMENT: + parent.getViews().add(indexSelectedMedia, + MetadataEditor.createUnrestrictedViewOn(mediaUnit)); + selectedMedia.add(new ImmutablePair<>(mediaUnit,parent)); break; default: throw new IllegalArgumentException("Position of new div element is not supported"); - } //upload file in sourceFolder - try (OutputStream outputStream = ServiceManager.getFileService().write(fileUri)) { + try (OutputStream outputStream = ServiceManager.getFileService().write(uploadFileUri)) { IOUtils.copy(event.getFile().getInputstream(), outputStream); } catch (IOException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } + generateNewUploadedImages(); + PrimeFaces.current().executeScript("PF('growl').renderMessage({'summary':'" + + Helper.getTranslation("mediaUploaded", Collections.singletonList(event.getFile().getFileName())) + + "','severity':'info'});"); } - generateNewUploadedImages(); } } diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 9378888986a..b62c494e507 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -159,6 +159,7 @@ cannotDeleteProject=Das Projekt kann nicht gel\u00F6scht werden, solange Vor\u00 cannotDeleteTemplate=Die Produktionsvorlage kann nicht gel\u00F6scht werden, da bereits Vor\u00E4nge auf dieser Grundlage erzeugt wurden. changeDocstructType=Typ des Strukturelements \u00E4ndern choice=Aktionen +choose=Ausw\u00E4hlen chooseFile=Datei ausw\u00E4hlen citation.accessTimestamp=Zugriff\: citation.containedIn=In\: @@ -579,6 +580,7 @@ manuellSingleWorkflow=manuell, regul\u00E4rer Worklflow massDownload=Massendownload massImport=Massenimport masterpieceProperties=Werkst\u00FCckeigenschaft +mediaUploaded={0} wurde erfolgreich hochgeladen mediaWillBeAssigned=ausgew\u00E4hlte Medien werden zugewiesen. meineAufgabenMsg=W\u00E4hlen Sie eine der unten gelisteten Aufgaben zur Bearbeitung aus. messageAdd=Nachricht hinzuf\u00FCgen @@ -1009,7 +1011,7 @@ uncounted=unnummeriert unlocked=Entsperrt up=hoch updateType=Art der Aktualisierung -upload=Images hochladen +upload=Hochladen uploadFile=Datei hochladen uploadImport=Dateiupload-Import uploadMedia=Medien hochladen diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index ad4200d85e3..afad1930a37 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -163,6 +163,7 @@ cannotDeleteProject=The project cannot be deleted when processes exist in this p cannotDeleteTemplate=This template cannot be deleted because it has already been used to create processes. changeDocstructType=Change docstruct type choice=Actions +choose=Choose chooseFile=Choose file citation.accessTimestamp=Accessed\: citation.containedIn=In\: @@ -591,6 +592,7 @@ manuellSingleWorkflow=Manual massDownload=Bulk downloads massImport=Mass import masterpieceProperties=workpiece property +mediaUploaded={0} is uploaded successfully mediaWillBeAssigned=selected media will be assigned. meineAufgabenMsg=Please select one of the listed tasks. messageAdd=Add message @@ -1025,7 +1027,7 @@ uncounted=uncounted unlocked=Unlocked up=up updateType=Update type -upload=Upload images +upload=Upload uploadFile=upload file uploadImport=file upload import uploadMedia=Upload media diff --git a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css index a71ded4507e..469916f1785 100644 --- a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css +++ b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css @@ -1749,12 +1749,33 @@ form#metadata div label, } #uploadFileDialog { - padding: 10px; + padding: 20px; + max-height: 550px; } -#uploadFileDialogForm { - height: 100%; - overflow-y: scroll; +#uploadFileDialog_content { + box-sizing: border-box; + overflow: visible; + padding: 0; +} + +#uploadFileDialog .ui-fileupload-buttonbar { + float: none; + text-align: right; +} + +#uploadFileDialog .dialogButtonWrapper { + margin-bottom: 10px; +} + +#uploadFileDialogForm\:progressBar .ui-progressbar-value { + background: #85b2cb; +} + +#uploadFileDialogForm, +#uploadFileDialogForm\:uploadFileGrid, +#uploadFileDialogForm\:uploadFileGrid_content{ + height: 90%; } #metadataAccordion\:metadata .ui-treetable-indent, diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml index ed20fcc23ed..6af4074e652 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml @@ -21,15 +21,17 @@ widgetVar="uploadFileDialog" width="600" height="550" + closable="true" modal="true" resizable="false" showHeader="false" dynamic="true" appendTo="@(body)"> + - -

#{msgs.fileUpload}

+ +

#{msgs.uploadMedia}

@@ -40,34 +42,60 @@
-
-
- + + -
+ update="logicalTree,metadataAccordion:logicalMetadataWrapperPanel,paginationForm:paginationWrapperPanel,galleryWrapperPanel" + oncomplete="PF('uploadFileDialog').hide();"/> +
+
diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml index a260fd963d2..0f4d7782b8e 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml @@ -388,6 +388,15 @@ metadataAccordion:logicalMetadataWrapperPanel @(.structureElementDataList) imagePreviewForm:mediaContextMenu"/> + + - Date: Wed, 26 May 2021 13:19:25 +0200 Subject: [PATCH 06/16] Delete unsaved uploaded media if the user exit the metadataeditor without saving the changes. --- .../forms/dataeditor/DataEditorForm.java | 29 +++++++++++++++++++ .../forms/dataeditor/UploadFileDialog.java | 1 + 2 files changed, 30 insertions(+) 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 fe96b22d85b..6a70f00426e 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 @@ -15,6 +15,7 @@ import java.io.OutputStream; import java.io.Serializable; import java.net.URI; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; @@ -43,6 +44,7 @@ import org.kitodo.api.dataformat.Workpiece; import org.kitodo.api.validation.State; import org.kitodo.api.validation.ValidationResult; +import org.kitodo.config.ConfigCore; import org.kitodo.data.database.beans.DataEditorSetting; import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.User; @@ -180,6 +182,8 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable { private static final String DESKTOP_LINK = "/pages/desktop.jsf"; + private List notSavedUploadedMedia = new ArrayList<>(); + /** * Public constructor. */ @@ -310,6 +314,7 @@ private void init() { * @return the referring view, to return there */ public String close() { + deleteNotSavedUploadedMedia(); metadataPanel.clear(); structurePanel.clear(); workpiece = null; @@ -328,6 +333,20 @@ public String close() { } } + private void deleteNotSavedUploadedMedia() { + URI uri = Paths.get(ConfigCore.getKitodoDataDirectory(), + ServiceManager.getProcessService().getProcessDataDirectory(this.process).getPath()).toUri(); + for (MediaUnit mediaUnit : this.notSavedUploadedMedia) { + for (URI fileURI : mediaUnit.getMediaFiles().values()) { + try { + ServiceManager.getFileService().delete(uri.resolve(fileURI)); + } catch (IOException e) { + logger.error(e.getMessage()); + } + } + } + } + /** * Validate the structure and metadata. * @@ -379,6 +398,7 @@ private String save(boolean close) { try (OutputStream out = ServiceManager.getFileService().write(mainFileUri)) { ServiceManager.getMetsService().save(workpiece, out); ServiceManager.getProcessService().saveToIndex(process,false); + notSavedUploadedMedia.clear(); if (close) { return close(); } else { @@ -439,6 +459,15 @@ public String getAcquisitionStage() { return acquisitionStage; } + /** + * Get notSavedUploadedMedia. + * + * @return value of notSavedUploadedMedia + */ + public List getNotSavedUploadedMedia() { + return notSavedUploadedMedia; + } + /** * Returns the backing bean for the add doc struc type dialog. This function * is used by PrimeFaces to access the elements of the add doc struc type 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 73d89b1611d..54911de93a6 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 @@ -360,6 +360,7 @@ public void uploadMedia(FileUploadEvent event) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } generateNewUploadedImages(); + dataEditor.getNotSavedUploadedMedia().add(mediaUnit); PrimeFaces.current().executeScript("PF('growl').renderMessage({'summary':'" + Helper.getTranslation("mediaUploaded", Collections.singletonList(event.getFile().getFileName())) + "','severity':'info'});"); From fed627b6dbcead07ba409c6ee1f8224792b1c57b Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Thu, 27 May 2021 12:07:26 +0200 Subject: [PATCH 07/16] Fix not found folders --- .../forms/dataeditor/UploadFileDialog.java | 50 ++++++++++++++----- .../includes/metadataEditor/gallery.xhtml | 2 - .../metadataEditor/logicalStructure.xhtml | 1 - 3 files changed, 37 insertions(+), 16 deletions(-) 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 54911de93a6..04dc2d1414d 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 @@ -38,6 +38,7 @@ import org.kitodo.exceptions.NoSuchMetadataFieldException; import org.kitodo.production.enums.GenerationMode; import org.kitodo.production.helper.Helper; +import org.kitodo.production.helper.VariableReplacer; import org.kitodo.production.helper.tasks.EmptyTask; import org.kitodo.production.helper.tasks.TaskManager; import org.kitodo.production.metadata.InsertionPosition; @@ -212,26 +213,49 @@ public void prepare() { progress = 0; generateMediaTasks = new ArrayList<>(); selectedMedia = new LinkedList<>(); - sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); - sourceFolderURI = Paths.get(ConfigCore.getKitodoDataDirectory(), - ServiceManager.getProcessService().getProcessDataDirectory(dataEditor.getProcess()).getPath(), - sourceFolder.getRelativePath()).toUri(); - if (Objects.isNull(sourceFolder) && ServiceManager.getFileService().fileExist(sourceFolderURI)) { - Helper.setErrorMessage("noSourceFolderConfiguredInProject"); - return; - } + if (!setUpFolders()) { return; } generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); mimeType = sourceFolder.getMimeType(); use = sourceFolder.getFileGroup(); mediaVariant = getMediaVariant(); fileExtension = generatorSource.getFileFormat().getExtension(false); - contentFolders.add(dataEditor.getProcess().getProject().getMediaView()); - contentFolders.add(dataEditor.getProcess().getProject().getPreview()); - if (Objects.isNull(contentFolders)) { - Helper.setErrorMessage("noImageFolderConfiguredInProject"); - } preparePossiblePositions(); initPosition(); + PrimeFaces.current().executeScript("PF('uploadFileDialog').show()"); + } + + private boolean setUpFolders() { + VariableReplacer variableReplacer = new VariableReplacer(null, null, dataEditor.getProcess(), null); + sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); + Folder mediaView = dataEditor.getProcess().getProject().getMediaView(); + Folder preview = dataEditor.getProcess().getProject().getPreview(); + + sourceFolder.setPath(variableReplacer.replace(sourceFolder.getRelativePath())); + mediaView.setPath(variableReplacer.replace(mediaView.getRelativePath())); + preview.setPath(variableReplacer.replace(preview.getRelativePath())); + + if ( folderExists(sourceFolder) && folderExists(mediaView) && folderExists(preview)) { + sourceFolderURI = getFolderURI(sourceFolder); + contentFolders.add(mediaView); + contentFolders.add(preview); + return true; + } + return false; + } + + private boolean folderExists(Folder folder) { + URI folderURI = getFolderURI(folder); + if (!ServiceManager.getFileService().fileExist(folderURI)) { + Helper.setErrorMessage("errorDirectoryNotFound", new Object[] {folderURI}); + return false; + } + return true; + } + + private URI getFolderURI(Folder folder) { + return Paths.get(ConfigCore.getKitodoDataDirectory(), + ServiceManager.getProcessService().getProcessDataDirectory(dataEditor.getProcess()).getPath(), + folder.getRelativePath()).toUri(); } private void initPosition() { diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml index 0f4d7782b8e..77e9f886c39 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml @@ -391,7 +391,6 @@ Date: Thu, 27 May 2021 13:24:24 +0200 Subject: [PATCH 08/16] Make maximum uploaded media at the same time configurable --- .../java/org/kitodo/config/enums/ParameterCore.java | 5 +++++ .../production/forms/dataeditor/UploadFileDialog.java | 11 +++++++++++ Kitodo/src/main/resources/kitodo_config.properties | 3 +++ .../includes/metadataEditor/dialogs/uploadFile.xhtml | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java index 0a5fa812d5d..a4f23fe177a 100644 --- a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java +++ b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java @@ -313,6 +313,11 @@ public enum ParameterCore implements ParameterInterface { */ METS_EDITOR_DISPLAY_FILE_MANIPULATION(new Parameter("metsEditor.displayFileManipulation")), + /** + * Maximum number of media that can be uploaded at the same time in mets editor. + */ + METS_EDITOR_MAX_UPLOADED_MEDIA(new Parameter("metsEditor.maxUploadedMedia")), + /** * Comma-separated list of Strings which may be enclosed in double quotes. * Separators available for double page pagination modes. 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 04dc2d1414d..ccc369622a7 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 @@ -33,6 +33,7 @@ import org.kitodo.api.dataformat.MediaVariant; import org.kitodo.api.dataformat.View; import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; import org.kitodo.data.database.beans.Folder; import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.exceptions.NoSuchMetadataFieldException; @@ -72,6 +73,7 @@ public class UploadFileDialog { private MediaUnit mediaUnit; private URI uploadFileUri; private Subfolder generatorSource; + private int fileLimit = ConfigCore.getIntParameter(ParameterCore.METS_EDITOR_MAX_UPLOADED_MEDIA); private List> selectedMedia = new LinkedList<>(); private Integer progress; private List generateMediaTasks = new ArrayList<>(); @@ -103,6 +105,15 @@ public void setFileExtension(String fileExtension) { this.fileExtension = fileExtension; } + /** + * Get fileLimit. + * + * @return value of fileLimit + */ + public int getFileLimit() { + return fileLimit; + } + /** * Get file. * diff --git a/Kitodo/src/main/resources/kitodo_config.properties b/Kitodo/src/main/resources/kitodo_config.properties index fcb042a01f8..5f1a556f7c0 100644 --- a/Kitodo/src/main/resources/kitodo_config.properties +++ b/Kitodo/src/main/resources/kitodo_config.properties @@ -291,6 +291,9 @@ metsEditor.pageSeparators=" " # Priority list of metadata keys used to display title information in the metadata editors structure and gallery panels metsEditor.titleMetadata=TitleDocMain +#Maximum number of media to be uploaded. +metsEditor.maxUploadedMedia=3 + # ----------------------------------- # backup of metadata configuration # ----------------------------------- diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml index 6af4074e652..d521a306c16 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml @@ -51,7 +51,7 @@ multiple="true" update="growl" dragDropSupport="false" - fileLimit="3" + fileLimit="#{DataEditorForm.uploadFileDialog.fileLimit}" sequential="true" allowTypes="/(\.|\/)(#{DataEditorForm.uploadFileDialog.fileExtension})$/" chooseIcon="fa fa-plus fa-lg" From 1db0994f4cc0bf9324e99c48cb64140aa1dd9505 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Fri, 4 Jun 2021 09:21:57 +0200 Subject: [PATCH 09/16] Remove migration file --- ...2_104__Add_Authoriies_for_upload_media.sql | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql deleted file mode 100644 index 1574a811b6b..00000000000 --- a/Kitodo-DataManagement/src/main/resources/db/migration/V2_104__Add_Authoriies_for_upload_media.sql +++ /dev/null @@ -1,20 +0,0 @@ --- --- (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. --- - --- Insert authorities for upload media in metadataeditor. - -INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_globalAssignable'); -INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_clientAssignable'); - -INSERT IGNORE INTO role_x_authority (role_id, authority_id) -SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_globalAssignable'; -INSERT IGNORE INTO role_x_authority (role_id, authority_id) -SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_clientAssignable'; From 8e8dbdf6e74e55190bac648e70e862f0d073fde6 Mon Sep 17 00:00:00 2001 From: Ikram Maalej Date: Tue, 8 Jun 2021 01:12:22 +0200 Subject: [PATCH 10/16] Code improvement part 2 --- .../forms/dataeditor/DataEditorForm.java | 16 +- .../forms/dataeditor/UploadFileDialog.java | 196 ++++++++++-------- .../resources/messages/messages_de.properties | 1 + .../resources/messages/messages_en.properties | 1 + .../webapp/WEB-INF/resources/css/kitodo.css | 10 + .../metadataEditor/dialogs/uploadFile.xhtml | 24 +-- 6 files changed, 143 insertions(+), 105 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 6a70f00426e..6fe06364fd8 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 @@ -182,7 +182,7 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable { private static final String DESKTOP_LINK = "/pages/desktop.jsf"; - private List notSavedUploadedMedia = new ArrayList<>(); + private List unsavedUploadedMedia = new ArrayList<>(); /** * Public constructor. @@ -259,6 +259,7 @@ public String open(String processID, String referringView) { return referringView; } selectedMedia = new LinkedList<>(); + unsavedUploadedMedia = new ArrayList<>(); init(); MetadataLock.setLocked(process.getId(), user); } catch (IOException | DAOException | InvalidImagesException | NoSuchElementException e) { @@ -336,7 +337,7 @@ public String close() { private void deleteNotSavedUploadedMedia() { URI uri = Paths.get(ConfigCore.getKitodoDataDirectory(), ServiceManager.getProcessService().getProcessDataDirectory(this.process).getPath()).toUri(); - for (MediaUnit mediaUnit : this.notSavedUploadedMedia) { + for (MediaUnit mediaUnit : this.unsavedUploadedMedia) { for (URI fileURI : mediaUnit.getMediaFiles().values()) { try { ServiceManager.getFileService().delete(uri.resolve(fileURI)); @@ -345,6 +346,7 @@ private void deleteNotSavedUploadedMedia() { } } } + this.unsavedUploadedMedia.clear(); } /** @@ -398,7 +400,7 @@ private String save(boolean close) { try (OutputStream out = ServiceManager.getFileService().write(mainFileUri)) { ServiceManager.getMetsService().save(workpiece, out); ServiceManager.getProcessService().saveToIndex(process,false); - notSavedUploadedMedia.clear(); + unsavedUploadedMedia.clear(); if (close) { return close(); } else { @@ -460,12 +462,12 @@ public String getAcquisitionStage() { } /** - * Get notSavedUploadedMedia. + * Get unsavedUploadedMedia. * - * @return value of notSavedUploadedMedia + * @return value of unsavedUploadedMedia */ - public List getNotSavedUploadedMedia() { - return notSavedUploadedMedia; + public List getUnsavedUploadedMedia() { + return unsavedUploadedMedia; } /** 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 ccc369622a7..8a152b9d0c3 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 @@ -17,12 +17,16 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; +import javax.faces.application.FacesMessage; import javax.faces.model.SelectItem; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -195,11 +199,6 @@ private Integer updateProgress() { } } - public void resetProgress() { - progress = 0; - generateMediaTasks.clear(); - } - private MediaVariant getMediaVariant() { MediaVariant mediaVariant = new MediaVariant(); mediaVariant.setMimeType(mimeType); @@ -217,26 +216,8 @@ private String getPhysicalDivType() { return MediaUnit.TYPE_OTHER; } - /** - * Prepare popup dialog. - */ - public void prepare() { - progress = 0; - generateMediaTasks = new ArrayList<>(); - selectedMedia = new LinkedList<>(); - if (!setUpFolders()) { return; } - generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); - mimeType = sourceFolder.getMimeType(); - use = sourceFolder.getFileGroup(); - mediaVariant = getMediaVariant(); - fileExtension = generatorSource.getFileFormat().getExtension(false); - preparePossiblePositions(); - initPosition(); - PrimeFaces.current().executeScript("PF('uploadFileDialog').show()"); - } - private boolean setUpFolders() { - VariableReplacer variableReplacer = new VariableReplacer(null, null, dataEditor.getProcess(), null); + VariableReplacer variableReplacer = new VariableReplacer(null, dataEditor.getProcess(), null); sourceFolder = dataEditor.getProcess().getProject().getGeneratorSource(); Folder mediaView = dataEditor.getProcess().getProject().getMediaView(); Folder preview = dataEditor.getProcess().getProject().getPreview(); @@ -245,7 +226,7 @@ private boolean setUpFolders() { mediaView.setPath(variableReplacer.replace(mediaView.getRelativePath())); preview.setPath(variableReplacer.replace(preview.getRelativePath())); - if ( folderExists(sourceFolder) && folderExists(mediaView) && folderExists(preview)) { + if (folderExists(sourceFolder) && folderExists(mediaView) && folderExists(preview)) { sourceFolderURI = getFolderURI(sourceFolder); contentFolders.add(mediaView); contentFolders.add(preview); @@ -254,10 +235,15 @@ private boolean setUpFolders() { return false; } + private void sortViews(List views) { + views.sort(Comparator.comparing(v -> FilenameUtils.getBaseName( + v.getMediaUnit().getMediaFiles().entrySet().iterator().next().getValue().getPath()))); + } + private boolean folderExists(Folder folder) { URI folderURI = getFolderURI(folder); if (!ServiceManager.getFileService().fileExist(folderURI)) { - Helper.setErrorMessage("errorDirectoryNotFound", new Object[] {folderURI}); + Helper.setErrorMessage("errorDirectoryNotFound", new Object[]{folderURI}); return false; } return true; @@ -311,52 +297,36 @@ private void preparePossiblePositions() { } } - private void generateNewUploadedImages() { - List outputs = SubfolderFactoryService.createAll(dataEditor.getProcess(), contentFolders); - ImageGenerator imageGenerator; - if (generatorSource.listContents().isEmpty()) { - imageGenerator = new ImageGenerator(generatorSource, GenerationMode.ALL, outputs); - } else { - imageGenerator = new ImageGenerator(generatorSource, GenerationMode.MISSING, outputs); - } - EmptyTask emptyTask = new TaskImageGeneratorThread(dataEditor.getProcess().getTitle(), imageGenerator); - TaskManager.addTask(emptyTask); - generateMediaTasks.add(emptyTask); - } - /** - * Refresh the metadataeditor after uploading media. + * Prepare popup dialog. */ - public void refresh() throws InvalidImagesException, NoSuchMetadataFieldException { - if (uploadFileUri != null && ServiceManager.getFileService().fileExist(uploadFileUri)) { - ServiceManager.getFileService().searchForMedia(dataEditor.getProcess(), dataEditor.getWorkpiece()); - dataEditor.getSelectedMedia().clear(); - dataEditor.getSelectedMedia().addAll(selectedMedia); - dataEditor.getStructurePanel().show(); - dataEditor.getStructurePanel().preserve(); - dataEditor.refreshStructurePanel(); - dataEditor.getGalleryPanel().show(); - //update selection with the last uploaded file - dataEditor.getStructurePanel().updateLogicalNodeSelection( - dataEditor.getGalleryPanel().getGalleryMediaContent(mediaUnit), parent); - StructureTreeNode structureTreeNode = new StructureTreeNode(mediaUnit.getLabel(), false, false, - MetadataEditor.createUnrestrictedViewOn(mediaUnit)); - dataEditor.switchStructure(structureTreeNode, false); - dataEditor.getPaginationPanel().show(); - uploadFileUri = null; - } + public void prepare() { + progress = 0; + generateMediaTasks = new ArrayList<>(); + selectedMedia = new LinkedList<>(); + if (!setUpFolders()) { return; } + generatorSource = new Subfolder(dataEditor.getProcess(), sourceFolder); + mimeType = sourceFolder.getMimeType(); + use = sourceFolder.getFileGroup(); + mediaVariant = getMediaVariant(); + fileExtension = generatorSource.getFileFormat().getExtension(false); + preparePossiblePositions(); + initPosition(); + PrimeFaces.current().executeScript("PF('uploadFileDialog').show()"); } /** * Upload media. + * * @param event as FileUploadEvent */ public void uploadMedia(FileUploadEvent event) { if (event.getFile() != null) { - //create MediaUnit and edit workpiece + mediaUnit = MetadataEditor.addMediaUnit(getPhysicalDivType(), dataEditor.getWorkpiece(), dataEditor.getWorkpiece().getMediaUnit(), InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT); uploadFileUri = sourceFolderURI.resolve(event.getFile().getFileName()); + //TODO: Find a better way to avoid overwriting an existing file if (ServiceManager.getFileService().fileExist(uploadFileUri)) { String newFileName = ServiceManager.getFileService().getFileName(uploadFileUri) @@ -364,41 +334,95 @@ public void uploadMedia(FileUploadEvent event) { uploadFileUri = sourceFolderURI.resolve(newFileName); } mediaUnit.getMediaFiles().put(mediaVariant, uploadFileUri); - switch (selectedPosition) { - case FIRST_CHILD_OF_CURRENT_ELEMENT: - this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add(0, - MetadataEditor.createUnrestrictedViewOn(mediaUnit)); - selectedMedia.add(new ImmutablePair<>(mediaUnit,this.dataEditor.getStructurePanel().getSelectedStructure().get())); - break; - case LAST_CHILD_OF_CURRENT_ELEMENT: - this.dataEditor.getStructurePanel().getSelectedStructure().get().getViews().add( - MetadataEditor.createUnrestrictedViewOn(mediaUnit)); - selectedMedia.add(new ImmutablePair<>(mediaUnit,this.dataEditor.getStructurePanel().getSelectedStructure().get())); - break; - case AFTER_CURRENT_ELEMENT: - parent.getViews().add(indexSelectedMedia + 1, - MetadataEditor.createUnrestrictedViewOn(mediaUnit)); - selectedMedia.add(new ImmutablePair<>(mediaUnit,parent)); - break; - case BEFORE_CURRENT_ELEMENT: - parent.getViews().add(indexSelectedMedia, - MetadataEditor.createUnrestrictedViewOn(mediaUnit)); - selectedMedia.add(new ImmutablePair<>(mediaUnit,parent)); - break; - default: - throw new IllegalArgumentException("Position of new div element is not supported"); - } //upload file in sourceFolder try (OutputStream outputStream = ServiceManager.getFileService().write(uploadFileUri)) { IOUtils.copy(event.getFile().getInputstream(), outputStream); } catch (IOException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } - generateNewUploadedImages(); - dataEditor.getNotSavedUploadedMedia().add(mediaUnit); - PrimeFaces.current().executeScript("PF('growl').renderMessage({'summary':'" + dataEditor.getUnsavedUploadedMedia().add(mediaUnit); + selectedMedia.add(new ImmutablePair(mediaUnit, parent)); + PrimeFaces.current().executeScript("PF('notifications').renderMessage({'summary':'" + Helper.getTranslation("mediaUploaded", Collections.singletonList(event.getFile().getFileName())) + "','severity':'info'});"); } } + + /** + * Generate newly uploaded media. + */ + public void generateNewUploadedMedia() { + List outputs = SubfolderFactoryService.createAll(dataEditor.getProcess(), contentFolders); + ImageGenerator imageGenerator; + if (generatorSource.listContents().isEmpty()) { + imageGenerator = new ImageGenerator(generatorSource, GenerationMode.ALL, outputs); + } else { + imageGenerator = new ImageGenerator(generatorSource, GenerationMode.MISSING, outputs); + } + EmptyTask emptyTask = new TaskImageGeneratorThread(dataEditor.getProcess().getTitle(), imageGenerator); + TaskManager.addTask(emptyTask); + generateMediaTasks.add(emptyTask); + } + + /** + * Reset the progress bar after generating media is completed and update the workpiece. + */ + public void updateWorkpiece() throws InvalidImagesException, NoSuchMetadataFieldException { + progress = 0; + generateMediaTasks.clear(); + addMediaToWorkpiece(); + refresh(); + Helper.setMessage(Helper.getTranslation("uploadMediaCompleted")); + } + + private void addMediaToWorkpiece() throws InvalidImagesException { + ServiceManager.getFileService().searchForMedia(dataEditor.getProcess(), dataEditor.getWorkpiece()); + + List views = selectedMedia.stream() + .map(v -> MetadataEditor.createUnrestrictedViewOn(v.getKey())) + .collect(Collectors.toList()); + sortViews(views); + switch (selectedPosition) { + case FIRST_CHILD_OF_CURRENT_ELEMENT: + parent.getViews().addAll(0, views); + break; + case LAST_CHILD_OF_CURRENT_ELEMENT: + parent.getViews().addAll(views); + break; + case AFTER_CURRENT_ELEMENT: + parent.getViews().addAll(indexSelectedMedia + 1, views); + break; + case BEFORE_CURRENT_ELEMENT: + parent.getViews().addAll(indexSelectedMedia, views); + break; + default: + throw new IllegalArgumentException("Position of new div element is not supported"); + } + } + + /** + * Refresh the metadataeditor after uploading media. + */ + public void refresh() throws NoSuchMetadataFieldException { + if (uploadFileUri != null && ServiceManager.getFileService().fileExist(uploadFileUri)) { + selectedMedia.sort((Comparator.comparing(v -> FilenameUtils.getBaseName( + v.getKey().getMediaFiles().entrySet().iterator().next().getValue().getPath())))); + dataEditor.getSelectedMedia().clear(); + dataEditor.getSelectedMedia().addAll(selectedMedia); + dataEditor.getStructurePanel().show(); + dataEditor.getStructurePanel().preserve(); + dataEditor.refreshStructurePanel(); + dataEditor.getGalleryPanel().show(); + dataEditor.getStructurePanel().updateLogicalNodeSelection( + dataEditor.getGalleryPanel().getGalleryMediaContent(selectedMedia.get(selectedMedia.size() - 1).getKey()), parent); + StructureTreeNode structureTreeNode = new StructureTreeNode(selectedMedia.get(selectedMedia.size() - 1).getKey().getLabel(), + false, false, + MetadataEditor.createUnrestrictedViewOn(selectedMedia.get(selectedMedia.size() - 1).getKey())); + dataEditor.switchStructure(structureTreeNode, false); + dataEditor.getPaginationPanel().show(); + uploadFileUri = null; + } + } + + } diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index b62c494e507..d51a7f92383 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -1015,6 +1015,7 @@ upload=Hochladen uploadFile=Datei hochladen uploadImport=Dateiupload-Import uploadMedia=Medien hochladen +uploadMediaCompleted=Hochladen und Generieren neuer Medien wurde erfolgreich beendet. uriMalformed=Der URI hat ein falsches Format. url=URL useExistingWorkflow=Bestehenden Workflow verwenden diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index afad1930a37..ec063aac371 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -1031,6 +1031,7 @@ upload=Upload uploadFile=upload file uploadImport=file upload import uploadMedia=Upload media +uploadMediaCompleted=Uploading and generating new media has been completed successfully. uriMalformed=The URI is malformed. url=URL useExistingWorkflow=Use existing workflow diff --git a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css index 469916f1785..185bf806a2d 100644 --- a/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css +++ b/Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css @@ -1772,6 +1772,16 @@ form#metadata div label, background: #85b2cb; } +#primefacesmessagedlg .ui-dialog-titlebar { + background: #52B415; + display: block; +} + +#primefacesmessagedlg .ui-dialog-content { + text-align: center; + padding-left: 5px; +} + #uploadFileDialogForm, #uploadFileDialogForm\:uploadFileGrid, #uploadFileDialogForm\:uploadFileGrid_content{ diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml index d521a306c16..f2acd5db7ca 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml @@ -27,8 +27,10 @@ showHeader="false" dynamic="true" appendTo="@(body)"> - +

#{msgs.uploadMedia}

@@ -46,10 +48,9 @@ widgetVar="uploadMedia" value="#{DataEditorForm.uploadFileDialog.file}" fileUploadListener="#{DataEditorForm.uploadFileDialog.uploadMedia}" - oncomplete="handleMultiFileUploadRequest(this);" + oncomplete="handleLastFileUploadRequest(this);" mode="advanced" multiple="true" - update="growl" dragDropSupport="false" fileLimit="#{DataEditorForm.uploadFileDialog.fileLimit}" sequential="true" @@ -69,26 +70,25 @@ value="#{DataEditorForm.uploadFileDialog.progress}" labelTemplate="{value}%" global="false"> + listener="#{DataEditorForm.uploadFileDialog.updateWorkpiece()}" + oncomplete="PF('uploadFileDialog').hide();" + update="logicalTree,metadataAccordion:logicalMetadataWrapperPanel,paginationForm:paginationWrapperPanel,galleryWrapperPanel"/> + styleClass="secondary right"/>
-