Search in sources :

Example 26 with Employment

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

the class AffiliationsManagerTest method testAddEmploymentToClaimedRecordPreserveUserDefaultVisibility.

@Test
public void testAddEmploymentToClaimedRecordPreserveUserDefaultVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Employment employment = getEmployment();
    employment = affiliationsManager.createEmploymentAffiliation(claimedOrcid, employment, true);
    employment = affiliationsManager.getEmploymentAffiliation(claimedOrcid, employment.getPutCode());
    assertNotNull(employment);
    assertEquals(Visibility.LIMITED, 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 27 with Employment

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

the class AffiliationsManagerTest method getEmployment.

private Employment getEmployment() {
    Employment employment = new Employment();
    Organization org = new Organization();
    org.setName("org-name");
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("city");
    address.setCountry(Iso3166Country.US);
    org.setAddress(address);
    employment.setOrganization(org);
    employment.setStartDate(new FuzzyDate(new Year(2016), new Month(3), new Day(29)));
    employment.setVisibility(Visibility.PUBLIC);
    return employment;
}
Also used : Month(org.orcid.jaxb.model.common_v2.Month) Organization(org.orcid.jaxb.model.common_v2.Organization) Year(org.orcid.jaxb.model.common_v2.Year) Employment(org.orcid.jaxb.model.record_v2.Employment) OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) Day(org.orcid.jaxb.model.common_v2.Day)

Example 28 with Employment

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

the class ActivityValidatorTest method validateEmployment_invalidPutCodeTest.

@Test(expected = InvalidPutCodeException.class)
public void validateEmployment_invalidPutCodeTest() {
    Employment employment = getEmployment();
    employment.setPutCode(1L);
    activityValidator.validateEmployment(employment, null, true, true, Visibility.PUBLIC);
}
Also used : Employment(org.orcid.jaxb.model.record_v2.Employment) Test(org.junit.Test)

Example 29 with Employment

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

the class BlackBoxBaseRC1 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 (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 (Work.class.equals(type)) {
            result = (Work) obj;
        } else if (PeerReview.class.equals(type)) {
            result = (PeerReview) obj;
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Error reading notification from classpath", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Employment(org.orcid.jaxb.model.record_rc1.Employment) Work(org.orcid.jaxb.model.record_rc1.Work) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException)

Example 30 with Employment

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

the class MemberV2Test method createViewUpdateAndDeleteEmployment.

@Test
public void createViewUpdateAndDeleteEmployment() throws JSONException, InterruptedException, URISyntaxException {
    Employment employment = (Employment) unmarshallFromPath("/record_2.0/samples/read_samples/employment-2.0.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/" + 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("employment:department-name", gotEmployment.getDepartmentName());
    assertEquals("employment:role-title", gotEmployment.getRoleTitle());
    //Save the original visibility
    Visibility originalVisibility = gotEmployment.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotEmployment.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
    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
    gotEmployment.setVisibility(originalVisibility);
    gotEmployment.setDepartmentName("updated dept. name");
    gotEmployment.setRoleTitle("updated role title");
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEmployment);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Employment gotAfterUpdateEmployment = getAfterUpdateResponse.getEntity(Employment.class);
    assertEquals("updated dept. name", gotAfterUpdateEmployment.getDepartmentName());
    assertEquals("updated 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) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) Employment(org.orcid.jaxb.model.record_v2.Employment) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Test(org.junit.Test)

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 Day (org.orcid.jaxb.model.common_v2.Day)3 Month (org.orcid.jaxb.model.common_v2.Month)3 Year (org.orcid.jaxb.model.common_v2.Year)3 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