Search in sources :

Example 1 with GivenNames

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

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

the class RecordNameManagerTest method testFailOnCreatingOnARecordThatAlreadyHaveRecordName.

@Test(expected = IllegalArgumentException.class)
public void testFailOnCreatingOnARecordThatAlreadyHaveRecordName() {
    Name name = new Name();
    long time = System.currentTimeMillis();
    name.setCreditName(new CreditName("Credit Name " + time));
    name.setFamilyName(new FamilyName("Family Name " + time));
    name.setGivenNames(new GivenNames("Given Names " + time));
    name.setVisibility(Visibility.PRIVATE);
    String orcid = "0000-0000-0000-0001";
    recordNameManager.createRecordName(orcid, name);
    fail();
}
Also used : FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) CreditName(org.orcid.jaxb.model.common_v2.CreditName) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 3 with GivenNames

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

the class OrcidSecurityManagerTestBase method createName.

protected Name createName(Visibility v) {
    Name name = new Name();
    name.setVisibility(v);
    name.setCreditName(new CreditName("Credit Name"));
    name.setFamilyName(new FamilyName("Family Name"));
    name.setGivenNames(new GivenNames("Given Names"));
    return name;
}
Also used : FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) CreditName(org.orcid.jaxb.model.common_v2.CreditName) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Name(org.orcid.jaxb.model.record_v2.Name)

Example 4 with GivenNames

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

the class ProfileEntityManagerImpl method clearRecord.

/**
 * Clears all record info but the email addresses, that stay unmodified
 */
private void clearRecord(String orcid, Boolean disableTokens) {
    // Remove works
    workManager.removeAllWorks(orcid);
    // Remove funding
    fundingManager.removeAllFunding(orcid);
    // Remove affiliations
    affiliationsManager.removeAllAffiliations(orcid);
    // Remove peer reviews
    peerReviewManager.removeAllPeerReviews(orcid);
    // Remove addresses
    addressManager.removeAllAddress(orcid);
    // Remove external identifiers
    externalIdentifierManager.removeAllExternalIdentifiers(orcid);
    // Remove researcher urls
    researcherUrlManager.removeAllResearcherUrls(orcid);
    // Remove other names
    otherNamesManager.removeAllOtherNames(orcid);
    // Remove keywords
    profileKeywordManager.removeAllKeywords(orcid);
    // Remove biography
    if (biographyManager.exists(orcid)) {
        Biography deprecatedBio = new Biography();
        deprecatedBio.setContent(null);
        deprecatedBio.setVisibility(Visibility.PRIVATE);
        biographyManager.updateBiography(orcid, deprecatedBio);
    }
    // Set the deactivated names
    if (recordNameManager.exists(orcid)) {
        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.PUBLIC);
        name.setPath(orcid);
        recordNameManager.updateRecordName(orcid, name);
    }
    // 
    userConnectionDao.deleteByOrcid(orcid);
    if (disableTokens) {
        // Disable any token that belongs to this record
        orcidOauth2TokenDetailService.disableAccessTokenByUserOrcid(orcid, RevokeReason.RECORD_DEACTIVATED);
    }
    // Change default visibility to private
    profileDao.updateDefaultVisibility(orcid, Visibility.PRIVATE);
}
Also used : FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Biography(org.orcid.jaxb.model.record_v2.Biography) CreditName(org.orcid.jaxb.model.record_v2.CreditName) CreditName(org.orcid.jaxb.model.record_v2.CreditName) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) Name(org.orcid.jaxb.model.record_v2.Name)

Example 5 with GivenNames

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

the class JpaJaxbNameAdapterTest method fromNameToRecordNameEntityTest.

@Test
public void fromNameToRecordNameEntityTest() throws JAXBException {
    Name name = new Name();
    name.setCreditName(new CreditName("Credit Name"));
    name.setFamilyName(new FamilyName("Family Name"));
    name.setGivenNames(new GivenNames("Given Names"));
    name.setPath("0000-0000-0000-0000");
    name.setVisibility(Visibility.PUBLIC);
    name.setSource(new Source("0000-0000-0000-0000"));
    RecordNameEntity entity = adapter.toRecordNameEntity(name);
    assertNotNull(entity);
    assertEquals("Credit Name", entity.getCreditName());
    assertEquals("Family Name", entity.getFamilyName());
    assertEquals("Given Names", entity.getGivenNames());
    assertEquals(Visibility.PUBLIC, entity.getVisibility());
    assertNotNull(entity.getProfile());
    assertEquals("0000-0000-0000-0000", entity.getProfile().getId());
}
Also used : FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) CreditName(org.orcid.jaxb.model.common_v2.CreditName) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Source(org.orcid.jaxb.model.common_v2.Source) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Aggregations

Name (org.orcid.jaxb.model.record_v2.Name)9 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)8 GivenNames (org.orcid.jaxb.model.record_v2.GivenNames)8 CreditName (org.orcid.jaxb.model.common_v2.CreditName)6 Test (org.junit.Test)3 Biography (org.orcid.jaxb.model.record_v2.Biography)3 OtherName (org.orcid.jaxb.model.record_v2.OtherName)3 BaseTest (org.orcid.core.BaseTest)2 CreditName (org.orcid.jaxb.model.record_v2.CreditName)2 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)2 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)2 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)2 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)2 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)2 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)2 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 ApplicationException (org.orcid.core.exception.ApplicationException)1