Skip to content

Commit

Permalink
further IT for product 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 b55d7aa commit 1eec67f
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 2 deletions.
9 changes: 9 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 @@ -593,6 +593,15 @@ public ItemBuilder withOrcidSynchronizationFundingsPreference(String value) {
return setMetadataSingleValue(item, "dspace", "orcid", "sync-fundings", value);
}

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

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


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

@Test
public void testOrcidQueueRecordCreationForProduct() 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)
.withOrcidSynchronizationProductsPreference(ALL)
.build();

Collection productCollection = createCollection("Products", "Product");

Item product = ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")
.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, product, "Product", null, INSERT));

addMetadata(product, "dc", "type", null, "http://purl.org/coar/resource_type/scheme/c_12cc", 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 @@ -618,6 +653,38 @@ public void testOrcidQueueRecordCreationToUpdateFunding() throws Exception {
assertThat(orcidQueueRecords.get(0), matches(profile, funding, "Funding", "123456", UPDATE));
}

@Test
public void testOrcidQueueRecordCreationToUpdateProduct() 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)
.withOrcidSynchronizationProductsPreference(ALL)
.build();

Collection productCollection = createCollection("Products", "Product");

Item product = ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")
.build();

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

addMetadata(product, "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, product, "Product", "123456", UPDATE));
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabled() throws Exception {

Expand Down Expand Up @@ -648,6 +715,36 @@ public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabl
assertThat(orcidQueueService.findAll(context), empty());
}

@Test
public void testNoOrcidQueueRecordCreationOccursIfProductSynchronizationIsDisabled() 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 productCollection = createCollection("Products", "Product");

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

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

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

addMetadata(profile, "dspace", "orcid", "sync-products", DISABLED.name(), null);
addMetadata(product, "dc", "description", "abstract", "Product Poduct Pduct Puct Pct Pt P", null);
context.commit();

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

@Test
public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier() throws Exception {

Expand All @@ -657,6 +754,7 @@ public void testNoOrcidQueueRecordCreationOccursIfProfileHasNotOrcidIdentifier()
.withTitle("Test User")
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.build();

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

Collection productCollection = createCollection("Products", "Product");

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

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

Expand Down Expand Up @@ -834,6 +939,7 @@ public void testWithMetadataFieldToIgnore() throws Exception {
.withOrcidAccessToken("ab4d18a0-8d9a-40f1-b601-a417255c8d20", eperson)
.withOrcidSynchronizationFundingsPreference(ALL)
.withOrcidSynchronizationPublicationsPreference(ALL)
.withOrcidSynchronizationProductsPreference(ALL)
.build();

Collection publicationCollection = createCollection("Publications", "Publication");
Expand Down Expand Up @@ -866,14 +972,20 @@ public void testWithMetadataFieldToIgnore() throws Exception {
.withFundingCoInvestigator("Test User", profile.getID().toString())
.build();

Collection productCollection = createCollection("Products", "Product");

Item firstProduct = ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")
.withAuthor("Test User", profile.getID().toString())
.build();

context.restoreAuthSystemState();

List<OrcidQueue> records = orcidQueueService.findAll(context);
assertThat(records, hasSize(3));
assertThat(records, hasItem(matches(profile, firstPublication, "Publication", null, INSERT)));
assertThat(records, hasItem(matches(profile, secondPublication, "Publication", null, INSERT)));
assertThat(records, hasItem(matches(profile, firstFunding, "Funding", null, INSERT)));

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4166,6 +4166,94 @@ public void testDeletionOfFundingToBeSynchronizedWithOrcid() throws Exception {

}

@Test
public void testDeletionOfProductToBeSynchronizedWithOrcid() throws Exception {

context.turnOffAuthorisationSystem();

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

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

Collection productCollection = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Products")
.withEntityType("Product")
.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)
.withOrcidSynchronizationProductsPreference(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)
.withOrcidSynchronizationProductsPreference(ALL)
.build();

Item product = ItemBuilder.createItem(context, productCollection)
.withTitle("Test product")

.build();

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

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

context.restoreAuthSystemState();

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

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

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(1));
assertThat(orcidQueueRecords, hasItem(matches(firstProfile, null, "Product", "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 1eec67f

Please sign in to comment.