use of org.orcid.jaxb.model.v3.dev1.record.Addresses in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_AddressesTest method testViewAddresses.
@Test
public void testViewAddresses() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.PERSON_READ_LIMITED);
Response response = serviceDelegator.viewAddresses("4444-4444-4444-4447");
assertNotNull(response);
Addresses addresses = (Addresses) response.getEntity();
assertNotNull(addresses);
assertEquals("/4444-4444-4444-4447/address", addresses.getPath());
Utils.verifyLastModified(addresses.getLastModifiedDate());
assertNotNull(addresses.getAddress());
assertEquals(3, addresses.getAddress().size());
for (Address address : addresses.getAddress()) {
Utils.verifyLastModified(address.getLastModifiedDate());
assertThat(address.getPutCode(), anyOf(is(2L), is(3L), is(4L)));
assertThat(address.getCountry().getValue(), anyOf(is(Iso3166Country.CR), is(Iso3166Country.US)));
if (address.getPutCode() == 2L) {
assertEquals(Visibility.PUBLIC, address.getVisibility());
assertEquals("4444-4444-4444-4447", address.getSource().retrieveSourcePath());
} else if (address.getPutCode() == 3L) {
assertEquals(Visibility.LIMITED, address.getVisibility());
assertEquals("APP-5555555555555555", address.getSource().retrieveSourcePath());
} else if (address.getPutCode() == 4L) {
assertEquals(Visibility.PRIVATE, address.getVisibility());
assertEquals("APP-5555555555555555", address.getSource().retrieveSourcePath());
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Addresses in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_AddressesTest method testReadPublicScope_Address.
@Test
public void testReadPublicScope_Address() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
// Public works
Response r = serviceDelegator.viewAddresses(ORCID);
assertNotNull(r);
assertEquals(Addresses.class.getName(), r.getEntity().getClass().getName());
Addresses a = (Addresses) r.getEntity();
assertNotNull(a);
assertEquals("/0000-0000-0000-0003/address", a.getPath());
Utils.verifyLastModified(a.getLastModifiedDate());
assertEquals(3, a.getAddress().size());
boolean found9 = false, found10 = false, found11 = false;
for (Address address : a.getAddress()) {
if (address.getPutCode() == 9) {
found9 = true;
} else if (address.getPutCode() == 10) {
found10 = true;
} else if (address.getPutCode() == 11) {
found11 = true;
} else {
fail("Invalid put code " + address.getPutCode());
}
}
assertTrue(found9);
assertTrue(found10);
assertTrue(found11);
r = serviceDelegator.viewAddress(ORCID, 9L);
assertNotNull(r);
assertEquals(Address.class.getName(), r.getEntity().getClass().getName());
// Limited where am the source should work
serviceDelegator.viewAddress(ORCID, 10L);
try {
// Limited am not the source should fail
serviceDelegator.viewAddress(ORCID, 12L);
fail();
} catch (OrcidAccessControlException e) {
} catch (Exception e) {
fail();
}
// Private where am the source should work
serviceDelegator.viewAddress(ORCID, 11L);
try {
// Private am not the source should fail
serviceDelegator.viewAddress(ORCID, 13L);
fail();
} catch (OrcidAccessControlException e) {
} catch (Exception e) {
fail();
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Addresses in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_AddressesTest method testViewAddressesReadPublic.
@Test
public void testViewAddressesReadPublic() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
Response r = serviceDelegator.viewAddresses(ORCID);
Addresses element = (Addresses) r.getEntity();
assertNotNull(element);
assertEquals("/0000-0000-0000-0003/address", element.getPath());
Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
use of org.orcid.jaxb.model.v3.dev1.record.Addresses in project ORCID-Source by ORCID.
the class PersonDetailsManagerReadOnlyImpl method getPersonDetails.
@Override
public Person getPersonDetails(String orcid) {
long lastModifiedTime = getLastModified(orcid);
Person person = new Person();
person.setName(recordNameManager.getRecordName(orcid));
person.setBiography(biographyManager.getBiography(orcid));
Addresses addresses = addressManager.getAddresses(orcid);
if (addresses.getAddress() != null) {
Addresses filteredAddresses = new Addresses();
filteredAddresses.setAddress(new ArrayList<Address>(addresses.getAddress()));
person.setAddresses(filteredAddresses);
}
PersonExternalIdentifiers extIds = externalIdentifierManager.getExternalIdentifiers(orcid);
if (extIds.getExternalIdentifiers() != null) {
PersonExternalIdentifiers filteredExtIds = new PersonExternalIdentifiers();
filteredExtIds.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>(extIds.getExternalIdentifiers()));
person.setExternalIdentifiers(filteredExtIds);
}
Keywords keywords = profileKeywordManager.getKeywords(orcid);
if (keywords.getKeywords() != null) {
Keywords filteredKeywords = new Keywords();
filteredKeywords.setKeywords(new ArrayList<Keyword>(keywords.getKeywords()));
person.setKeywords(filteredKeywords);
}
OtherNames otherNames = otherNameManager.getOtherNames(orcid);
if (otherNames.getOtherNames() != null) {
OtherNames filteredOtherNames = new OtherNames();
filteredOtherNames.setOtherNames(new ArrayList<OtherName>(otherNames.getOtherNames()));
person.setOtherNames(filteredOtherNames);
}
ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(orcid);
if (rUrls.getResearcherUrls() != null) {
ResearcherUrls filteredRUrls = new ResearcherUrls();
filteredRUrls.setResearcherUrls(new ArrayList<ResearcherUrl>(rUrls.getResearcherUrls()));
person.setResearcherUrls(filteredRUrls);
}
Emails emails = emailManager.getEmails(orcid);
if (emails.getEmails() != null) {
Emails filteredEmails = new Emails();
filteredEmails.setEmails(new ArrayList<Email>(emails.getEmails()));
person.setEmails(filteredEmails);
}
return person;
}
use of org.orcid.jaxb.model.v3.dev1.record.Addresses in project ORCID-Source by ORCID.
the class ManageProfileController method getProfileCountryJson.
@RequestMapping(value = "/countryForm.json", method = RequestMethod.GET)
@ResponseBody
public AddressesForm getProfileCountryJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
Addresses addresses = addressManager.getAddresses(getCurrentUserOrcid());
AddressesForm form = AddressesForm.valueOf(addresses);
// Set country name
if (form != null && form.getAddresses() != null) {
Map<String, String> countries = retrieveIsoCountries();
for (AddressForm addressForm : form.getAddresses()) {
addressForm.setCountryName(countries.get(addressForm.getIso2Country().getValue().name()));
}
}
ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
// Set the default visibility
if (profile.getActivitiesVisibilityDefault() != null) {
form.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
}
// Return an empty country in case we dont have any
if (form.getAddresses() == null) {
form.setAddresses(new ArrayList<AddressForm>());
}
if (form.getAddresses().isEmpty()) {
AddressForm address = new AddressForm();
address.setDisplayIndex(1L);
address.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
form.getAddresses().add(address);
}
return form;
}
Aggregations