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;
}
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());
}
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);
}
}
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;
}
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.");
}
}
}
Aggregations