Skip to content

Commit

Permalink
consider removed metadata in orcidqueueconsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Jan 30, 2024
1 parent fe36309 commit 2ff0b1e
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.dspace.event.Event;
import org.dspace.orcid.OrcidHistory;
import org.dspace.orcid.OrcidOperation;
import org.dspace.orcid.OrcidQueue;
import org.dspace.orcid.factory.OrcidServiceFactory;
import org.dspace.orcid.model.OrcidEntityType;
import org.dspace.orcid.model.factory.OrcidProfileSectionFactory;
Expand Down Expand Up @@ -181,7 +182,48 @@ private void consumeEntity(Context context, Item entity) throws SQLException {
orcidQueueService.create(context, relatedItem, entity);

}
deleteOrcidQueueEntriesNotInMetadata(context, entity, metadataValues);
}

/**
* Loop through all orcid queue entries of entity and check if there is some metadata with authority between the
* entity and the profileitem of the orcidqueue entry. If no metadata is found and it the record is some
* insert action delete the entry
*/
private void deleteOrcidQueueEntriesNotInMetadata(Context context, Item entity,
List<MetadataValue> metadataValues) throws SQLException {
for (OrcidQueue oq : orcidQueueService.findByProfileItemOrEntity(context, entity)) {
boolean anyexistence = false;
for (MetadataValue metadata : metadataValues) {

String authority = metadata.getAuthority();

if (isNestedMetadataPlaceholder(metadata) || shouldBeIgnoredForOrcid(metadata)) {
continue;
}

UUID relatedItemUuid = UUIDUtils.fromString(authority);
if (relatedItemUuid == null) {
// possible some authority from controlled vocabulary
continue;
}

Item relatedItem = itemService.find(context, relatedItemUuid);

if (relatedItem == null || isNotProfileItem(relatedItem)) {
LOGGER.warn("Item " + entity.getID() +
" relates to missing entity reference with uuid" + authority);
continue;
}

if (oq.getProfileItem().getID().equals(relatedItemUuid)) {
anyexistence = true;
}
}
if (!anyexistence && oq.isInsertAction()) {
orcidQueueService.delete(context, oq);
}
}
}

private void consumeProfile(Context context, Item item) throws SQLException {
Expand Down
102 changes: 102 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 @@ -521,6 +521,58 @@ public void testOrcidQueueRecordCreationToUpdatePublication() throws Exception {
assertThat(orcidQueueRecords.get(0), matches(profile, publication, "Publication", "123456", UPDATE));
}

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

Collection publicationCollection = createCollection("Publications", "Publication");

Item publication = ItemBuilder.createItem(context, publicationCollection)
.withTitle("Test publication")
.build();

Item publication1 = ItemBuilder.createItem(context, publicationCollection)
.withTitle("Test publication1")
.build();

createOrcidHistory(context, profile, publication)
.withPutCode("123456")
.withOperation(INSERT)
.build();

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

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

List<OrcidQueue> orcidQueueRecordsMore = orcidQueueService.findAll(context);
assertThat(orcidQueueRecordsMore, hasSize(2));
assertThat(orcidQueueRecordsMore, hasItem(matches(profile, publication, "Publication", "123456", UPDATE)));
assertThat(orcidQueueRecordsMore, hasItem(matches(profile, publication1, "Publication", INSERT)));

context.turnOffAuthorisationSystem();

removeMetadata(publication1, "dc", "contributor", "author");

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

List<OrcidQueue> orcidQueueRecordsAfterDeletion = orcidQueueService.findAll(context);
assertThat(orcidQueueRecordsAfterDeletion, hasSize(1));
assertThat(orcidQueueRecordsAfterDeletion.get(0),
matches(profile, publication, "Publication", "123456", UPDATE));

}

@Test
public void testNoOrcidQueueRecordCreationOccursIfPublicationSynchronizationIsDisabled() throws Exception {

Expand Down Expand Up @@ -618,6 +670,56 @@ public void testOrcidQueueRecordCreationToUpdateFunding() throws Exception {
assertThat(orcidQueueRecords.get(0), matches(profile, funding, "Funding", "123456", UPDATE));
}

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

Collection fundingCollection = createCollection("Fundings", "Funding");

Item funding = ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding")
.build();

Item funding1 = ItemBuilder.createItem(context, fundingCollection)
.withTitle("Test funding1")
.build();

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

addMetadata(funding, "crisfund", "coinvestigators", null, "Test User", profile.getID().toString());
addMetadata(funding1, "crisfund", "investigators", null, "Test User", profile.getID().toString());

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

List<OrcidQueue> orcidQueueRecords = orcidQueueService.findAll(context);
assertThat(orcidQueueRecords, hasSize(2));
assertThat(orcidQueueRecords, hasItem(matches(profile, funding, "Funding", "123456", UPDATE)));
assertThat(orcidQueueRecords, hasItem(matches(profile, funding1, "Funding", INSERT)));

context.turnOffAuthorisationSystem();

removeMetadata(funding1, "crisfund", "investigators", null);

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

List<OrcidQueue> orcidQueueRecordsAfterDeletion = orcidQueueService.findAll(context);
assertThat(orcidQueueRecordsAfterDeletion, hasSize(1));
assertThat(orcidQueueRecordsAfterDeletion.get(0), matches(profile, funding, "Funding", "123456", UPDATE));

}

@Test
public void testNoOrcidQueueRecordCreationOccursIfFundingSynchronizationIsDisabled() throws Exception {

Expand Down

0 comments on commit 2ff0b1e

Please sign in to comment.