use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegatorImpl method viewExternalIdentifiers.
@Override
public Response viewExternalIdentifiers(String orcid) {
PersonExternalIdentifiers extIds = externalIdentifierManagerReadOnly.getExternalIdentifiers(orcid);
// Lets copy the list so we don't modify the cached collection
if (extIds.getExternalIdentifiers() != null) {
List<PersonExternalIdentifier> filteredList = new ArrayList<PersonExternalIdentifier>(extIds.getExternalIdentifiers());
extIds = new PersonExternalIdentifiers();
extIds.setExternalIdentifiers(filteredList);
}
orcidSecurityManager.checkAndFilter(orcid, extIds.getExternalIdentifiers(), ScopePathType.ORCID_BIO_READ_LIMITED);
ElementUtils.setPathToExternalIdentifiers(extIds, orcid);
Api3_0_Dev1LastModifiedDatesHelper.calculateLastModified(extIds);
sourceUtils.setSourceName(extIds);
return Response.ok(extIds).build();
}
use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testViewPublicExternalIdentifier.
@Test
public void testViewPublicExternalIdentifier() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED);
Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 2L);
assertNotNull(response);
PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
assertNotNull(extId);
assertEquals("/4444-4444-4444-4442/external-identifiers/2", extId.getPath());
Utils.verifyLastModified(extId.getLastModifiedDate());
assertEquals("Facebook", extId.getType());
assertEquals(Long.valueOf(2), extId.getPutCode());
assertEquals("abc123", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://www.facebook.com/abc123", extId.getUrl().getValue());
assertEquals(Visibility.PUBLIC, extId.getVisibility());
assertNotNull(extId.getSource());
assertEquals("APP-5555555555555555", extId.getSource().retrieveSourcePath());
assertNotNull(extId.getCreatedDate());
Utils.verifyLastModified(extId.getLastModifiedDate());
}
use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testAddExternalIdentifier.
@Test
public void testAddExternalIdentifier() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
Response response = serviceDelegator.viewExternalIdentifiers("4444-4444-4444-4443");
assertNotNull(response);
PersonExternalIdentifiers extIds = (PersonExternalIdentifiers) response.getEntity();
assertNotNull(extIds);
assertNotNull(extIds.getExternalIdentifiers());
assertEquals(1, extIds.getExternalIdentifiers().size());
assertEquals(Long.valueOf(1), extIds.getExternalIdentifiers().get(0).getPutCode());
assertNotNull(extIds.getExternalIdentifiers().get(0).getUrl());
assertEquals("http://www.facebook.com/d3clan", extIds.getExternalIdentifiers().get(0).getUrl().getValue());
assertEquals("d3clan", extIds.getExternalIdentifiers().get(0).getValue());
assertEquals(Visibility.PUBLIC, extIds.getExternalIdentifiers().get(0).getVisibility());
response = serviceDelegator.createExternalIdentifier("4444-4444-4444-4443", Utils.getPersonExternalIdentifier());
assertNotNull(response);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Map<?, ?> map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List<?> resultWithPutCode = (List<?>) map.get("Location");
Long putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
response = serviceDelegator.viewExternalIdentifiers("4444-4444-4444-4443");
assertNotNull(response);
extIds = (PersonExternalIdentifiers) response.getEntity();
assertNotNull(extIds);
Utils.verifyLastModified(extIds.getLastModifiedDate());
assertNotNull(extIds.getExternalIdentifiers());
assertEquals(2, extIds.getExternalIdentifiers().size());
for (PersonExternalIdentifier extId : extIds.getExternalIdentifiers()) {
Utils.verifyLastModified(extId.getLastModifiedDate());
assertNotNull(extId.getUrl());
if (extId.getPutCode() != 1L) {
assertEquals(Visibility.PUBLIC, extId.getVisibility());
assertEquals("new-common-name", extId.getType());
assertEquals("new-reference", extId.getValue());
assertEquals("http://newUrl.com", extId.getUrl().getValue());
assertEquals(putCode, extId.getPutCode());
} else {
assertEquals(Visibility.PUBLIC, extId.getVisibility());
assertEquals("Facebook", extId.getType());
assertEquals("d3clan", extId.getValue());
assertEquals("http://www.facebook.com/d3clan", extId.getUrl().getValue());
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testUpdateExternalIdentifier.
@Test
public void testUpdateExternalIdentifier() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 2L);
assertNotNull(response);
PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
assertNotNull(extId);
Utils.verifyLastModified(extId.getLastModifiedDate());
LastModifiedDate before = extId.getLastModifiedDate();
assertEquals("Facebook", extId.getType());
assertEquals("abc123", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://www.facebook.com/abc123", extId.getUrl().getValue());
extId.setType("updated-common-name");
extId.setValue("updated-reference");
extId.setUrl(new Url("http://updatedUrl.com"));
response = serviceDelegator.updateExternalIdentifier("4444-4444-4444-4442", 2L, extId);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 2L);
assertNotNull(response);
PersonExternalIdentifier updatedExtId = (PersonExternalIdentifier) response.getEntity();
assertNotNull(updatedExtId);
Utils.verifyLastModified(updatedExtId.getLastModifiedDate());
assertTrue(updatedExtId.getLastModifiedDate().after(before));
assertEquals("updated-common-name", updatedExtId.getType());
assertEquals("updated-reference", updatedExtId.getValue());
assertNotNull(updatedExtId.getUrl());
assertEquals("http://updatedUrl.com", updatedExtId.getUrl().getValue());
// Revert changes so other tests still works
extId.setType("Facebook");
extId.setValue("abc123");
extId.setUrl(new Url("http://www.facebook.com/abc123"));
response = serviceDelegator.updateExternalIdentifier("4444-4444-4444-4442", 2L, extId);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testDeleteExternalIdentifierYouAreNotTheSourceOf.
@Test(expected = WrongSourceException.class)
public void testDeleteExternalIdentifierYouAreNotTheSourceOf() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 3L);
assertNotNull(response);
PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
assertNotNull(extId);
assertEquals("Facebook", extId.getType());
assertEquals("abc456", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://www.facebook.com/abc456", extId.getUrl().getValue());
serviceDelegator.deleteExternalIdentifier("4444-4444-4444-4442", 3L);
fail();
}
Aggregations