use of org.orcid.jaxb.model.record_v2.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 {
long lastModifiedTime = profileEntityManager.getLastModified(getCurrentUserOrcid());
Addresses addresses = addressManager.getAddresses(getCurrentUserOrcid(), lastModifiedTime);
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;
}
use of org.orcid.jaxb.model.record_v2.Addresses in project ORCID-Source by ORCID.
the class AddressManagerTest method getPublicTest.
@Test
public void getPublicTest() {
String orcid = "0000-0000-0000-0003";
Addresses elements = addressManager.getPublicAddresses(orcid, System.currentTimeMillis());
assertNotNull(elements);
assertNotNull(elements.getAddress());
assertEquals(1, elements.getAddress().size());
assertEquals(Long.valueOf(9), elements.getAddress().get(0).getPutCode());
}
use of org.orcid.jaxb.model.record_v2.Addresses in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method testUnmarshallAddress.
@Test
public void testUnmarshallAddress() throws SAXException, URISyntaxException {
Addresses addresses = (Addresses) unmarshallFromPath("/record_2.0_rc2/samples/addresses-2.0_rc2.xml", Addresses.class, "/record_2.0_rc2/address-2.0_rc2.xsd");
assertNotNull(addresses);
assertNotNull(addresses.getAddress());
assertEquals(2, addresses.getAddress().size());
for (Address address : addresses.getAddress()) {
assertNotNull(address.getPutCode());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getCountry());
if (address.getPutCode().equals(new Long(1))) {
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertEquals(Visibility.PUBLIC, address.getVisibility());
} else {
assertEquals(Iso3166Country.CR, address.getCountry().getValue());
assertEquals(Visibility.LIMITED, address.getVisibility());
}
}
Address address = (Address) unmarshallFromPath("/record_2.0_rc2/samples/address-2.0_rc2.xml", Address.class);
assertNotNull(address);
assertNotNull(address.getPutCode());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getCountry());
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertEquals(Visibility.PUBLIC, address.getVisibility());
}
use of org.orcid.jaxb.model.record_v2.Addresses in project ORCID-Source by ORCID.
the class ValidateV2_1SamplesTest method testUnmarshallAddress.
@Test
public void testUnmarshallAddress() throws SAXException, URISyntaxException {
Addresses addresses = (Addresses) unmarshallFromPath("/record_2.1/samples/read_samples/addresses-2.1.xml", Addresses.class, "/record_2.1/address-2.1.xsd");
assertNotNull(addresses);
assertNotNull(addresses.getAddress());
assertEquals(2, addresses.getAddress().size());
for (Address address : addresses.getAddress()) {
validateSourceInHttps(address.getSource());
assertNotNull(address.getPutCode());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getCountry());
if (address.getPutCode().equals(new Long(1))) {
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertEquals(Visibility.PUBLIC, address.getVisibility());
} else {
assertEquals(Iso3166Country.CR, address.getCountry().getValue());
assertEquals(Visibility.LIMITED, address.getVisibility());
}
}
Address address = (Address) unmarshallFromPath("/record_2.1/samples/read_samples/address-2.1.xml", Address.class);
assertNotNull(address);
assertNotNull(address.getPutCode());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getCountry());
validateSourceInHttps(address.getSource());
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertEquals(Visibility.PUBLIC, address.getVisibility());
}
use of org.orcid.jaxb.model.record_v2.Addresses in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewAddresses.
@Override
public Response viewAddresses(String orcid) {
Addresses addresses = addressManagerReadOnly.getAddresses(orcid, getLastModifiedTime(orcid));
// Lets copy the list so we don't modify the cached collection
if (addresses.getAddress() != null) {
List<Address> filteredAddresses = new ArrayList<Address>(addresses.getAddress());
addresses = new Addresses();
addresses.setAddress(filteredAddresses);
}
orcidSecurityManager.checkAndFilter(orcid, addresses.getAddress(), ScopePathType.ORCID_BIO_READ_LIMITED);
ElementUtils.setPathToAddresses(addresses, orcid);
// Set the latest last modified
Api2_0_LastModifiedDatesHelper.calculateLastModified(addresses);
sourceUtils.setSourceName(addresses);
return Response.ok(addresses).build();
}
Aggregations