Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider removed metadata in orcidqueueconsumer #418

Open
wants to merge 1 commit into
base: main-cris
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading