Skip to content
91 changes: 91 additions & 0 deletions src/main/resources/application-context-schema-org.xml
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add your "schema_org_creator_role_name" and "schema_org_creator_list_role_name" beans to the application-context-json-ld.xml file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 87881f0.

Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,97 @@
</constructor-arg>
</bean>

<!-- This query extracts the name from a creator field that uses no list when there is a single creator,
and also nests creator fields with @type definitions.
{
"@context": {
"@vocab": "https://schema.org/"
},
"@graph": {
"creator": {
"@type": "Role",
"creator": {
"@type": "Person",
...
"name": "..."
}
}
}
}
-->
<bean id="schema_org_creator_role_name" class="org.dataone.cn.indexer.annotation.SparqlField">
<constructor-arg name="name" value="origin" />
<constructor-arg name="query">
<value>
<![CDATA[
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>
PREFIX SO: <http://schema.org/>

SELECT (?name as ?origin)
WHERE {
?dsId rdf:type SO:Dataset .
?dsId SO:creator $creator .
$creator SO:creator ?role .
$role SO:name ?name .
}
]]>
</value>
</constructor-arg>
</bean>

<!-- This query extracts the names from a creator field that uses ordered list syntax when there are multiple creators,
and also nests creator fields with @type definitions.
{
"@context": {
"@vocab": "https://schema.org/"
},
"@graph": {
"creator": [
{
"@type": "Role",
"creator": {
"@type": "Person",
...
"name": "Person 1"
}
},
{
"@type": "Role",
"creator": {
"@type": "Person",
...
"name": "Person 2"
}
}
]
}
}
-->
<bean id="schema_org_creator_list_role_name" class="org.dataone.cn.indexer.annotation.SparqlField">
<constructor-arg name="name" value="origin" />
<constructor-arg name="query">
<value>
<![CDATA[
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX list: <http://jena.hpl.hp.com/ARQ/list#>
PREFIX SO: <http://schema.org/>

SELECT (?name as ?origin)
WHERE {
?dsId rdf:type SO:Dataset .
?dsId SO:creator ?creatorList .
?creatorList list:member ?creator .
?creatorList list:index ?pos .
?creator SO:creator ?role .
?role SO:name ?name .
}
order by (?pos)
]]>
</value>
</constructor-arg>
</bean>

<bean id="schema_org_prov_hadDerivation" class="org.dataone.cn.indexer.annotation.SparqlField">
<constructor-arg name="name" value="prov_hasDerivations" />
<constructor-arg name="query">
Expand Down
61 changes: 60 additions & 1 deletion src/test/java/org/dataone/cn/index/JsonLdSubprocessorTest.java
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both these new tests fail for me:

