list tr rules

This commit is contained in:
Michele Artini 2024-01-17 12:45:56 +01:00
parent 2d9f71b2b3
commit 78c2810878
9 changed files with 287 additions and 37 deletions

View File

@ -38,6 +38,7 @@ import eu.dnetlib.domain.wfs.templates.WfTemplate;
import eu.dnetlib.domain.wfs.templates.WfTemplateDesc;
import eu.dnetlib.errors.WorkflowManagerException;
import eu.dnetlib.wfs.manager.service.WorkflowManagerService;
import eu.dnetlib.wfs.manager.suppliers.ValidTermsSupplierFactory;
import eu.dnetlib.wfs.utils.WfConfigurationUtils;
@RestController
@ -50,6 +51,9 @@ public class ApiController extends DnetRestController {
@Autowired
private DnetServiceClientFactory clientFactory;
@Autowired
private ValidTermsSupplierFactory validTermsSupplierFactory;
@GetMapping("/history")
public List<WfJournalEntry> history(
@RequestParam(required = true) final int total,
@ -189,6 +193,11 @@ public class ApiController extends DnetRestController {
for (final String wf : workflows) {
for (final WfParam p : client.findResourceContent(WorkflowsConstants.WF_TEMPLATE, wf, WfTemplate.class).getParameters()) {
if (p.getValidTermsSupplier() != null) {
p.setValidTerms(this.validTermsSupplierFactory.findTerms(p.getValidTermsSupplier()));
}
if (params.containsKey(p.getName())) {
final WfParam main = params.get(p.getName());
main.setDefaultValue(StringUtils.firstNonBlank(main.getDefaultValue(), p.getDefaultValue()));

View File

@ -0,0 +1,34 @@
package eu.dnetlib.wfs.manager.suppliers;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import eu.dnetlib.common.clients.DnetServiceClientFactory;
import eu.dnetlib.common.clients.SimpleResourceClient;
import eu.dnetlib.domain.resource.SimpleResource;
import eu.dnetlib.domain.wfs.templates.WfParamValidTermsSupplier;
@Component
public class ValidTermsSupplierFactory {
@Autowired
private DnetServiceClientFactory clientFactory;
public List<String> findTerms(final WfParamValidTermsSupplier ts) {
return switch (ts) {
case LIST_TRANSFORMATION_RULES -> listTransformationRules();
default -> new ArrayList<>();
};
}
private List<String> listTransformationRules() {
return this.clientFactory.getClient(SimpleResourceClient.class)
.findResources("transformation_rule_xslt", null)
.stream()
.map(SimpleResource::getName)
.toList();
}
}

View File

@ -10,7 +10,8 @@
},
{
"name":"xsltRuleId",
"description":"Transformation Rule ID"
"description":"Transformation Rule ID",
"validTermsSupplier": "LIST_TRANSFORMATION_RULES"
},
{
"name":"cleanedMdStoreFilterXpath",

View File

@ -0,0 +1,198 @@
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:transformExt="http://namespace.openaire.eu/java/org.apache.commons.codec.digest.DigestUtils" xmlns:datetime="http://exslt.org/dates-and-times" xmlns:exslt="http://exslt.org/common" xmlns:oai="http://www.openarchives.org/OAI/2.0/"
xmlns:dnet="eu.dnetlib.data.utils.XsltFunctions"
xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:TransformationFunction="eu.dnetlib.data.collective.transformation.core.xsl.ext.TransformationFunctionProxy" xmlns:dc="http://purl.org/dc/elements/1.1/" exclude-result-prefixes="xsl transformExt TransformationFunction dnet datetime exslt dc ">
<xsl:param name="varOfficialName"/>
<xsl:variable name="tf" select="TransformationFunction:getInstance()" />
<xsl:template match="/">
<xsl:variable name="tmpRights">
<xsl:choose>
<xsl:when test=".//dc:rights[.='info:eu-repo/semantics/closedAccess']">Closed Access</xsl:when>
<xsl:when test=".//dc:rights[.='info:eu-repo/semantics/restrictedAccess']">Restricted</xsl:when>
<xsl:when test=".//dc:rights[.='info:eu-repo/semantics/embargoedAccess']">Embargo</xsl:when>
<xsl:when test=".//dc:rights[.='info:eu-repo/semantics/openAccess']">Open Access</xsl:when>
<xsl:otherwise>Unknown</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rights" select="normalize-space($tmpRights)"/>
<oai:record>
<xsl:copy-of select="//*[local-name() = 'header']"/>
<oai:metadata>
<record>
<identifier><xsl:value-of select="normalize-space(//dri:recordIdentifier)"/></identifier>
<title><xsl:value-of select="//dc:title[1]" /></title>
<creators>
<xsl:for-each select="//dc:creator">
<xsl:for-each select="tokenize(dnet:cleanNames(.), '#')">
<xsl:if test="string-length(.) &amp;gt; 0">
<creator><xsl:value-of select="."/></creator>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</creators>
<publisher><xsl:value-of select="//dc:publisher[1]"/></publisher>
<subjects>
<xsl:for-each select="//dc:subject">
<subject><xsl:value-of select="."/></subject>
</xsl:for-each>
</subjects>
<contributors>
<xsl:for-each select="//dc:contributor">
<xsl:for-each select="tokenize(., ',')">
<contributor><xsl:value-of select="normalize-space(.)"/></contributor>
</xsl:for-each>
</xsl:for-each>
</contributors>
<date><xsl:value-of select="//dc:date[1]"/></date>
<language><xsl:value-of select="TransformationFunction:convertString($tf, //dc:language[1], 'Languages')"/></language>
<xsl:variable name="infoType" select="normalize-space(//dc:type[contains(.,'info:eu-repo/semantics')])"/>
<xsl:variable name="peopleType" select="normalize-space(//dc:type[not(contains(.,'info:eu-repo/semantics'))])"/>
<xsl:choose>
<xsl:when test="contains($infoType,'masterThesis')">
<type>Master thesis</type>
</xsl:when>
<xsl:when test="contains($infoType,'doctoralThesis')">
<type>Doctoral thesis</type>
</xsl:when>
<xsl:when test="contains($infoType,'bachelorThesis')">
<type>Bachelor thesis</type>
</xsl:when>
<xsl:otherwise>
<type><xsl:value-of select="TransformationFunction:convertString($tf, $peopleType, 'IopTypologies')" /></type>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="starts-with(normalize-space(//dri:repositoryId), '807f0d50-2dc9-447d-8914-b91c34cb5841')">
<documentPage>
<xsl:value-of select="concat('https://openportal.isti.cnr.it/doc?id=people______::', dnet:md5(normalize-space(//dri:recordIdentifier)))"/>
</documentPage>
</xsl:when>
<xsl:when test="starts-with(normalize-space(//dri:repositoryId), 'a58f6fed-ac2d-4cfe-a175-d809858b0eeb')">
<documentPage>
<xsl:value-of select="concat('https://openportal.ispc.cnr.it/doc?id=people______::', dnet:md5(normalize-space(//dri:recordIdentifier)))"/>
</documentPage>
</xsl:when>
<xsl:when test="starts-with(normalize-space(//dri:repositoryId), 'db0e729d-38d0-44e1-9750-80d3c048525d')">
<documentPage>
<xsl:value-of select="concat('https://openportal.ismar.cnr.it/doc?id=people______::', dnet:md5(normalize-space(//dri:recordIdentifier)))"/>
</documentPage>
</xsl:when>
<xsl:when test="starts-with(normalize-space(//dri:repositoryId), '5bdb0333-29f0-40c9-ad33-1fc4de6b2efa')">
<documentPage>
<xsl:value-of select="concat('https://openportal.ino.cnr.it/doc?id=people______::', dnet:md5(normalize-space(//dri:recordIdentifier)))"/>
</documentPage>
</xsl:when>
</xsl:choose>
<urls>
<xsl:for-each select="//dc:identifier">
<xsl:if test="starts-with(., 'http') and contains(., 'www.cnr.it')">
<!-- <url rights="Unknown" hostedBy="CNR People"><xsl:value-of select="."/></url>-->
</xsl:if>
<xsl:if test="starts-with(., 'http') and contains(., 'publications.cnr.it')">
<url rights="Unknown" hostedBy="CNR ExploRA"><xsl:value-of select="."/></url>
</xsl:if>
<xsl:if test="starts-with(., 'http') and not(contains(., 'doi.org/')) and not(contains(., '/www.cnr.it/')) and not(contains(., '/publications.cnr.it/'))">
<url rights="{$rights}" hostedBy="{dnet:serverName(.)}"><xsl:value-of select="."/></url>
</xsl:if>
<xsl:if test="starts-with(., 'http') and contains(., 'doi.org/')">
<xsl:variable name="doi" select="dnet:cleanDoi(substring-after(., 'doi.org/'))" />
<url rights="{$rights}" hostedBy="DOI Resolver"><xsl:value-of select="concat('https://dx.doi.org/', $doi)"/></url>
</xsl:if>
<xsl:if test="starts-with(., 'info:doi:')">
<xsl:variable name="doi" select="dnet:cleanDoi(substring-after(., 'info:doi:'))" />
<url rights="{$rights}" hostedBy="DOI Resolver"><xsl:value-of select="concat('https://dx.doi.org/', $doi)"/></url>
</xsl:if>
</xsl:for-each>
</urls>
<dois>
<xsl:for-each select="//dc:identifier">
<xsl:if test="starts-with(., 'info:doi:')">
<xsl:variable name="doi" select="dnet:cleanDoi(substring-after(., 'info:doi:'))" />
<xsl:if test="$doi"><doi><xsl:value-of select="$doi"/></doi></xsl:if>
</xsl:if>
<xsl:if test="starts-with(., 'http') and contains(., 'doi.org/')">
<xsl:variable name="doi" select="dnet:cleanDoi(substring-after(., 'doi.org/'))" />
<xsl:if test="$doi"><doi><xsl:value-of select="$doi"/></doi></xsl:if>
</xsl:if>
</xsl:for-each>
</dois>
<xsl:choose>
<xsl:when test="//dc:identifier[starts-with(., 'http') and not(contains(., '/www.cnr.it/')) and not(contains(., '/publications.cnr.it/'))]">
<bestRights><xsl:value-of select="$rights"/></bestRights>
</xsl:when>
<xsl:when test="//dc:identifier[starts-with(., 'info:doi:')]">
<bestRights><xsl:value-of select="$rights"/></bestRights>
</xsl:when>
<xsl:otherwise>
<bestRights>Unknown</bestRights>
</xsl:otherwise>
</xsl:choose>
<abstract><xsl:value-of select="//dc:description[1]"/></abstract>
<xsl:for-each select="//dc:source[(string-length(.) > 10) and not(starts-with(.,'info:cnr-pdr/source')) ]">
<xsl:if test="position() = 1">
<source><xsl:value-of select="." /></source>
</xsl:if>
</xsl:for-each>
<projects>
<xsl:for-each select="//dc:relation[starts-with(., 'info:eu-repo/grantAgreement')]">
<xsl:if test="dnet:isValidProject(.)">
<project>
<infoId><xsl:value-of select="." /></infoId>
<openaireId><xsl:value-of select="position()" /></openaireId>
<code><xsl:value-of select="position()" /></code>
<name><xsl:value-of select="position()" /></name>
<acronym><xsl:value-of select="position()" /></acronym>
<funder><xsl:value-of select="position()" /></funder>
<program><xsl:value-of select="position()" /></program>
<jurisdiction><xsl:value-of select="position()" /></jurisdiction>
</project>
</xsl:if>
</xsl:for-each>
</projects>
<cnrPersons>
<xsl:for-each select="//dc:relation[starts-with(., 'info:cnr-pdr/author')]">
<cnrPerson>
<infoId><xsl:value-of select="." /></infoId>
<name><xsl:value-of select="dnet:calculatePersonName(.)" /></name>
</cnrPerson>
</xsl:for-each>
</cnrPersons>
<citations />
<collections>
<xsl:for-each select="//oai:setSpec[normalize-space(.) != 'openaire']">
<inCollection>
<code><xsl:value-of select="normalize-space(.)" /></code>
<name />
<acronym />
</inCollection>
</xsl:for-each>
</collections>
</record>
</oai:metadata>
</oai:record>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,6 +1,5 @@
package eu.dnetlib.common.clients;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -65,14 +64,13 @@ public class SimpleResourceClient extends DnetServiceClient {
public List<SimpleResource> findResources(final String type, final String subType) {
final StringWriter path = new StringWriter();
path.append("/api/resources/byType/{type}");
final String path = "/api/resources/byType/{type}";
if (StringUtils.isNotBlank(subType)) {
path.append("?subtype={subtype}");
}
final SimpleResource[] arr = StringUtils.isBlank(subType)
? httpGet(path, SimpleResource[].class, Map.of("type", type))
: httpGet(path + "?subtype={subtype}", SimpleResource[].class, Map.of("type", type, "subtype", subType));
return Arrays.asList(httpGet(path.toString(), SimpleResource[].class, Map.of("type", type, "subtype", subType)));
return Arrays.asList(arr);
}
}

View File

@ -95,12 +95,12 @@ public class Api implements Comparable<Api>, Serializable {
if (this == o) { return true; }
if ((o == null) || (getClass() != o.getClass())) { return false; }
final Api api = (Api) o;
return Objects.equals(id, api.id);
return Objects.equals(this.id, api.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
return Objects.hash(this.id);
}
@Override
@ -118,7 +118,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getId() {
return id;
return this.id;
}
public void setId(final String id) {
@ -126,7 +126,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getProtocol() {
return protocol;
return this.protocol;
}
public void setProtocol(final String protocol) {
@ -134,7 +134,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getDatasource() {
return datasource;
return this.datasource;
}
public void setDatasource(final String datasource) {
@ -142,7 +142,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getContentdescription() {
return contentdescription;
return this.contentdescription;
}
public void setContentdescription(final String contentdescription) {
@ -150,7 +150,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Boolean getActive() {
return active;
return this.active;
}
public void setActive(final Boolean active) {
@ -158,7 +158,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Boolean getRemovable() {
return removable;
return this.removable;
}
public void setRemovable(final Boolean removable) {
@ -166,7 +166,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getCompatibility() {
return compatibility;
return this.compatibility;
}
public void setCompatibility(final String compatibility) {
@ -174,7 +174,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public boolean isCompatibilityOverrided() {
return compatibilityOverrided;
return this.compatibilityOverrided;
}
public void setCompatibilityOverrided(final boolean compatibilityOverrided) {
@ -182,7 +182,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getMetadataIdentifierPath() {
return metadataIdentifierPath;
return this.metadataIdentifierPath;
}
public void setMetadataIdentifierPath(final String metadataIdentifierPath) {
@ -190,7 +190,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Integer getLastCollectionTotal() {
return lastCollectionTotal;
return this.lastCollectionTotal;
}
public void setLastCollectionTotal(final Integer lastCollectionTotal) {
@ -198,7 +198,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Timestamp getLastCollectionDate() {
return lastCollectionDate;
return this.lastCollectionDate;
}
public void setLastCollectionDate(final Timestamp lastCollectionDate) {
@ -206,7 +206,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getLastCollectionMdid() {
return lastCollectionMdid;
return this.lastCollectionMdid;
}
public void setLastCollectionMdid(final String lastCollectionMdid) {
@ -214,7 +214,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Integer getLastAggregationTotal() {
return lastAggregationTotal;
return this.lastAggregationTotal;
}
public void setLastAggregationTotal(final Integer lastAggregationTotal) {
@ -222,7 +222,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Timestamp getLastAggregationDate() {
return lastAggregationDate;
return this.lastAggregationDate;
}
public void setLastAggregationDate(final Timestamp lastAggregationDate) {
@ -230,7 +230,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getLastAggregationMdid() {
return lastAggregationMdid;
return this.lastAggregationMdid;
}
public void setLastAggregationMdid(final String lastAggregationMdid) {
@ -238,7 +238,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Integer getLastDownloadTotal() {
return lastDownloadTotal;
return this.lastDownloadTotal;
}
public void setLastDownloadTotal(final Integer lastDownloadTotal) {
@ -246,7 +246,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Timestamp getLastDownloadDate() {
return lastDownloadDate;
return this.lastDownloadDate;
}
public void setLastDownloadDate(final Timestamp lastDownloadDate) {
@ -254,7 +254,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getLastDownloadObjid() {
return lastDownloadObjid;
return this.lastDownloadObjid;
}
public void setLastDownloadObjid(final String lastDownloadObjid) {
@ -262,7 +262,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getLastValidationJob() {
return lastValidationJob;
return this.lastValidationJob;
}
public void setLastValidationJob(final String lastValidationJob) {
@ -270,7 +270,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getBaseurl() {
return baseurl;
return this.baseurl;
}
public void setBaseurl(final String baseurl) {
@ -278,7 +278,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public Set<ApiParam> getApiParams() {
return apiParams;
return this.apiParams;
}
public void setApiParams(final Set<ApiParam> apiParams) {
@ -286,7 +286,7 @@ public class Api implements Comparable<Api>, Serializable {
}
public String getCompatibilityOverride() {
return compatibilityOverride;
return this.compatibilityOverride;
}
public void setCompatibilityOverride(final String compatibilityOverride) {

View File

@ -18,6 +18,7 @@ public class WfParam implements Serializable {
private String defaultValue;
private List<String> validTerms = new ArrayList<>();
private boolean required = true;
private WfParamValidTermsSupplier validTermsSupplier;
public String getName() {
return this.name;
@ -67,4 +68,12 @@ public class WfParam implements Serializable {
this.validTerms = validTerms;
}
public WfParamValidTermsSupplier getValidTermsSupplier() {
return this.validTermsSupplier;
}
public void setValidTermsSupplier(final WfParamValidTermsSupplier validTermsSupplier) {
this.validTermsSupplier = validTermsSupplier;
}
}

View File

@ -1,5 +0,0 @@
package eu.dnetlib.domain.wfs.templates;
public class WfParamDesc {
// TODO (LOW PRIORITY) - ???
}

View File

@ -0,0 +1,6 @@
package eu.dnetlib.domain.wfs.templates;
public enum WfParamValidTermsSupplier {
LIST_TRANSFORMATION_RULES
}