use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsDontModifyProfile.
@Test
public void testAddDuplicatedExtIdsDontModifyProfile() {
String userOrcid = "0000-0000-0000-0005";
OrcidMessage message = new OrcidMessage();
message.setMessageVersion("1.2_rc6");
message.setOrcidProfile(new OrcidProfile());
message.getOrcidProfile().setOrcidBio(new OrcidBio());
ExternalIdentifiers extIds = new ExternalIdentifiers();
ExternalIdentifier extId1 = new ExternalIdentifier();
String commonName = "common-name-1-" + System.currentTimeMillis();
extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
extIds.getExternalIdentifier().add(extId1);
message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
// Add for client 1
SecurityContextTestUtils.setUpSecurityContext(userOrcid, "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
assertNotNull(r);
OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
assertNotNull(newMessage1);
assertNotNull(newMessage1.getOrcidProfile());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
// Reset message to add it again
message = new OrcidMessage();
message.setMessageVersion("1.2_rc6");
message.setOrcidProfile(new OrcidProfile());
message.getOrcidProfile().setOrcidBio(new OrcidBio());
extId1.setSource(null);
message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
// If we add it again, no error, but it is not duplicated
assertNotNull(r);
OrcidMessage newMessage2 = (OrcidMessage) r.getEntity();
assertNotNull(newMessage2);
assertNotNull(newMessage2.getOrcidProfile());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("APP-5555555555555555", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method deactivateOrcidProfile.
@Override
@Transactional
@Deprecated
public OrcidProfile deactivateOrcidProfile(OrcidProfile existingOrcidProfile) {
OrcidProfile blankedOrcidProfile = new OrcidProfile();
OrcidBio existingBio = existingOrcidProfile.getOrcidBio();
OrcidBio minimalBio = new OrcidBio();
ContactDetails minimalContactDetails = new ContactDetails();
minimalContactDetails.getEmail().addAll(existingBio.getContactDetails().getEmail());
OrcidInternal minimalOrcidInternal = new OrcidInternal();
minimalOrcidInternal.setSecurityDetails(existingOrcidProfile.getOrcidInternal().getSecurityDetails());
OrcidHistory deactivatedOrcidHistory = existingOrcidProfile.getOrcidHistory();
deactivatedOrcidHistory.setDeactivationDate(new DeactivationDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
blankedOrcidProfile.setOrcidHistory(deactivatedOrcidHistory);
// only names names from bio with a visibility setting
PersonalDetails minimalPersonalDetails = new PersonalDetails();
minimalPersonalDetails.setOtherNames(null);
CreditName creditName = new CreditName();
creditName.setVisibility(Visibility.PUBLIC);
minimalPersonalDetails.setCreditName(creditName);
minimalPersonalDetails.setGivenNames(new GivenNames("Given Names Deactivated"));
minimalPersonalDetails.setFamilyName(new FamilyName("Family Name Deactivated"));
for (Email email : minimalContactDetails.getEmail()) {
setVisibilityToPrivate(email);
}
setVisibilityToPrivate(minimalPersonalDetails.getOtherNames());
if (minimalPersonalDetails.getOtherNames() != null && minimalPersonalDetails.getOtherNames().getOtherName() != null) {
for (OtherName name : minimalPersonalDetails.getOtherNames().getOtherName()) setVisibilityToPrivate(name);
}
minimalBio.setPersonalDetails(minimalPersonalDetails);
minimalBio.setContactDetails(minimalContactDetails);
minimalBio.setBiography(new Biography());
minimalBio.setExternalIdentifiers(new ExternalIdentifiers());
blankedOrcidProfile.setOrcidBio(minimalBio);
blankedOrcidProfile.setOrcidIdentifier(existingOrcidProfile.getOrcidIdentifier().getPath());
OrcidProfile profileToReturn = updateOrcidProfile(blankedOrcidProfile);
userConnectionDao.deleteByOrcid(existingOrcidProfile.getOrcidIdentifier().getPath());
notificationManager.sendAmendEmail(profileToReturn, AmendedSection.UNKNOWN);
return profileToReturn;
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class OrcidProfileManagerReadOnlyImpl method createReservedForClaimOrcidProfile.
protected OrcidProfile createReservedForClaimOrcidProfile(String orcid, OrcidDeprecated deprecatedInfo, LastModifiedDate lastModifiedDate) {
OrcidProfile op = new OrcidProfile();
if (jpaJaxbAdapter != null) {
op.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
} else {
op.setOrcidIdentifier(orcid);
}
if (deprecatedInfo != null)
op.setOrcidDeprecated(deprecatedInfo);
OrcidHistory oh = new OrcidHistory();
oh.setClaimed(new Claimed(false));
oh.setLastModifiedDate(lastModifiedDate);
op.setOrcidHistory(oh);
GivenNames gn = new GivenNames();
PersonalDetails pd = new PersonalDetails();
gn.setContent(localeManager.resolveMessage("orcid.reserved_for_claim"));
gn.setVisibility(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility());
pd.setGivenNames(gn);
OrcidBio ob = new OrcidBio();
ob.setPersonalDetails(pd);
op.setOrcidBio(ob);
return op;
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class OrcidMessageUtil method setSourceName.
public void setSourceName(OrcidProfile orcidProfile) {
if (orcidProfile != null) {
if (orcidProfile.getOrcidActivities() != null) {
OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
if (orcidActivities.getAffiliations() != null) {
Affiliations affs = orcidActivities.getAffiliations();
List<Affiliation> affList = affs.getAffiliation();
if (affList != null) {
for (Affiliation aff : affList) {
setSourceName(aff);
}
}
}
if (orcidActivities.getFundings() != null) {
FundingList fundingList = orcidActivities.getFundings();
List<Funding> fundings = fundingList.getFundings();
if (fundings != null) {
for (Funding funding : fundings) {
setSourceName(funding);
}
}
}
if (orcidActivities.getOrcidWorks() != null) {
OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
List<OrcidWork> works = orcidWorks.getOrcidWork();
if (works != null) {
for (OrcidWork work : works) {
setSourceName(work);
}
}
}
}
if (orcidProfile.getOrcidBio() != null) {
OrcidBio orcidBio = orcidProfile.getOrcidBio();
if (orcidBio.getContactDetails() != null) {
Address address = orcidBio.getContactDetails().getAddress();
if (address != null) {
setSourceName(address);
}
}
if (orcidBio.getExternalIdentifiers() != null) {
ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
if (extIdsList != null) {
for (ExternalIdentifier extId : extIdsList) {
setSourceName(extId);
}
}
}
if (orcidBio.getKeywords() != null) {
Keywords keywords = orcidBio.getKeywords();
List<Keyword> keywordList = keywords.getKeyword();
if (keywordList != null) {
for (Keyword keyword : keywordList) {
setSourceName(keyword);
}
}
}
if (orcidBio.getPersonalDetails() != null) {
OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
if (otherNames != null) {
List<OtherName> otherNameList = otherNames.getOtherName();
if (otherNameList != null) {
for (OtherName otherName : otherNameList) {
setSourceName(otherName);
}
}
}
}
if (orcidBio.getResearcherUrls() != null) {
ResearcherUrls rUrls = orcidBio.getResearcherUrls();
List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
if (rUrlList != null) {
for (ResearcherUrl rUrl : rUrlList) {
setSourceName(rUrl);
}
}
}
}
}
}
use of org.orcid.jaxb.model.message.OrcidBio in project ORCID-Source by ORCID.
the class EmailsTest method updateEmailsUsingAlreadyExistingEmailTest.
/**
* Test update email using already existing email
* */
@Test
public void updateEmailsUsingAlreadyExistingEmailTest() throws JSONException, InterruptedException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String user2Email = getUser2UserName();
String accessToken = getAccessToken(userId, password, Arrays.asList("/orcid-bio/update"), clientId, clientSecret, clientRedirectUri, true);
//Email already used by 9999-9999-9999-9990
ContactDetails contactDetails = new ContactDetails();
contactDetails.getEmail().add(new Email(user2Email));
OrcidBio orcidBio = new OrcidBio();
orcidBio.setContactDetails(contactDetails);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setType(OrcidType.USER);
orcidProfile.setOrcidBio(orcidBio);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
orcidMessage.setOrcidProfile(orcidProfile);
ClientResponse clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(400, clientResponse.getStatus());
OrcidMessage errorMessage = clientResponse.getEntity(OrcidMessage.class);
assertNotNull(errorMessage);
assertNotNull(errorMessage.getErrorDesc());
assertEquals("Bad Request: Invalid incoming message: Email " + user2Email + " belongs to other user", errorMessage.getErrorDesc().getContent());
}
Aggregations