Search in sources :

Example 51 with OtherName

use of org.orcid.jaxb.model.v3.dev1.record.OtherName in project ORCID-Source by ORCID.

the class OtherNameForm method toOtherName.

public OtherName toOtherName() {
    OtherName otherName = new OtherName();
    if (!PojoUtil.isEmpty(this.getContent())) {
        otherName.setContent(this.getContent());
    }
    if (this.visibility != null && this.visibility.getVisibility() != null) {
        otherName.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(this.getVisibility().getVisibility().value()));
    }
    if (!PojoUtil.isEmpty(this.getPutCode())) {
        otherName.setPutCode(Long.valueOf(this.getPutCode()));
    }
    if (displayIndex != null) {
        otherName.setDisplayIndex(displayIndex);
    } else {
        otherName.setDisplayIndex(0L);
    }
    otherName.setSource(new Source(source));
    return otherName;
}
Also used : OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) Source(org.orcid.jaxb.model.v3.dev1.common.Source)

Example 52 with OtherName

use of org.orcid.jaxb.model.v3.dev1.record.OtherName in project ORCID-Source by ORCID.

the class OtherNamesTest method testInvalidPutCodeReturns404.

@Test
public void testInvalidPutCodeReturns404() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.OtherName otherName = new org.orcid.jaxb.model.v3.dev1.record.OtherName();
    otherName.setContent("Other Name #1 " + System.currentTimeMillis());
    otherName.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    otherName.setPutCode(1234567890L);
    ClientResponse response = memberV3Dev1ApiClient.updateOtherName(getUser1OrcidId(), otherName, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 53 with OtherName

use of org.orcid.jaxb.model.v3.dev1.record.OtherName in project ORCID-Source by ORCID.

the class OtherNamesTest method testCreateGetUpdateAndDeleteOtherName.

@SuppressWarnings({ "rawtypes", "deprecation" })
@Test
public void testCreateGetUpdateAndDeleteOtherName() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    changeCurrentOtherNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.OtherName newOtherName = new org.orcid.jaxb.model.v3.dev1.record.OtherName();
    newOtherName.setContent("other-name-3" + System.currentTimeMillis());
    newOtherName.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    // Create
    ClientResponse response = memberV3Dev1ApiClient.createOtherName(getUser1OrcidId(), newOtherName, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get and verify
    response = memberV3Dev1ApiClient.viewOtherNames(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.OtherNames otherNames = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherNames.class);
    assertNotNull(otherNames);
    assertNotNull(otherNames.getOtherNames());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.v3.dev1.record.OtherName existingOtherName : otherNames.getOtherNames()) {
        if (otherName1.equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingOtherName.getVisibility());
            found1 = true;
        } else if (otherName2.equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, existingOtherName.getVisibility());
            found2 = true;
        } else if (newOtherName.getContent().equals(existingOtherName.getContent())) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, existingOtherName.getVisibility());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV3Dev1ApiClient.viewOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.v3.dev1.record.OtherName otherName = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherName.class);
    assertNotNull(otherName);
    assertEquals(newOtherName.getContent(), otherName.getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
    assertEquals(putCode, otherName.getPutCode());
    assertNotNull(otherName.getDisplayIndex());
    Long originalDisplayIndex = otherName.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.v3.dev1.common.Visibility originalVisibility = otherName.getVisibility();
    org.orcid.jaxb.model.v3.dev1.common.Visibility updatedVisibility = org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC;
    // Verify you cant update the visibility
    otherName.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClient.updateOtherName(this.getUser1OrcidId(), otherName, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.error.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.v3.dev1.error.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    otherName.setVisibility(originalVisibility);
    // Update it
    otherName.setContent("Other Name #1 - Updated");
    response = memberV3Dev1ApiClient.updateOtherName(this.getUser1OrcidId(), otherName, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV3Dev1ApiClient.viewOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    otherName = response.getEntity(org.orcid.jaxb.model.v3.dev1.record.OtherName.class);
    assertNotNull(otherName);
    assertEquals("Other Name #1 - Updated", otherName.getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
    assertEquals(putCode, otherName.getPutCode());
    assertEquals(originalDisplayIndex, otherName.getDisplayIndex());
    // Delete
    response = memberV3Dev1ApiClient.deleteOtherName(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 54 with OtherName

use of org.orcid.jaxb.model.v3.dev1.record.OtherName in project ORCID-Source by ORCID.

the class PersonalDetailsTest method testGetWithMemberAPI.

@Test
public void testGetWithMemberAPI() throws Exception {
    String accessToken = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
    assertNotNull(accessToken);
    ClientResponse getPersonalDetailsResponse = memberV3Dev1ApiClient.viewPersonalDetailsXML(getUser1OrcidId(), accessToken);
    assertNotNull(getPersonalDetailsResponse);
    org.orcid.jaxb.model.v3.dev1.record.PersonalDetails personalDetails = getPersonalDetailsResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.PersonalDetails.class);
    assertNotNull(personalDetails);
    // Check bio
    assertNotNull(personalDetails.getBiography());
    assertEquals(getUser1Bio(), personalDetails.getBiography().getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC.value(), personalDetails.getBiography().getVisibility().value());
    // Check other names
    assertNotNull(personalDetails.getOtherNames());
    assertNotNull(personalDetails.getOtherNames().getOtherNames());
    boolean found1 = false, found2 = false;
    for (org.orcid.jaxb.model.v3.dev1.record.OtherName otherName : personalDetails.getOtherNames().getOtherNames()) {
        // Assert that PRIVATE ones belongs to himself
        if (org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.equals(otherName.getVisibility())) {
            assertEquals(getClient2ClientId(), otherName.getSource().retrieveSourcePath());
        }
        if (otherName.getContent().equals(otherName1)) {
            found1 = true;
        } else if (otherName.getContent().equals(otherName2)) {
            found2 = true;
        }
    }
    assertTrue("found1: " + found1 + " found2: " + found2, found1 && found2);
    // Check names
    assertNotNull(personalDetails.getName());
    assertNotNull(personalDetails.getName().getGivenNames());
    assertEquals(getUser1GivenName(), personalDetails.getName().getGivenNames().getContent());
    assertNotNull(personalDetails.getName().getFamilyName());
    assertEquals(getUser1FamilyNames(), personalDetails.getName().getFamilyName().getContent());
    assertNotNull(personalDetails.getName().getCreditName());
    assertEquals(getUser1CreditName(), personalDetails.getName().getCreditName().getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, personalDetails.getName().getVisibility());
    // Change all to LIMITED
    showMyOrcidPage();
    changeNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED.name());
    setOtherNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
    changeBiography(null, org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED.name());
    // Verify they are still visible
    getPersonalDetailsResponse = memberV3Dev1ApiClient.viewPersonalDetailsXML(getUser1OrcidId(), accessToken);
    assertNotNull(getPersonalDetailsResponse);
    personalDetails = getPersonalDetailsResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.PersonalDetails.class);
    assertNotNull(personalDetails);
    // Check bio
    assertNotNull(personalDetails.getBiography());
    assertEquals(getUser1Bio(), personalDetails.getBiography().getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED.value(), personalDetails.getBiography().getVisibility().value());
    // Check other names
    assertNotNull(personalDetails.getOtherNames());
    assertNotNull(personalDetails.getOtherNames().getOtherNames());
    // Check other names
    assertNotNull(personalDetails.getOtherNames());
    assertNotNull(personalDetails.getOtherNames().getOtherNames());
    found1 = false;
    found2 = false;
    for (org.orcid.jaxb.model.v3.dev1.record.OtherName otherName : personalDetails.getOtherNames().getOtherNames()) {
        // Assert that PRIVATE ones belongs to himself
        if (org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.equals(otherName.getVisibility())) {
            assertEquals(getClient2ClientId(), otherName.getSource().retrieveSourcePath());
        }
        if (otherName.getContent().equals(otherName1)) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
            found1 = true;
        } else if (otherName.getContent().equals(otherName2)) {
            assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, otherName.getVisibility());
            found2 = true;
        }
    }
    assertTrue("found1: " + found1 + " found2: " + found2, found1 && found2);
    // Check names
    assertNotNull(personalDetails.getName());
    assertNotNull(personalDetails.getName().getGivenNames());
    assertEquals(getUser1GivenName(), personalDetails.getName().getGivenNames().getContent());
    assertNotNull(personalDetails.getName().getFamilyName());
    assertEquals(getUser1FamilyNames(), personalDetails.getName().getFamilyName().getContent());
    assertNotNull(personalDetails.getName().getCreditName());
    assertEquals(getUser1CreditName(), personalDetails.getName().getCreditName().getContent());
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED, personalDetails.getName().getVisibility());
    // Change all to PRIVATE
    showMyOrcidPage();
    changeNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.name());
    setOtherNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE);
    changeBiography(null, org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.name());
    // Check nothing is visible
    getPersonalDetailsResponse = memberV3Dev1ApiClient.viewPersonalDetailsXML(getUser1OrcidId(), accessToken);
    assertNotNull(getPersonalDetailsResponse);
    personalDetails = getPersonalDetailsResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.PersonalDetails.class);
    assertNotNull(personalDetails);
    assertNull(personalDetails.getBiography());
    assertNull(personalDetails.getName());
    assertNotNull(personalDetails.getOtherNames());
    assertNotNull(personalDetails.getOtherNames().getOtherNames());
    assertTrue(personalDetails.getOtherNames().getOtherNames().isEmpty());
    // Change all to PUBLIC
    showMyOrcidPage();
    changeNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC.name());
    setOtherNamesVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    changeBiography(null, org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC.name());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 55 with OtherName

