Search in sources :

Example 16 with Distinction

use of org.orcid.jaxb.model.v3.dev1.record.Distinction 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 17 with Distinction

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

the class AffiliationsManagerTest method testAddDistinctionToClaimedRecordPreserveUserDefaultVisibility.

@Test
public void testAddDistinctionToClaimedRecordPreserveUserDefaultVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Distinction element = getDistinction();
    element = affiliationsManager.createDistinctionAffiliation(claimedOrcid, element, true);
    element = affiliationsManager.getDistinctionAffiliation(claimedOrcid, element.getPutCode());
    assertNotNull(element);
    assertEquals(Visibility.LIMITED, element.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 18 with Distinction

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

the class AffiliationsManagerImpl method createItemList.

private List<Item> createItemList(OrgAffiliationRelationEntity orgAffiliationEntity) {
    Item item = new Item();
    item.setItemName(orgAffiliationEntity.getOrg().getName());
    ItemType itemType = null;
    switch(orgAffiliationEntity.getAffiliationType()) {
        case DISTINCTION:
            itemType = ItemType.DISTINCTION;
            break;
        case EDUCATION:
            itemType = ItemType.EDUCATION;
            break;
        case EMPLOYMENT:
            itemType = ItemType.EMPLOYMENT;
            break;
        case INVITED_POSITION:
            itemType = ItemType.INVITED_POSITION;
            break;
        case MEMBERSHIP:
            itemType = ItemType.MEMBERSHIP;
            break;
        case QUALIFICATION:
            itemType = ItemType.QUALIFICATION;
            break;
        case SERVICE:
            itemType = ItemType.SERVICE;
            break;
    }
    item.setItemType(itemType);
    item.setPutCode(String.valueOf(orgAffiliationEntity.getId()));
    return Arrays.asList(item);
}
Also used : Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) ItemType(org.orcid.jaxb.model.v3.dev1.notification.permission.ItemType)

Example 19 with Distinction

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

the class AffiliationsManagerImpl method updateAffiliation.

public Affiliation updateAffiliation(String orcid, Affiliation affiliation, boolean isApiRequest, AffiliationType type) {
    OrgAffiliationRelationEntity entity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, affiliation.getPutCode());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = entity.getSourceId();
    String existingClientSourceId = entity.getClientSourceId();
    org.orcid.jaxb.model.common_v2.Visibility originalVisibility = entity.getVisibility();
    orcidSecurityManager.checkSource(entity);
    activityValidator.validateAffiliation(affiliation, sourceEntity, false, isApiRequest, org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(originalVisibility.value()));
    if (isApiRequest) {
        checkAffiliationExternalIDsForDuplicates(orcid, affiliation, sourceEntity);
    }
    switch(type) {
        case DISTINCTION:
            jpaJaxbDistinctionAdapter.toOrgAffiliationRelationEntity((Distinction) affiliation, entity);
            break;
        case EDUCATION:
            jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity((Education) affiliation, entity);
            break;
        case EMPLOYMENT:
            jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity((Employment) affiliation, entity);
            break;
        case INVITED_POSITION:
            jpaJaxbInvitedPositionAdapter.toOrgAffiliationRelationEntity((InvitedPosition) affiliation, entity);
            break;
        case MEMBERSHIP:
            jpaJaxbMembershipAdapter.toOrgAffiliationRelationEntity((Membership) affiliation, entity);
            break;
        case QUALIFICATION:
            jpaJaxbQualificationAdapter.toOrgAffiliationRelationEntity((Qualification) affiliation, entity);
            break;
        case SERVICE:
            jpaJaxbServiceAdapter.toOrgAffiliationRelationEntity((Service) affiliation, entity);
            break;
    }
    entity.setVisibility(originalVisibility);
    // Be sure it doesn't overwrite the source
    entity.setSourceId(existingSourceId);
    entity.setClientSourceId(existingClientSourceId);
    // Updates the give organization with the latest organization from
    // database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(affiliation);
    entity.setOrg(updatedOrganization);
    entity.setAffiliationType(type);
    entity = orgAffiliationRelationDao.merge(entity);
    orgAffiliationRelationDao.flush();
    Affiliation result = null;
    switch(type) {
        case DISTINCTION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.DISTINCTION, createItemList(entity));
            result = jpaJaxbDistinctionAdapter.toDistinction(entity);
            break;
        case EDUCATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(entity));
            result = jpaJaxbEducationAdapter.toEducation(entity);
            break;
        case EMPLOYMENT:
            notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(entity));
            result = jpaJaxbEmploymentAdapter.toEmployment(entity);
            break;
        case INVITED_POSITION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.INVITED_POSITION, createItemList(entity));
            result = jpaJaxbInvitedPositionAdapter.toInvitedPosition(entity);
            break;
        case MEMBERSHIP:
            notificationManager.sendAmendEmail(orcid, AmendedSection.MEMBERSHIP, createItemList(entity));
            result = jpaJaxbMembershipAdapter.toMembership(entity);
            break;
        case QUALIFICATION:
            notificationManager.sendAmendEmail(orcid, AmendedSection.QUALIFICATION, createItemList(entity));
            result = jpaJaxbQualificationAdapter.toQualification(entity);
            break;
        case SERVICE:
            notificationManager.sendAmendEmail(orcid, AmendedSection.SERVICE, createItemList(entity));
            result = jpaJaxbServiceAdapter.toService(entity);
            break;
    }
    return result;
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Example 20 with Distinction

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

the class AffiliationsManagerReadOnlyImpl method getAffiliations.

@Override
public List<Affiliation> getAffiliations(String orcid) {
    List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
    List<Affiliation> result = new ArrayList<Affiliation>();
    if (affiliations != null) {
        for (OrgAffiliationRelationEntity affiliation : affiliations) {
            switch(affiliation.getAffiliationType()) {
                case DISTINCTION:
                    result.add(jpaJaxbDistinctionAdapter.toDistinction(affiliation));
                    break;
                case EDUCATION:
                    result.add(jpaJaxbEducationAdapter.toEducation(affiliation));
                    break;
                case EMPLOYMENT:
                    result.add(jpaJaxbEmploymentAdapter.toEmployment(affiliation));
                    break;
                case INVITED_POSITION:
                    result.add(jpaJaxbInvitedPositionAdapter.toInvitedPosition(affiliation));
                    break;
                case MEMBERSHIP:
                    result.add(jpaJaxbMembershipAdapter.toMembership(affiliation));
                    break;
                case QUALIFICATION:
                    result.add(jpaJaxbQualificationAdapter.toQualification(affiliation));
                    break;
                case SERVICE:
                    result.add(jpaJaxbServiceAdapter.toService(affiliation));
                    break;
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation)

Aggregations

Distinction (org.orcid.jaxb.model.v3.dev1.record.Distinction)41 Test (org.junit.Test)31 DBUnitTest (org.orcid.test.DBUnitTest)18 Response (javax.ws.rs.core.Response)17 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 Qualification (org.orcid.jaxb.model.v3.dev1.record.Qualification)10 Affiliation (org.orcid.jaxb.model.v3.dev1.record.Affiliation)8 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)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 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 Work (org.orcid.jaxb.model.v3.dev1.record.Work)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)3