Skip to content

Commit

Permalink
updated plugin to new ui
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed Dec 10, 2024
1 parent 65ad8dc commit 66f6362
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public class NewspaperPageImporterWorkflowPlugin implements IWorkflowPlugin, IPu
@Getter
private int itemCurrent = 0;
@Getter
int itemsTotal = 0;
private int itemsTotal = 0;
@Getter
private transient Queue<LogMessage> logQueue = new CircularFifoQueue<>(48);
private int errors;
@Getter
private transient Queue<LogMessage> logQueue = new CircularFifoQueue<>(1000);
// folder containing images to import
private String importFolder;
// name of the workflow template that shall be used
Expand Down Expand Up @@ -147,7 +149,7 @@ public NewspaperPageImporterWorkflowPlugin() {
*/
private void readConfiguration() {
updateLog("Start reading the configuration");

errors = 0;
// read some main configuration
XMLConfiguration config = ConfigPlugins.getPluginConfig(title);
importFolder = config.getString("importFolder");
Expand Down Expand Up @@ -247,6 +249,7 @@ public void startImport() {
List<NewspaperPage> issuePages = issueEntry.getValue();
boolean success = tryUpdateOldProcessForIssue(process, issuePages);
if (!success) {
errors++;
String message = "Failed to add issue for date " + issueDate;
reportError(message);
}
Expand All @@ -266,6 +269,7 @@ public void startImport() {
updateLog("Import completed.");

} catch (InterruptedException | ReadException | IOException | SwapException | WriteException | PreferencesException e) {
errors++;
Helper.setFehlerMeldung("Error while trying to execute the import: " + e.getMessage());
log.error("Error while trying to execute the import", e);
updateLog("Error while trying to execute the import: " + e.getMessage(), 3);
Expand Down Expand Up @@ -341,19 +345,22 @@ private boolean tryUpdateOldProcessForIssue(Process process, List<NewspaperPage>

} catch (ReadException | IOException | SwapException e1) {
// read Fileformat error
errors++;
String message = "Failed to read the fileformat.";
reportError(message);
e1.printStackTrace();
return false;

} catch (PreferencesException e) {
// DigitalDocument error
errors++;
String message = "Failed to get the digital document.";
reportError(message);
e.printStackTrace();
return false;

} catch (Exception e) {
errors++;
log.debug("Unknown exception caught while updating process: " + process.getTitel());
e.printStackTrace();
return false;
Expand All @@ -365,6 +372,7 @@ private boolean tryUpdateOldProcessForIssue(Process process, List<NewspaperPage>
return true;

} catch (IOException | SwapException | DAOException e) {
errors++;
log.error("Error while trying to copy files into the media folder", e);
String message = "Error while trying to copy files into the media folder: " + e.getMessage();
reportError(message);
Expand Down Expand Up @@ -403,6 +411,7 @@ private void updateMetadataOfProcessForIssue(Process process, List<NewspaperPage
}

} catch (Exception e) {
errors++;
log.debug("Exception caught while updating metadata of process: " + process.getTitel());
e.printStackTrace();
}
Expand Down Expand Up @@ -480,6 +489,7 @@ private Fileformat prepareFileformatForNewProcess(Process template, NewspaperPag
logical.addChild(volume);

} catch (TypeNotAllowedAsChildException e) {
errors++;
String message = "Failed to add volume.";
reportError(message);
e.printStackTrace();
Expand All @@ -489,6 +499,7 @@ private Fileformat prepareFileformatForNewProcess(Process template, NewspaperPag
return fileformat;

} catch (PreferencesException | TypeNotAllowedForParentException | MetadataTypeNotAllowedException | IncompletePersonObjectException e) {
errors++;
String message = "Error while preparing the Fileformat for the new process: " + e.getMessage();
reportError(message);
return null;
Expand Down Expand Up @@ -621,7 +632,8 @@ private void createMetadataFields(Prefs prefs, DocStruct ds, List<ImportMetadata
ds.addMetadata(md);
}
} catch (MetadataTypeNotAllowedException e) {
String message = "MetadataType " + target + " is not allowed. Skipping...";
errors++;
String message = "MetadataType " + target + " is not allowed. Skipping ...";
reportError(message);
e.printStackTrace();
}
Expand Down Expand Up @@ -688,6 +700,7 @@ private DocStruct createNewIssue(Prefs prefs, DigitalDocument dd, NewspaperPage
return issue;

} catch (TypeNotAllowedForParentException | MetadataTypeNotAllowedException e) {
errors++;
String message = "Failed to create a new issue for " + page.getDate();
reportError(message);
e.printStackTrace();
Expand Down Expand Up @@ -730,6 +743,7 @@ private void addPageToIssue(Prefs prefs, DigitalDocument dd, DocStruct issue, Ne
dsPage.addContentFile(contentFileTiff);

} catch (TypeNotAllowedForParentException | TypeNotAllowedAsChildException | MetadataTypeNotAllowedException e) {
errors++;
String message = "Failed to add page '" + page.getFileName() + "' to issue.";
reportError(message);
e.printStackTrace();
Expand Down Expand Up @@ -807,6 +821,7 @@ private Process createAndSaveNewProcess(BeanHelper bhelp, Process template, Stri
ProcessManager.saveProcess(process);

} catch (DAOException e) {
errors++;
String message = "Error while trying to save the process: " + e.getMessage();
reportError(message);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.jfree.util.Log;

import lombok.Getter;

Expand Down Expand Up @@ -121,6 +122,16 @@ public boolean isFileValid() {
boolean vdate = isDateValid();
boolean vpage = isPageNumberValid();
boolean vsize = isFileSizeValid();

if (!vdate) {
Log.error("Date is invalid");
}
if (!vpage) {
Log.error("Page number is invalid");
}
if (!vsize) {
Log.error("File size is invalid");
}
return vdate && vpage && vsize;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:composite="http://xmlns.jcp.org/jsf/composite" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:x="http://myfaces.apache.org/tomahawk" xmlns:intranda="http://xmlns.jcp.org/jsf/composite/composites" xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" xmlns:o="http://omnifaces.org/ui" xmlns:p="http://primefaces.org/ui" xmlns:jsf="http://xmlns.jcp.org/jsf">

<composite:interface>
</composite:interface>

<composite:implementation>

<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:intranda="http://xmlns.jcp.org/jsf/composite/composites"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:o="http://omnifaces.org/ui"
xmlns:p="http://primefaces.org/ui"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:button="http://goobi.io/button"
xmlns:section="http://goobi.io/section">
<style>
.progress {
border: 1px solid #EFAD4E;
Expand Down Expand Up @@ -41,81 +47,90 @@
<h:panelGroup>
<div class="row">
<div class="col-sm-12">
<div class="box box-color box-bordered lightgrey">

<h:form
id="myform"
styleClass="form-horizontal form-bordered"
onkeypress="submitOnEnter(event);">

<div class="box-title">
<h3>
<i class="fa fa-plug"></i>
<h:outputText value="#{msgs[NavigationForm.workflowPlugin.title]}" />
</h3>
</div>
<div class="box-content">
<h:panelGroup
rendered="#{!LoginForm.hasRole('Plugin_workflow_newspaper_pages_importer')}">
<h:outputText
styleClass="alert alert-danger alert-dismissable margin-bottom-10 margin-top-10"
value="#{msgs.plugin_administration_missingPermission} Plugin_workflow_newspaper_pages_importer"/>
</h:panelGroup>

<h:panelGroup id="actionform" styleClass="col-sm-12"
rendered="#{LoginForm.hasRole('Plugin_workflow_newspaper_pages_importer')}">

<!-- <h:outputText -->
<!-- styleClass="alert alert-warning alert-dismissable margin-bottom-10 margin-top-10" -->
<!-- value="#{msgs.plugin_intranda_workflow_sample_introduction}: #{NavigationForm.workflowPlugin.importFolder}"/> -->

<h:panelGroup
rendered="#{!LoginForm.hasRole('Plugin_workflow_wu_wma_import')}"
layout="block">
<h:outputText
styleClass="alert alert-danger"
value="#{msgs.plugin_administration_missingPermission} Plugin_workflow_newspaper_pages_importer"/>
</h:panelGroup>
<ui:fragment rendered="#{LoginForm.hasRole('Plugin_workflow_newspaper_pages_importer')}">
<section:section type="neutral">
<section:header
icon="plug"
title="#{msgs[NavigationForm.workflowPlugin.title]}" />

<h:form
id="myform"
onkeypress="submitOnEnter(event);">
<section:body padding="true">


<!-- <h:outputText
value="#{msgs.plugin_intranda_workflow_kick_start_introduction}: #{NavigationForm.workflowPlugin.importFolder}"/> -->
<h:panelGroup
class="col-sm-8 progress"
id="resultProgress"
rendered="#{NavigationForm.workflowPlugin.progress ge 0}">
<div
class="progress-bar #{NavigationForm.workflowPlugin.run ? 'progress-bar-striped active' : ''}"
role="progressbar"
aria-valuenow="#{NavigationForm.workflowPlugin.progress}"
aria-valuemin="0"
aria-valuemax="100"
style="width:#{NavigationForm.workflowPlugin.progress}%">
<span>
<h:outputText
value="#{NavigationForm.workflowPlugin.itemCurrent} #{msgs.of} #{NavigationForm.workflowPlugin.itemsTotal} - #{NavigationForm.workflowPlugin.progress}%" />
</span>
</div>
</h:panelGroup>
<ui:fragment rendered="#{NavigationForm.workflowPlugin.errors > 0}">
<div class="alert alert-danger mt-3" role="alert">
<div>
<h:outputText value="#{msgs.ProcessCreationError_mets_save_error} (#{msgs.count}: #{NavigationForm.workflowPlugin.errors})"/>
</div>
</div>
</ui:fragment>

<div class="form-actions">

<div class="row">

<!-- progress bar -->
<h:panelGroup class="col-sm-8 progress" id="resultProgress" rendered="#{NavigationForm.workflowPlugin.progress ge 0}">
<div class="progress-bar #{NavigationForm.workflowPlugin.run ? 'progress-bar-striped active' : ''}" role="progressbar"
aria-valuenow="#{NavigationForm.workflowPlugin.progress}"
aria-valuemin="0" aria-valuemax="100"
style="width:#{NavigationForm.workflowPlugin.progress}%">
<span>
<h:outputText
value="#{NavigationForm.workflowPlugin.itemCurrent} #{msgs.of} #{NavigationForm.workflowPlugin.itemsTotal} - #{NavigationForm.workflowPlugin.progress}%" />
</span>
</div>
</h:panelGroup>
<!-- // progress bar -->
<!-- // progress bar -->
</section:body>
<section:footer>
<button:row>
<!-- buttons -->
<!-- import button -->
<div
class="d-inline"
data-bs-toggle="tooltip"
title="#{msgs.plugin_intranda_workflow_startImport}">

<!-- buttons -->
<h:panelGroup class="#{NavigationForm.workflowPlugin.progress ge 0 ? 'col-sm-4' : 'col-sm-12'}">

<!-- import button -->
<button jsf:action="#{NavigationForm.workflowPlugin.startImport()}"
data-toggle="tooltip" title="#{msgs.plugin_intranda_workflow_startImport}"
aria-label="Volksblatt" class="btn btn-blue font-size-s pull-right">
<i class="fa fa-play-circle margin-right-10"></i>
<h:outputText value="#{msgs.plugin_intranda_workflow_startImport}" />
</button>

<!-- Cancel button -->
<button jsf:id="cancel" class="btn font-size-s margin-right-5 pull-right" jsf:action="#{NavigationForm.workflowPlugin.cancel}" jsf:rendered="#{NavigationForm.workflowPlugin.run}">
<h:outputText value="#{msgs.abbrechen}" />
</button>

</h:panelGroup>
<!-- // buttons -->

</div>
<!-- import button -->
<button jsf:action="#{NavigationForm.workflowPlugin.startImport()}"
data-toggle="tooltip" title="#{msgs.plugin_intranda_workflow_startImport}"
aria-label="Volksblatt" class="btn btn-primary">
<span aria-hidden="true" class="fa fa-play-circle" />
<span>
#{msgs.plugin_intranda_workflow_startImport}
</span>
</button>
</div>
</h:panelGroup>

</div>
</h:form>
<!-- Cancel button -->
<button
jsf:id="cancel"
class="btn btn-blank"
jsf:action="#{NavigationForm.workflowPlugin.cancel}"
jsf:rendered="#{NavigationForm.workflowPlugin.run}">
<h:outputText value="#{msgs.abbrechen}" />
</button>
<!-- // buttons -->
</button:row>
</section:footer>
</h:form>
</section:section>
</ui:fragment>
</div>
</div>
</div>

</h:panelGroup>

<!-- log view -->
Expand All @@ -138,6 +153,4 @@
<f:ajax event="error" render="globalMessage" />
</o:socket>
<!-- // websocket communication -->

</composite:implementation>
</ui:composition>

0 comments on commit 66f6362

Please sign in to comment.