Search in sources :

Example 51 with Education

use of org.orcid.jaxb.model.record_rc2.Education in project ORCID-Source by ORCID.

the class MemberV2Test method createViewUpdateAndDeleteEducation.

@Test
public void createViewUpdateAndDeleteEducation() throws JSONException, InterruptedException, URISyntaxException {
    Education education = (Education) unmarshallFromPath("/record_2.0_rc4/samples/education-2.0_rc4.xml", Education.class);
    education.setPutCode(null);
    education.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createEducationXml(this.getUser1OrcidId(), education, 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_rc4/" + this.getUser1OrcidId() + "/education/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Education gotEducation = getResponse.getEntity(Education.class);
    assertEquals("education:department-name", gotEducation.getDepartmentName());
    assertEquals("education:role-title", gotEducation.getRoleTitle());
    //Save the original visibility
    Visibility originalVisibility = gotEducation.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotEducation.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
    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
    gotEducation.setVisibility(originalVisibility);
    gotEducation.setDepartmentName("updated dept. name");
    gotEducation.setRoleTitle("updated role title");
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotEducation);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Education gotAfterUpdateEducation = getAfterUpdateResponse.getEntity(Education.class);
    assertEquals("updated dept. name", gotAfterUpdateEducation.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateEducation.getRoleTitle());
    ClientResponse deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), gotEducation.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_rc4.OrcidError) Education(org.orcid.jaxb.model.record_rc4.Education) Visibility(org.orcid.jaxb.model.common_rc4.Visibility) Test(org.junit.Test)

Example 52 with Education

use of org.orcid.jaxb.model.record_rc2.Education in project ORCID-Source by ORCID.

the class BlackBoxBaseV2Release 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 53 with Education

use of org.orcid.jaxb.model.record_rc2.Education in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method getEducation.

private Education getEducation(String userOrcid) {
    Education education = new Education();
    education.setOrganization(getOrganization());
    education = affiliationsManager.createEducationAffiliation(userOrcid, education, true);
    return affiliationsManager.getEducationAffiliation(userOrcid, education.getPutCode());
}
Also used : Education(org.orcid.jaxb.model.record_v2.Education)

Example 54 with Education

use of org.orcid.jaxb.model.record_rc2.Education in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method getAffiliationWithPutCode.

private Education getAffiliationWithPutCode(String userOrcid) {
    Education education = new Education();
    education.setOrganization(getOrganization());
    education.setPutCode(Long.valueOf(111));
    education = affiliationsManager.createEducationAffiliation(userOrcid, education, true);
    return affiliationsManager.getEducationAffiliation(userOrcid, education.getPutCode());
}
Also used : Education(org.orcid.jaxb.model.record_v2.Education)

Example 55 with Education

use of org.orcid.jaxb.model.record_rc2.Education in project ORCID-Source by ORCID.

the class JpaJaxbEducationAdapterTest method fromOrgAffiliationRelationEntityToEducation.

@Test
public void fromOrgAffiliationRelationEntityToEducation() {
    OrgAffiliationRelationEntity entity = getEducationEntity();
    assertNotNull(entity);
    Education education = jpaJaxbEducationAdapter.toEducation(entity);
    assertNotNull(education);
    assertEquals("education:department", education.getDepartmentName());
    assertEquals(Long.valueOf(123456), education.getPutCode());
    assertEquals("education:title", education.getRoleTitle());
    assertEquals("private", education.getVisibility().value());
    assertNotNull(education.getStartDate());
    assertEquals("2000", education.getStartDate().getYear().getValue());
    assertEquals("01", education.getStartDate().getMonth().getValue());
    assertEquals("01", education.getStartDate().getDay().getValue());
    assertEquals("2020", education.getEndDate().getYear().getValue());
    assertEquals("02", education.getEndDate().getMonth().getValue());
    assertEquals("02", education.getEndDate().getDay().getValue());
    assertNotNull(education.getOrganization());
    assertEquals("org:name", education.getOrganization().getName());
    assertNotNull(education.getOrganization().getAddress());
    assertEquals("org:city", education.getOrganization().getAddress().getCity());
    assertEquals("org:region", education.getOrganization().getAddress().getRegion());
    assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.US, education.getOrganization().getAddress().getCountry());
    assertNotNull(education.getSource());
    assertNotNull(education.getSource().retrieveSourcePath());
    assertEquals("APP-000000001", education.getSource().retrieveSourcePath());
}
Also used : Education(org.orcid.jaxb.model.record_v2.Education) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Test(org.junit.Test)

Aggregations

Education (org.orcid.jaxb.model.record_v2.Education)45 Test (org.junit.Test)42 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 Response (javax.ws.rs.core.Response)13 DBUnitTest (org.orcid.test.DBUnitTest)13 Funding (org.orcid.jaxb.model.record_v2.Funding)8 Work (org.orcid.jaxb.model.record_v2.Work)8 Education (org.orcid.jaxb.model.record_rc1.Education)7 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 ArrayList (java.util.ArrayList)6 Employment (org.orcid.jaxb.model.record_v2.Employment)6 OtherName (org.orcid.jaxb.model.record_v2.OtherName)5 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)5 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)4 Education (org.orcid.jaxb.model.record_rc2.Education)4 Education (org.orcid.jaxb.model.record_rc3.Education)4 Education (org.orcid.jaxb.model.record_rc4.Education)4 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)4