diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/DataEditorSetting.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/DataEditorSetting.java index 93d18fd5428..c43218eed5c 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/DataEditorSetting.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/DataEditorSetting.java @@ -22,8 +22,8 @@ public class DataEditorSetting extends BaseBean { @Column(name = "user_id") private int userId; - @Column(name = "task_id") - private int taskId; + @Column(name = "task_id", nullable = true) + private Integer taskId; @Column(name = "structure_width") private float structureWidth; @@ -59,20 +59,20 @@ public void setUserId(int userId) { } /** - * Get taskId. + * Get taskId. Either the id of the task or null, for a task-independent default layout. * * @return value of taskId */ - public int getTaskId() { + public Integer getTaskId() { return taskId; } /** - * Set taskId. + * Set taskId. Either the id of the task or null, for a task-independent default layout. * * @param taskId as int */ - public void setTaskId(int taskId) { + public void setTaskId(Integer taskId) { this.taskId = taskId; } diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_133__Allow_null_for_taskid_in_dataeditorsetting.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_133__Allow_null_for_taskid_in_dataeditorsetting.sql new file mode 100644 index 00000000000..64496cd7986 --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_133__Allow_null_for_taskid_in_dataeditorsetting.sql @@ -0,0 +1,17 @@ +-- +-- (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. +-- + +SET SQL_SAFE_UPDATES = 0; + +-- allow null in column task_id of table dataeditor_setting to store task-independent layout +ALTER TABLE dataeditor_setting MODIFY COLUMN task_id INT(11) NULL; + +SET SQL_SAFE_UPDATES = 1; \ No newline at end of file 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 f4425d7034b..2e4b2ccec74 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 @@ -313,10 +313,15 @@ public void open(String processID, String referringView, String taskId) { } private void showDataEditorSettingsLoadedMessage() throws DAOException { - String task = ServiceManager.getTaskService().getById(templateTaskId).getTitle(); Locale locale = LocaleHelper.getCurrentLocale(); String title = Helper.getString(locale, "dataEditor.layoutLoadedSuccessfullyTitle"); - String text = MessageFormat.format(Helper.getString(locale, "dataEditor.layoutLoadedSuccessfullyText"), task); + String text = Helper.getString(locale, "dataEditor.layoutLoadedSuccessfullyDefaultText"); + if (templateTaskId > 0) { + String task = ServiceManager.getTaskService().getById(templateTaskId).getTitle(); + text = MessageFormat.format( + Helper.getString(locale, "dataEditor.layoutLoadedSuccessfullyForTaskText"), task + ); + } String script = GROWL_MESSAGE.replace("SUMMARY", title).replace("DETAIL", text) .replace("SEVERITY", "info"); PrimeFaces.current().executeScript("PF('notifications').removeAll();"); @@ -338,16 +343,13 @@ private void checkProjectFolderConfiguration() { } private void loadDataEditorSettings() { - if (templateTaskId > 0) { - dataEditorSetting = ServiceManager.getDataEditorSettingService().loadDataEditorSetting(user.getId(), - templateTaskId); - if (Objects.isNull(dataEditorSetting)) { - dataEditorSetting = new DataEditorSetting(); - dataEditorSetting.setUserId(user.getId()); - dataEditorSetting.setTaskId(templateTaskId); - } - } else { - dataEditorSetting = null; + // use template task id if it exists, otherwise use null for task-independent layout + Integer taskId = templateTaskId > 0 ? templateTaskId : null; + dataEditorSetting = ServiceManager.getDataEditorSettingService().loadDataEditorSetting(user.getId(), taskId); + if (Objects.isNull(dataEditorSetting)) { + dataEditorSetting = new DataEditorSetting(); + dataEditorSetting.setUserId(user.getId()); + dataEditorSetting.setTaskId(taskId); } } @@ -1068,7 +1070,7 @@ public void updateNumberOfScans() { * Save current metadata editor layout. */ public void saveDataEditorSetting() { - if (Objects.nonNull(dataEditorSetting) && dataEditorSetting.getTaskId() > 0) { + if (Objects.nonNull(dataEditorSetting)) { try { ServiceManager.getDataEditorSettingService().saveToDatabase(dataEditorSetting); PrimeFaces.current().executeScript("PF('dataEditorSavingResultDialog').show();"); @@ -1076,6 +1078,7 @@ public void saveDataEditorSetting() { Helper.setErrorMessage("errorSaving", new Object[] {ObjectType.USER.getTranslationSingular() }, logger, e); } } else { + // should never happen any more, since layout settings are always created (even outside of task context) logger.error("Could not save DataEditorSettings with userId {} and templateTaskId {}", user.getId(), templateTaskId); } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/DataEditorSettingService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/DataEditorSettingService.java index 706a1134e31..926aeef477f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/DataEditorSettingService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/DataEditorSettingService.java @@ -89,11 +89,11 @@ public boolean areDataEditorSettingsDefinedForWorkflow(Workflow workflow) { /** * Delete data editor settings identified by task id. - * @param taskId ID of the associated task + * @param taskId ID of the associated task (or null for task-independent default layout) * @throws DAOException if data editor setting could not be deleted from database * */ - public void removeFromDatabaseByTaskId(int taskId) throws DAOException { + public void removeFromDatabaseByTaskId(Integer taskId) throws DAOException { List dataEditorSettings = getByTaskId(taskId); for (DataEditorSetting dataEditorSetting: dataEditorSettings) { dao.remove(dataEditorSetting.getId()); @@ -102,30 +102,41 @@ public void removeFromDatabaseByTaskId(int taskId) throws DAOException { /** * Retrieve data editor settings by task id. - * @param taskId ID of the task + * @param taskId ID of the task (or null for task-independent default layout) * * @return List of DataEditorSetting objects */ - public List getByTaskId(int taskId) { + public List getByTaskId(Integer taskId) { Map parameterMap = new HashMap<>(); - parameterMap.put("taskId", taskId); - return getByQuery("FROM DataEditorSetting WHERE task_id = :taskId ORDER BY id ASC", parameterMap); + if (Objects.nonNull(taskId)) { + parameterMap.put("taskId", taskId); + return getByQuery("FROM DataEditorSetting WHERE task_id = :taskId ORDER BY id ASC", parameterMap); + } + return getByQuery("FROM DataEditorSetting WHERE task_id is NULL ORDER BY id ASC", parameterMap); } - private List getByUserAndTask(int userId, int taskId) { + private List getByUserAndTask(int userId, Integer taskId) { Map parameterMap = new HashMap<>(); parameterMap.put("userId", userId); - parameterMap.put("taskId", taskId); - return getByQuery("FROM DataEditorSetting WHERE user_id = :userId AND task_id = :taskId ORDER BY id ASC", parameterMap); + if (Objects.nonNull(taskId)) { + parameterMap.put("taskId", taskId); + return getByQuery( + "FROM DataEditorSetting WHERE user_id = :userId AND task_id = :taskId ORDER BY id ASC", parameterMap + ); + } + return getByQuery( + "FROM DataEditorSetting WHERE user_id = :userId AND task_id IS NULL ORDER BY id ASC", parameterMap + ); } /** * Load DataEditorSetting from database or return null if no entry matches the specified ids. * @param userId id of the user - * @param taskId id of the corresponding template task for the task that is currently edited + * @param taskId id of the corresponding template task for the task that is currently edited + * (or null for task-independent default layout) * @return settings for the data editor */ - public DataEditorSetting loadDataEditorSetting(int userId, int taskId) { + public DataEditorSetting loadDataEditorSetting(int userId, Integer taskId) { List results = getByUserAndTask(userId, taskId); if (Objects.nonNull(results) && !results.isEmpty()) { return results.get(0); diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index fe2485120bf..c6193009791 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -281,7 +281,6 @@ dataEditor.addMetadata.newMetadata=Neue Metadaten hinzuf\u00FCgen dataEditor.addMetadata.noMetadataAddable=Zu dem ausgew\u00E4hlten Strukturelement k\u00F6nnen keine weiteren Metadaten hinzugef\u00FCgt werden! dataEditor.addMetadata.noMetadataAddableToGroup=Zu dieser Gruppe k\u00F6nnen keine weiteren Metadaten hinzugef\u00FCgt werden! dataEditor.addMetadata.toGroup=Metadaten zu Gruppe hinzuf\u00FCgen -dataEditor.cannotSaveLayout=Layout kann nur gespeichert werden, wenn der Editor \u00FCber eine Aufgabe ge\u00F6ffnet wird. dataEditor.childNotContainedError=Elternelement von Struktur {0} enth\u00E4lt die Struktur nicht! dataEditor.comment.correctionWorkflowAlreadyActive=Dieser Vorgang befindet sich bereits in einem Korrektur-Workflow dataEditor.comment.firstTaskInWorkflow=Sie k\u00F6nnen f\u00FCr diesen Vorgang derzeit keinen Korrekturkommentar verfassen, da noch keine seiner Aufgaben abgeschlossen sind. @@ -309,7 +308,8 @@ dataEditor.galleryStructuredView=Strukturierte Ansicht dataEditor.galleryDetailView=Detailansicht dataEditor.invalidMetadataValue=\u201E{0}\u201C kann nicht gespeichert werden: Der Wert ist ung\u00FCltig. Wert: {1} dataEditor.invalidStructureField=\u201E{0}\u201C kann nicht gespeichert werden: Es gibt kein solches Feld ({1}). -dataEditor.saveLayout=Aktuelle Spaltenaufteilung als Standard f\u00FCr diese Aufgabe speichern +dataEditor.saveLayoutDefault=Aktuelle Spaltenaufteilung als Standard speichern +dataEditor.saveLayoutForTask=Aktuelle Spaltenaufteilung als Standard f\u00FCr diese Aufgabe speichern dataEditor.mediaNotFound=Es wurden keine Medien gefunden, aber mindestens eine Dateireferenz ist vorhanden. Die automatische Entfernung der fehlenden Medien aus dem Werkst\u00FCck wurde \u00FCbersprungen. dataEditor.multipleMetadataTasksText=Sie haben mehrere Aufgaben zum Editieren von Metadaten in Bearbeitung. Bitte w\u00E4hlen Sie eine dieser Aufgaben aus! dataEditor.noParentsError=Elternelement von {0} konnte nicht gefunden werden! @@ -323,7 +323,8 @@ dataEditor.position.currentPosition=Aktuelle Position dataEditor.removeElement.noConsecutivePagesSelected=Strukturelemente k\u00F6nnen nur aus fortlaufenden Medien erstellt werden! dataEditor.selectMetadataTask=Aufgabe w\u00E4hlen dataEditor.layoutLoadedSuccessfullyTitle=Metadaten-Editor-Layout geladen -dataEditor.layoutLoadedSuccessfullyText=Spalteneinstellungen f\u00FCr Aufgabe "{0}" erfolgreich geladen +dataEditor.layoutLoadedSuccessfullyDefaultText=Allgemeine Spalteneinstellungen erfolgreich geladen +dataEditor.layoutLoadedSuccessfullyForTaskText=Spalteneinstellungen f\u00FCr Aufgabe "{0}" erfolgreich geladen dataEditor.layoutSavedSuccessfullyTitle=Aktuelle Spaltenaufteilung erfolgreich gespeichert dataEditor.layoutSavedSuccessfullyText=Ihre aktuellen Metadaten-Editor-Einstellungen wurden erfolgreich gespeichert! Sie werden f\u00FCr alle zuk\u00FCnftigen Aufgaben dieses Typs wiederverwendet. dataEditor.renamingMediaComplete=Das Umbenennen der Medien ist abgeschlossen diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 85e06dcaca2..020f4c097d8 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -281,7 +281,6 @@ dataEditor.addMetadata.newMetadata=Add new metadata dataEditor.addMetadata.noMetadataAddable=No additional metadata can be added to this structure! dataEditor.addMetadata.noMetadataAddableToGroup=No further metadata can be added to this group dataEditor.addMetadata.toGroup=Add metadata to group -dataEditor.cannotSaveLayout=Layout can only be saved, when the editor is accessed from a task. dataEditor.childNotContainedError=Parents of structure {0} do not contain structure! dataEditor.comment.correctionWorkflowAlreadyActive=This process is already in a correction workflow state dataEditor.comment.firstTaskInWorkflow=Correction comments cannot be created for the first task in a workflow. @@ -309,7 +308,8 @@ dataEditor.galleryStructuredView=Structured view dataEditor.galleryDetailView=Detail view dataEditor.invalidMetadataValue=Cannot store "{0}": The value is invalid. Value: {1} dataEditor.invalidStructureField=Cannot save "{0}": There is no such field ({1}). -dataEditor.saveLayout=Save current layout as preset for this task +dataEditor.saveLayoutDefault=Save current layout as general preset +dataEditor.saveLayoutForTask=Save current layout as preset for this task dataEditor.mediaNotFound=No media found, but at least one file reference is present. The automatic removal of missing media from the workpiece was skipped. dataEditor.multipleMetadataTasksText=There are multiple metadata editing tasks assigned to you for the current process. Please select the task you want to work on! dataEditor.noParentsError=No parents of structure {0} found! @@ -323,7 +323,8 @@ dataEditor.position.currentPosition=Current position dataEditor.removeElement.noConsecutivePagesSelected=Select consecutive pages to create structure elements! dataEditor.selectMetadataTask=Select task dataEditor.layoutLoadedSuccessfullyTitle=Custom layout loaded -dataEditor.layoutLoadedSuccessfullyText=Custom column settings for task "{0}" loaded successfully +dataEditor.layoutLoadedSuccessfullyDefaultText=Custom column settings loaded successfully +dataEditor.layoutLoadedSuccessfullyForTaskText=Custom column settings for task "{0}" loaded successfully dataEditor.layoutSavedSuccessfullyTitle=Current layout successfully saved dataEditor.layoutSavedSuccessfullyText=Your current editor settings have been saved successfully and will be applied to all future tasks of the same type. dataEditor.renamingMediaComplete=Finished renaming media diff --git a/Kitodo/src/main/resources/messages/messages_es.properties b/Kitodo/src/main/resources/messages/messages_es.properties index 12b5013c394..ab063f540dc 100644 --- a/Kitodo/src/main/resources/messages/messages_es.properties +++ b/Kitodo/src/main/resources/messages/messages_es.properties @@ -281,7 +281,6 @@ dataEditor.addMetadata.newMetadata=Añadir nuevos metadatos dataEditor.addMetadata.noMetadataAddable=No se pueden añadir más metadatos al elemento de estructura seleccionado. dataEditor.addMetadata.noMetadataAddableToGroup=No se pueden añadir más metadatos a este grupo. dataEditor.addMetadata.toGroup=Añadir metadatos al grupo -dataEditor.cannotSaveLayout=El diseño sólo se puede guardar si el editor se abre a través de una tarea. dataEditor.childNotContainedError=El elemento padre de la estructura {0} no contiene la estructura. dataEditor.comment.correctionWorkflowAlreadyActive=Esta tarea ya se encuentra en un flujo de trabajo de corrección. dataEditor.comment.firstTaskInWorkflow=No puede escribir un comentario de corrección para esta tarea en este momento porque ninguna de sus tareas se ha completado todavía. @@ -309,7 +308,9 @@ dataEditor.galleryStructuredView=Vista estructurada dataEditor.galleryDetailView=Vista detallada dataEditor.invalidMetadataValue=„{0}“ no se puede guardar: El valor no es válido. Valor: {1} dataEditor.invalidStructureField=„{0}“ no se puede guardar: No existe tal campo ({1}). -dataEditor.saveLayout=Guarda el diseño de columna actual como el predeterminado para esta tarea. +# please check google translation below and remove comment if translation is acceptable +dataEditor.saveLayoutDefault=Guardar el diseño actual como preestablecido general +dataEditor.saveLayoutForTask=Guarda el diseño de columna actual como el predeterminado para esta tarea. dataEditor.mediaNotFound=No se encontraron los medios, pero al menos un archivo de referencia está presente. La eleminación de los medios faltantes de la pieza de trabajo fue omitida. dataEditor.multipleMetadataTasksText=Tiene varias tareas de edición de metadatos en curso. Por favor, seleccione una de estas tareas. dataEditor.noParentsError=No se ha encontrado el elemento padre de {0}. @@ -323,7 +324,9 @@ dataEditor.position.currentPosition=Posición actual dataEditor.removeElement.noConsecutivePagesSelected=Los elementos estructurales sólo pueden crearse a partir de medios continuos. dataEditor.selectMetadataTask=Seleccionar la tarea dataEditor.layoutLoadedSuccessfullyTitle=¡La plantilla personificada está cargada! -dataEditor.layoutLoadedSuccessfullyText=La configuración de la columna personalizada para la tarea "{0}" se ha cargado correctamente. +# please check google translation below and remove comment if translation is acceptable +dataEditor.layoutLoadedSuccessfullyDefaultText=La configuración de columna personalizada se cargó correctamente +dataEditor.layoutLoadedSuccessfullyForTaskText=La configuración de la columna personalizada para la tarea "{0}" se ha cargado correctamente. dataEditor.layoutSavedSuccessfullyTitle=La plantilla actual se guardó correctamente dataEditor.layoutSavedSuccessfullyText=Su configuración actual del editor ha sido guardada con éxito y será aplicadad a todas las tareas futuras del mismo tipo. dataEditor.renamingMediaComplete=El cambio de nombre de los medios ha finalizado diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/header.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/header.xhtml index 6c2afa2a238..2287dafb6de 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/header.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/header.xhtml @@ -37,8 +37,7 @@