From 47d7bd1d7b18d045da73a446e49818ba1fccf117 Mon Sep 17 00:00:00 2001 From: "Gantner, Florian Klaus" Date: Thu, 7 Mar 2024 11:15:46 +0100 Subject: [PATCH] further IT for patent as orcid entity sync settings and orcid queue --- .../java/org/dspace/builder/ItemBuilder.java | 7 ++ .../dspace/orcid/OrcidQueueConsumerIT.java | 113 ++++++++++++++++++ .../dspace/app/rest/ItemRestRepositoryIT.java | 87 ++++++++++++++ .../ResearcherProfileRestRepositoryIT.java | 105 +++++++++++++++- 4 files changed, 310 insertions(+), 2 deletions(-) diff --git a/dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java b/dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java index 88acf447e928..ba4c529eb28d 100644 --- a/dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java +++ b/dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java @@ -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()); diff --git a/dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java b/dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java index 4fb9de54e153..102474981f49 100644 --- a/dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java +++ b/dspace-api/src/test/java/org/dspace/orcid/OrcidQueueConsumerIT.java @@ -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 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 newOrcidQueueRecords = orcidQueueService.findAll(context); + assertThat(newOrcidQueueRecords, hasSize(1)); + + assertThat(orcidQueueRecords.get(0), equalTo(newOrcidQueueRecords.get(0))); + } + @Test public void testOrcidQueueRecordCreationToUpdateFunding() throws Exception { @@ -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 orcidQueueRecords = orcidQueueService.findAll(context); + assertThat(orcidQueueRecords, hasSize(1)); + assertThat(orcidQueueRecords.get(0), matches(profile, patent, "Patent", "123456", UPDATE)); + } + @Test public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabled() throws Exception { @@ -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 { @@ -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"); @@ -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(); @@ -940,6 +1045,7 @@ public void testWithMetadataFieldToIgnore() throws Exception { .withOrcidSynchronizationFundingsPreference(ALL) .withOrcidSynchronizationPublicationsPreference(ALL) .withOrcidSynchronizationProductsPreference(ALL) + .withOrcidSynchronizationPatentsPreference(ALL) .build(); Collection publicationCollection = createCollection("Publications", "Publication"); @@ -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 records = orcidQueueService.findAll(context); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java index 2d6cead4fabb..b261d4b65fed 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemRestRepositoryIT.java @@ -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("owner2@test.com") + .build(); + + EPerson secondOwner = EPersonBuilder.createEPerson(context) + .withEmail("owner3@test.com") + .build(); + + EPerson thirdOwner = EPersonBuilder.createEPerson(context) + .withEmail("owner1@test.com") + .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 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 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(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ResearcherProfileRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ResearcherProfileRestRepositoryIT.java index b0328b3a73dd..b9e3ad2ae394 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ResearcherProfileRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ResearcherProfileRestRepositoryIT.java @@ -58,6 +58,7 @@ import org.dspace.app.rest.model.patch.Operation; import org.dspace.app.rest.model.patch.RemoveOperation; import org.dspace.app.rest.model.patch.ReplaceOperation; +import org.dspace.app.rest.repository.ResearcherProfileRestRepository; import org.dspace.app.rest.repository.patch.operation.ResearcherProfileAddOrcidOperation; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.dspace.authorize.AuthorizeException; @@ -1172,6 +1173,7 @@ public void testOrcidMetadataOfEpersonAreCopiedOnProfile() throws Exception { .andExpect(jsonPath("$.orcidSynchronization.publicationsPreference", is("DISABLED"))) .andExpect(jsonPath("$.orcidSynchronization.fundingsPreference", is("DISABLED"))) .andExpect(jsonPath("$.orcidSynchronization.productsPreference", is("DISABLED"))) + .andExpect(jsonPath("$.orcidSynchronization.patentsPreference", is("DISABLED"))) .andExpect(jsonPath("$.orcidSynchronization.profilePreferences", empty())); String itemId = getItemIdByProfileId(authToken, ePersonId); @@ -1367,6 +1369,65 @@ public void testPatchToSetOrcidSynchronizationPreferenceForProduct() throws Exce } + @Test + public void testPatchToSetOrcidSynchronizationPreferenceForPatent() throws Exception { + + context.turnOffAuthorisationSystem(); + + EPerson ePerson = EPersonBuilder.createEPerson(context) + .withCanLogin(true) + .withOrcid("0000-1111-2222-3333") + .withEmail("test@email.it") + .withPassword(password) + .withNameInMetadata("Test", "User") + .withOrcidScope("/first-scope") + .withOrcidScope("/second-scope") + .build(); + + OrcidTokenBuilder.create(context, ePerson, "af097328-ac1c-4a3e-9eb4-069897874910").build(); + + context.restoreAuthSystemState(); + + String ePersonId = ePerson.getID().toString(); + String authToken = getAuthToken(ePerson.getEmail(), password); + + getClient(authToken).perform(post("/api/eperson/profiles/") + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isCreated()); + + List operations = asList(new ReplaceOperation("/orcid/patents", ALL.name())); + + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId) + .content(getPatchContent(operations)) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.orcidSynchronization.patentsPreference", is(ALL.name()))); + + getClient(authToken).perform(get("/api/eperson/profiles/{id}", ePersonId)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.orcidSynchronization.patentsPreference", is(ALL.name()))); + + operations = asList(new ReplaceOperation("/orcid/patents", MINE.name())); + + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId) + .content(getPatchContent(operations)) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.orcidSynchronization.patentsPreference", is(MINE.name()))); + + getClient(authToken).perform(get("/api/eperson/profiles/{id}", ePersonId)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.orcidSynchronization.patentsPreference", is(MINE.name()))); + + operations = asList(new ReplaceOperation("/orcid/patents", "INVALID_VALUE")); + + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId) + .content(getPatchContent(operations)) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isUnprocessableEntity()); + + } + @Test public void testPatchToSetOrcidSynchronizationPreferenceForProfile() throws Exception { @@ -2215,6 +2276,11 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation Item firstFunding = createFundingWithInvestigator(fundings, "First funding", profile); Item secondFunding = createFundingWithCoInvestigator(fundings, "Second funding", profile); + Collection patents = createCollection("Patents", "Patent"); + + Item firstPatent = createPatent(patents, "First patent", profile); + Item secondPatent = createPatent(patents, "Second patent", profile); + context.restoreAuthSystemState(); // no preferences configured, so no orcid queue records created @@ -2254,16 +2320,32 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondFunding))); assertThat(queueRecords, has(orcidQueueRecordWithEntity(product))); + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString()) + .content(getPatchContent(asList(new ReplaceOperation("/orcid/patents", "ALL")))) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); + + queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId); + assertThat(queueRecords, hasSize(6)); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(publication))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstFunding))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondFunding))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(product))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent))); + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString()) .content(getPatchContent(asList(new ReplaceOperation("/orcid/publications", "DISABLED")))) .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId); - assertThat(queueRecords, hasSize(3)); + assertThat(queueRecords, hasSize(5)); assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstFunding))); assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondFunding))); assertThat(queueRecords, has(orcidQueueRecordWithEntity(product))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent))); getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString()) .content(getPatchContent(asList(new ReplaceOperation("/orcid/fundings", "DISABLED")))) @@ -2271,14 +2353,26 @@ public void testOrcidSynchronizationPreferenceUpdateForceOrcidQueueRecalculation .andExpect(status().isOk()); queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId); - assertThat(queueRecords, hasSize(1)); + assertThat(queueRecords, hasSize(3)); assertThat(queueRecords, has(orcidQueueRecordWithEntity(product))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent))); getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString()) .content(getPatchContent(asList(new ReplaceOperation("/orcid/products", "DISABLED")))) .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isOk()); + queueRecords = orcidQueueService.findByProfileItemId(context, profileItemId); + assertThat(queueRecords, hasSize(2)); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(firstPatent))); + assertThat(queueRecords, has(orcidQueueRecordWithEntity(secondPatent))); + + getClient(authToken).perform(patch("/api/eperson/profiles/{id}", ePersonId.toString()) + .content(getPatchContent(asList(new ReplaceOperation("/orcid/patents", "DISABLED")))) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); + assertThat(orcidQueueService.findByProfileItemId(context, profileItemId), empty()); configurationService.setProperty("orcid.linkable-metadata-fields.ignore", "crisfund.coinvestigators"); @@ -2708,6 +2802,13 @@ private Item createProduct(Collection collection, String title, Item author) { .build(); } + private Item createPatent(Collection collection, String title, Item author) { + return ItemBuilder.createItem(context, collection) + .withTitle(title) + .withAuthor(author.getName(), author.getID().toString()) + .build(); + } + private Item createFundingWithInvestigator(Collection collection, String title, Item investigator) { return ItemBuilder.createItem(context, collection) .withTitle(title)