Skip to content

Commit

Permalink
Pass created, modified, issued date from thesaurus to the schemas (#6972
Browse files Browse the repository at this point in the history
)

* add isFileSystemDate flag to thesaurus model

* pass thesaurus created, issued, modified date to the schemas.

* Fixed null pointer exception.

* remove date conversion

* Revert default thesaurus date to original code

* add more dateformat to parsing Thesaurus date

* Update thesaurus-transformation.xsl

---------

Co-authored-by: Jose García <josegar74@gmail.com>
  • Loading branch information
wangf1122 and josegar74 committed Apr 24, 2023
1 parent 68b32ce commit f616aae
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 6 deletions.
31 changes: 30 additions & 1 deletion core/src/main/java/org/fao/geonet/kernel/Thesaurus.java
Expand Up @@ -99,6 +99,12 @@ public class Thesaurus {

private String date;

private String createdDate;

private String issuedDate;

private String modifiedDate;

private String defaultNamespace;

private String downloadUrl;
Expand Down Expand Up @@ -258,6 +264,18 @@ public String getDate() {
return date;
}

public String getCreatedDate() {
return createdDate;
}

public String getIssuedDate() {
return issuedDate;
}

public String getModifiedDate() {
return modifiedDate;
}

@Nonnull
public FileTime getLastModifiedTime() {
FileTime lastModified;
Expand Down Expand Up @@ -965,8 +983,17 @@ private void retrieveThesaurusInformation(Path thesaurusFile, String defaultTitl
this.defaultNamespace = DEFAULT_THESAURUS_NAMESPACE;
}

Element dateEl = Xml.selectElement(thesaurusEl, "skos:ConceptScheme/dcterms:issued|skos:Collection/dc:date", theNSs);
Element issuedDateEl = Xml.selectElement(thesaurusEl, "skos:ConceptScheme/dcterms:issued", theNSs);
this.issuedDate = issuedDateEl==null? "": issuedDateEl.getText();

Element modifiedDateEl = Xml.selectElement(thesaurusEl, "skos:ConceptScheme/dcterms:modified", theNSs);
this.modifiedDate = modifiedDateEl==null? "": modifiedDateEl.getText();

Element createdDateEl = Xml.selectElement(thesaurusEl, "skos:ConceptScheme/dcterms:created", theNSs);
this.createdDate = createdDateEl==null? "": createdDateEl.getText();

// Default date
Element dateEl = Xml.selectElement(thesaurusEl, "skos:ConceptScheme/dcterms:issued|skos:Collection/dc:date", theNSs);
Date thesaususDate = parseThesaurusDate(dateEl);

if (thesaususDate == null) {
Expand Down Expand Up @@ -1027,6 +1054,8 @@ private Date parseThesaurusDate(Element dateEl) {
dfList.add(new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"));
dfList.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
dfList.add(new SimpleDateFormat("yyyy-MM-dd"));
dfList.add(new SimpleDateFormat("yyyy-MM"));
dfList.add(new SimpleDateFormat("yyyy"));

StringBuffer errorMsg = new StringBuffer("Error parsing the thesaurus date value: ");
errorMsg.append(dateVal);
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/org/fao/geonet/kernel/ThesaurusManager.java
Expand Up @@ -551,6 +551,18 @@ public Element buildResultfromThTable(ServiceContext context) throws SQLExceptio
String date = currentTh.getDate();
elDate.addContent(date);

Element elCreatedDate = new Element("createdDate");
String createdDate = currentTh.getCreatedDate();
elCreatedDate.addContent(createdDate);

Element elIssuedDate = new Element("issuedDate");
String issuedDate = currentTh.getIssuedDate();
elIssuedDate.addContent(issuedDate);

Element elModifiedDate = new Element("modifiedDate");
String modifiedDate = currentTh.getModifiedDate();
elModifiedDate.addContent(modifiedDate);

Element elUrl = new Element("url");
String url = currentTh.getDownloadUrl();
elUrl.addContent(url);
Expand All @@ -568,6 +580,9 @@ public Element buildResultfromThTable(ServiceContext context) throws SQLExceptio
elLoop.addContent(elDublinCoreMultilingual);
elLoop.addContent(elMultilingualDescriptions);
elLoop.addContent(elDate);
elLoop.addContent(elCreatedDate);
elLoop.addContent(elIssuedDate);
elLoop.addContent(elModifiedDate);
elLoop.addContent(elUrl);
elLoop.addContent(elDefaultURI);
elLoop.addContent(elType);
Expand Down
Expand Up @@ -272,6 +272,12 @@

<xsl:variable name="thesaurusDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/date)" />
<xsl:variable name="thesaurusCreatedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/createdDate)"/>
<xsl:variable name="thesaurusIssuedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/issuedDate)"/>
<xsl:variable name="thesaurusModifiedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/modifiedDate)"/>

<xsl:if test="$thesaurusDate != ''">
<cit:date>
Expand Down Expand Up @@ -299,6 +305,87 @@
</cit:date>
</xsl:if>

<!-- Publication Date-->
<xsl:choose>
<xsl:when test="$thesaurusIssuedDate != ''">
<cit:date>
<cit:CI_Date>
<cit:date>
<xsl:choose>
<xsl:when test="contains($thesaurusIssuedDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusIssuedDate" />
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusIssuedDate" />
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="publication" />
</cit:dateType>
</cit:CI_Date>
</cit:date>
</xsl:when>
<xsl:otherwise>
<cit:date>
<cit:CI_Date>
<cit:date>
<xsl:choose>
<xsl:when test="contains($thesaurusDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusDate" />
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusDate" />
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="publication" />
</cit:dateType>
</cit:CI_Date>
</cit:date>
</xsl:otherwise>
</xsl:choose>

<!--Creation Date-->
<xsl:if test="$thesaurusCreatedDate != ''">
<cit:date>
<cit:CI_Date>
<cit:date>
<xsl:choose>
<xsl:when test="contains($thesaurusCreatedDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusCreatedDate" />
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusCreatedDate" />
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</cit:date>
<cit:dateType>
<cit:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="creation" />
</cit:dateType>
</cit:CI_Date>
</cit:date>
</xsl:if>

<xsl:if test="$withThesaurusAnchor">
<cit:identifier>
<mcc:MD_Identifier>
Expand Down
Expand Up @@ -330,28 +330,89 @@

<xsl:variable name="thesaurusDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/date)"/>
<xsl:variable name="thesaurusCreatedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/createdDate)"/>
<xsl:variable name="thesaurusIssuedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/issuedDate)"/>
<xsl:variable name="thesaurusModifiedDate"
select="normalize-space($thesauri/thesaurus[key = $currentThesaurus]/modifiedDate)"/>

<!-- Publication Date-->
<xsl:choose>
<xsl:when test="$thesaurusIssuedDate != ''">
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<xsl:choose>
<xsl:when test="contains($thesaurusIssuedDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusIssuedDate"/>
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusIssuedDate"/>
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="publication"/>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</xsl:when>
<xsl:otherwise>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<xsl:choose>
<xsl:when test="contains($thesaurusDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusDate"/>
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusDate"/>
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="publication"/>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</xsl:otherwise>
</xsl:choose>

<xsl:if test="$thesaurusDate != ''">
<!--Creation Date-->
<xsl:if test="$thesaurusCreatedDate != ''">
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<xsl:choose>
<xsl:when test="contains($thesaurusDate, 'T')">
<xsl:when test="contains($thesaurusCreatedDate, 'T')">
<gco:DateTime>
<xsl:value-of select="$thesaurusDate"/>
<xsl:value-of select="$thesaurusCreatedDate"/>
</gco:DateTime>
</xsl:when>
<xsl:otherwise>
<gco:Date>
<xsl:value-of select="$thesaurusDate"/>
<xsl:value-of select="$thesaurusCreatedDate"/>
</gco:Date>
</xsl:otherwise>
</xsl:choose>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode
codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode"
codeListValue="publication"/>
codeListValue="creation"/>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
Expand Down

0 comments on commit f616aae

Please sign in to comment.