Skip to content

Commit

Permalink
fix: Make validated items to be default preferred source for grouping (
Browse files Browse the repository at this point in the history
…#7039)

* fix: Make validated items to be default preferred source for grouping

* fix: Make elements added via API preferred sources

* test: Fix add multiple items modify indexing status tests

---------

Co-authored-by: Daniel Palafox <daniel.p4l4fox@gmail.com>
  • Loading branch information
DanielPalafox and Daniel Palafox authored Jun 7, 2024
1 parent 78fddb9 commit 3b24826
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.orcid.core.manager.ProfileEntityCacheManager;

import org.orcid.core.togglz.OrcidTogglzConfiguration;
import org.orcid.core.utils.DisplayIndexCalculatorHelper;
import org.orcid.core.utils.v3.ContributorUtils;
import org.orcid.persistence.dao.WorkDao;
import org.orcid.persistence.jpa.entities.WorkEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,12 @@ public void createNewWorkGroup(List<Long> workIds, String orcid) throws MissingG
MinimizedWorkEntity userPreferred = null;

boolean groupableExternalIdFound = false;
for (MinimizedWorkEntity work : works) {
for (MinimizedWorkEntity work : works) {
if (orcid.equals(work.getSourceId())) {
userVersions.add(work);
work.setDisplayIndex(0L);
} else {
work.setDisplayIndex(1L);
}
if (userPreferred == null || userPreferred.getDisplayIndex() < work.getDisplayIndex()) {
userPreferred = work;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static void setDisplayIndexOnExistingEntity(DisplayIndexInterface entity,

private static void setDisplayIndex(DisplayIndexInterface e, boolean isApiRequest) {
if(isApiRequest) {
e.setDisplayIndex(0L);
} else {
e.setDisplayIndex(1L);
} else {
e.setDisplayIndex(0L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,27 @@ public void testAddAddressToClaimedRecordPreserveUserDefaultVisibility() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Address address = getAddress(Iso3166Country.MX);

address = addressManager.createAddress(claimedOrcid, address, false);
address = addressManager.getAddress(claimedOrcid, address.getPutCode());

assertNotNull(address);
assertEquals(Long.valueOf(1), address.getDisplayIndex());
assertEquals(Long.valueOf(0), address.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Address address = getAddress(Iso3166Country.PE);

address = addressManager.createAddress(claimedOrcid, address, true);
address = addressManager.getAddress(claimedOrcid, address.getPutCode());

assertNotNull(address);
assertEquals(Long.valueOf(0), address.getDisplayIndex());
assertEquals(Long.valueOf(1), address.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ public void testAddEqualsExternalIdentifiersFromSameSource() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, false);
extId1 = externalIdentifierManager.getExternalIdentifier(claimedOrcid, extId1.getPutCode());

assertNotNull(extId1);
assertEquals(Long.valueOf(1), extId1.getDisplayIndex());
assertEquals(Long.valueOf(0), extId1.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, true);
extId1 = externalIdentifierManager.getExternalIdentifier(claimedOrcid, extId1.getPutCode());

assertNotNull(extId1);
assertEquals(Long.valueOf(0), extId1.getDisplayIndex());
assertEquals(Long.valueOf(1), extId1.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testAddOtherNameToClaimedRecordPreserveUserDefaultVisibility() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
OtherName otherName = getOtherName();
otherName.setContent(otherName.getContent() + " fromUI");
Expand All @@ -100,11 +100,11 @@ public void displayIndexIsSetTo_1_FromUI() {
otherName = otherNameManager.getOtherName(claimedOrcid, otherName.getPutCode());

assertNotNull(otherName);
assertEquals(Long.valueOf(1), otherName.getDisplayIndex());
assertEquals(Long.valueOf(0), otherName.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
OtherName otherName = getOtherName();
otherName.setContent(otherName.getContent() + " fromAPI");
Expand All @@ -113,7 +113,7 @@ public void displayIndexIsSetTo_0_FromAPI() {
otherName = otherNameManager.getOtherName(claimedOrcid, otherName.getPutCode());

assertNotNull(otherName);
assertEquals(Long.valueOf(0), otherName.getDisplayIndex());
assertEquals(Long.valueOf(1), otherName.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void testAddMultipleModifiesIndexingStatus() {
assertNotNull(entity1.getDisplayIndex());
assertNotNull(entity2.getDisplayIndex());
assertNotNull(entity3.getDisplayIndex());
assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
assertEquals(Long.valueOf(1), entity3.getDisplayIndex());

// Rollback all changes
peerReviewDao.remove(entity1.getId());
Expand All @@ -146,25 +146,25 @@ public void testAddMultipleModifiesIndexingStatus() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PeerReview p1 = getPeerReview("fromUI-1");
p1 = peerReviewManager.createPeerReview(claimedOrcid, p1, false);
PeerReviewEntity p = peerReviewDao.find(p1.getPutCode());

assertNotNull(p);
assertEquals(Long.valueOf(1), p.getDisplayIndex());
assertEquals(Long.valueOf(0), p.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PeerReview p1 = getPeerReview("fromAPI-1");
p1 = peerReviewManager.createPeerReview(claimedOrcid, p1, true);
PeerReviewEntity p = peerReviewDao.find(p1.getPutCode());

assertNotNull(91);
assertEquals(Long.valueOf(0), p.getDisplayIndex());
assertEquals(Long.valueOf(1), p.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testAddMultipleModifiesIndexingStatus() {
assertNotNull(entity1.getDisplayIndex());
assertNotNull(entity2.getDisplayIndex());
assertNotNull(entity3.getDisplayIndex());
assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
assertEquals(Long.valueOf(1), entity3.getDisplayIndex());

// Rollback all changes
profileFundingDao.remove(entity1.getId());
Expand All @@ -134,27 +134,27 @@ public void testAddMultipleModifiesIndexingStatus() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));

Funding f1 = getFunding("fromUI-1");
f1 = profileFundingManager.createFunding(claimedOrcid, f1, false);
ProfileFundingEntity f = profileFundingDao.find(f1.getPutCode());

assertNotNull(f);
assertEquals(Long.valueOf(1), f.getDisplayIndex());
assertEquals(Long.valueOf(0), f.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));

Funding f1 = getFunding("fromAPI-1");
f1 = profileFundingManager.createFunding(claimedOrcid, f1, true);
ProfileFundingEntity f = profileFundingDao.find(f1.getPutCode());

assertNotNull(f);
assertEquals(Long.valueOf(0), f.getDisplayIndex());
assertEquals(Long.valueOf(1), f.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testAddKeywordToClaimedRecordPreserveUserDefaultVisibility() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Keyword keyword = getKeyword();
keyword.setContent(keyword.getContent() + " fromUI1");
Expand All @@ -95,11 +95,11 @@ public void displayIndexIsSetTo_1_FromUI() {
keyword = profileKeywordManager.getKeyword(claimedOrcid, keyword.getPutCode());

assertNotNull(keyword);
assertEquals(Long.valueOf(1), keyword.getDisplayIndex());
assertEquals(Long.valueOf(0), keyword.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Keyword keyword = getKeyword();
keyword.setContent(keyword.getContent() + " fromAPI1");
Expand All @@ -108,7 +108,7 @@ public void displayIndexIsSetTo_0_FromAPI() {
keyword = profileKeywordManager.getKeyword(claimedOrcid, keyword.getPutCode());

assertNotNull(keyword);
assertEquals(Long.valueOf(0), keyword.getDisplayIndex());
assertEquals(Long.valueOf(1), keyword.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testAddResearcherUrToClaimedRecordPreserveUserDefaultVisibility() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
ResearcherUrl rUrl = getResearcherUrl();
rUrl.getUrl().setValue(rUrl.getUrl().getValue() + "/fromUI");
Expand All @@ -96,11 +96,11 @@ public void displayIndexIsSetTo_1_FromUI() {
rUrl = researcherUrlManager.getResearcherUrl(claimedOrcid, rUrl.getPutCode());

assertNotNull(rUrl);
assertEquals(Long.valueOf(1), rUrl.getDisplayIndex());
assertEquals(Long.valueOf(0), rUrl.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
ResearcherUrl rUrl = getResearcherUrl();
rUrl.getUrl().setValue(rUrl.getUrl().getValue() + "/fromAPI");
Expand All @@ -109,7 +109,7 @@ public void displayIndexIsSetTo_0_FromAPI() {
rUrl = researcherUrlManager.getResearcherUrl(claimedOrcid, rUrl.getPutCode());

assertNotNull(rUrl);
assertEquals(Long.valueOf(0), rUrl.getDisplayIndex());
assertEquals(Long.valueOf(1), rUrl.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void testAddMultipleModifiesIndexingStatus() {
assertNotNull(entity1.getDisplayIndex());
assertNotNull(entity2.getDisplayIndex());
assertNotNull(entity3.getDisplayIndex());
assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
assertEquals(Long.valueOf(1), entity3.getDisplayIndex());

// Rollback all changes
workDao.remove(entity1.getId());
Expand All @@ -221,23 +221,23 @@ public void testAddMultipleModifiesIndexingStatus() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
Work w1 = getWork("fromUI-1");
w1 = workManager.createWork(claimedOrcid, w1, false);
WorkEntity w = workDao.find(w1.getPutCode());

assertNotNull(w1);
assertEquals(Long.valueOf(1), w.getDisplayIndex());
assertEquals(Long.valueOf(0), w.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
Work w1 = getWork("fromAPI-1");
w1 = workManager.createWork(claimedOrcid, w1, true);
WorkEntity w = workDao.find(w1.getPutCode());

assertNotNull(w1);
assertEquals(Long.valueOf(0), w.getDisplayIndex());
assertEquals(Long.valueOf(1), w.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,27 @@ public void testAddAddressToClaimedRecordPreserveUserDefaultVisibility() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(mockSourceManager.retrieveActiveSource()).thenReturn(Source.forClient(CLIENT_1_ID));
Address address = getAddress(Iso3166Country.MX);

address = addressManager.createAddress(claimedOrcid, address, false);
address = addressManager.getAddress(claimedOrcid, address.getPutCode());

assertNotNull(address);
assertEquals(Long.valueOf(1), address.getDisplayIndex());
assertEquals(Long.valueOf(0), address.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(mockSourceManager.retrieveActiveSource()).thenReturn(Source.forClient(CLIENT_1_ID));
Address address = getAddress(Iso3166Country.PE);

address = addressManager.createAddress(claimedOrcid, address, true);
address = addressManager.getAddress(claimedOrcid, address.getPutCode());

assertNotNull(address);
assertEquals(Long.valueOf(0), address.getDisplayIndex());
assertEquals(Long.valueOf(1), address.getDisplayIndex());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,27 @@ public void testAddEqualsExternalIdentifiersFromSameSource() {
}

@Test
public void displayIndexIsSetTo_1_FromUI() {
public void displayIndexIsSetTo_0_FromUI() {
when(mockSourceManager.retrieveActiveSource()).thenReturn(Source.forClient(CLIENT_1_ID));
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, false);
extId1 = externalIdentifierManager.getExternalIdentifier(claimedOrcid, extId1.getPutCode());

assertNotNull(extId1);
assertEquals(Long.valueOf(1), extId1.getDisplayIndex());
assertEquals(Long.valueOf(0), extId1.getDisplayIndex());
}

@Test
public void displayIndexIsSetTo_0_FromAPI() {
public void displayIndexIsSetTo_1_FromAPI() {
when(mockSourceManager.retrieveActiveSource()).thenReturn(Source.forClient(CLIENT_1_ID));
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, true);
extId1 = externalIdentifierManager.getExternalIdentifier(claimedOrcid, extId1.getPutCode());

assertNotNull(extId1);
assertEquals(Long.valueOf(0), extId1.getDisplayIndex());
assertEquals(Long.valueOf(1), extId1.getDisplayIndex());
}

@Test
Expand Down
Loading

0 comments on commit 3b24826

Please sign in to comment.