Skip to content

Commit dc5e6c1

Browse files
committed
Merge pull request 'Release v26.01' (#17) from release_26.01 into master
2 parents 20640c0 + 90f5175 commit dc5e6c1

File tree

7 files changed

+183
-38
lines changed

7 files changed

+183
-38
lines changed

install/plugin_intranda_administration_arche_project_export.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@
2727
if list was selected: subelement select contains label and actual value
2828
-->
2929

30-
<!--
30+
3131
<property name="VocabularySample" default="" type="vocabularyreference" ttlField="VocabularySample" ttlType="resource">
32-
<vocabulary name="Location" label="Location" value="Authority Value" />
32+
<vocabulary
33+
name="Licenses"
34+
label="Label"
35+
value="URI"
36+
url="https://vocabs.acdh.oeaw.ac.at/rest/v1/arche_licenses/data?format=application/rdf%2Bxml"
37+
xslt="/home/robert/git/goobi-plugin-administration-arche-project-export/install/rdf2csv.xsl" />
3338
</property>
34-
-->
39+
3540

3641
<property name="Contact" default="" type="list" ttlField="hasContact" ttlType="resource">
3742
<select label="Austrian Centre for Digital Humanities and Cultural Heritage" value="https://arche.acdh.oeaw.ac.at/api/48505" />

install/rdf2csv.xsl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet version="1.0"
3+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5+
xmlns:skos="http://www.w3.org/2004/02/skos/core#">
6+
7+
<xsl:output method="text" encoding="UTF-8"/>
8+
9+
<xsl:template match="/">
10+
<xsl:text>ID,Label,URI&#10;</xsl:text>
11+
12+
<!-- Sortierte obere Descriptions -->
13+
<xsl:apply-templates select="//rdf:Description[skos:prefLabel and skos:exactMatch]">
14+
<xsl:sort
15+
select="(skos:prefLabel[@xml:lang='de']
16+
| skos:prefLabel[@xml:lang='en']
17+
| skos:prefLabel)[1]"
18+
data-type="text"
19+
order="ascending"/>
20+
</xsl:apply-templates>
21+
</xsl:template>
22+
23+
24+
<xsl:template match="rdf:Description">
25+
26+
<!-- Gewünschtes PrefLabel -->
27+
<xsl:variable name="pref">
28+
<xsl:choose>
29+
<xsl:when test="skos:prefLabel[@xml:lang='de']">
30+
<xsl:value-of select="skos:prefLabel[@xml:lang='de'][1]"/>
31+
</xsl:when>
32+
<xsl:when test="skos:prefLabel[@xml:lang='en']">
33+
<xsl:value-of select="skos:prefLabel[@xml:lang='en'][1]"/>
34+
</xsl:when>
35+
<xsl:otherwise>
36+
<xsl:value-of select="skos:prefLabel[1]"/>
37+
</xsl:otherwise>
38+
</xsl:choose>
39+
</xsl:variable>
40+
41+
<!-- exactMatch der oberen Description -->
42+
<xsl:variable name="upperMatch" select="skos:exactMatch/@rdf:resource"/>
43+
44+
<!-- passende untere Description suchen -->
45+
<xsl:variable name="lower"
46+
select="//rdf:Description[@rdf:about = $upperMatch]"/>
47+
48+
<!-- Das exactMatch der unteren Description -->
49+
<xsl:variable name="lowerMatch"
50+
select="$lower/skos:exactMatch/@rdf:resource"/>
51+
52+
<!-- Nur Ausgabe wenn beide existieren -->
53+
<xsl:if test="string($pref) and string($lowerMatch)">
54+
<xsl:text>,</xsl:text>
55+
<xsl:value-of select="$pref"/>
56+
<xsl:text>,</xsl:text>
57+
<xsl:value-of select="$lowerMatch"/>
58+
<xsl:text>&#10;</xsl:text>
59+
</xsl:if>
60+
61+
</xsl:template>
62+
63+
</xsl:stylesheet>

