Skip to content

Commit

Permalink
move exception handling to Form class
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathrin-Huber committed Feb 23, 2022
1 parent 4be8fa7 commit 9b39405
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,9 @@ void showPhysical(Optional<PhysicalDivision> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Separator> pageSeparators = Separator.factory(ConfigCore.getParameter(ParameterCore.PAGE_SEPARATORS));
String initializer = paginationTypeSelectSelectedItem.format(selectPaginationModeSelectedItem.getValue(),
paginationStartValue, fictitiousCheckboxChecked, pageSeparators.get(0).getSeparatorString());
Expand Down
2 changes: 1 addition & 1 deletion Kitodo/src/main/webapp/pages/metadataEditor.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<ui:define name="content">

<p:remoteCommand name="preserveMetadata"
actionListener="#{DataEditorForm.metadataPanel.preserve}"/>
actionListener="#{DataEditorForm.preserveMetadataPanel()}"/>

<!--@elvariable id="viewStructure" type="boolean"-->
<ui:param name="viewStructure" value="#{SecurityAccessController.hasAuthorityToViewProcessStructureData()}"/>
Expand Down

0 comments on commit 9b39405

Please sign in to comment.