Search in sources :

Example 11 with OrcidIdentifier

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

the class AddDelegateForm method getOrcidProfile.

public OrcidProfile getOrcidProfile(String orcid) {
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidProfile.setOrcidIdentifier(orcid);
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    Delegation delegation = new Delegation();
    orcidBio.setDelegation(delegation);
    GivenPermissionTo givenPermissionTo = new GivenPermissionTo();
    delegation.setGivenPermissionTo(givenPermissionTo);
    DelegationDetails delegationDetails = new DelegationDetails();
    givenPermissionTo.getDelegationDetails().add(delegationDetails);
    DelegateSummary delegateSummary = new DelegateSummary(new OrcidIdentifier(delegateOrcid));
    delegationDetails.setDelegateSummary(delegateSummary);
    return orcidProfile;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) GivenPermissionTo(org.orcid.jaxb.model.message.GivenPermissionTo) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Delegation(org.orcid.jaxb.model.message.Delegation)

Example 12 with OrcidIdentifier

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

the class OrcidProfileManagerImplTest method testRevokeDelegate.

@Test
@Transactional
@Rollback(true)
public void testRevokeDelegate() {
    OrcidProfile profile1 = createBasicProfile();
    Delegation delegation = new Delegation();
    profile1.getOrcidBio().setDelegation(delegation);
    GivenPermissionTo givenPermissionTo = new GivenPermissionTo();
    delegation.setGivenPermissionTo(givenPermissionTo);
    DelegationDetails delegationDetails = new DelegationDetails();
    delegationDetails.setApprovalDate(new ApprovalDate(DateUtils.convertToXMLGregorianCalendar("2011-03-14T02:34:16")));
    DelegateSummary profileSummary = new DelegateSummary(new OrcidIdentifier(DELEGATE_ORCID));
    delegationDetails.setDelegateSummary(profileSummary);
    givenPermissionTo.getDelegationDetails().add(delegationDetails);
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    orcidProfileManager.revokeDelegate(TEST_ORCID, DELEGATE_ORCID);
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNull(retrievedProfile.getOrcidBio().getDelegation());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) GivenPermissionTo(org.orcid.jaxb.model.message.GivenPermissionTo) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Delegation(org.orcid.jaxb.model.message.Delegation) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 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)

Example 14 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 15 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)

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