module-base/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<parent>
55
<groupId>io.goobi.workflow.plugin</groupId>
66
<artifactId>plugin-administration-arche-project-export</artifactId>
7-
<version>25.11</version>
7+
<version>26.01</version>
88
</parent>
99
<artifactId>plugin-administration-arche-project-export-base</artifactId>
1010
<packaging>jar</packaging>
1111
<dependencies>
1212
<dependency>
1313
<groupId>io.goobi.workflow.plugin</groupId>
1414
<artifactId>plugin-step-arche-export-lib</artifactId>
15-
<version>25.11</version>
15+
<version>26.01</version>
1616
<scope>compile</scope>
1717
</dependency>
1818
</dependencies>

module-base/src/main/java/de/intranda/goobi/plugins/ArcheProjectExportAdministrationPlugin.java

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package de.intranda.goobi.plugins;
22

3-
import java.io.FileOutputStream;
4-
import java.io.IOException;
5-
import java.io.OutputStream;
3+
import java.io.*;
64
import java.nio.file.Path;
75
import java.nio.file.Paths;
86
import java.text.SimpleDateFormat;
97
import java.util.ArrayList;
108
import java.util.List;
119

10+
import io.goobi.workflow.api.vocabulary.APIException;
11+
import io.goobi.workflow.api.vocabulary.helper.APIExceptionExtractor;
1212
import org.apache.commons.configuration.HierarchicalConfiguration;
1313
import org.apache.commons.lang3.StringUtils;
1414
import org.apache.jena.datatypes.xsd.XSDDatatype;
@@ -32,6 +32,7 @@
3232
import de.sub.goobi.persistence.managers.ProcessManager;
3333
import de.sub.goobi.persistence.managers.ProjectManager;
3434
import de.sub.goobi.persistence.managers.PropertyManager;
35+
import io.goobi.workflow.api.connection.HttpUtils;
3536
import io.goobi.workflow.api.vocabulary.VocabularyAPIManager;
3637
import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabulary;
3738
import io.goobi.workflow.api.vocabulary.helper.ExtendedVocabularyRecord;
@@ -43,6 +44,10 @@
4344
import lombok.extern.log4j.Log4j2;
4445
import net.xeoh.plugins.base.annotations.PluginImplementation;
4546

