use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ReadRecordTest method assertAllPublicButEmails.
private void assertAllPublicButEmails(Person p) {
assertNotNull(p);
Utils.verifyLastModified(p.getLastModifiedDate());
// Address
assertNotNull(p.getAddresses());
Addresses a = p.getAddresses();
assertNotNull(a);
Utils.verifyLastModified(a.getLastModifiedDate());
assertEquals(1, a.getAddress().size());
assertEquals(Long.valueOf(9), a.getAddress().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, a.getAddress().get(0).getVisibility());
// Biography
assertNotNull(p.getBiography());
Biography b = p.getBiography();
assertNotNull(b);
Utils.verifyLastModified(b.getLastModifiedDate());
assertEquals("Biography for 0000-0000-0000-0003", b.getContent());
// External identifiers
assertNotNull(p.getExternalIdentifiers());
PersonExternalIdentifiers extIds = p.getExternalIdentifiers();
assertNotNull(extIds);
Utils.verifyLastModified(extIds.getLastModifiedDate());
assertEquals(1, extIds.getExternalIdentifiers().size());
assertEquals(Long.valueOf(13), extIds.getExternalIdentifiers().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, extIds.getExternalIdentifiers().get(0).getVisibility());
// Keywords
assertNotNull(p.getKeywords());
Keywords k = p.getKeywords();
assertNotNull(k);
Utils.verifyLastModified(k.getLastModifiedDate());
assertEquals(1, k.getKeywords().size());
assertEquals(Long.valueOf(9), k.getKeywords().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, k.getKeywords().get(0).getVisibility());
// Name
assertNotNull(p.getName());
assertEquals("Credit Name", p.getName().getCreditName().getContent());
assertEquals("Given Names", p.getName().getGivenNames().getContent());
assertEquals("Family Name", p.getName().getFamilyName().getContent());
// Other names
assertNotNull(p.getOtherNames());
OtherNames o = p.getOtherNames();
assertNotNull(o);
Utils.verifyLastModified(o.getLastModifiedDate());
assertEquals(1, o.getOtherNames().size());
assertEquals(Long.valueOf(13), o.getOtherNames().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, o.getOtherNames().get(0).getVisibility());
// Researcher urls
assertNotNull(p.getResearcherUrls());
ResearcherUrls ru = p.getResearcherUrls();
assertNotNull(ru);
Utils.verifyLastModified(ru.getLastModifiedDate());
assertEquals(1, ru.getResearcherUrls().size());
assertEquals(Long.valueOf(13), ru.getResearcherUrls().get(0).getPutCode());
assertEquals(Visibility.PUBLIC, ru.getResearcherUrls().get(0).getVisibility());
}
use of org.orcid.jaxb.model.v3.dev1.record.OtherNames 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.OtherNames in project ORCID-Source by ORCID.
the class OtherNameManagerImpl method updateOtherNames.
@Override
@Transactional
public OtherNames updateOtherNames(String orcid, OtherNames otherNames) {
List<OtherNameEntity> existingOtherNamesEntityList = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
// Delete the deleted ones
for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
boolean deleteMe = true;
if (otherNames.getOtherNames() != null) {
for (OtherName updatedOrNew : otherNames.getOtherNames()) {
if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
otherNameDao.deleteOtherName(existingOtherName);
} catch (Exception e) {
throw new ApplicationException("Unable to delete other name " + existingOtherName.getId(), e);
}
}
}
if (otherNames != null && otherNames.getOtherNames() != null) {
for (OtherName updatedOrNew : otherNames.getOtherNames()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
existingOtherName.setLastModified(new Date());
existingOtherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
existingOtherName.setDisplayName(updatedOrNew.getContent());
existingOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.merge(existingOtherName);
}
}
} else {
// Add the new ones
OtherNameEntity newOtherName = jpaJaxbOtherNameAdapter.toOtherNameEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newOtherName.setProfile(profile);
newOtherName.setDateCreated(new Date());
// Set the source
if (sourceEntity.getSourceProfile() != null) {
newOtherName.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newOtherName.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newOtherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.persist(newOtherName);
}
}
}
return otherNames;
}
use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.
the class ValidateV3_dev1SamplesTest method testMarshallOtherNames.
@Test
public void testMarshallOtherNames() throws JAXBException, SAXException, URISyntaxException {
OtherNames object = (OtherNames) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/other-names-3.0_dev1.xml", OtherNames.class);
marshall(object, "/record_3.0_dev1/other-name-3.0_dev1.xsd");
}
use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.
the class ValidateV3_dev1SamplesTest method unmarshallFromPath.
private Object unmarshallFromPath(String path, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type, schemaPath);
Object result = null;
if (ResearcherUrls.class.equals(type)) {
result = (ResearcherUrls) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (PersonExternalIdentifiers.class.equals(type)) {
result = (PersonExternalIdentifiers) obj;
} else if (Biography.class.equals(type)) {
result = (Biography) obj;
} else if (Name.class.equals(type)) {
result = (Name) obj;
} else if (CreditName.class.equals(type)) {
result = (CreditName) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (OtherNames.class.equals(type)) {
result = (OtherNames) obj;
} else if (Keywords.class.equals(type)) {
result = (Keywords) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Addresses.class.equals(type)) {
result = (Addresses) obj;
} else if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Emails.class.equals(type)) {
result = (Emails) obj;
} else if (Email.class.equals(type)) {
result = (Email) obj;
} else if (Person.class.equals(type)) {
result = (Person) obj;
} else if (Deprecated.class.equals(type)) {
result = (Deprecated) obj;
} else if (Preferences.class.equals(type)) {
result = (Preferences) obj;
} else if (History.class.equals(type)) {
result = (History) obj;
} else if (Record.class.equals(type)) {
result = (Record) obj;
} else if (ActivitiesSummary.class.equals(type)) {
result = (ActivitiesSummary) obj;
} else if (Works.class.equals(type)) {
result = (Works) obj;
} else if (Education.class.equals(type)) {
result = (Education) obj;
} else if (Educations.class.equals(type)) {
result = (Educations) obj;
} else if (Employment.class.equals(type)) {
result = (Employment) obj;
} else if (Employments.class.equals(type)) {
result = (Employments) obj;
} else if (Distinction.class.equals(type)) {
result = (Distinction) obj;
} else if (Distinctions.class.equals(type)) {
result = (Distinctions) obj;
} else if (InvitedPosition.class.equals(type)) {
result = (InvitedPosition) obj;
} else if (InvitedPositions.class.equals(type)) {
result = (InvitedPositions) obj;
} else if (Membership.class.equals(type)) {
result = (Membership) obj;
} else if (Memberships.class.equals(type)) {
result = (Memberships) obj;
} else if (Qualification.class.equals(type)) {
result = (Qualification) obj;
} else if (Qualifications.class.equals(type)) {
result = (Qualifications) obj;
} else if (Service.class.equals(type)) {
result = (Service) obj;
} else if (Services.class.equals(type)) {
result = (Services) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
Aggregations