Skip to content

Commit

Permalink
further IT for patent as orcid entity sync settings and orcid queue
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Mar 7, 2024
1 parent 5f68e21 commit 47d7bd1
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 2 deletions.
7 changes: 7 additions & 0 deletions dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ public ItemBuilder withOrcidSynchronizationProductsPreference(String value) {
return setMetadataSingleValue(item, "dspace", "orcid", "sync-products", value);
}

public ItemBuilder withOrcidSynchronizationPatentsPreference(OrcidEntitySyncPreference value) {
return withOrcidSynchronizationPatentsPreference(value.name());
}

public ItemBuilder withOrcidSynchronizationPatentsPreference(String value) {
return setMetadataSingleValue(item, "dspace", "orcid", "sync-patents", value);
}

public ItemBuilder withOrcidSynchronizationProfilePreference(OrcidProfileSyncPreference value) {
return withOrcidSynchronizationProfilePreference(value.name());
Expand Down
113 changes: 113 additions & 0 deletions dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,41 @@ public void testOrcidQueueRecordCreationForProduct() throws Exception {
assertThat(orcidQueueRecords.get(0), equalTo(newOrcidQueueRecords.get(0)));
}

@Test
public void testOrcidQueueRecordCreationForPatent() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection patentCollection = createCollection("Patents", "Patent");

Item patent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.withAuthor("Test User", profile.getID().toString())
.build();

context.restoreAuthSystemState();
context.commit();

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
assertThat(orcidQueueRecords.get(0), matches(profile, patent, "Patent", null, INSERT));

addMetadata(patent, "dc", "type", null, "http://purl.org/coar/resource_type/scheme/Z907-YMBB", null);
context.commit();

List<OrcidQueue> newOrcidQueueRecords = orcidQueueService.findAll(context);
assertThat(newOrcidQueueRecords, hasSize(1));

assertThat(orcidQueueRecords.get(0), equalTo(newOrcidQueueRecords.get(0)));
}

@Test
public void testOrcidQueueRecordCreationToUpdateFunding() throws Exception {

Expand Down Expand Up @@ -685,6 +720,38 @@ public void testOrcidQueueRecordCreationToUpdateProduct() throws Exception {
assertThat(orcidQueueRecords.get(0), matches(profile, product, "Product", "123456", UPDATE));
}

@Test
public void testOrcidQueueRecordCreationToUpdatePatent() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection patentCollection = createCollection("Patents", "Patent");

Item patent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.build();

createOrcidHistory(context, profile, patent)
.withPutCode("123456")
.build();

addMetadata(patent, "dc", "contributor", "author", "Test User", profile.getID().toString());

context.restoreAuthSystemState();
context.commit();

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
assertThat(orcidQueueRecords.get(0), matches(profile, patent, "Patent", "123456", UPDATE));
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabled() throws Exception {

Expand Down Expand Up @@ -745,6 +812,36 @@ public void testNoOrcidQueueRecordCreationOccursIfProductSynchronizationIsDisabl
assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfPatentSynchronizationIsDisabled() throws Exception {

context.turnOffAuthorisationSystem();

Item profile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.build();

Collection patentCollection = createCollection("Patents", "Patent");

Item patent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.withAuthor("Test User", profile.getID().toString())
.build();

context.restoreAuthSystemState();
context.commit();

assertThat(orcidQueueService.findAll(context), empty());

addMetadata(profile, "dspace", "orcid", "sync-patents", DISABLED.name(), null);
addMetadata(patent, "dc", "description", "abstract", "Patent Ptent Pent Pnt Pt P", null);
context.commit();

assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier() throws Exception {

Expand All @@ -755,6 +852,7 @@ public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier()
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection fundingCollection = createCollection("Fundings", "Funding");
Expand All @@ -771,6 +869,13 @@ public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier()
.withAuthor("Test User", profile.getID().toString())
.build();

Collection patentsCollection = createCollection("Patents", "Patent");

ItemBuilder.createItem(context, patentsCollection)
.withTitle("Test patent")
.withAuthor("Test User", profile.getID().toString())
.build();

context.restoreAuthSystemState();
context.commit();

Expand Down Expand Up @@ -940,6 +1045,7 @@ public void testWithMetadataFieldToIgnore() throws Exception {
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationPublicationsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Collection publicationCollection = createCollection("Publications", "Publication");
Expand Down Expand Up @@ -979,6 +1085,13 @@ public void testWithMetadataFieldToIgnore() throws Exception {
.withAuthor("Test User", profile.getID().toString())
.build();

Collection patentCollection = createCollection("Patents", "Patent");

Item firstPatent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.withAuthor("Test User", profile.getID().toString())
.build();

context.restoreAuthSystemState();

List<OrcidQueue> records = orcidQueueService.findAll(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,93 @@ public void testDeletionOfProductToBeSynchronizedWithOrcid() throws Exception {

}

@Test
public void testDeletionOfPatentToBeSynchronizedWithOrcid() throws Exception {

context.turnOffAuthorisationSystem();

parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();

Collection profileCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Profiles")
.withEntityType("Person")
.build();

Collection patentCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Patents")
.withEntityType("Patent")
.build();

EPerson firstOwner = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.build();

EPerson secondOwner = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.build();

EPerson thirdOwner = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.build();

Item firstProfile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withDspaceObjectOwner(firstOwner.getFullName(), firstOwner.getID().toString())
.withOrcidIdentifier("0000-1111-2222-3333")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", firstOwner)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Item secondProfile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withDspaceObjectOwner(secondOwner.getFullName(), secondOwner.getID().toString())
.withOrcidIdentifier("4444-1111-2222-3333")
.withOrcidAccessToken("bb4d18a0-8d9a-40f1-b601-a417255c8d20", secondOwner)
.build();

Item thirdProfile = ItemBuilder.createItem(context, profileCollection)
.withTitle("Test User")
.withDspaceObjectOwner(thirdOwner.getFullName(), thirdOwner.getID().toString())
.withOrcidIdentifier("5555-1111-2222-3333")
.withOrcidAccessToken("cb4d18a0-8d9a-40f1-b601-a417255c8d20", thirdOwner)
.withOrcidSynchronizationPatentsPreference(ALL)
.build();

Item patent = ItemBuilder.createItem(context, patentCollection)
.withTitle("Test patent")
.build();

createOrcidQueue(context, firstProfile, patent).build();
createOrcidQueue(context, secondProfile, patent).build();

List<OrcidHistory> historyRecords = new ArrayList<>();
historyRecords.add(createOrcidHistory(context, firstProfile, patent).build());
historyRecords.add(createOrcidHistory(context, firstProfile, patent).withPutCode("12345").build());
historyRecords.add(createOrcidHistory(context, secondProfile, patent).build());
historyRecords.add(createOrcidHistory(context, secondProfile, patent).withPutCode("67891").build());
historyRecords.add(createOrcidHistory(context, thirdProfile, patent).build());

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(delete("/api/core/items/" + patent.getID()))
.andExpect(status().is(204));

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
assertThat(orcidQueueRecords, hasItem(matches(firstProfile, null, "Patent", "12345", DELETE)));

for (OrcidHistory historyRecord : historyRecords) {
historyRecord = context.reloadEntity(historyRecord);
assertThat(historyRecord, notNullValue());
assertThat(historyRecord.getEntity(), nullValue());
}

}

private void initPublicationAuthorsRelationships() throws SQLException {
context.turnOffAuthorisationSystem();

Expand Down
Loading

0 comments on commit 47d7bd1

Please sign in to comment.