47+
import javax.xml.transform.*;
48+
import javax.xml.transform.stream.StreamResult;
49+
import javax.xml.transform.stream.StreamSource;
50+
4651
@PluginImplementation
4752
@Log4j2
4853
public class ArcheProjectExportAdministrationPlugin implements IAdministrationPlugin {
@@ -154,23 +159,7 @@ public void setProjectId(Integer inProjektAuswahl) {
154159
String vocabularyName = hc.getString("/vocabulary/@name");
155160
String labelField = hc.getString("/vocabulary/@label");
156161
String valueField = hc.getString("/vocabulary/@value");
157-
158-
ExtendedVocabulary currentVocabulary = VocabularyAPIManager.getInstance().vocabularies().findByName(vocabularyName);
159-
160-
List<ExtendedVocabularyRecord> recordList = VocabularyAPIManager.getInstance()
161-
.vocabularyRecords()
162-
.list(currentVocabulary.getId())
163-
.all()
164-
.request()
165-
.getContent();
166-
167-
for (ExtendedVocabularyRecord rec : recordList) {
168-
String label = rec.getFieldForDefinitionName(labelField).get().getFieldValue();
169-
String value = rec.getFieldForDefinitionName(valueField).get().getFieldValue();
170-
171-
pp.getPossibleValues().add(new SelectItem(value, label));
172-
}
173-
pp.setType(org.goobi.production.properties.Type.LIST);
162+
initializeProperty(vocabularyName, labelField, valueField, pp);
174163
}
175164

176165
for (HierarchicalConfiguration selectItem : hc.configurationsAt("/select")) {
@@ -180,6 +169,32 @@ public void setProjectId(Integer inProjektAuswahl) {
180169
}
181170
}
182171

172+
private static void initializeProperty(String vocabularyName, String labelField, String valueField, DisplayProperty pp) {
173+
try {
174+
ExtendedVocabulary currentVocabulary = VocabularyAPIManager.getInstance().vocabularies().findByName(vocabularyName);
175+
176+
List<ExtendedVocabularyRecord> recordList = VocabularyAPIManager.getInstance()
177+
.vocabularyRecords()
178+
.list(currentVocabulary.getId())
179+
.all()
180+
.request()
181+
.getContent();
182+
183+
pp.getPossibleValues().clear();
184+
for (ExtendedVocabularyRecord rec : recordList) {
185+
String label = rec.getFieldForDefinitionName(labelField).get().getFieldValue();
186+
String value = rec.getFieldForDefinitionName(valueField).get().getFieldValue();
187+
188+
pp.getPossibleValues().add(new SelectItem(value, label));
189+
}
190+
} catch (APIException e) {
191+
APIExceptionExtractor extractor = new APIExceptionExtractor(e);
192+
String message = "Failed to load vocabulary \"" + vocabularyName + "\" records, Reason: \n" + extractor.getLocalizedMessage(Helper.getSessionLocale());
193+
log.error(message, e);
194+
Helper.setFehlerMeldung(message, e.getMessage());
195+
}
196+
}
197+
183198
public List<Project> getPossibleProjects() {
184199
if (possibleProjects == null) {
185200
log.trace("project list is not initialized, load them from database");
@@ -457,4 +472,57 @@ private void writePropertyValue(String languageCode, Model model, Resource proje
457472
}
458473
}
459474
}
475+
476+
public void updateVocabulary(DisplayProperty property) {
477+
HierarchicalConfiguration hc = archeConfiguration.getConfig().configurationAt("/project/property[@name='" + property.getName() + "']");
478+
String vocabularyName = hc.getString("/vocabulary/@name");
479+
String labelField = hc.getString("/vocabulary/@label");
480+
String valueField = hc.getString("/vocabulary/@value");
481+
482+
try {
483+
long vocabularyId = VocabularyAPIManager.getInstance().vocabularies().findByName(vocabularyName).getId();
484+
485+
String skosURI = hc.getString("/vocabulary/@url");
486+
String xsltPath = hc.getString("/vocabulary/@xslt");
487+
488+
// if uri and xslt are configured
489+
if (StringUtils.isNotBlank(skosURI) && StringUtils.isNotBlank(xsltPath)) {
490+
491+
// get data from uri
492+
String data = HttpUtils.getStringFromUrl(skosURI);
493+
494+
// if data is found
495+
if (StringUtils.isNotBlank(data)) {
496+
try {
497+
StreamSource input = new StreamSource(new StringReader(data));
498+
StreamSource xslt = new StreamSource(xsltPath);
499+
500+
TransformerFactory transformerFactory = TransformerFactory.newInstance();
501+
Transformer transformer = transformerFactory.newTransformer(xslt);
502+
503+
ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream();
504+
transformer.transform(input, new StreamResult(csvOutputStream));
505+
ByteArrayInputStream csvInputStream = new ByteArrayInputStream(csvOutputStream.toByteArray());
506+
VocabularyAPIManager.getInstance().vocabularies().cleanImportCsv(vocabularyId, csvInputStream);
507+
508+
initializeProperty(vocabularyName, labelField, valueField, property);
509+
} catch (TransformerException e) {
510+
String message = "Error while transforming vocabulary data from " + skosURI + " to CSV";
511+
log.error(message, e);
512+
Helper.setFehlerMeldung(message, e.getMessage());
513+
} catch (APIException e) {
514+
APIExceptionExtractor extractor = new APIExceptionExtractor(e);
515+
String message = "Failed to update vocabulary \"" + vocabularyName + "\", Reason: \n" + extractor.getLocalizedMessage(Helper.getSessionLocale());
516+
log.error(message, e);
517+
Helper.setFehlerMeldung(message, e.getMessage());
518+
}
519+
}
520+
}
521+
} catch (APIException e) {
522+
APIExceptionExtractor extractor = new APIExceptionExtractor(e);
523+
String message = "Failed to update vocabulary \"" + vocabularyName + "\", Reason: \n" + extractor.getLocalizedMessage(Helper.getSessionLocale());
524+
log.error(message, e);
525+
Helper.setFehlerMeldung(message, e.getMessage());
526+
}
527+
}
460528
}

module-gui/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.goobi.workflow.plugin</groupId>
66
<artifactId>plugin-administration-arche-project-export</artifactId>
7-
<version>25.11</version>
7+
<version>26.01</version>
88
</parent>
99
<artifactId>plugin-administration-arche-project-export-gui</artifactId>
1010
<packaging>jar</packaging>

