Search in sources :

Example 21 with OrcidIdentifier

use of org.orcid.jaxb.model.message.OrcidIdentifier in project ORCID-Source by ORCID.

the class DefaultPermissionChecker method performClientChecks.

private void performClientChecks(OAuth2Authentication oAuth2Authentication, ScopePathType requiredScope, OrcidMessage orcidMessage, String orcid) {
    OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
    // as an update
    if (orcidMessage != null && orcidMessage.getOrcidProfile() != null && StringUtils.isNotBlank(orcid)) {
        OrcidIdentifier orcidOb = orcidMessage.getOrcidProfile().getOrcidIdentifier();
        String messageOrcid = orcidOb != null ? orcidOb.getPath() : orcid;
        if (StringUtils.isNotBlank(messageOrcid) && !orcid.equals(messageOrcid)) {
            throw new IllegalArgumentException("The ORCID in the body and the URI do NOT match. Body ORCID: " + messageOrcid + " URI ORCID: " + orcid + " do NOT match.");
        }
        profileEntityCacheManager.retrieve(messageOrcid);
        if (!profileEntityManager.existsAndNotClaimedAndBelongsTo(messageOrcid, authorizationRequest.getClientId())) {
            throw new AccessControlException("You cannot update this profile as it has been claimed, or you are not the owner.");
        }
    }
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) AccessControlException(java.security.AccessControlException)

Example 22 with OrcidIdentifier

use of org.orcid.jaxb.model.message.OrcidIdentifier in project ORCID-Source by ORCID.

the class VisibilityFilterImpl method getMessageIdForLog.

private String getMessageIdForLog(OrcidMessage messageToBeFiltered) {
    String messageIdForLog = "unknown";
    OrcidSearchResults orcidSearchResults = messageToBeFiltered.getOrcidSearchResults();
    OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile();
    if (orcidSearchResults != null) {
        messageIdForLog = "orcid-search-results";
    } else if (orcidProfile != null) {
        OrcidIdentifier orcidIdentifier = orcidProfile.getOrcidIdentifier();
        if (orcidIdentifier != null) {
            messageIdForLog = orcidIdentifier.getPath();
        }
        Orcid orcid = orcidProfile.getOrcid();
        if (orcid != null) {
            messageIdForLog = orcid.getValue();
        }
    }
    return messageIdForLog;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSearchResults(org.orcid.jaxb.model.message.OrcidSearchResults) Orcid(org.orcid.jaxb.model.message.Orcid) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier)

Example 23 with OrcidIdentifier

use of org.orcid.jaxb.model.message.OrcidIdentifier in project ORCID-Source by ORCID.

the class RegistrationController method getDupicateResearcher.

@RequestMapping(value = "/dupicateResearcher.json", method = RequestMethod.GET)
@ResponseBody
public List<DupicateResearcher> getDupicateResearcher(@RequestParam("givenNames") String givenNames, @RequestParam("familyNames") String familyNames) {
    List<DupicateResearcher> drList = new ArrayList<DupicateResearcher>();
    List<OrcidProfile> potentialDuplicates = findPotentialDuplicatesByFirstNameLastName(givenNames, familyNames);
    for (OrcidProfile op : potentialDuplicates) {
        DupicateResearcher dr = new DupicateResearcher();
        if (op.getOrcidBio() != null) {
            if (op.getOrcidBio().getContactDetails() != null) {
                if (op.getOrcidBio().getContactDetails().retrievePrimaryEmail() != null) {
                    dr.setEmail(op.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue());
                }
            }
            FamilyName familyName = op.getOrcidBio().getPersonalDetails().getFamilyName();
            if (familyName != null) {
                dr.setFamilyNames(familyName.getContent());
            }
            dr.setGivenNames(op.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
            dr.setInstitution(null);
        }
        OrcidIdentifier orcidIdentifier = op.getOrcidIdentifier();
        // check for null just in case.
        if (orcidIdentifier != null) {
            dr.setOrcid(orcidIdentifier.getPath());
        }
        drList.add(dr);
    }
    return drList;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) DupicateResearcher(org.orcid.pojo.DupicateResearcher) FamilyName(org.orcid.jaxb.model.message.FamilyName) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with OrcidIdentifier

use of org.orcid.jaxb.model.message.OrcidIdentifier in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.

@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
    final String orcid = "0000-0000-0000-0003";
    String delegateOrcid = "1234-5678-1234-5678";
    ProfileEntity profile = new ProfileEntity();
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    profile.setSendAdministrativeChangeNotifications(true);
    profile.setSendChangeNotifications(true);
    profile.setSendMemberUpdateRequests(true);
    profile.setSendOrcidNews(true);
    EmailEntity emailEntity = new EmailEntity();
    emailEntity.setId("test@email.com");
    emailEntity.setPrimary(true);
    emailEntity.setCurrent(true);
    Set<EmailEntity> emails = new HashSet<EmailEntity>();
    emails.add(emailEntity);
    profile.setEmails(emails);
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    DelegationDetails firstNewDelegate = new DelegationDetails();
    DelegateSummary firstNewDelegateSummary = new DelegateSummary();
    firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
    firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
    firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", firstNewDelegate);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) CreditName(org.orcid.jaxb.model.message.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)24 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)22 Test (org.junit.Test)16 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)16 DBUnitTest (org.orcid.test.DBUnitTest)15 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)14 Response (javax.ws.rs.core.Response)8 Organization (org.orcid.jaxb.model.message.Organization)8 OrganizationAddress (org.orcid.jaxb.model.message.OrganizationAddress)8 Affiliation (org.orcid.jaxb.model.message.Affiliation)7 Affiliations (org.orcid.jaxb.model.message.Affiliations)7 Transactional (org.springframework.transaction.annotation.Transactional)6 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)5 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)5 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)5 Title (org.orcid.jaxb.model.message.Title)5 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)5 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)4 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)4 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)4