Search in sources :

Example 11 with Qualification

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

the class MemberV3Dev1Test method createViewUpdateAndDeleteQualification.

@Test
public void createViewUpdateAndDeleteQualification() throws JSONException, InterruptedException, URISyntaxException {
    Qualification qualification = (Qualification) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/qualification-3.0_dev1.xml", Qualification.class);
    qualification.setPutCode(null);
    qualification.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createQualificationXml(this.getUser1OrcidId(), qualification, 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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/qualification/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Qualification gotQualification = getResponse.getEntity(Qualification.class);
    assertEquals("department-name", gotQualification.getDepartmentName());
    assertEquals("role-title", gotQualification.getRoleTitle());
    // Save the original visibility
    Visibility originalVisibility = gotQualification.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotQualification.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotQualification);
    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
    gotQualification.setVisibility(originalVisibility);
    gotQualification.setDepartmentName("updated dept. name");
    gotQualification.setRoleTitle("updated role title");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotQualification);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Qualification gotAfterUpdateQualification = getAfterUpdateResponse.getEntity(Qualification.class);
    assertEquals("updated dept. name", gotAfterUpdateQualification.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateQualification.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteQualificationXml(this.getUser1OrcidId(), gotQualification.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Example 12 with Qualification

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

the class AffiliationForm method toAffiliation.

public Affiliation toAffiliation() {
    Affiliation affiliation = null;
    if (AffiliationType.DISTINCTION.value().equals(affiliationType.getValue())) {
        affiliation = new Distinction();
    } else if (AffiliationType.EDUCATION.value().equals(affiliationType.getValue())) {
        affiliation = new Education();
    } else if (AffiliationType.EMPLOYMENT.value().equals(affiliationType.getValue())) {
        affiliation = new Employment();
    } else if (AffiliationType.INVITED_POSITION.value().equals(affiliationType.getValue())) {
        affiliation = new InvitedPosition();
    } else if (AffiliationType.MEMBERSHIP.value().equals(affiliationType.getValue())) {
        affiliation = new Membership();
    } else if (AffiliationType.QUALIFICATION.value().equals(affiliationType.getValue())) {
        affiliation = new Qualification();
    } else if (AffiliationType.SERVICE.value().equals(affiliationType.getValue())) {
        affiliation = new Service();
    }
    if (!PojoUtil.isEmpty(putCode)) {
        affiliation.setPutCode(Long.valueOf(putCode.getValue()));
    }
    if (visibility != null && visibility.getVisibility() != null) {
        affiliation.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(visibility.getVisibility().value()));
    }
    Organization organization = new Organization();
    affiliation.setOrganization(organization);
    organization.setName(affiliationName.getValue());
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    organizationAddress.setCity(city.getValue());
    if (!PojoUtil.isEmpty(region)) {
        organizationAddress.setRegion(region.getValue());
    }
    if (!PojoUtil.isEmpty(disambiguatedAffiliationSourceId)) {
        organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
        organization.getDisambiguatedOrganization().setDisambiguatedOrganizationIdentifier(disambiguatedAffiliationSourceId.getValue());
        organization.getDisambiguatedOrganization().setDisambiguationSource(disambiguationSource.getValue());
    }
    organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
    if (!PojoUtil.isEmpty(roleTitle)) {
        affiliation.setRoleTitle(roleTitle.getValue());
    }
    if (!PojoUtil.isEmpty(departmentName)) {
        affiliation.setDepartmentName(departmentName.getValue());
    }
    if (!PojoUtil.isEmpty(startDate)) {
        affiliation.setStartDate(startDate.toV3FuzzyDate());
    }
    if (!PojoUtil.isEmpty(endDate)) {
        affiliation.setEndDate(endDate.toV3FuzzyDate());
    }
    if (!PojoUtil.isEmpty(url)) {
        affiliation.setUrl(new Url(url.getValue()));
    }
    if (affiliationExternalIdentifiers != null) {
        ExternalIDs externalIDs = new ExternalIDs();
        for (AffiliationExternalIdentifier affiliationExternalIdentifier : affiliationExternalIdentifiers) {
            externalIDs.getExternalIdentifier().add(affiliationExternalIdentifier.toExternalID());
        }
        affiliation.setExternalIDs(externalIDs);
    }
    return affiliation;
}
Also used : Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) Service(org.orcid.jaxb.model.v3.dev1.record.Service) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Example 13 with Qualification

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

the class AffiliationForm method valueOf.

public static AffiliationForm valueOf(Affiliation affiliation) {
    AffiliationForm form = new AffiliationForm();
    if (affiliation instanceof Distinction) {
        form.setAffiliationType(Text.valueOf(AffiliationType.DISTINCTION.value()));
    } else if (affiliation instanceof Education) {
        form.setAffiliationType(Text.valueOf(AffiliationType.EDUCATION.value()));
    } else if (affiliation instanceof Employment) {
        form.setAffiliationType(Text.valueOf(AffiliationType.EMPLOYMENT.value()));
    } else if (affiliation instanceof InvitedPosition) {
        form.setAffiliationType(Text.valueOf(AffiliationType.INVITED_POSITION.value()));
    } else if (affiliation instanceof Membership) {
        form.setAffiliationType(Text.valueOf(AffiliationType.MEMBERSHIP.value()));
    } else if (affiliation instanceof Qualification) {
        form.setAffiliationType(Text.valueOf(AffiliationType.QUALIFICATION.value()));
    } else if (affiliation instanceof Service) {
        form.setAffiliationType(Text.valueOf(AffiliationType.SERVICE.value()));
    }
    form.setPutCode(Text.valueOf(affiliation.getPutCode()));
    form.setVisibility(Visibility.valueOf(affiliation.getVisibility()));
    Organization organization = affiliation.getOrganization();
    form.setDateSortString(PojoUtil.createDateSortString(affiliation));
    form.setAffiliationName(Text.valueOf(organization.getName()));
    OrganizationAddress address = organization.getAddress();
    form.setCity(Text.valueOf(address.getCity()));
    if (organization.getDisambiguatedOrganization() != null) {
        if (organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier() != null) {
            form.setDisambiguatedAffiliationSourceId(Text.valueOf(organization.getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier()));
            form.setDisambiguationSource(Text.valueOf(organization.getDisambiguatedOrganization().getDisambiguationSource()));
            form.setOrgDisambiguatedId(Text.valueOf(String.valueOf(organization.getDisambiguatedOrganization().getId())));
        }
    }
    if (address.getRegion() != null) {
        form.setRegion(Text.valueOf(address.getRegion()));
    } else {
        form.setRegion(new Text());
    }
    if (address.getCountry() != null) {
        form.setCountry(Text.valueOf(address.getCountry().value()));
    } else {
        form.setCountry(new Text());
    }
    if (affiliation.getDepartmentName() != null) {
        form.setDepartmentName(Text.valueOf(affiliation.getDepartmentName()));
    } else {
        form.setDepartmentName(new Text());
    }
    if (affiliation.getRoleTitle() != null) {
        form.setRoleTitle(Text.valueOf(affiliation.getRoleTitle()));
    } else {
        form.setRoleTitle(new Text());
    }
    if (affiliation.getStartDate() != null) {
        form.setStartDate(Date.valueOf(affiliation.getStartDate()));
    }
    if (affiliation.getEndDate() != null) {
        form.setEndDate(Date.valueOf(affiliation.getEndDate()));
    }
    Source source = affiliation.getSource();
    if (source != null) {
        form.setSource(source.retrieveSourcePath());
        if (source.getSourceName() != null) {
            form.setSourceName(source.getSourceName().getContent());
        }
    }
    if (affiliation.getUrl() != null) {
        form.setUrl(Text.valueOf(affiliation.getUrl().getValue()));
    } else {
        form.setUrl(new Text());
    }
    if (affiliation.getExternalIDs() != null) {
        List<AffiliationExternalIdentifier> affiliationExternalIdentifiers = new ArrayList<>();
        for (ExternalID externalID : affiliation.getExternalIDs().getExternalIdentifier()) {
            affiliationExternalIdentifiers.add(AffiliationExternalIdentifier.valueOf(externalID));
        }
        form.setAffiliationExternalIdentifiers(affiliationExternalIdentifiers);
    }
    form.setCreatedDate(Date.valueOf(affiliation.getCreatedDate()));
    form.setLastModified(Date.valueOf(affiliation.getLastModifiedDate()));
    return form;
}
Also used : Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) ArrayList(java.util.ArrayList) Service(org.orcid.jaxb.model.v3.dev1.record.Service) Source(org.orcid.jaxb.model.v3.dev1.common.Source) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction)

Example 14 with Qualification

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

the class MapperFacadeFactory method getQualificationMapperFacade.

public MapperFacade getQualificationMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Qualification, OrgAffiliationRelationEntity> classMap = mapperFactory.classMap(Qualification.class, OrgAffiliationRelationEntity.class);
    ClassMapBuilder<QualificationSummary, OrgAffiliationRelationEntity> summaryClassMap = mapperFactory.classMap(QualificationSummary.class, OrgAffiliationRelationEntity.class);
    return generateMapperFacadeForAffiliation(mapperFactory, classMap, summaryClassMap);
}
Also used : Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) QualificationSummary(org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)

Example 15 with Qualification

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

the class AffiliationsManagerTest method testAddQualificationToUnclaimedRecordPreserveQualificationVisibility.

@Test
public void testAddQualificationToUnclaimedRecordPreserveQualificationVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Qualification element = getQualification();
    element = affiliationsManager.createQualificationAffiliation(unclaimedOrcid, element, true);
    element = affiliationsManager.getQualificationAffiliation(unclaimedOrcid, element.getPutCode());
    assertNotNull(element);
    assertEquals(Visibility.PUBLIC, element.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)40 Test (org.junit.Test)31 DBUnitTest (org.orcid.test.DBUnitTest)18 Response (javax.ws.rs.core.Response)17 Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)11 Education (org.orcid.jaxb.model.v3.dev1.record.Education)11 Membership (org.orcid.jaxb.model.v3.dev1.record.Membership)11 Service (org.orcid.jaxb.model.v3.dev1.record.Service)11 Employment (org.orcid.jaxb.model.v3.dev1.record.Employment)10 InvitedPosition (org.orcid.jaxb.model.v3.dev1.record.InvitedPosition)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)8 QualificationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary)7 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)5 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 Work (org.orcid.jaxb.model.v3.dev1.record.Work)4 Qualifications (org.orcid.jaxb.model.v3.dev1.record.summary.Qualifications)4