Search in sources :

Example 11 with Service

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());
}
Also used : Response(javax.ws.rs.core.Response) Services(org.orcid.jaxb.model.v3.dev1.record.summary.Services) ServiceSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with Service

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());
}
Also used : Response(javax.ws.rs.core.Response) Service(org.orcid.jaxb.model.v3.dev1.record.Service) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with Service

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()));
}
Also used : Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Service(org.orcid.jaxb.model.v3.dev1.record.Service) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Example 14 with Service

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Service(org.orcid.jaxb.model.v3.dev1.record.Service) T2OAuthAPIService(org.orcid.integration.blackbox.api.v12.T2OAuthAPIService) IOException(java.io.IOException) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction)

Example 15 with Service

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) Service(org.orcid.jaxb.model.v3.dev1.record.Service) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Aggregations

Service (org.orcid.jaxb.model.v3.dev1.record.Service)41 Test (org.junit.Test)31 DBUnitTest (org.orcid.test.DBUnitTest)18 Response (javax.ws.rs.core.Response)17 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Education (org.orcid.jaxb.model.v3.dev1.record.Education)11 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)11 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)10 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)10 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)8 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)7 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 Work (org.orcid.jaxb.model.v3.dev1.record.Work)4 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)4 Services (org.orcid.jaxb.model.v3.dev1.record.summary.Services)4