module-gui/src/main/webapp/resources/uii/plugin_administration_arche_project_export.xhtml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
xmlns:jsf="http://xmlns.jcp.org/jsf"
1212
xmlns:section="http://goobi.io/section">
1313
<h:panelGroup>
14-
14+
1515

1616
<h:panelGroup
1717
styleClass="mt-3"
1818
rendered="#{!LoginForm.hasRole('Plugin_administration_arche_project_export')}"
1919
layout="block">
2020
<h:outputText
2121
styleClass="alert alert-danger"
22-
value="#{msgs.plugin_administration_missingPermission} Plugin_administration_arche_project_export"/>
22+
value="#{msgs.plugin_administration_missingPermission} Plugin_administration_arche_project_export" />
2323
</h:panelGroup>
24-
24+
2525
<ui:fragment rendered="#{LoginForm.hasRole('Plugin_administration_arche_project_export')}">
2626
<!-- select project to export -->
2727
<intranda:box
@@ -31,7 +31,7 @@
3131
icon="fa fa-plug"
3232
id="selectionBox"
3333
title="#{msgs[AdministrationForm.administrationPlugin.title]}">
34-
34+
3535
<h:form
3636
id="actionForm"
3737
enctype="multipart/form-data">
@@ -54,7 +54,7 @@
5454
</intranda:box>
5555

5656
<br />
57-
57+
5858
<!-- display selected project and edit configured properties -->
5959
<intranda:box
6060
boxForm="true"
@@ -216,13 +216,22 @@
216216

217217
</ui:fragment>
218218

219-
<ui:fragment rendered="#{property.type.name == 'list'}">
219+
<ui:fragment rendered="#{property.type.name == 'list' or property.type.name == 'vocabularyreference'}">
220220
<div class="row">
221221
<div class="col-12 col-md-3">
222222
<intranda:formLabel
223223
label="#{property.name}"
224224
labelFor="select"
225225
labelRequired="#{property.showProcessGroupAccessCondition == 'WRITEREQUIRED'}" />
226+
227+
<button
228+
jsf:rendered="#{property.type.name == 'vocabularyreference'}"
229+
jsf:action="#{AdministrationForm.administrationPlugin.updateVocabulary(property)}"
230+
aria-label="#{msgs.plugin_administration_arche_updateVocabulary}"
231+
class="btn btn-blank float-end">
232+
<i class="fa fa-refresh"></i>
233+
234+
</button>
226235
</div>
227236
<div class="col-12 col-md-9">
228237
<h:selectOneMenu
@@ -298,24 +307,24 @@
298307
</ui:fragment>
299308
</ui:repeat>
300309
<div class="form-actions">
301-
<button
310+
<button
302311
jsf:action="#{AdministrationForm.administrationPlugin.exportProject(true)}"
303312
aria-label="#{msgs.plugin_administration_arche_save_test}"
304313
class="btn btn-primary">
305314
<i class="fa fa-floppy-o"></i>
306315
<span>
307316
<h:outputText value="#{msgs.plugin_administration_arche_save_test}" />
308-
</span>
317+
</span>
309318
</button>
310-
319+
311320
<button
312321
jsf:action="#{AdministrationForm.administrationPlugin.exportProject(true)}"
313322
aria-label="#{msgs.plugin_administration_arche_save_prod}"
314323
class="btn btn-primary">
315324
<i class="fa fa-floppy-o"></i>
316325
<span>
317326
<h:outputText value="#{msgs.plugin_administration_arche_save_prod}" />
318-
</span>
327+
</span>
319328
</button>
320329
</div>
321330
</h:form>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.goobi.workflow</groupId>
66
<artifactId>workflow-base</artifactId>
7-
<version>25.11</version>
7+
<version>26.01</version>
88
<relativePath/>
99
</parent>
1010
<groupId>io.goobi.workflow.plugin</groupId>
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>io.goobi.workflow</groupId>
2626
<artifactId>workflow-core</artifactId>
27-
<version>25.11</version>
27+
<version>26.01</version>
2828
<classifier>classes</classifier>
2929
</dependency>
3030
</dependencies>

0 commit comments

Comments
 (0)