+++++++++++++++++++The value of the field authorGivenName from Solr is null
The expected value of the field authorGivenName is Ian

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class JsonLdSubprocessorTest extends DataONESolrJettyTestBase {
private String schemaOrgTestDocDryad2Pid = "doi.org_10.5061_dryad.41sk145.jsonld";
private Resource schemaOrgTesHakaiDeep;
private String schemaOrgTesHakaiDeepPid = "hakai-deep-schema.jsonld";
private Resource schemaOrgTestCreatorRole;
private String schemaOrgTestCreatorRolePid = "creator-role.jsonld";
private Resource schemaOrgTestCreatorRoleList;
private String schemaOrgTestCreatorRoleListPid = "creator-role-list.jsonld";


/* An instance of the RDF/XML Subprocessor */
private JsonLdSubprocessor jsonLdSubprocessor;
Expand Down Expand Up @@ -122,6 +127,8 @@ public void setUp() throws Exception {
schemaOrgTestDocDryad1 = (Resource) context.getBean("schemaOrgTestDryad1");
schemaOrgTestDocDryad2 = (Resource) context.getBean("schemaOrgTestDryad2");
schemaOrgTesHakaiDeep = (Resource) context.getBean("schemaOrgTesHakaiDeep");
schemaOrgTestCreatorRole = (Resource) context.getBean("schemaOrgTestCreatorRole");
schemaOrgTestCreatorRoleList = (Resource) context.getBean("schemaOrgTestCreatorRoleList");

// instantiate the subprocessor
jsonLdSubprocessor = (JsonLdSubprocessor) context.getBean("jsonLdSubprocessor");
Expand Down Expand Up @@ -532,5 +539,57 @@ public void testHakaiDeep() throws Exception {
String[] license = {"https://creativecommons.org/licenses/by/4.0/"};
assertTrue(compareFieldValue(id, "licenseUrl", license));
}


/**
* Test that the JsonLdSubprocessor can successfully index JSONLD documents with creator roles.
*
* @throws Exception
*/
@Test
public void testCreatorRole() throws Exception {
String id = schemaOrgTestCreatorRolePid;
indexObjectToSolr(id, schemaOrgTestCreatorRole);

Thread.sleep(2*SLEEPTIME);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as line 579

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 3151375.

// now process the tasks
//processor.processIndexTaskQueue();
for (int i=0; i<TIMES; i++) {
try {
Thread.sleep(SLEEP);
assertPresentInSolrIndex(id);
break;
} catch (Throwable e) {

}
}
assertTrue(compareFieldValue(id, "authorGivenName", "Ian"));
assertTrue(compareFieldValue(id, "authorLastName", "Nesbitt"));
}

/**
* Test that the JsonLdSubprocessor can successfully index JSONLD documents with creator role lists.
*
* @throws Exception
*/
@Test
public void testCreatorRoleList() throws Exception {
String id = schemaOrgTestCreatorRoleListPid;
indexObjectToSolr(id, schemaOrgTestCreatorRoleList);

Thread.sleep(2*SLEEPTIME);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I understand you copied this from an existing test method, but...) is this definitely needed? In the best case this test will take a minimum of 18 seconds to run (2 * SLEEPTIME + SLEEP). The whole class will take nearly 2 minutes, best case.

Suggested solution is to remove Thread.sleep(2*SLEEPTIME) altogether, and then edit your loop (on line 582) as follows:

  1. Reduce the SLEEP time in that loop to, say, 500mS.
  2. Increase the value of TIMES to make the loop duration the same as it is now (i.e. 2 * 8 + 10 * 2), given the new shorter sleep time.

That way, flow will continue as soon as the test passes, with the potential to be a lot quicker.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(FYI, this is an approach we're gradually moving to in the metacat codebase, too)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in aab0578.

// now process the tasks
//processor.processIndexTaskQueue();
for (int i=0; i<TIMES; i++) {
try {
Thread.sleep(SLEEP);
assertPresentInSolrIndex(id);
break;
} catch (Throwable e) {

}
}
assertTrue(compareFieldValue(id, "authorGivenName", "Ian"));
assertTrue(compareFieldValue(id, "authorLastName", "Nesbitt"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"@context": "http://schema.org/",
"@type":"Dataset",
"description":"Vocab https://schema.org/, creator without @list and with @type: 'Role'. Modeled after CanWIN SO format.",
"name":"test of alternative creator field configuration",
"creator": [
{
"@type": "Role",
"creator": {
"@type": "Person",
"Affiliation": {
"@type": "Organization",
"name": "National Center for Ecological Analaysis and Synthesis"
},
"Email": "nesbitt@nceas.ucsb.edu",
"Identifier": {
"@type": "PropertyValue",
"propertyID": "https://registry.identifiers.org/registry/orcid",
"url": "http://orcid.org/0000-0001-5828-6070",
"value": "0000-0001-5828-6070"
},
"Name": "Nesbitt, Ian\t"
}
},
{
"@type": "Role",
"creator": {
"@type": "Person",
"Affiliation": {
"@type": "Organization",
"name": "National Center for Ecological Analaysis and Synthesis"
},
"Email": "tao@nceas.ucsb.edu",
"Identifier": {
"@type": "PropertyValue",
"propertyID": "https://registry.identifiers.org/registry/orcid",
"url": "http://orcid.org/0000-0002-1209-5268",
"value": "0000-0002-1209-5268"
},
"Name": "Tao, Jing\t"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<ns1:systemMetadata xmlns:ns1="http://ns.dataone.org/service/types/v2.0">
<serialVersion>1</serialVersion>
<identifier>creator-role-list.jsonld</identifier>
<formatId>science-on-schema.org/Dataset;ld+json</formatId>
<size>498</size>
<checksum algorithm="MD5"></checksum>
<submitter>dataone_integration_test_user</submitter>
<rightsHolder>dataone_integration_test_user</rightsHolder>
<accessPolicy>
<allow>
<subject>dataone_public_user</subject>
<permission>read</permission>
</allow>
<allow>
<subject>dataone_integration_test_user</subject>
<permission>write</permission>
</allow>
</accessPolicy>
<replicationPolicy replicationAllowed="true"/>
<dateUploaded>2024-08-17T12:59:47.171874</dateUploaded>
<dateSysMetadataModified>2024-08-17T12:59:47.173344</dateSysMetadataModified>
<originMemberNode>test_documents</originMemberNode>
<authoritativeMemberNode>test_documents</authoritativeMemberNode>
</ns1:systemMetadata>

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"@context": "http://schema.org/",
"@type":"Dataset",
"description":"Vocab https://schema.org/, creator without @list and with @type: 'Role'. Modeled after CanWIN SO format.",
"name":"test of alternative creator field configuration",
"creator": {
"@type": "Role",
"creator": {
"@type": "Person",
"Affiliation": {
"@type": "Organization",
"name": "National Center for Ecological Analaysis and Synthesis"
},
"Email": "nesbitt@nceas.ucsb.edu",
"Identifier": {
"@type": "PropertyValue",
"propertyID": "https://registry.identifiers.org/registry/orcid",
"url": "http://orcid.org/0000-0001-5828-6070",
"value": "0000-0001-5828-6070"
},
"Name": "Nesbitt, Ian\t"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<ns1:systemMetadata xmlns:ns1="http://ns.dataone.org/service/types/v2.0">
<serialVersion>1</serialVersion>
<identifier>creator-role.jsonld</identifier>
<formatId>science-on-schema.org/Dataset;ld+json</formatId>
<size>498</size>
<checksum algorithm="MD5"></checksum>
<submitter>dataone_integration_test_user</submitter>
<rightsHolder>dataone_integration_test_user</rightsHolder>
<accessPolicy>
<allow>
<subject>dataone_public_user</subject>
<permission>read</permission>
</allow>
<allow>
<subject>dataone_integration_test_user</subject>
<permission>write</permission>
</allow>
</accessPolicy>
<replicationPolicy replicationAllowed="true"/>
<dateUploaded>2024-08-17T11:59:47.171874</dateUploaded>
<dateSysMetadataModified>2024-08-17T11:59:47.173344</dateSysMetadataModified>
<originMemberNode>test_documents</originMemberNode>
<authoritativeMemberNode>test_documents</authoritativeMemberNode>
</ns1:systemMetadata>

10 changes: 10 additions & 0 deletions src/test/resources/org/dataone/cn/index/test-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ xmlns:context="http://www.springframework.org/schema/context"
value="org/dataone/cn/index/resources/d1_testdocs/json-ld/doi.org_10.5061_dryad.41sk145/doi.org_10.5061_dryad.41sk145.jsonld"/>
</bean>

<bean id="schemaOrgTestCreatorRole" class="org.springframework.core.io.ClassPathResource" >
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/json-ld/creator-role/creator-role.jsonld"/>
</bean>

<bean id="schemaOrgTestCreatorRoleList" class="org.springframework.core.io.ClassPathResource" >
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/json-ld/creator-role-list/creator-role-list.jsonld"/>
</bean>

<bean id="emlWithDataTableTestDoc" class="org.springframework.core.io.ClassPathResource" >
<constructor-arg type="java.lang.String"
value="org/dataone/cn/index/resources/d1_testdocs/eml220/eml2.2.0testdatatable/eml2.2.0testdatatable.xml"/>
Expand Down