Skip to content

Commit

Permalink
added error messages on top in case they appear
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed Dec 5, 2024
1 parent 3861175 commit aceae58
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.goobi.beans.JournalEntry;
import org.goobi.beans.JournalEntry.EntryType;
import org.goobi.beans.Process;
Expand Down Expand Up @@ -83,6 +84,8 @@ public class WuWmaImportWorkflowPlugin implements IWorkflowPlugin, IPushPlugin {
int itemsTotal = 0;
@Getter
private Queue<LogMessage> logQueue = new CircularFifoQueue<LogMessage>(50000);
@Getter
private int errors = 0;

private String workflow;

Expand Down Expand Up @@ -112,6 +115,8 @@ public WuWmaImportWorkflowPlugin() {
private void readConfiguration() {
updateLog("Start reading the configuration");

errors = 0;

// set specific title
title = ConfigPlugins.getPluginConfig(id).getString("title");

Expand Down Expand Up @@ -274,9 +279,11 @@ public void startImport(ImportSet importset) {
updateLog("Process successfully created with ID: " + process.getId());

} catch (Exception e) {
log.error("Error while creating a process during the import", e);
updateLog("Error while creating a process during the import: " + e.getMessage(), 3);
Helper.setFehlerMeldung("Error while creating a process during the import: " + e.getMessage());
log.error("Error while creating a process during the import for file " + file.getAbsolutePath(), e);
updateLog("Error while creating a process during the import for file " + file.getAbsolutePath() + ": " + e.getMessage(),
3);
Helper.setFehlerMeldung(
"Error while creating a process during the import for file " + file.getAbsolutePath() + ": " + e.getMessage());
pusher.send("error");
}

Expand Down Expand Up @@ -311,9 +318,9 @@ public void startImport(ImportSet importset) {
* @throws MetadataTypeNotAllowedException
*/
private Corporate getCorporate(Prefs prefs, SimpleCorporate sc) throws MetadataTypeNotAllowedException {
MetadataType mdt = prefs.getMetadataTypeByName(sc.getRole());
MetadataType mdt = prefs.getMetadataTypeByName(sc.getRole().trim());
if (mdt == null) {
updateLog("The metadata type with name '" + sc.getRole()
updateLog("The metadata type with name '" + sc.getRole().trim()
+ "' does not exist within the ruleset.", 3);
}
Corporate c = new Corporate(mdt);
Expand All @@ -337,13 +344,17 @@ private Corporate getCorporate(Prefs prefs, SimpleCorporate sc) throws MetadataT
* @throws MetadataTypeNotAllowedException
*/
private Metadata getMetadata(Prefs prefs, SimpleMetadata sm) throws MetadataTypeNotAllowedException {
MetadataType mdt = prefs.getMetadataTypeByName(sm.getType());
MetadataType mdt = prefs.getMetadataTypeByName(sm.getType().trim());
if (mdt == null) {
updateLog("The metadata type with name '" + sm.getType()
updateLog("The metadata type with name '" + sm.getType().trim()
+ "' does not exist within the ruleset.", 3);
}
if (StringUtils.isBlank(sm.getValue())) {
updateLog("The metadata of type '" + sm.getType().trim()
+ "' is empty.", 3);
}
Metadata m = new Metadata(mdt);
m.setValue(sm.getValue());
m.setValue(sm.getValue().trim());
m.setAuthorityFile(sm.getAuthority(), sm.getAuthorityURI(), sm.getValueURI());
return m;
}
Expand All @@ -357,9 +368,9 @@ private Metadata getMetadata(Prefs prefs, SimpleMetadata sm) throws MetadataType
* @throws MetadataTypeNotAllowedException
*/
private Person getPerson(Prefs prefs, SimplePerson sp) throws MetadataTypeNotAllowedException {
MetadataType mdt = prefs.getMetadataTypeByName(sp.getRole());
MetadataType mdt = prefs.getMetadataTypeByName(sp.getRole().trim());
if (mdt == null) {
updateLog("The metadata type with name '" + sp.getRole()
updateLog("The metadata type with name '" + sp.getRole().trim()
+ "' does not exist within the ruleset.", 3);
}
Person p = new Person(mdt);
Expand All @@ -378,9 +389,9 @@ private Person getPerson(Prefs prefs, SimplePerson sp) throws MetadataTypeNotAll
* @throws MetadataTypeNotAllowedException
*/
private MetadataGroup getGroup(Prefs prefs, SimpleGroup sg) throws MetadataTypeNotAllowedException {
MetadataGroupType mdt = prefs.getMetadataGroupTypeByName(sg.getType());
MetadataGroupType mdt = prefs.getMetadataGroupTypeByName(sg.getType().trim());
if (mdt == null) {
updateLog("The metadata group type with name '" + sg.getType()
updateLog("The metadata group type with name '" + sg.getType().trim()
+ "' does not exist within the ruleset.", 3);
}
MetadataGroup group = new MetadataGroup(mdt);
Expand All @@ -391,9 +402,9 @@ private MetadataGroup getGroup(Prefs prefs, SimpleGroup sg) throws MetadataTypeN
}

// create all corporates
// for (SimpleCorporate sc : sg.getCorporates()) {
// group.addCorporate(getCorporate(prefs, sc));
// }
for (SimpleCorporate sc : sg.getCorporates()) {
group.addCorporate(getCorporate(prefs, sc));
}

// create all metadata groups
for (SimpleGroup ssg : sg.getGroups()) {
Expand Down Expand Up @@ -428,6 +439,10 @@ private void updateLog(String logmessage) {
* @param logmessage
*/
private void updateLog(String logmessage, int level) {
if (level > 1) {
errors++;
}

logQueue.add(new LogMessage(logmessage, level));
log.debug(logmessage);
if (pusher != null && System.currentTimeMillis() - lastPush > 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

Expand All @@ -13,6 +15,9 @@
@Setter
public class SimpleCorporate {

@JacksonXmlProperty(isAttribute = true)
private String label;

@JacksonXmlProperty(localName = "subname")
@JacksonXmlElementWrapper(useWrapping = false)
private List<String> subnames = new ArrayList<String>();
Expand All @@ -34,4 +39,25 @@ public class SimpleCorporate {
@JacksonXmlProperty(isAttribute = true)
private String name;

/**
* add authority information based on just one url
*
* @param authorityEntryUrl
*/
public void analyzeAuthority(String authorityEntryUrl) {
authority = null;
authorityURI = null;
valueURI = null;

// split authority information
if (StringUtils.isNotBlank(authorityEntryUrl)) {
if (authorityEntryUrl.contains("d-nb.info")) {
authority = "gnd";
}
if (authorityEntryUrl.contains("/")) {
authorityURI = authorityEntryUrl.substring(0, authorityEntryUrl.lastIndexOf("/") + 1);
valueURI = authorityEntryUrl.substring(authorityEntryUrl.lastIndexOf("/") + 1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

Expand Down Expand Up @@ -31,4 +33,46 @@ public class SimpleData {

@JacksonXmlProperty(isAttribute = true)
private String type;

/**
* Add a {@link SimpleMetadata}
*
* @param md
*/
public void add(SimpleMetadata md) {
if (StringUtils.isNoneBlank(md.getValue(), md.getType())) {
metadatas.add(md);
}
}

/**
* add a {@link SimplePerson}
*
* @param p
*/
public void add(SimplePerson p) {
if (StringUtils.isNoneBlank(p.getRole(), p.getLastname())) {
persons.add(p);
}
}

/**
* add a {@link SimpleCorporate}
*
* @param c
*/
public void add(SimpleCorporate c) {
if (StringUtils.isNoneBlank(c.getName(), c.getRole())) {
corporates.add(c);
}
}

/**
* add a {@link SimpleGroup}
*
* @param g
*/
public void add(SimpleGroup g) {
groups.add(g);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

Expand Down Expand Up @@ -35,4 +37,45 @@ public class SimpleGroup {
@JacksonXmlProperty(localName = "group")
private List<SimpleGroup> groups = new ArrayList<SimpleGroup>();

/**
* Add a {@link SimpleMetadata}
*
* @param md
*/
public void add(SimpleMetadata md) {
if (StringUtils.isNoneBlank(md.getValue(), md.getType())) {
metadatas.add(md);
}
}

/**
* add a {@link SimplePerson}
*
* @param p
*/
public void add(SimplePerson p) {
if (StringUtils.isNoneBlank(p.getRole(), p.getLastname())) {
persons.add(p);
}
}

/**
* add a {@link SimpleCorporate}
*
* @param c
*/
public void add(SimpleCorporate c) {
if (StringUtils.isNoneBlank(c.getName(), c.getRole())) {
corporates.add(c);
}
}

/**
* add a {@link SimpleGroup}
*
* @param g
*/
public void add(SimpleGroup g) {
groups.add(g);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.goobi.workflow.importer.model;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;

Expand Down Expand Up @@ -30,4 +32,26 @@ public class SimpleMetadata {

@JacksonXmlText
private String value;

/**
* add authority information based on just one url
*
* @param authorityEntryUrl
*/
public void analyzeAuthority(String authorityEntryUrl) {
authority = null;
authorityURI = null;
valueURI = null;

// split authority information
if (StringUtils.isNotBlank(authorityEntryUrl)) {
if (authorityEntryUrl.contains("d-nb.info")) {
authority = "gnd";
}
if (authorityEntryUrl.contains("/")) {
authorityURI = authorityEntryUrl.substring(0, authorityEntryUrl.lastIndexOf("/") + 1);
valueURI = authorityEntryUrl.substring(authorityEntryUrl.lastIndexOf("/") + 1);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.goobi.workflow.importer.model;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

import lombok.Getter;
Expand Down Expand Up @@ -30,4 +32,47 @@ public class SimplePerson {
@JacksonXmlProperty(isAttribute = true)
private String lastname;

/**
* split given fullname into first and lastname if the given string looks like "Lastname Firstname1 Firstname2" or like "Lastname, Firstname1
* Firstname2"
*
* @param fullName
*/
public void analyzeFullName(String fullName) {
firstname = "";
lastname = fullName;

int spaceIndex = fullName.indexOf(" ");
if (spaceIndex != -1) {
firstname = fullName.substring(spaceIndex + 1).trim();
lastname = fullName.substring(0, spaceIndex).trim();
}

if (lastname.endsWith(",")) {
lastname = lastname.substring(0, lastname.length() - 1).trim();
}
}

/**
* add authority information based on just one url
*
* @param authorityEntryUrl
*/
public void analyzeAuthority(String authorityEntryUrl) {
authority = null;
authorityURI = null;
valueURI = null;

// split authority information
if (StringUtils.isNotBlank(authorityEntryUrl)) {
if (authorityEntryUrl.contains("d-nb.info")) {
authority = "gnd";
}
if (authorityEntryUrl.contains("/")) {
authorityURI = authorityEntryUrl.substring(0, authorityEntryUrl.lastIndexOf("/") + 1);
valueURI = authorityEntryUrl.substring(authorityEntryUrl.lastIndexOf("/") + 1);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
font-weight: bold;
}

.logs {
.logs {
border: 1px solid #ddd;
display: block;
margin-top: 20px;
Expand Down Expand Up @@ -80,6 +80,14 @@
</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>

<!-- // progress bar -->
</section:body>
<section:footer>
Expand Down

0 comments on commit aceae58

Please sign in to comment.