use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class ExternalIdentifiersForm method toPersonExternalIdentifiers.
public PersonExternalIdentifiers toPersonExternalIdentifiers() {
if (externalIdentifiers == null) {
return null;
}
PersonExternalIdentifiers result = new PersonExternalIdentifiers();
result.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>());
for (ExternalIdentifierForm form : externalIdentifiers) {
result.getExternalIdentifiers().add(form.toPersonExternalIdentifier());
}
return result;
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class FundingForm method toFunding.
public Funding toFunding() {
Funding result = new Funding();
Amount orcidAmount = new Amount();
if (!PojoUtil.isEmpty(amount))
orcidAmount.setContent(amount.getValue());
if (!PojoUtil.isEmpty(currencyCode))
orcidAmount.setCurrencyCode(currencyCode.getValue());
result.setAmount(orcidAmount);
if (!PojoUtil.isEmpty(description))
result.setDescription(description.getValue());
if (!PojoUtil.isEmpty(startDate))
result.setStartDate(new FuzzyDate(startDate.toFuzzyDate()));
if (!PojoUtil.isEmpty(endDate))
result.setEndDate(new FuzzyDate(endDate.toFuzzyDate()));
if (!PojoUtil.isEmpty(putCode))
result.setPutCode(Long.valueOf(putCode.getValue()));
if (fundingTitle != null) {
result.setTitle(fundingTitle.toFundingTitle());
}
if (!PojoUtil.isEmpty(fundingType))
result.setType(FundingType.fromValue(fundingType.getValue()));
if (organizationDefinedFundingSubType != null && !PojoUtil.isEmpty(organizationDefinedFundingSubType.getSubtype()))
result.setOrganizationDefinedType(new OrganizationDefinedFundingSubType(organizationDefinedFundingSubType.getSubtype().getValue()));
if (!PojoUtil.isEmpty(url))
result.setUrl(new Url(url.getValue()));
else
result.setUrl(new Url());
if (visibility != null)
result.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(visibility.getVisibility().value()));
// Set Organization
Organization organization = new Organization();
if (!PojoUtil.isEmpty(fundingName))
organization.setName(fundingName.getValue());
OrganizationAddress organizationAddress = new OrganizationAddress();
organization.setAddress(organizationAddress);
if (!PojoUtil.isEmpty(city))
organizationAddress.setCity(city.getValue());
if (!PojoUtil.isEmpty(region)) {
organizationAddress.setRegion(region.getValue());
}
if (!PojoUtil.isEmpty(country)) {
organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
}
if (!PojoUtil.isEmpty(disambiguatedFundingSourceId)) {
organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
organization.getDisambiguatedOrganization().setDisambiguatedOrganizationIdentifier(disambiguatedFundingSourceId.getValue());
organization.getDisambiguatedOrganization().setDisambiguationSource(disambiguationSource.getValue());
}
result.setOrganization(organization);
// Set contributors
if (contributors != null && !contributors.isEmpty()) {
FundingContributors fContributors = new FundingContributors();
for (Contributor contributor : contributors) {
if (!PojoUtil.isEmtpy(contributor))
fContributors.getContributor().add(contributor.toFundingContributor());
}
result.setContributors(fContributors);
}
// Set external identifiers
if (externalIdentifiers != null && !externalIdentifiers.isEmpty()) {
ExternalIDs fExternalIdentifiers = new ExternalIDs();
for (FundingExternalIdentifierForm fExternalIdentifier : externalIdentifiers) {
if (!PojoUtil.isEmtpy(fExternalIdentifier))
fExternalIdentifiers.getExternalIdentifier().add(fExternalIdentifier.toFundingExternalIdentifier());
}
result.setExternalIdentifiers(fExternalIdentifiers);
}
return result;
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class AddressesForm method toAddresses.
public Addresses toAddresses() {
Addresses result = new Addresses();
if (addresses != null) {
List<Address> addressList = new ArrayList<Address>();
for (AddressForm form : addresses) {
addressList.add(form.toAddress());
}
result.setAddress(addressList);
}
return result;
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class ManageProfileControllerTest method initMocks.
@Before
public void initMocks() throws Exception {
controller = new ManageProfileController();
MockitoAnnotations.initMocks(this);
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManagerReadOnly", mockGivenPermissionToManagerReadOnly);
TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
TargetProxyHelper.injectIntoProxy(controller, "orcidIdentifierUtils", mockOrcidIdentifierUtils);
TargetProxyHelper.injectIntoProxy(controller, "profileLastModifiedAspect", profileLastModifiedAspect);
when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID), Mockito.eq(ProfileEntity.USER_DRIVEN_DEPRECATION), Mockito.isNull())).thenReturn(true);
when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(false);
when(profileLastModifiedAspect.retrieveLastModifiedDate(anyString())).thenReturn(new Date());
when(mockOrcidIdentifierUtils.buildOrcidIdentifier(Mockito.anyString())).thenAnswer(new Answer<OrcidIdentifier>() {
@Override
public OrcidIdentifier answer(InvocationOnMock invocation) throws Throwable {
OrcidIdentifier result = new OrcidIdentifier();
result.setPath(invocation.getArgument(0));
return result;
}
});
when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
});
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
ProfileEntity entity = new ProfileEntity();
entity.setId(invocation.getArgument(0));
Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
IntStream.range(0, 2).forEachOrdered(i -> {
GivenPermissionToEntity e1 = new GivenPermissionToEntity();
e1.setId(Long.valueOf(i));
Date now = new Date();
e1.setApprovalDate(now);
e1.setDateCreated(now);
e1.setGiver(invocation.getArgument(0));
ProfileSummaryEntity ps = new ProfileSummaryEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
if (i == 0) {
ps.setId("0000-0000-0000-0004");
recordName.setCreditName("Credit Name");
} else {
ps.setId("0000-0000-0000-0005");
recordName.setFamilyName("Family Name");
recordName.setGivenNames("Given Names");
}
ps.setRecordNameEntity(recordName);
e1.setReceiver(ps);
givenPermissionTo.add(e1);
});
entity.setGivenPermissionTo(givenPermissionTo);
EmailEntity email1 = new EmailEntity();
email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVerified(true);
email1.setCurrent(true);
email1.setDateCreated(new Date());
email1.setLastModified(new Date());
email1.setPrimary(true);
email1.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
EmailEntity email2 = new EmailEntity();
email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVerified(true);
email2.setCurrent(false);
email2.setDateCreated(new Date());
email2.setLastModified(new Date());
email2.setPrimary(false);
email2.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(email1);
emails.add(email2);
entity.setEmails(emails);
entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
entity.setEncryptedPassword("password");
return entity;
}
});
when(mockEmailManager.getEmails(Mockito.anyString())).thenAnswer(new Answer<Emails>() {
@Override
public Emails answer(InvocationOnMock invocation) throws Throwable {
Emails emails = new Emails();
Email email1 = new Email();
email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email1);
Email email2 = new Email();
email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email2);
return emails;
}
});
when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {
@Override
public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
String emailString = invocation.getArgument(0);
String orcidString = emailString.substring(0, (emailString.indexOf("_")));
EmailEntity email = new EmailEntity();
email.setId(emailString);
email.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
ProfileEntity entity = new ProfileEntity(orcidString);
entity.setEncryptedPassword("password");
entity.setRecordNameEntity(getRecordName(orcidString));
email.setProfile(entity);
return email;
}
});
when(mockGivenPermissionToManagerReadOnly.findByGiver(anyString(), anyLong())).thenAnswer(new Answer<List<DelegateForm>>() {
@Override
public List<DelegateForm> answer(InvocationOnMock invocation) throws Throwable {
XMLGregorianCalendar now = DateUtils.convertToXMLGregorianCalendar(new Date());
List<DelegateForm> list = new ArrayList<DelegateForm>();
DelegateForm one = new DelegateForm();
one.setGiverOrcid(new OrcidIdentifier(USER_ORCID));
one.setReceiverOrcid(new OrcidIdentifier("0000-0000-0000-0004"));
one.setReceiverName(Text.valueOf("Credit Name"));
one.setApprovalDate(now);
list.add(one);
DelegateForm two = new DelegateForm();
two.setGiverOrcid(new OrcidIdentifier(USER_ORCID));
two.setReceiverOrcid(new OrcidIdentifier("0000-0000-0000-0005"));
two.setReceiverName(Text.valueOf("Given Names Family Name"));
two.setApprovalDate(now);
list.add(two);
return list;
}
});
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateAffiliation.
public Affiliation updateAffiliation(String orcid, Affiliation affiliation, boolean isApiRequest, AffiliationType type) {
OrgAffiliationRelationEntity entity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliation.getPutCode());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = entity.getSourceId();
String existingClientSourceId = entity.getClientSourceId();
org.orcid.jaxb.model.common_v2.Visibility originalVisibility = entity.getVisibility();
orcidSecurityManager.checkSource(entity);
activityValidator.validateAffiliation(affiliation, sourceEntity, false, isApiRequest, org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(originalVisibility.value()));
if (isApiRequest) {
checkAffiliationExternalIDsForDuplicates(orcid, affiliation, sourceEntity);
}
switch(type) {
case DISTINCTION:
jpaJaxbDistinctionAdapter.toOrgAffiliationRelationEntity((Distinction) affiliation, entity);
break;
case EDUCATION:
jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity((Education) affiliation, entity);
break;
case EMPLOYMENT:
jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity((Employment) affiliation, entity);
break;
case INVITED_POSITION:
jpaJaxbInvitedPositionAdapter.toOrgAffiliationRelationEntity((InvitedPosition) affiliation, entity);
break;
case MEMBERSHIP:
jpaJaxbMembershipAdapter.toOrgAffiliationRelationEntity((Membership) affiliation, entity);
break;
case QUALIFICATION:
jpaJaxbQualificationAdapter.toOrgAffiliationRelationEntity((Qualification) affiliation, entity);
break;
case SERVICE:
jpaJaxbServiceAdapter.toOrgAffiliationRelationEntity((Service) affiliation, entity);
break;
}
entity.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
entity.setSourceId(existingSourceId);
entity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(affiliation);
entity.setOrg(updatedOrganization);
entity.setAffiliationType(type);
entity = orgAffiliationRelationDao.merge(entity);
orgAffiliationRelationDao.flush();
Affiliation result = null;
switch(type) {
case DISTINCTION:
notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity));
result = jpaJaxbDistinctionAdapter.toDistinction(entity);
break;
case EDUCATION:
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity));
result = jpaJaxbEducationAdapter.toEducation(entity);
break;
case EMPLOYMENT:
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity));
result = jpaJaxbEmploymentAdapter.toEmployment(entity);
break;
case INVITED_POSITION:
notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity));
result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity);
break;
case MEMBERSHIP:
notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity));
result = jpaJaxbMembershipAdapter.toMembership(entity);
break;
case QUALIFICATION:
notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity));
result = jpaJaxbQualificationAdapter.toQualification(entity);
break;
case SERVICE:
notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity));
result = jpaJaxbServiceAdapter.toService(entity);
break;
}
return result;
}
Aggregations