metadata101 / iso19139.ca.HNAP

ISO Harmonized North American Profile (HNAP)
GNU General Public License v2.0
4 stars 18 forks source link

validate publication date is after creation date #352

Closed wangf1122 closed 9 months ago

wangf1122 commented 11 months ago

If publication date is before creation date. image

then there will be validation error image

ianwallen commented 11 months ago

I tested the code and the error is not displayed in the form like it should be. It is only displayed in the validation section.

I would expect something like the following:

image

May want to consider creating a new rule like the following

   <!-- Creation/revision dates compare -->
    <sch:rule context="//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='gmd:MD_DataIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='srv:SV_ServiceIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date">

      <sch:let name="creationDate" value="../../../gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_366']/gmd:date/gco:Date" />
      <sch:let name="missingCreation" value="not(string($creationDate))" />
      <sch:let name="publicationDate" value="gco:Date" />
      <sch:let name="missingPublication" value="not(string($publicationDate))" />

      <sch:assert test="$missingPublication or $missingCreation or XslUtilHnap:compareDates($publicationDate, $creationDate) &gt;= 0 ">$loc/strings/PublicationDateBeforeCreationDate</sch:assert>
    </sch:rule>

With that code, it display the rule in the form.
The only issue was when I double clicked on the message from the validation section - it was not going to the error message in the form - maybe you can look into that issue - but if it is causing issues we can look at it later.

wangf1122 commented 11 months ago

@ianwallen

The code looks good.

image

I will update the PR with this block of code

wangf1122 commented 11 months ago

@josegar74

The gco:DateTime was nested into the gmd:date. Doesn't looks it's necessary.

image

ianwallen commented 10 months ago

@wangf1122 I just did a test and the following validated and it should have failed. - I'm guessing that this is what @josegar74 was referring too.

image

image

wangf1122 commented 10 months ago

@ianwallen @josegar74

I have added the xpath and util Java function to handle both gco:Date and gco:DateTime. I did test locally and they are acceptable.

1) No validation error. image

2) Validation error. image

ianwallen commented 10 months ago

@wangf1122 Can you explain why you feel you have to create a new function compareDateTimes The Extents date validation is able to handle all 3 date formats without any issues that I could see? I tested modifying my previous sample to the following and it seemed to have worked

   <!-- Creation/revision dates compare -->
    <sch:rule context="//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='gmd:MD_DataIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='srv:SV_ServiceIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date">

      <sch:let name="creationDate" value="../../../gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_366']/gmd:date" />
      <sch:let name="missingCreation" value="not(string($creationDate))" />
      <sch:let name="publicationDate" value="." />
      <sch:let name="missingPublication" value="not(string($publicationDate))" />

      <sch:assert test="$missingPublication or $missingCreation or XslUtilHnap:compareDates($publicationDate, $creationDate) &gt;= 0 ">$loc/strings/PublicationDateBeforeCreationDate</sch:assert>
    </sch:rule>

Another variation of the fix could be the following

   <!-- Creation/revision dates compare -->
    <sch:rule context="//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='gmd:MD_DataIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date
            |//*[@gco:isoType='srv:SV_ServiceIdentification']/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_367']/gmd:date">

      <sch:let name="creationDate" value="../../../gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_366']/gmd:date/gco:Date 
                                         |../../../gmd:date/gmd:CI_Date[gmd:dateType/gmd:CI_DateTypeCode/@codeListValue = 'RI_366']/gmd:date/gco:DateTime" />
      <sch:let name="missingCreation" value="not(string($creationDate))" />
      <sch:let name="publicationDate" value="gco:Date|gco:DateTime" />
      <sch:let name="missingPublication" value="not(string($publicationDate))" />

      <sch:assert test="$missingPublication or $missingCreation or XslUtilHnap:compareDates($publicationDate, $creationDate) &gt;= 0 ">$loc/strings/PublicationDateBeforeCreationDate</sch:assert>
    </sch:rule>

I have tested both and they seem to fix the issue raised by @josegar74

wangf1122 commented 10 months ago

@ianwallen @josegar74

I have copy pasted Ian's code and it works fine with local test.

jodygarnett commented 10 months ago

I believe all feedback has been accounted for here.

ianwallen commented 9 months ago

I would expect that there should only be one creation date. But I believe it may be possible to have multiple publication dates.

For now, maybe <sch:let name="creationDate could be modified to get the first occurrence so that if it does happen users will still be able validate the record without getting an array issues.

We can create another issue that can look into validating the number of occurrences of the creation date. We would need to look into HNAP to see if it allows multiple creation dates - if not then we can add a check to fail validation if multiple creation dates are added.

wangf1122 commented 9 months ago

@ianwallen @josegar74

I have update the code to use first creation date which is /gmd:date[1]/gco:Date[1]. It does not cause harm to our case but will also handle if this element is an array.