Search in sources :

Example 31 with Employment

use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.

the class MemberV2Test method testUpdateEmploymentWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateEmploymentWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    Employment employment = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
    employment.setPutCode(null);
    employment.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(this.getUser1OrcidId(), employment, 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(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/employment/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Employment gotEmployment = getResponse.getEntity(Employment.class);
    assertEquals("affiliation:department-name", gotEmployment.getDepartmentName());
    assertEquals("affiliation:role-title", gotEmployment.getRoleTitle());
    gotEmployment.setDepartmentName("updated dept. name");
    gotEmployment.setRoleTitle("updated role title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotEmployment);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Employment gotAfterUpdateEmployment = getAfterUpdateResponse.getEntity(Employment.class);
    assertEquals("affiliation:department-name", gotAfterUpdateEmployment.getDepartmentName());
    assertEquals("affiliation:role-title", gotAfterUpdateEmployment.getRoleTitle());
    ClientResponse deleteResponse = memberV2ApiClient.deleteEmploymentXml(this.getUser1OrcidId(), gotEmployment.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Employment(org.orcid.jaxb.model.record_rc1.Employment) Test(org.junit.Test)

Example 32 with Employment

use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl method createEmployment.

@Override
public Response createEmployment(String orcid, Employment employment) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.AFFILIATIONS_CREATE);
    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.record_v2.Employment) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 33 with Employment

use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl method viewEmployment.

@Override
public Response viewEmployment(String orcid, Long putCode) {
    Employment e = affiliationsManagerReadOnly.getEmploymentAffiliation(orcid, putCode);
    orcidSecurityManager.checkAndFilter(orcid, e, ScopePathType.AFFILIATIONS_READ_LIMITED);
    ActivityUtils.setPathToActivity(e, orcid);
    sourceUtils.setSourceName(e);
    return Response.ok(e).build();
}
Also used : Employment(org.orcid.jaxb.model.record_v2.Employment)

Example 34 with Employment

use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.

the class AffiliationsManagerTest method testAddEmploymentToUnclaimedRecordPreserveEmploymentVisibility.

@Test
public void testAddEmploymentToUnclaimedRecordPreserveEmploymentVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Employment employment = getEmployment();
    employment = affiliationsManager.createEmploymentAffiliation(unclaimedOrcid, employment, true);
    employment = affiliationsManager.getEmploymentAffiliation(unclaimedOrcid, employment.getPutCode());
    assertNotNull(employment);
    assertEquals(Visibility.PUBLIC, employment.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Employment(org.orcid.jaxb.model.record_v2.Employment) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 35 with Employment

use of org.orcid.jaxb.model.record_rc3.Employment in project ORCID-Source by ORCID.

the class BlackBoxBaseRC3 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;
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Error reading notification from classpath", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Education(org.orcid.jaxb.model.record_rc3.Education) Funding(org.orcid.jaxb.model.record_rc3.Funding) Work(org.orcid.jaxb.model.record_rc3.Work) OtherName(org.orcid.jaxb.model.record_rc3.OtherName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ResearcherUrl(org.orcid.jaxb.model.record_rc3.ResearcherUrl) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)41 Employment (org.orcid.jaxb.model.record_v2.Employment)38 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 Response (javax.ws.rs.core.Response)13 DBUnitTest (org.orcid.test.DBUnitTest)13 Employment (org.orcid.jaxb.model.record_rc1.Employment)8 ArrayList (java.util.ArrayList)6 Education (org.orcid.jaxb.model.record_v2.Education)6 Funding (org.orcid.jaxb.model.record_v2.Funding)4 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)4 Work (org.orcid.jaxb.model.record_v2.Work)4 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)3 Address (org.orcid.jaxb.model.record_v2.Address)3 Keyword (org.orcid.jaxb.model.record_v2.Keyword)3 OtherName (org.orcid.jaxb.model.record_v2.OtherName)3 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)3 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)3 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2