Skip to content

Commit

Permalink
Merge pull request #6822 from ORCID/AddingFlagForIndexing
Browse files Browse the repository at this point in the history
Add a property to indicate if a record should have the noindex metatag
  • Loading branch information
amontenegro authored Jun 19, 2023
2 parents c3b0441 + 6a43d43 commit b5b7205
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public ModelAndView publicPreview(HttpServletRequest request, HttpServletRespons
info.put("EFFECTIVE_USER_ORCID", orcid);
info.put("IS_LOCKED", String.valueOf(!profile.isAccountNonLocked()));
info.put("IS_DEACTIVATED", String.valueOf(!(profile.getDeactivationDate() == null)));
info.put("READY_FOR_INDEXING", String.valueOf(isRecordReadyForIndexing(profile)));
if (profile.getPrimaryRecord() != null) {
info.put("PRIMARY_RECORD", profile.getPrimaryRecord().getId());
}
Expand All @@ -255,6 +256,27 @@ public ModelAndView publicPreview(HttpServletRequest request, HttpServletRespons

return info;
}

private boolean isRecordReadyForIndexing(ProfileEntity profile) {
// False if it is locked
if(!profile.isAccountNonLocked()) {
return false;
}

// False if it is deprecated
if (profile.getPrimaryRecord() != null) {
return false;
}

// False if it is not reviewed and doesn't have any integration
if(!profile.isReviewed()) {
if (!orcidOauth2TokenService.hasToken(profile.getId(), getLastModifiedTime(profile.getId()))) {
return false;
}
}

return true;
}

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/person.json", method = RequestMethod.GET)
public @ResponseBody PublicRecordPersonDetails getPersonDetails(@PathVariable("orcid") String orcid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -28,6 +30,8 @@
import org.mockito.MockitoAnnotations;
import org.orcid.core.locale.LocaleManager;
import org.orcid.core.manager.EncryptionManager;
import org.orcid.core.manager.ProfileEntityCacheManager;
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
import org.orcid.jaxb.model.common.Iso3166Country;
import org.orcid.jaxb.model.v3.release.common.Visibility;
import org.orcid.jaxb.model.v3.release.record.Address;
Expand All @@ -44,6 +48,7 @@
import org.orcid.pojo.ajaxForm.AffiliationGroupForm;
import org.orcid.test.DBUnitTest;
import org.orcid.test.OrcidJUnit4ClassRunner;
import org.orcid.test.TargetProxyHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.servlet.ModelAndView;
Expand All @@ -64,7 +69,13 @@ public class PublicProfileControllerTest extends DBUnitTest {
private String unclaimedUserOrcid = "0000-0000-0000-0001";
private String userOrcid = "0000-0000-0000-0003";
private String deprecatedUserOrcid = "0000-0000-0000-0004";
private String lockedUserOrcid = "0000-0000-0000-0006";
private String lockedUserOrcid = "0000-0000-0000-0006";

String reviewedNoIntegrationsOrcid = "0009-0000-0000-0001";
String reviewedWithIntegrationsOrcid = "0009-0000-0000-0002";
String unreviewedNoIntegrationsOrcid = "0009-0000-0000-0003";
String unreviewedWithIntegrationsOrcid = "0009-0000-0000-0004";
String primaryRecord = "0000-0000-0000-0000";

@Resource
PublicProfileController publicProfileController;
Expand All @@ -79,17 +90,20 @@ public class PublicProfileControllerTest extends DBUnitTest {
private EncryptionManager encryptionManager;

@Mock
//private HttpServletRequest request;
private HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

@Mock
//private HttpServletRequest request;
private HttpServletResponse response = Mockito.mock(HttpServletResponse.class);

@Mock
private ProfileEntityCacheManager profileEntityCacheManagerMock;

@Mock
private OrcidOauth2TokenDetailService orcidOauth2TokenServiceMock;

@Before
public void before() {
MockitoAnnotations.initMocks(this);
assertNotNull(publicProfileController);
MockitoAnnotations.initMocks(this);
Mockito.when(request.getRequestURI()).thenReturn("/");
}

Expand Down Expand Up @@ -194,33 +208,7 @@ public void testViewValidUser() {
assertTrue(model.containsKey("effectiveUserOrcid"));
assertEquals(userOrcid, model.get("effectiveUserOrcid"));
assertFalse(model.containsKey("noIndex"));
}

@Test
public void testViewLockedUser() {
String displayName = localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name");
ModelAndView mav = publicProfileController.publicPreview(request, response, 1, 0, 15, lockedUserOrcid);
Map<String, Object> model = mav.getModel();
assertUnavailableProfileBasicData(mav, lockedUserOrcid, displayName);
}

@Test
public void testViewDeprecatedUser() {
ModelAndView mav = publicProfileController.publicPreview(request, response, 1, 0, 15, deprecatedUserOrcid);
Map<String, Object> model = mav.getModel();
assertUnavailableProfileBasicData(mav, deprecatedUserOrcid, null);
}

@Test
public void testViewClaimedUserBeforeIsLongEnough() {
ProfileEntity profile = profileDao.find(unclaimedUserOrcid);
profile.setSubmissionDate(new Date());
profileDao.merge(profile);
profileDao.flush();
String displayName = localeManager.resolveMessage("orcid.reserved_for_claim");
ModelAndView mav = publicProfileController.publicPreview(request, response, 1, 0, 15, unclaimedUserOrcid);
assertUnavailableProfileBasicData(mav, unclaimedUserOrcid, displayName);
}
}

@Test
public void testViewClaimedUserWhenIsLongEnough() {
Expand Down Expand Up @@ -298,18 +286,128 @@ public void testGetGroupedAffiliations() {
assertTrue(memberships);
assertTrue(qualifications);
assertTrue(services);
}

@Test
public void getUserInfoTest() {
setupUserInfoMocks();
// Check un-reviewed record with no integrations
Map<String, String> map1 = publicProfileController.getUserInfo(unreviewedNoIntegrationsOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), unreviewedNoIntegrationsOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "false");
assertFalse(map1.containsKey("PRIMARY_RECORD"));

// Check un-reviewed record with integrations
map1 = publicProfileController.getUserInfo(unreviewedWithIntegrationsOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), unreviewedWithIntegrationsOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "true");
assertFalse(map1.containsKey("PRIMARY_RECORD"));

// Check reviewed record with no integrations
map1 = publicProfileController.getUserInfo(reviewedNoIntegrationsOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), reviewedNoIntegrationsOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "true");
assertFalse(map1.containsKey("PRIMARY_RECORD"));

// Check reviewed record with integrations
map1 = publicProfileController.getUserInfo(reviewedWithIntegrationsOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), reviewedWithIntegrationsOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "true");
assertFalse(map1.containsKey("PRIMARY_RECORD"));

// Check deprecated
map1 = publicProfileController.getUserInfo(deprecatedUserOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), deprecatedUserOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "false");
assertEquals(map1.get("PRIMARY_RECORD"), primaryRecord);

