use of org.orcid.jaxb.model.message.ExternalIdentifiers in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testDefaultPrivacyOnBio.
@Test
public void testDefaultPrivacyOnBio() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4499", ScopePathType.ORCID_BIO_UPDATE);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4499"));
orcidMessage.setOrcidProfile(orcidProfile);
OrcidBio orcidBio = new OrcidBio();
orcidProfile.setOrcidBio(orcidBio);
PersonalDetails personalDetails = new PersonalDetails();
orcidBio.setPersonalDetails(personalDetails);
GivenNames givenNames = new GivenNames("Test given names");
personalDetails.setGivenNames(givenNames);
CreditName creditName = new CreditName("Credit Name");
personalDetails.setCreditName(creditName);
ExternalIdentifier id = new ExternalIdentifier();
id.setExternalIdCommonName(new ExternalIdCommonName("cn1"));
id.setExternalIdReference(new ExternalIdReference("value1"));
orcidBio.setExternalIdentifiers(new ExternalIdentifiers());
orcidBio.getExternalIdentifiers().getExternalIdentifier().add(id);
personalDetails.setOtherNames(new OtherNames());
personalDetails.getOtherNames().addOtherName("on1", null);
orcidBio.setKeywords(new Keywords());
orcidBio.getKeywords().getKeyword().add(new Keyword("kw1", null));
orcidBio.setResearcherUrls(new ResearcherUrls());
orcidBio.getResearcherUrls().getResearcherUrl().add(new ResearcherUrl(new Url("http://rurl2.com"), null));
t2OrcidApiServiceDelegator.updateBioDetails(mockedUriInfo, "4444-4444-4444-4499", orcidMessage);
OrcidProfile p = orcidProfileManager.retrieveOrcidProfile("4444-4444-4444-4499");
assertEquals("cn1", p.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals(Visibility.PUBLIC, p.getOrcidBio().getExternalIdentifiers().getVisibility());
assertEquals("on1", p.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
assertEquals(Visibility.PUBLIC, p.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
assertEquals("kw1", p.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
assertEquals(Visibility.PUBLIC, p.getOrcidBio().getKeywords().getVisibility());
assertEquals(new Url("http://rurl2.com"), p.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl());
assertEquals(Visibility.PUBLIC, p.getOrcidBio().getResearcherUrls().getVisibility());
// now test what happens if we add a new one.
}
use of org.orcid.jaxb.model.message.ExternalIdentifiers in project ORCID-Source by ORCID.
the class Api12MembersTest method addExternalIdentifiersTest.
@Test
public void addExternalIdentifiersTest() throws InterruptedException, JSONException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String accessToken = getAccessToken(userId, password, Arrays.asList("/person/update", "/orcid-bio/read-limited"), clientId, clientSecret, clientRedirectUri, true);
// Check the current record and get the num of existing ext ids
ClientResponse response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
OrcidMessage orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithExtIds);
assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
int initialNumberOfExtIds = 0;
if (orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers() != null && orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier() != null) {
initialNumberOfExtIds = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size();
}
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
OrcidBio orcidBio = new OrcidBio();
ExternalIdentifier extId = new ExternalIdentifier();
Long time = System.currentTimeMillis();
String commonName = "ext-id-common-name-" + time;
String idReference = "ext-id-reference-" + time;
extId.setExternalIdCommonName(new ExternalIdCommonName(commonName));
extId.setExternalIdReference(new ExternalIdReference(idReference));
ExternalIdentifiers extIds = new ExternalIdentifiers();
extIds.getExternalIdentifier().add(extId);
orcidBio.setExternalIdentifiers(extIds);
orcidProfile.setOrcidBio(orcidBio);
orcidMessage.setOrcidProfile(orcidProfile);
ClientResponse clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithExtIds);
assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
boolean found = false;
for (ExternalIdentifier newExtId : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
if (commonName.equals(newExtId.getExternalIdCommonName().getContent())) {
assertEquals(idReference, newExtId.getExternalIdReference().getContent());
found = true;
}
}
assertTrue(found);
// Try to add a duplicate
long initialSize = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size();
ExternalIdentifier dupExtId = new ExternalIdentifier();
dupExtId.setExternalIdCommonName(new ExternalIdCommonName(commonName));
dupExtId.setExternalIdReference(new ExternalIdReference(idReference));
orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
assertEquals(initialSize + 1, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithExtIds);
assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertEquals(initialSize, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
found = false;
for (ExternalIdentifier newExtId : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
if (commonName.equals(newExtId.getExternalIdCommonName().getContent())) {
assertEquals(idReference, newExtId.getExternalIdReference().getContent());
found = true;
}
}
assertTrue(found);
// Add a new one and the duplicate again, verify only the new one was added
String newExtIdValue = "new-ext-id-" + System.currentTimeMillis();
ExternalIdentifier newExtId = new ExternalIdentifier();
newExtId.setExternalIdCommonName(new ExternalIdCommonName(newExtIdValue));
newExtId.setExternalIdReference(new ExternalIdReference(newExtIdValue));
orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().add(newExtId);
assertEquals(initialSize + 2, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithExtIds);
assertNotNull(orcidMessageWithExtIds.getOrcidProfile());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
assertEquals(initialSize + 1, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
boolean foundOld = false;
boolean foundNew = false;
for (ExternalIdentifier element : orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
if (commonName.equals(element.getExternalIdCommonName().getContent())) {
assertEquals(idReference, element.getExternalIdReference().getContent());
foundOld = true;
} else if (newExtIdValue.equals(element.getExternalIdCommonName().getContent())) {
assertEquals(newExtIdValue, element.getExternalIdReference().getContent());
foundNew = true;
}
}
assertTrue(foundOld);
assertTrue(foundNew);
// Delete both ext ids
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithExtIds = response.getEntity(OrcidMessage.class);
Iterator<ExternalIdentifier> it = orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator();
while (it.hasNext()) {
ExternalIdentifier element = it.next();
if (commonName.equals(element.getExternalIdCommonName().getContent()) || newExtIdValue.equals(element.getExternalIdCommonName().getContent())) {
it.remove();
}
}
clientResponse = t2OAuthClient_1_2.addExternalIdentifiersXml(userId, orcidMessageWithExtIds, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
// It should have the same number of ext ids as before the test
assertEquals(initialNumberOfExtIds, orcidMessageWithExtIds.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
}
Aggregations