Skip to content

Commit

Permalink
UBO-378 Allow to choose data sources used for enrichment in list impo…
Browse files Browse the repository at this point in the history
…rt (#446)

* UBO-378 Added form elements to import-list.xed for selecting DataSources for enrichment

* UBO-378 Allow to handle custom enrichment config ids in DozBibImportServlet and ImportJob

* UBO-378 Added toggleDataSources to ImportList.js

* UBO-378 Added class EnrichmentConfigMgr to reuse code in ImportListJobAction

* UBO-378 Load existing configs via uri resolver and do not cach in enrichmentDebugger.xed

* UBO-378 Fixed javadoc

* UBO-378 Removed class form-control from select affected by bootstrap-select

* UBO-378 Added class attributes to selects

* UBO-378 Updated javadoc in EnrichmentConfigMgr

* UBO-378 Simplified control flow

* UBO-378 Include changes from UBO-372

* UBO-378 Updated col classes for DataSource select and input

* UBO-378 Reduce diff

* UBO-378 Applied requested changes

* UBO-378 Removed form-group class from <div> containing the DataSource select/inputs
  • Loading branch information
Possommi authored Dec 16, 2024
1 parent c1d55e7 commit 9768997
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ private void handleImportJob(HttpServletRequest req, HttpServletResponse res) th

boolean enrich = "true".equals(formInput.getAttributeValue("enrich"));
if (enrich) {
importJob.enrich();
String enricherId = EnrichmentConfigMgr.getEnricherId(formInput);
if (enricherId != null) {
importJob.enrich(enricherId);
} else {
importJob.enrich();
}
}

String targetType = formInput.getAttributeValue("targetType");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.mycore.ubo.importer;

import org.jdom2.Element;
import org.mycore.common.config.MCRConfiguration2;

import java.util.Optional;

/**
* Class retrieves the enricher id from the form input of import-list.xed.
*
* @author shermann (Silvio Hermann)
*/
public class EnrichmentConfigMgr {
static final String DEFAULT_CONFIG_ID = "custom";

private EnrichmentConfigMgr() {
}

/**
* Retrieves the enricher id from the import list form element.
* If the value of the DataSource element is a valid enrichment config id that id is returned. Otherwise,
* it assumed a list of enrichment sources e.g. <em>GBV Unpaywall ...</em> is provided. In that case a new
* configuration with id <code>custom</code> is created and the returned id will be <code>custom</code>.
*
* @param formInput the form input (usually provided by import-list.xed)
*
* @return the enricher id or <code>null</code>
*/
public static String getEnricherId(Element formInput) {
Optional<Element> dataSource = formInput.getChildren("DataSources")
.stream()
.filter(element -> !element.getText().isEmpty())
.findFirst();

if (dataSource.isEmpty()) {
return null;
}

String dataSrcTxt = dataSource.get().getText();
if (MCRConfiguration2.getString("MCR.MODS.EnrichmentResolver.DataSources." + dataSrcTxt).isPresent()) {
return dataSrcTxt;
} else {
String property = "MCR.MODS.EnrichmentResolver.DataSources." + DEFAULT_CONFIG_ID;
MCRConfiguration2.set(property, dataSrcTxt);
return DEFAULT_CONFIG_ID;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public void transform(MCRContent source) throws IOException, JDOMException, SAXE
}
}

public void enrich(String configId){
for (Document publication : publications) {
MCREnricher enricher = new MCREnricher(configId);
enricher.enrich(getContainedMODS(publication));
}
}

public void enrich() {
for (Document publication : publications) {
MCREnricher enricher = new MCREnricher(ENRICHER_CONFIG_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public void execute() throws ExecutionException {
job.setParameter(IMPORT_JOB_ID_PARAMETER, importJob.getID());

if ("true".equals(formInput.getAttributeValue("enrich"))) {
importJob.enrich();
String enricherId = EnrichmentConfigMgr.getEnricherId(formInput);
if (enricherId != null) {
importJob.enrich(enricherId);
} else {
importJob.enrich();
}
}

try {
Expand All @@ -80,7 +85,7 @@ private void sendMail(ImportJob importJob) {
String userName = job.getParameter(ImportListJobAction.USER_ID_PARAMETER);
MCRUser mcrUser = MCRUserManager.getUser(userName);

if(mcrUser == null) {
if (mcrUser == null) {
LOGGER.error("User {} not found", userName);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="card-body">
<xed:form xmlns:xed="http://www.mycore.de/xeditor" method="post" role="form">

<xed:source uri="cache:enrichmentConfig:custom" />
<xed:source uri="enrichmentConfig:custom" />

<xed:bind xpath="enrichmentDebugger">

Expand Down
28 changes: 24 additions & 4 deletions ubo-common/src/main/resources/META-INF/resources/import-list.xed
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</legend>

<xed:bind xpath="partOf">
<div class="form-group form-inline">
<div class="form-group form-inline ubo-import-list-select-partOf">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.partOf" />:
</label>
Expand All @@ -69,7 +69,7 @@
</xed:bind>

<xed:bind xpath="status">
<div class="form-group form-inline">
<div class="form-group form-inline ubo-import-list-select-status">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="search.dozbib.status" />:
</label>
Expand All @@ -85,7 +85,7 @@
<hr/>

<xed:repeat xpath="subject" max="5">
<div class="form-group form-inline">
<div class="form-group form-inline ubo-import-list-select-fachreferate">
<label for="subject" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.subject" />:
</label>
Expand All @@ -100,7 +100,7 @@
</xed:repeat>

<xed:bind xpath="origin">
<div class="form-group form-inline">
<div class="form-group form-inline ubo-import-list-select-origin">
<label for="{generate-id()}" class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.department" />:
</label>
Expand Down Expand Up @@ -137,6 +137,26 @@

<hr/>

<div class="form-inline">
<label class="mycore-form-label text-nowrap">
<xed:output i18n="ubo.import.list.label.dataSources"/>:
</label>

<xed:bind xpath="DataSources[@type='provided']">
<select id="datasource-source-select" class="form-control mycore-form-input custom-select" onchange="UBOImportList.toggleDataSources(this)">
<option value="">
<xed:output i18n="search.select"/>
</option>
<xed:include uri="xslStyle:enrichers2options:enrichmentConfig:custom" />
</select>
</xed:bind>

<label class="mycore-form-label text-nowrap pt-1"/>
<xed:bind xpath="DataSources[@type='custom']">
<input id="datasource-input-custom" type="text" class="form-control mycore-form-input custom-select mt-3" placeholder="{i18n:ubo.import.list.placeholder.dataSources.custom}" oninput="UBOImportList.toggleDataSources(this)"/>
</xed:bind>
</div>

<xed:bind xpath="@enrich" initially="false">
<div class="form-group form-inline">
<label class="mycore-form-label text-nowrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $(document).ready(function () {
width:'auto',
dropupAuto: false
});

});

const UBOImportList = {
Expand Down Expand Up @@ -41,5 +41,21 @@ const UBOImportList = {
} else {
$("#submitBtn").removeAttr("disabled");
}
},

toggleDataSources: function (element) {
switch (element.id) {
case "datasource-input-custom":
if (element.value != null && element.value.length > 0) {
document.getElementById('datasource-source-select').selectedIndex = 0;
}
break;

case "datasource-source-select":
if (element.value != null && element.value.length > 0) {
document.getElementById('datasource-input-custom').value = "";
}
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,11 @@ ubo.import.list.email.body = Liebe Kollegin, lieber Kollege
ubo.import.list.email.subject = Listenimport vom {0} abgeschlossen
ubo.import.list.form.headline = Literaturliste importieren
ubo.import.list.label.async = Import nebenl\u00E4ufig ausf\u00FChren
ubo.import.list.label.dataSources = Datenquellen
ubo.import.list.label.enrich = aus externen Datenquellen anreichern
ubo.import.list.label.outputFormat = Ausgabeformat
ubo.import.list.label.sourceFormat = Quellformat
ubo.import.list.placeholder.dataSources.custom = eigene Angaben, z.B. GBV Unpaywall \u2026
ubo.import.list.submission.success = Ein Importauftrag wurde im System angelegt. Sobald dieser abgearbeitet wurde, erhalten Sie eine E-Mail an die in Ihrem Profil hinterlegte Adresse.
ubo.import.list.textarea.placeholder = BibTeX Quellcode bzw. ORCID bzw. PPN/CSV-Literaturliste hierhin kopieren
ubo.import.list.tooltip.async = Wenn Sie hier den Haken setzen, wird Ihr Importauftrag ansynchron ausgef\u00FChrt. Das bedeutet, Sie werden nicht unmittelbar zur Ergebnisanzeige weitergeleitet sondern erhalten eine Benachrichtigungs-E-Mail, wenn der Import abgeschlossen ist. Setzen Sie den Haken, wenn Sie eine gro\u00DFe Menge an Publikationen \u00FCber IDs importieren wollen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,11 @@ ubo.import.list.email.body = Dear colleague,\n\n
ubo.import.list.email.subject = List import from {} completed
ubo.import.list.form.headline = Import bibliography
ubo.import.list.label.async = Run import concurrently
ubo.import.list.label.dataSources = Data Sources
ubo.import.list.label.enrich = enrich from external data sources
ubo.import.list.label.outputFormat = Output format
ubo.import.list.label.sourceFormat = Source format
ubo.import.list.placeholder.dataSources.custom = custom settings e.g. GBV Unpaywall \u2026
ubo.import.list.submission.success = An import job has been created in the system. As soon as this has been processed, you will receive an email to the address stored in your user profile.
ubo.import.list.textarea.placeholder = Copy BibTeX source code or ORCID or PPN/CSV bibliography here
ubo.import.list.tooltip.async = If you tick this box, your import job will be carried out asynchronously. This means that you will not be redirected to the results display immediately, but will receive a notification email when the import is completed. Tick this box if you want to import a large number of publications using IDs.
Expand Down
19 changes: 19 additions & 0 deletions ubo-common/src/main/resources/xsl/enrichers2options.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl">
<xsl:output method="html"/>

<xsl:template match="/">
<result>
<xsl:apply-templates select="enrichmentDebugger/enrichers/enricher">
<xsl:sort select="@id"/>
</xsl:apply-templates>
</result>
</xsl:template>

<xsl:template match="enricher">
<option value="{@id}" title="{@id}">
<xsl:value-of select="text()"/>
</option>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 9768997

Please sign in to comment.