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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations