Search in sources :

Example 31 with Employment

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

the class BlackBoxBase 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_v2.Education) Funding(org.orcid.jaxb.model.record_v2.Funding) Work(org.orcid.jaxb.model.record_v2.Work) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) IOException(java.io.IOException)

Example 32 with Employment

use of org.orcid.jaxb.model.record_v2.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)

Example 33 with Employment

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

the class MapperFacadeFactory method getEmploymentMapperFacade.

public MapperFacade getEmploymentMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Employment, OrgAffiliationRelationEntity> classMap = mapperFactory.classMap(Employment.class, OrgAffiliationRelationEntity.class);
    addV2CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.fieldBToA("org.name", "organization.name");
    classMap.fieldBToA("org.city", "organization.address.city");
    classMap.fieldBToA("org.region", "organization.address.region");
    classMap.fieldBToA("org.country", "organization.address.country");
    classMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    classMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    classMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    classMap.field("departmentName", "department");
    classMap.field("roleTitle", "title");
    classMap.register();
    ClassMapBuilder<EmploymentSummary, OrgAffiliationRelationEntity> employmentSummaryClassMap = mapperFactory.classMap(EmploymentSummary.class, OrgAffiliationRelationEntity.class);
    addV2CommonFields(employmentSummaryClassMap);
    registerSourceConverters(mapperFactory, employmentSummaryClassMap);
    employmentSummaryClassMap.fieldBToA("org.name", "organization.name");
    employmentSummaryClassMap.fieldBToA("org.city", "organization.address.city");
    employmentSummaryClassMap.fieldBToA("org.region", "organization.address.region");
    employmentSummaryClassMap.fieldBToA("org.country", "organization.address.country");
    employmentSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    employmentSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    employmentSummaryClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    employmentSummaryClassMap.field("departmentName", "department");
    employmentSummaryClassMap.field("roleTitle", "title");
    employmentSummaryClassMap.register();
    mapperFactory.classMap(FuzzyDate.class, StartDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
    mapperFactory.classMap(FuzzyDate.class, EndDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
    return mapperFactory.getMapperFacade();
}
Also used : Employment(org.orcid.jaxb.model.record_v2.Employment) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) EmploymentSummary(org.orcid.jaxb.model.record.summary_v2.EmploymentSummary) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)

Example 34 with Employment

use of org.orcid.jaxb.model.record_v2.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/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());
    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("employment:department-name", gotAfterUpdateEmployment.getDepartmentName());
    assertEquals("employment: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_v2.Employment) Test(org.junit.Test)

Example 35 with Employment

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

the class MemberV2ApiServiceDelegator_EmploymentsTest method testViewEmployment.

@Test
public void testViewEmployment() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewEmployment("4444-4444-4444-4446", 5L);
    assertNotNull(response);
    Employment employment = (Employment) response.getEntity();
    assertNotNull(employment);
    Utils.verifyLastModified(employment.getLastModifiedDate());
    assertEquals(Long.valueOf(5L), employment.getPutCode());
    assertEquals("/4444-4444-4444-4446/employment/5", employment.getPath());
    assertEquals("Employment Dept # 1", employment.getDepartmentName());
    assertEquals(Visibility.PRIVATE.value(), employment.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Employment(org.orcid.jaxb.model.record_v2.Employment) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)43 Employment (org.orcid.jaxb.model.record_v2.Employment)38 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 Response (javax.ws.rs.core.Response)14 DBUnitTest (org.orcid.test.DBUnitTest)14 Education (org.orcid.jaxb.model.record_v2.Education)10 OtherName (org.orcid.jaxb.model.record_v2.OtherName)9 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)9 Employment (org.orcid.jaxb.model.record_rc1.Employment)8 Funding (org.orcid.jaxb.model.record_v2.Funding)8 Work (org.orcid.jaxb.model.record_v2.Work)8 ArrayList (java.util.ArrayList)6 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)6 Address (org.orcid.jaxb.model.record_v2.Address)6 Keyword (org.orcid.jaxb.model.record_v2.Keyword)6 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)6 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)5 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)5 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)5 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)5