Search in sources :

Example 1 with Employment

use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method createEmployment.

@Override
public Response createEmployment(String orcid, Employment employment) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE, ScopePathType.AFFILIATIONS_UPDATE);
    clearSource(employment);
    Employment e = affiliationsManager.createEmploymentAffiliation(orcid, employment, true);
    sourceUtils.setSourceName(e);
    try {
        return Response.created(new URI(String.valueOf(e.getPutCode()))).build();
    } catch (URISyntaxException ex) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.createemployment_response.exception"), ex);
    }
}
Also used : Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with Employment

use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method updateEmployment.

@Override
public Response updateEmployment(String orcid, Long putCode, Employment employment) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_UPDATE);
    if (!putCode.equals(employment.getPutCode())) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("urlPutCode", String.valueOf(putCode));
        params.put("bodyPutCode", String.valueOf(employment.getPutCode()));
        throw new MismatchedPutCodeException(params);
    }
    clearSource(employment);
    Employment e = affiliationsManager.updateEmploymentAffiliation(orcid, employment, true);
    sourceUtils.setSourceName(e);
    return Response.ok(e).build();
}
Also used : HashMap(java.util.HashMap) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 3 with Employment

use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_EmploymentsTest method testUpdateEmploymentDuplicateExternalIDs.

@Test(expected = OrcidDuplicatedActivityException.class)
public void testUpdateEmploymentDuplicateExternalIDs() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    ExternalID e1 = new ExternalID();
    e1.setRelationship(Relationship.SELF);
    e1.setType("erm");
    e1.setUrl(new Url("https://orcid.org"));
    e1.setValue("err");
    ExternalID e2 = new ExternalID();
    e2.setRelationship(Relationship.SELF);
    e2.setType("err");
    e2.setUrl(new Url("http://bbc.co.uk"));
    e2.setValue("erm");
    ExternalIDs externalIDs = new ExternalIDs();
    externalIDs.getExternalIdentifier().add(e1);
    externalIDs.getExternalIdentifier().add(e2);
    Employment employment = (Employment) Utils.getAffiliation(AffiliationType.EMPLOYMENT);
    employment.setExternalIDs(externalIDs);
    Response response = serviceDelegator.createEmployment(ORCID, employment);
    assertNotNull(response);
    assertEquals(HttpStatus.SC_CREATED, response.getStatus());
    Map<?, ?> map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List<?> resultWithPutCode = (List<?>) map.get("Location");
    Long putCode1 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    Employment another = (Employment) Utils.getAffiliation(AffiliationType.EMPLOYMENT);
    response = serviceDelegator.createEmployment(ORCID, another);
    map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    resultWithPutCode = (List<?>) map.get("Location");
    Long putCode2 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    response = serviceDelegator.viewEmployment(ORCID, putCode2);
    another = (Employment) response.getEntity();
    another.setExternalIDs(externalIDs);
    try {
        serviceDelegator.updateEmployment(ORCID, putCode2, another);
    } finally {
        serviceDelegator.deleteAffiliation(ORCID, putCode1);
        serviceDelegator.deleteAffiliation(ORCID, putCode2);
    }
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) List(java.util.List) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with Employment

use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_EmploymentsTest method testAddEmploymentsDuplicateExternalIDs.

@Test(expected = OrcidDuplicatedActivityException.class)
public void testAddEmploymentsDuplicateExternalIDs() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    ExternalID e1 = new ExternalID();
    e1.setRelationship(Relationship.SELF);
    e1.setType("erm");
    e1.setUrl(new Url("https://orcid.org"));
    e1.setValue("err");
    ExternalID e2 = new ExternalID();
    e2.setRelationship(Relationship.SELF);
    e2.setType("err");
    e2.setUrl(new Url("http://bbc.co.uk"));
    e2.setValue("erm");
    ExternalIDs externalIDs = new ExternalIDs();
    externalIDs.getExternalIdentifier().add(e1);
    externalIDs.getExternalIdentifier().add(e2);
    Employment employment = (Employment) Utils.getAffiliation(AffiliationType.EMPLOYMENT);
    employment.setExternalIDs(externalIDs);
    Response response = serviceDelegator.createEmployment(ORCID, employment);
    assertNotNull(response);
    assertEquals(HttpStatus.SC_CREATED, 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)));
    try {
        Employment duplicate = (Employment) Utils.getAffiliation(AffiliationType.EMPLOYMENT);
        duplicate.setExternalIDs(externalIDs);
        serviceDelegator.createEmployment(ORCID, duplicate);
    } finally {
        serviceDelegator.deleteAffiliation(ORCID, putCode);
    }
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) List(java.util.List) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Employment

use of org.orcid.jaxb.model.v3.dev1.record.Employment in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_EmploymentsTest method testViewEmployment.

@Test
public void testViewEmployment() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewEmployment(ORCID, 19L);
    assertNotNull(response);
    Employment employment = (Employment) response.getEntity();
    assertNotNull(employment);
    Utils.verifyLastModified(employment.getLastModifiedDate());
    assertEquals(Long.valueOf(19L), employment.getPutCode());
    assertEquals("/0000-0000-0000-0003/employment/19", employment.getPath());
    assertEquals("PRIVATE Department", employment.getDepartmentName());
    assertEquals(Visibility.PRIVATE.value(), employment.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)61 Test (org.junit.Test)53 DBUnitTest (org.orcid.test.DBUnitTest)21 Response (javax.ws.rs.core.Response)20 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)18 Education (org.orcid.jaxb.model.v3.dev1.record.Education)13 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)11 Service (org.orcid.jaxb.model.v3.dev1.record.Service)11 FuzzyDate (org.orcid.jaxb.model.v3.dev1.common.FuzzyDate)10 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)10 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Day (org.orcid.jaxb.model.v3.dev1.common.Day)8 Month (org.orcid.jaxb.model.v3.dev1.common.Month)8 Year (org.orcid.jaxb.model.v3.dev1.common.Year)8 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)8 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)8 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)7 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6