use of org.orcid.jaxb.model.v3.dev1.record.OtherName in project ORCID-Source by ORCID.

the class JpaJaxbOtherNameAdapterTest method fromOtherNameEntityToOtherNameTest.

@Test
public void fromOtherNameEntityToOtherNameTest() {
    OtherNameEntity entity = getOtherNameEntity();
    OtherName otherName = adapter.toOtherName(entity);
    assertNotNull(otherName);
    assertEquals("display-name", otherName.getContent());
    assertNotNull(otherName.getCreatedDate());
    assertNotNull(otherName.getLastModifiedDate());
    assertEquals(Long.valueOf(1), otherName.getPutCode());
    assertNotNull(otherName.getSource());
    assertEquals("APP-000000001", otherName.getSource().retrieveSourcePath());
    assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Also used : OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Test(org.junit.Test)

Aggregations

OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)104 Test (org.junit.Test)82 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)53 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)43 Address (org.orcid.jaxb.model.v3.dev1.record.Address)39 Name (org.orcid.jaxb.model.v3.dev1.record.Name)39 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)39 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)38 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)38 Email (org.orcid.jaxb.model.v3.dev1.record.Email)36 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)30 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)30 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)30 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)30 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)30 Person (org.orcid.jaxb.model.v3.dev1.record.Person)28 DBUnitTest (org.orcid.test.DBUnitTest)22 Response (javax.ws.rs.core.Response)20 PersonalDetails (org.orcid.jaxb.model.v3.dev1.record.PersonalDetails)17 ArrayList (java.util.ArrayList)16