From 9b39405248c535c5631b5db147aad89d9ad6baad Mon Sep 17 00:00:00 2001 From: Kathrin Huber Date: Fri, 4 Feb 2022 14:29:30 +0100 Subject: [PATCH] move exception handling to Form class --- .../forms/dataeditor/AddDocStrucTypeDialog.java | 8 +++++++- .../production/forms/dataeditor/DataEditorForm.java | 13 ++++++++++++- .../production/forms/dataeditor/MetadataPanel.java | 10 +++------- .../forms/dataeditor/PaginationPanel.java | 11 ++++++++++- Kitodo/src/main/webapp/pages/metadataEditor.xhtml | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) 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 fda70eb0d95..4d216359fc6 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 @@ -44,6 +44,8 @@ import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; +import org.kitodo.exceptions.InvalidMetadataValueException; +import org.kitodo.exceptions.NoSuchMetadataFieldException; import org.kitodo.exceptions.UnknownTreeNodeDataException; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.helper.Helper; @@ -115,7 +117,11 @@ public void setLinkSubDialogVisible(boolean visible) { * Add structure element. */ public void addDocStruc(boolean preview) { - dataEditor.getMetadataPanel().preserve(); + try { + dataEditor.getMetadataPanel().preserve(); + } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { + logger.info(e.getMessage()); + } if (this.elementsToAddSpinnerValue > 1) { this.addMultiDocStruc(); } else { 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 769b70ce7ab..9331e020cad 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 @@ -441,8 +441,8 @@ public void save() { } private String save(boolean close) { - metadataPanel.preserve(); try { + metadataPanel.preserve(); structurePanel.preserve(); ServiceManager.getFileService().createBackupFile(process); try (OutputStream out = ServiceManager.getFileService().write(mainFileUri)) { @@ -948,4 +948,15 @@ public UploadFileDialog getUploadFileDialog() { public boolean isFolderConfigurationComplete() { return folderConfigurationComplete; } + + /** + * Preserve changes in the metadata panel. + */ + public void preserveMetadataPanel() { + try { + metadataPanel.preserve(); + } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { + logger.info(e.getMessage()); + } + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java index 9417f7f7f3b..fc0841dbc79 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/MetadataPanel.java @@ -184,13 +184,9 @@ void showPhysical(Optional optionalPhysicalDivision) { /** * Preserve metadata. */ - public void preserve() { - try { - this.preserveLogical(); - this.preservePhysical(); - } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { - logger.info(e.getMessage()); - } + public void preserve() throws InvalidMetadataValueException, NoSuchMetadataFieldException { + this.preserveLogical(); + this.preservePhysical(); } void preserveLogical() throws InvalidMetadataValueException, NoSuchMetadataFieldException { 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 8a9c2e15e38..5da2034edaf 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 @@ -22,12 +22,16 @@ 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.LogicalDivision; import org.kitodo.api.dataformat.PhysicalDivision; import org.kitodo.api.dataformat.View; import org.kitodo.config.ConfigCore; import org.kitodo.config.enums.ParameterCore; import org.kitodo.exceptions.InvalidImagesException; +import org.kitodo.exceptions.InvalidMetadataValueException; +import org.kitodo.exceptions.NoSuchMetadataFieldException; import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.metadata.pagination.Paginator; import org.kitodo.production.helper.metadata.pagination.PaginatorMode; @@ -39,6 +43,7 @@ * Backing bean for the pagination panel. */ public class PaginationPanel { + private static final Logger logger = LogManager.getLogger(PaginationPanel.class); private final DataEditorForm dataEditor; private boolean fictitiousCheckboxChecked = false; @@ -332,7 +337,11 @@ public void startPaginationClick() { Helper.setErrorMessage("fehlerBeimEinlesen", "No pages selected for pagination."); return; } - dataEditor.getMetadataPanel().preserve(); + try { + dataEditor.getMetadataPanel().preserve(); + } catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) { + logger.info(e.getMessage()); + } List pageSeparators = Separator.factory(ConfigCore.getParameter(ParameterCore.PAGE_SEPARATORS)); String initializer = paginationTypeSelectSelectedItem.format(selectPaginationModeSelectedItem.getValue(), paginationStartValue, fictitiousCheckboxChecked, pageSeparators.get(0).getSeparatorString()); diff --git a/Kitodo/src/main/webapp/pages/metadataEditor.xhtml b/Kitodo/src/main/webapp/pages/metadataEditor.xhtml index cc776951b25..71dedebf826 100644 --- a/Kitodo/src/main/webapp/pages/metadataEditor.xhtml +++ b/Kitodo/src/main/webapp/pages/metadataEditor.xhtml @@ -29,7 +29,7 @@ + actionListener="#{DataEditorForm.preserveMetadataPanel()}"/>