Skip to content

Commit

Permalink
Merge pull request kitodo#5872 from effective-webwork/handle-missing-…
Browse files Browse the repository at this point in the history
…meta-xml

Handle error opening metadata file
  • Loading branch information
solth authored Jan 22, 2024
2 parents cf58099 + b601d37 commit ce51a2b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package org.kitodo.production.forms.dataeditor;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -209,6 +210,7 @@ public class DataEditorForm implements MetadataTreeTableInterface, RulesetSetupI
private int numberOfNewMappings = 0;

private String renamingError = "";
private String metadataFileLoadingError = "";

/**
* Public constructor.
Expand Down Expand Up @@ -294,6 +296,8 @@ public void open(String processID, String referringView, String taskId) {
} else {
PrimeFaces.current().executeScript("PF('metadataLockedDialog').show();");
}
} catch (FileNotFoundException e) {
metadataFileLoadingError = e.getLocalizedMessage();
} catch (IOException | DAOException | InvalidImagesException | NoSuchElementException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
Expand Down Expand Up @@ -341,6 +345,7 @@ private boolean openMetsFile() throws IOException, InvalidImagesException, Media
logger.warn("Workpiece has no ID. Cannot verify workpiece ID. Setting workpiece ID.");
workpiece.setId(process.getId().toString());
}
metadataFileLoadingError = "";
return ServiceManager.getFileService().searchForMedia(process, workpiece);
}

Expand Down Expand Up @@ -390,15 +395,19 @@ public String closeAndReturn() {
public void close() {
deleteNotSavedUploadedMedia();
unsavedDeletedMedia.clear();
ServiceManager.getFileService().revertRenaming(filenameMapping.inverseBidiMap(), workpiece);
if (Objects.nonNull(workpiece)) {
ServiceManager.getFileService().revertRenaming(filenameMapping.inverseBidiMap(), workpiece);
}
metadataPanel.clear();
structurePanel.clear();
workpiece = null;
workpieceOriginalState = null;
mainFileUri = null;
ruleset = null;
currentChildren.clear();
selectedMedia.clear();
if (Objects.nonNull(selectedMedia)) {
selectedMedia.clear();
}
if (!FacesContext.getCurrentInstance().isPostback()) {
mediaProvider.resetMediaResolverForProcess(process.getId());
}
Expand Down Expand Up @@ -1154,4 +1163,12 @@ private void showPanels() {
paginationPanel.show();
structurePanel.show();
}

/**
* Get metadata file loading error.
* @return metadata file loading error
*/
public String getMetadataFileLoadingError() {
return metadataFileLoadingError;
}
}
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ invalidIdentifierSame=Das Identifikationsmerkmal {0} enth\u00E4lt in {1} und {2}
errorLoadingDocTypes=Regelsatz Konfigurationsfehler: Kein DocType ('division') gefunden
errorLoadingMany=Fehler beim Laden von ''{0}''
errorLoadingOne=Fehler beim Laden von ''{0}'' mit ID {1}
errorLoadingMetadataFile=Fehler beim Laden der Metadatendatei
ldapGroupInUse=Die LDAP Gruppe ist noch mit Benutzern verkn\u00FCpft und kann nicht gel\u00F6scht werden.
loginInUse=Login ist bereits vergeben
loginNotValid=Login ''{0}'' enth\u00E4lt ung\u00FCltige Zeichen oder ist auf Blackliste.
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ invalidIdentifierSame=The identifier {0} has the same value in {1} and {2}.
errorLoadingDocTypes=Ruleset configuration error: No DocType ('division') found
errorLoadingMany=Error loading ''{0}''
errorLoadingOne=Error loading ''{0}'' with ID {1}
errorLoadingMetadataFile=Error loading metadata file
ldapGroupInUse=The LDAP group is still associated with users and could not be deleted.
loginInUse=Login already in use
loginNotValid=Login ''{0}'' uses not valid characters or is on black list.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* 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.
*
-->

<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dialog id="errorLoadingMetadataDialog"
widgetVar="errorLoadingMetadataDialog"
width="500px"
showHeader="false"
visible="#{not empty DataEditorForm.metadataFileLoadingError}"
onShow="if($('#loadingScreen').length) {$('#loadingScreen').hide();}"
appendTo="@(body)"
resizable="false"
closable="false"
modal="true">
<h:panelGroup>
<h3>#{err['errorLoadingMetadataFile']}</h3>
<h:panelGroup layout="block"
styleClass="select-note ui-messages-error">
<h:outputText value="#{DataEditorForm.metadataFileLoadingError}"/>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup layout="block"
styleClass="dialogButtonWrapper">
<p:button outcome="/pages/desktop.jsf"
value="#{msgs['ok']}"
styleClass="primary right"
icon="fa fa-close"
iconPos="right"/>
</h:panelGroup>
</p:dialog>
</ui:composition>
5 changes: 4 additions & 1 deletion Kitodo/src/main/webapp/pages/metadataEditor.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
<!--@elvariable id="commentsNumber" type="Integer"-->
<ui:param name="commentsNumber" value="#{CommentForm.getAllComments().size()}"/>

<p:panel id="metadataEditorContainer" style="margin: auto 16px; padding: 0;">
<p:panel id="metadataEditorContainer"
rendered="#{empty DataEditorForm.getMetadataFileLoadingError()}"
style="margin: auto 16px; padding: 0;">

<p:panel id="metadataEditor">
<!-- Header -->
Expand Down Expand Up @@ -253,6 +255,7 @@
<ui:include src="/WEB-INF/templates/includes/comments/newCommentDialog.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/uploadFile.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/metadataLocked.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/errorLoadingMetadataDialog.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/fileReferencesUpdatedDialog.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/dataEditorSettingSavingResult.xhtml"/>
<ui:include src="/WEB-INF/templates/includes/metadataEditor/dialogs/renamingMediaResults.xhtml"/>
Expand Down

0 comments on commit ce51a2b

Please sign in to comment.