Search in sources :

Example 61 with OrcidBio

use of org.orcid.jaxb.model.message.OrcidBio 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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Test(org.junit.Test)

Example 62 with OrcidBio

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());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.message.Email) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Aggregations

OrcidBio (org.orcid.jaxb.model.message.OrcidBio)62 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)44 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)31 Test (org.junit.Test)30 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)23 GivenNames (org.orcid.jaxb.model.message.GivenNames)22 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)21 Email (org.orcid.jaxb.model.message.Email)20 FamilyName (org.orcid.jaxb.model.message.FamilyName)18 BaseTest (org.orcid.core.BaseTest)16 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)16 CreditName (org.orcid.jaxb.model.message.CreditName)15 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)15 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)11 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)11 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)10 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)10 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)10 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)9 OtherName (org.orcid.jaxb.model.message.OtherName)9