use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class PublicV3ApiServiceDelegatorTest method testViewServices.
@Test
public void testViewServices() {
Response response = serviceDelegator.viewServices(ORCID);
assertNotNull(response);
Services services = (Services) response.getEntity();
assertNotNull(services);
assertEquals("/0000-0000-0000-0003/services", services.getPath());
assertNotNull(services.getLastModifiedDate());
assertNotNull(services.getLastModifiedDate().getValue());
assertEquals(1, services.getSummaries().size());
ServiceSummary service = services.getSummaries().get(0);
assertEquals(Long.valueOf(47), service.getPutCode());
assertNotNull(service.getLastModifiedDate());
assertNotNull(service.getLastModifiedDate().getValue());
assertEquals("/0000-0000-0000-0003/service/47", service.getPath());
assertEquals("PUBLIC Department", service.getDepartmentName());
assertEquals(Visibility.PUBLIC.value(), service.getVisibility().value());
assertEquals("APP-5555555555555555", service.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class PublicV3ApiServiceDelegatorTest method testViewService.
// Service
@Test
public void testViewService() {
Response response = serviceDelegator.viewService(ORCID, 47L);
assertNotNull(response);
Service service = (Service) response.getEntity();
assertNotNull(service);
assertNotNull(service.getLastModifiedDate());
assertNotNull(service.getLastModifiedDate().getValue());
assertEquals(Long.valueOf(47), service.getPutCode());
assertEquals("/0000-0000-0000-0003/service/47", service.getPath());
assertEquals("PUBLIC Department", service.getDepartmentName());
assertEquals(Visibility.PUBLIC.value(), service.getVisibility().value());
assertEquals("APP-5555555555555555", service.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class AffiliationsController method addAffiliation.
/**
* Adds a new affiliations
*
* @param affiliationForm
*/
private void addAffiliation(AffiliationForm affiliationForm) {
Affiliation affiliation = affiliationForm.toAffiliation();
if (affiliation instanceof Distinction) {
affiliation = affiliationsManager.createDistinctionAffiliation(getCurrentUserOrcid(), (Distinction) affiliation, false);
} else if (affiliation instanceof Education) {
affiliation = affiliationsManager.createEducationAffiliation(getCurrentUserOrcid(), (Education) affiliation, false);
} else if (affiliation instanceof Employment) {
affiliation = affiliationsManager.createEmploymentAffiliation(getCurrentUserOrcid(), (Employment) affiliation, false);
} else if (affiliation instanceof InvitedPosition) {
affiliation = affiliationsManager.createInvitedPositionAffiliation(getCurrentUserOrcid(), (InvitedPosition) affiliation, false);
} else if (affiliation instanceof Membership) {
affiliation = affiliationsManager.createMembershipAffiliation(getCurrentUserOrcid(), (Membership) affiliation, false);
} else if (affiliation instanceof Qualification) {
affiliation = affiliationsManager.createQualificationAffiliation(getCurrentUserOrcid(), (Qualification) affiliation, false);
} else if (affiliation instanceof Service) {
affiliation = affiliationsManager.createServiceAffiliation(getCurrentUserOrcid(), (Service) affiliation, false);
} else {
throw new IllegalArgumentException("Invalid affiliation type: " + affiliation.getClass().getName());
}
affiliationForm.setPutCode(Text.valueOf(affiliation.getPutCode()));
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class BlackBoxBaseV3_0_dev1 method unmarshallFromPath.
public Object unmarshallFromPath(String path, Class<?> type) {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type);
Object result = null;
if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Education.class.equals(type)) {
result = (Education) obj;
} else if (Employment.class.equals(type)) {
result = (Employment) obj;
} else if (Funding.class.equals(type)) {
result = (Funding) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Work.class.equals(type)) {
result = (Work) obj;
} else if (PeerReview.class.equals(type)) {
result = (PeerReview) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (Distinction.class.equals(type)) {
result = (Distinction) obj;
} else if (InvitedPosition.class.equals(type)) {
result = (InvitedPosition) obj;
} else if (Membership.class.equals(type)) {
result = (Membership) obj;
} else if (Qualification.class.equals(type)) {
result = (Qualification) obj;
} else if (Service.class.equals(type)) {
result = (Service) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Service in project ORCID-Source by ORCID.
the class MemberV3Dev1Test method createViewUpdateAndDeleteService.
@Test
public void createViewUpdateAndDeleteService() throws JSONException, InterruptedException, URISyntaxException {
Service service = (Service) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/service-3.0_dev1.xml", Service.class);
service.setPutCode(null);
service.setVisibility(Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClientImpl.createServiceXml(this.getUser1OrcidId(), service, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/service/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Service gotService = getResponse.getEntity(Service.class);
assertEquals("department-name", gotService.getDepartmentName());
assertEquals("role-title", gotService.getRoleTitle());
// Save the original visibility
Visibility originalVisibility = gotService.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
// Verify you cant update the visibility
gotService.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotService);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
// Set the visibility again to the initial one
gotService.setVisibility(originalVisibility);
gotService.setDepartmentName("updated dept. name");
gotService.setRoleTitle("updated role title");
putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotService);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Service gotAfterUpdateService = getAfterUpdateResponse.getEntity(Service.class);
assertEquals("updated dept. name", gotAfterUpdateService.getDepartmentName());
assertEquals("updated role title", gotAfterUpdateService.getRoleTitle());
ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteServiceXml(this.getUser1OrcidId(), gotService.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations