Search in sources :

Example 6 with OrgAffiliationRelationEntity

use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.

the class Jaxb2JpaAdapterImpl method setOrgAffiliationRelations.

private void setOrgAffiliationRelations(ProfileEntity profileEntity, Affiliations affiliations) {
    SortedSet<OrgAffiliationRelationEntity> existingOrgAffiliationEntities = profileEntity.getOrgAffiliationRelations();
    if (existingOrgAffiliationEntities == null) {
        existingOrgAffiliationEntities = new TreeSet<>();
    }
    Map<String, OrgAffiliationRelationEntity> existingOrgAffiliationsEntitiesMap = createOrgAffiliationEntitiesMap(existingOrgAffiliationEntities);
    SortedSet<OrgAffiliationRelationEntity> updatedOrgAffiliationEntities = new TreeSet<>();
    if (affiliations != null && !affiliations.getAffiliation().isEmpty()) {
        for (Affiliation affiliation : affiliations.getAffiliation()) {
            OrgAffiliationRelationEntity orgRelationEntity = getOrgAffiliationRelationEntity(affiliation, existingOrgAffiliationsEntitiesMap.get(affiliation.getPutCode()));
            orgRelationEntity.setProfile(profileEntity);
            updatedOrgAffiliationEntities.add(orgRelationEntity);
        }
    }
    Map<String, OrgAffiliationRelationEntity> updatedOrgAffiliationEntitiesMap = createOrgAffiliationEntitiesMap(updatedOrgAffiliationEntities);
    // Remove orphans
    for (Iterator<OrgAffiliationRelationEntity> iterator = existingOrgAffiliationEntities.iterator(); iterator.hasNext(); ) {
        OrgAffiliationRelationEntity existingEntity = iterator.next();
        if (!updatedOrgAffiliationEntitiesMap.containsKey(String.valueOf(existingEntity.getId()))) {
            iterator.remove();
        }
    }
    // Add new
    for (OrgAffiliationRelationEntity updatedEntity : updatedOrgAffiliationEntities) {
        if (updatedEntity.getId() == null) {
            existingOrgAffiliationEntities.add(updatedEntity);
        }
    }
    profileEntity.setOrgAffiliationRelations(existingOrgAffiliationEntities);
}
Also used : TreeSet(java.util.TreeSet) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 7 with OrgAffiliationRelationEntity

use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method persistAddedAffiliations.

private void persistAddedAffiliations(String orcid, List<Affiliation> updatedAffiliationsList) {
    ProfileEntity profileEntity = profileDao.find(orcid);
    for (Affiliation updatedAffiliation : updatedAffiliationsList) {
        OrgAffiliationRelationEntity orgAffiliationRelationEntity = jaxb2JpaAdapter.getNewOrgAffiliationRelationEntity(updatedAffiliation, profileEntity);
        orgAffiliationRelationDao.persist(orgAffiliationRelationEntity);
    }
    orcidProfileCacheManager.remove(orcid);
}
Also used : OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 8 with OrgAffiliationRelationEntity

use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method deprecateProfile.

/**
     * Deprecates a profile
     * 
     * @param deprecatedProfile
     *            The profile that want to be deprecated
     * @param primaryProfile
     *            The primary profile for the deprecated profile
     * @return true if the account was successfully deprecated, false otherwise
     */
@Override
@Transactional
public boolean deprecateProfile(String deprecatedOrcid, String primaryOrcid) {
    boolean wasDeprecated = profileDao.deprecateProfile(deprecatedOrcid, primaryOrcid);
    // If it was successfully deprecated
    if (wasDeprecated) {
        LOGGER.info("Account {} was deprecated to primary account: {}", deprecatedOrcid, primaryOrcid);
        ProfileEntity deprecated = profileDao.find(deprecatedOrcid);
        // Remove works
        workManager.removeAllWorks(deprecatedOrcid);
        // Remove funding
        if (deprecated.getProfileFunding() != null) {
            for (ProfileFundingEntity funding : deprecated.getProfileFunding()) {
                fundingManager.removeProfileFunding(funding.getProfile().getId(), funding.getId());
            }
        }
        // Remove affiliations
        if (deprecated.getOrgAffiliationRelations() != null) {
            for (OrgAffiliationRelationEntity affiliation : deprecated.getOrgAffiliationRelations()) {
                orgAffiliationRelationDao.removeOrgAffiliationRelation(affiliation.getProfile().getId(), affiliation.getId());
            }
        }
        // Remove external identifiers
        if (deprecated.getExternalIdentifiers() != null) {
            for (ExternalIdentifierEntity externalIdentifier : deprecated.getExternalIdentifiers()) {
                externalIdentifierManager.deleteExternalIdentifier(deprecated.getId(), externalIdentifier.getId(), false);
            }
        }
        // Remove researcher urls
        if (deprecated.getResearcherUrls() != null) {
            for (ResearcherUrlEntity rUrl : deprecated.getResearcherUrls()) {
                researcherUrlManager.deleteResearcherUrl(deprecatedOrcid, rUrl.getId(), false);
            }
        }
        // Remove other names
        if (deprecated.getOtherNames() != null) {
            for (OtherNameEntity otherName : deprecated.getOtherNames()) {
                otherNamesManager.deleteOtherName(deprecatedOrcid, otherName.getId(), false);
            }
        }
        // Remove keywords
        if (deprecated.getKeywords() != null) {
            for (ProfileKeywordEntity keyword : deprecated.getKeywords()) {
                profileKeywordManager.deleteKeyword(deprecatedOrcid, keyword.getId(), false);
            }
        }
        //Remove biography                        
        if (biographyManager.exists(deprecatedOrcid)) {
            Biography deprecatedBio = new Biography();
            deprecatedBio.setContent(null);
            deprecatedBio.setVisibility(Visibility.PRIVATE);
            biographyManager.updateBiography(deprecatedOrcid, deprecatedBio);
        }
        //Set the deactivated names
        if (recordNameManager.exists(deprecatedOrcid)) {
            Name name = new Name();
            name.setCreditName(new CreditName());
            name.setGivenNames(new GivenNames("Given Names Deactivated"));
            name.setFamilyName(new FamilyName("Family Name Deactivated"));
            name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
            name.setPath(deprecatedOrcid);
            recordNameManager.updateRecordName(deprecatedOrcid, name);
        }
        userConnectionDao.deleteByOrcid(deprecatedOrcid);
        // Move all emails to the primary email
        Set<EmailEntity> deprecatedAccountEmails = deprecated.getEmails();
        if (deprecatedAccountEmails != null) {
            // For each email in the deprecated profile                            
            for (EmailEntity email : deprecatedAccountEmails) {
                // Delete each email from the deprecated
                // profile
                LOGGER.info("About to move email {} from profile {} to profile {}", new Object[] { email.getId(), deprecatedOrcid, primaryOrcid });
                emailManager.moveEmailToOtherAccount(email.getId(), deprecatedOrcid, primaryOrcid);
            }
        }
        return true;
    }
    return false;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) CreditName(org.orcid.jaxb.model.record_v2.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) CreditName(org.orcid.jaxb.model.record_v2.CreditName) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) Name(org.orcid.jaxb.model.record_v2.Name) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Biography(org.orcid.jaxb.model.record_v2.Biography) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with OrgAffiliationRelationEntity

use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.

the class JpaJaxbEducationAdapterTest method fromOrgAffiliationRelationEntityToEducationSummary.

@Test
public void fromOrgAffiliationRelationEntityToEducationSummary() {
    OrgAffiliationRelationEntity entity = getEducationEntity();
    assertNotNull(entity);
    EducationSummary educationSummary = jpaJaxbEducationAdapter.toEducationSummary(entity);
    assertNotNull(educationSummary);
    assertEquals("education:department", educationSummary.getDepartmentName());
    assertEquals(Long.valueOf(123456), educationSummary.getPutCode());
    assertEquals("education:title", educationSummary.getRoleTitle());
    assertEquals("private", educationSummary.getVisibility().value());
    assertNotNull(educationSummary.getStartDate());
    assertEquals("2000", educationSummary.getStartDate().getYear().getValue());
    assertEquals("01", educationSummary.getStartDate().getMonth().getValue());
    assertEquals("01", educationSummary.getStartDate().getDay().getValue());
    assertEquals("2020", educationSummary.getEndDate().getYear().getValue());
    assertEquals("02", educationSummary.getEndDate().getMonth().getValue());
    assertEquals("02", educationSummary.getEndDate().getDay().getValue());
    assertNotNull(educationSummary.getSource());
    assertNotNull(educationSummary.getSource().retrieveSourcePath());
    assertEquals("APP-000000001", educationSummary.getSource().retrieveSourcePath());
}
Also used : EducationSummary(org.orcid.jaxb.model.record.summary_v2.EducationSummary) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Test(org.junit.Test)

Example 10 with OrgAffiliationRelationEntity

use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.

the class JpaJaxbEducationAdapterTest method getEducationEntity.

private OrgAffiliationRelationEntity getEducationEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
    result.setAffiliationType(AffiliationType.EDUCATION);
    result.setDepartment("education:department");
    result.setEndDate(new EndDateEntity(2020, 2, 2));
    result.setId(123456L);
    result.setOrg(orgEntity);
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setTitle("education:title");
    result.setVisibility(Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)28 Test (org.junit.Test)8 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 Education (org.orcid.jaxb.model.record_v2.Education)3 Employment (org.orcid.jaxb.model.record_v2.Employment)3 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)3 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)3 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)3 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)3 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)3 TreeSet (java.util.TreeSet)2 MapperFactory (ma.glasnost.orika.MapperFactory)2 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 Affiliation (org.orcid.jaxb.model.message.Affiliation)2 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)2