// Check locked
map1 = publicProfileController.getUserInfo(lockedUserOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), lockedUserOrcid);
assertEquals(map1.get("IS_LOCKED"), "true");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "false");
assertFalse(map1.containsKey("PRIMARY_RECORD"));

// Check all OK user
map1 = publicProfileController.getUserInfo(userOrcid);
assertEquals(map1.get("EFFECTIVE_USER_ORCID"), userOrcid);
assertEquals(map1.get("IS_LOCKED"), "false");
assertEquals(map1.get("IS_DEACTIVATED"), "false");
assertEquals(map1.get("READY_FOR_INDEXING"), "true");
assertFalse(map1.containsKey("PRIMARY_RECORD"));
}

private void assertUnavailableProfileBasicData(ModelAndView mav, String orcid, String displayName) {
assertEquals("public_profile_v3", mav.getViewName());
PublicRecordPersonDetails personDetails = publicProfileController.getPersonDetails(orcid);
Map<String, Object> model = mav.getModel();
assertTrue(model.containsKey("effectiveUserOrcid"));
assertEquals(orcid, model.get("effectiveUserOrcid"));
if(displayName != null) {
assertNotNull(personDetails.getDisplayName());
assertEquals(displayName, personDetails.getDisplayName());
assertNull(personDetails.getTitle());
}
private void setupUserInfoMocks() {
TargetProxyHelper.injectIntoProxy(publicProfileController, "orcidOauth2TokenService", orcidOauth2TokenServiceMock);
TargetProxyHelper.injectIntoProxy(publicProfileController, "profileEntityCacheManager", profileEntityCacheManagerMock);

// Reviewed record with no integrations
ProfileEntity reviewedNoIntegrations = new ProfileEntity(reviewedNoIntegrationsOrcid);
reviewedNoIntegrations.setRecordLocked(false);
reviewedNoIntegrations.setReviewed(true);

when(orcidOauth2TokenServiceMock.hasToken(eq(reviewedNoIntegrationsOrcid), anyLong())).thenReturn(false);
when(profileEntityCacheManagerMock.retrieve(reviewedNoIntegrationsOrcid)).thenReturn(reviewedNoIntegrations);

// Reviewed record with integrations
ProfileEntity reviewedWithIntegrations = new ProfileEntity(reviewedWithIntegrationsOrcid);
reviewedWithIntegrations.setRecordLocked(false);
reviewedWithIntegrations.setReviewed(true);

when(orcidOauth2TokenServiceMock.hasToken(eq(reviewedWithIntegrationsOrcid), anyLong())).thenReturn(true);
when(profileEntityCacheManagerMock.retrieve(reviewedWithIntegrationsOrcid)).thenReturn(reviewedWithIntegrations);

// Un reviewed record with no integrations
ProfileEntity unreviewedNoIntegrations = new ProfileEntity(unreviewedNoIntegrationsOrcid);
unreviewedNoIntegrations.setRecordLocked(false);
unreviewedNoIntegrations.setReviewed(false);

when(orcidOauth2TokenServiceMock.hasToken(eq(unreviewedNoIntegrationsOrcid), anyLong())).thenReturn(false);
when(profileEntityCacheManagerMock.retrieve(unreviewedNoIntegrationsOrcid)).thenReturn(unreviewedNoIntegrations);

// Un reviewed record with integrations
ProfileEntity unreviewedWithIntegrations = new ProfileEntity(unreviewedWithIntegrationsOrcid);
unreviewedWithIntegrations.setRecordLocked(false);
unreviewedWithIntegrations.setReviewed(false);

when(orcidOauth2TokenServiceMock.hasToken(eq(unreviewedWithIntegrationsOrcid), anyLong())).thenReturn(true);
when(profileEntityCacheManagerMock.retrieve(unreviewedWithIntegrationsOrcid)).thenReturn(unreviewedWithIntegrations);

// Deprecated
ProfileEntity deprecated = new ProfileEntity(deprecatedUserOrcid);
deprecated.setRecordLocked(false);
deprecated.setReviewed(true);
deprecated.setPrimaryRecord(new ProfileEntity(primaryRecord));

when(orcidOauth2TokenServiceMock.hasToken(eq(deprecatedUserOrcid), anyLong())).thenReturn(true);
when(profileEntityCacheManagerMock.retrieve(deprecatedUserOrcid)).thenReturn(deprecated);

// Locked
ProfileEntity locked = new ProfileEntity(lockedUserOrcid);
locked.setRecordLocked(true);
locked.setReviewed(true);

when(orcidOauth2TokenServiceMock.hasToken(eq(lockedUserOrcid), anyLong())).thenReturn(true);
when(profileEntityCacheManagerMock.retrieve(lockedUserOrcid)).thenReturn(locked);


// All OK user
ProfileEntity allOk = new ProfileEntity(userOrcid);
allOk.setRecordLocked(false);
allOk.setReviewed(true);

when(orcidOauth2TokenServiceMock.hasToken(eq(userOrcid), anyLong())).thenReturn(true);
when(profileEntityCacheManagerMock.retrieve(userOrcid)).thenReturn(allOk);
}
}

0 comments on commit b5b7205

Please sign in to comment.