Skip to content

Commit

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

* 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 <[email protected]>
  • Loading branch information
2 people authored and ianwallen committed Apr 24, 2023
1 parent 9c56ccc commit cd829fc
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 @@ -210,6 +216,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 @@ -838,8 +856,17 @@ private void retrieveThesaurusTitle(Path thesaurusFile, String defaultTitle, boo
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 @@ -900,6 +927,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
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,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 Down Expand Up @@ -519,6 +531,9 @@ public Element buildResultfromThTable(ServiceContext context) throws SQLExceptio
elLoop.addContent(elMultilingualTitles);
elLoop.addContent(elDublinCoreMultilingual);
elLoop.addContent(elDate);
elLoop.addContent(elCreatedDate);
elLoop.addContent(elIssuedDate);
elLoop.addContent(elModifiedDate);
elLoop.addContent(elUrl);
elLoop.addContent(elDefaultURI);
elLoop.addContent(elType);
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -320,28 +320,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 cd829fc

Please sign in to comment.