Search in sources :

Example 61 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerContributorVisibilityTest method orcidProvidedAndDoesExistInDbAndCreditNameAndEmailArePublic.

@Test
@Transactional
public void orcidProvidedAndDoesExistInDbAndCreditNameAndEmailArePublic() {
    // Unmarshall message containing contributor email
    OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_orcid.xml");
    // Change orcid to one that exists in DB
    orcidMessage.getOrcidProfile().retrieveOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor().get(0).getContributorOrcid().setPath("4444-4444-4444-444X");
    // Add the work
    orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
    // Get it back from the API
    OrcidWork retrievedWork = retrieveAddedWorkFromApi();
    Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
    // Check that the contributor name is included in the resulting work
    assertEquals("U. Name", workContributor.getCreditName().getContent());
    // Check that the email is not included in the resulting work, because
    // never want to show email
    assertNull(workContributor.getContributorEmail());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerContributorVisibilityTest method orcidProvidedAndDoesExistInDbButCreditNameAndEmailArePrivate.

@Test
@Transactional
public void orcidProvidedAndDoesExistInDbButCreditNameAndEmailArePrivate() {
    // Unmarshall message containing contributor email
    OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_orcid.xml");
    // Change email to one that exists in DB
    orcidMessage.getOrcidProfile().retrieveOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor().get(0).getContributorOrcid().setPath("4444-4444-4444-4447");
    // Add the work
    orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
    // Get it back from the API
    OrcidWork retrievedWork = retrieveAddedWorkFromApi();
    Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
    // Check that the contributor name is not included in the resulting
    // work, because it is private
    assertNull(workContributor.getCreditName());
    // Check that the email is not included in the resulting work, because
    // never want to show email
    assertNull(workContributor.getContributorEmail());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerContributorVisibilityTest method emailProvidedAndDoesExistInDbAndCreditNameAndEmailArePublic.

@Test
@Transactional
public void emailProvidedAndDoesExistInDbAndCreditNameAndEmailArePublic() {
    // Unmarshall message containing contributor email
    OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_email_and_name.xml");
    // Change email to one that exists in DB
    orcidMessage.getOrcidProfile().retrieveOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor().get(0).getContributorEmail().setValue("user@email.com");
    // Add the work
    orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
    // Get it back from the API
    OrcidWork retrievedWork = retrieveAddedWorkFromApi();
    Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
    // Check that the contributor name is included in the resulting work
    assertEquals("U. Name", workContributor.getCreditName().getContent());
    // Check that the email is not included in the resulting work, because
    // never want to show email
    assertNull(workContributor.getContributorEmail());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerContributorVisibilityTest method orcidProvidedButDoesNotExistInDb.

@Test
@Transactional
public void orcidProvidedButDoesNotExistInDb() {
    // Unmarshall message containing contributor ORCID that does not exist
    // in DB
    OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_orcid.xml");
    // Add the work
    orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
    // Get it back from the API
    OrcidWork retrievedWork = retrieveAddedWorkFromApi();
    Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
    // Check that the contributor name is not included in the resulting
    // work, because the ORCID does not exist
    assertNull(workContributor.getCreditName());
    // Check that the email is not included in the resulting work, because
    // never want to show email
    assertNull(workContributor.getContributorEmail());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidIndexManagerImpl method persistProfileInformationForIndexing.

@Override
@Deprecated
public void persistProfileInformationForIndexing(OrcidProfile orcidProfile) {
    // Check if the profile is locked
    if (orcidProfile.isLocked()) {
        orcidProfile.downgradeToOrcidIdentifierOnly();
    }
    OrcidMessage messageToFilter = new OrcidMessage();
    messageToFilter.setOrcidProfile(orcidProfile);
    OrcidMessage filteredMessage = visibilityFilter.filter(messageToFilter, Visibility.PUBLIC);
    OrcidProfile filteredProfile = filteredMessage.getOrcidProfile();
    OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
    profileIndexDocument.setOrcid(filteredProfile.getOrcidIdentifier().getPath());
    OrcidDeprecated orcidDeprecated = filteredProfile.getOrcidDeprecated();
    if (orcidDeprecated != null) {
        profileIndexDocument.setPrimaryRecord(orcidDeprecated.getPrimaryRecord() != null ? orcidDeprecated.getPrimaryRecord().getOrcidIdentifier().getPath() : null);
    }
    OrcidBio orcidBio = filteredProfile.getOrcidBio();
    if (orcidBio != null) {
        PersonalDetails personalDetails = orcidBio.getPersonalDetails();
        boolean persistPersonalDetails = personalDetails != null;
        if (persistPersonalDetails) {
            profileIndexDocument.setFamilyName(personalDetails.getFamilyName() != null ? personalDetails.getFamilyName().getContent() : null);
            profileIndexDocument.setGivenNames(personalDetails.getGivenNames() != null ? personalDetails.getGivenNames().getContent() : null);
            profileIndexDocument.setCreditName(personalDetails.getCreditName() != null ? personalDetails.getCreditName().getContent() : null);
            List<OtherName> otherNames = personalDetails.getOtherNames() != null ? personalDetails.getOtherNames().getOtherName() : null;
            if (otherNames != null && !otherNames.isEmpty()) {
                List<String> names = new ArrayList<String>();
                for (OtherName otherName : otherNames) {
                    names.add(otherName.getContent());
                }
                profileIndexDocument.setOtherNames(names);
            }
        }
        ContactDetails contactDetails = orcidBio.getContactDetails();
        if (contactDetails != null) {
            for (Email email : contactDetails.getEmail()) {
                profileIndexDocument.addEmailAddress(email.getValue());
            }
        }
        ExternalIdentifiers externalIdentifiers = orcidBio.getExternalIdentifiers();
        if (externalIdentifiers != null) {
            List<String> extIdOrcids = new ArrayList<String>();
            List<String> extIdRefs = new ArrayList<String>();
            List<String> extIdOrcidsAndRefs = new ArrayList<String>();
            for (ExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) {
                Source source = externalIdentifier.getSource();
                String sourcePath = null;
                if (source != null) {
                    sourcePath = source.retrieveSourcePath();
                    if (sourcePath != null) {
                        extIdOrcids.add(sourcePath);
                    }
                }
                ExternalIdReference externalIdReference = externalIdentifier.getExternalIdReference();
                if (externalIdReference != null) {
                    extIdRefs.add(externalIdReference.getContent());
                }
                if (NullUtils.noneNull(sourcePath, externalIdReference)) {
                    extIdOrcidsAndRefs.add(sourcePath + "=" + externalIdReference.getContent());
                }
            }
            if (!extIdOrcids.isEmpty()) {
                profileIndexDocument.setExternalIdSources(extIdOrcids);
            }
            if (!extIdRefs.isEmpty()) {
                profileIndexDocument.setExternalIdReferences(extIdRefs);
            }
            if (!extIdOrcidsAndRefs.isEmpty()) {
                profileIndexDocument.setExternalIdSourcesAndReferences(extIdOrcidsAndRefs);
            }
        }
        OrcidActivities orcidActivities = filteredProfile.getOrcidActivities();
        if (orcidActivities != null) {
            // Affiliations affiliations =
            // orcidActivities.getAffiliations();
            // if (affiliations != null) {
            // List<Affiliation> pastInsts = affiliations
            // .getAffiliationsByType(AffiliationType.PAST_INSTITUTION);
            // if (pastInsts != null && !pastInsts.isEmpty()) {
            // List<String> pastInstNames = new ArrayList<String>();
            // for (Affiliation pastAffiliation : pastInsts) {
            // pastInstNames.add(pastAffiliation
            // .getAffiliationName());
            // }
            // 
            // profileIndexDocument
            // .setAffiliatePastInstitutionNames(pastInstNames);
            // }
            // 
            // List<Affiliation> primaryInsts = affiliations
            // .getAffiliationsByType(AffiliationType.CURRENT_PRIMARY_INSTITUTION);
            // if (primaryInsts != null && !primaryInsts.isEmpty()) {
            // List<String> primaryInstNames = new ArrayList<String>();
            // for (Affiliation primaryAffiliation : primaryInsts) {
            // primaryInstNames.add(primaryAffiliation
            // .getAffiliationName());
            // }
            // 
            // profileIndexDocument
            // .setAffiliatePrimaryInstitutionNames(primaryInstNames);
            // }
            // 
            // List<Affiliation> currentNonPrimaryInsts = affiliations
            // .getAffiliationsByType(AffiliationType.CURRENT_INSTITUTION);
            // if (currentNonPrimaryInsts != null
            // && !currentNonPrimaryInsts.isEmpty()) {
            // List<String> affiliateInstNames = new ArrayList<String>();
            // for (Affiliation currentAffiliation : currentNonPrimaryInsts)
            // {
            // affiliateInstNames.add(currentAffiliation
            // .getAffiliationName());
            // }
            // 
            // profileIndexDocument
            // .setAffiliateInstitutionNames(affiliateInstNames);
            // }
            // }
            List<String> keywords = extractKeywordsAsStringFromBio(orcidBio);
            if (keywords != null) {
                profileIndexDocument.setKeywords(keywords);
            }
        }
        List<OrcidWork> orcidWorks = filteredProfile.retrieveOrcidWorks() != null ? filteredProfile.retrieveOrcidWorks().getOrcidWork() : null;
        if (orcidWorks != null) {
            List<String> workTitles = new ArrayList<String>();
            Map<WorkExternalIdentifierType, List<String>> allExternalIdentifiers = new HashMap<WorkExternalIdentifierType, List<String>>();
            for (OrcidWork orcidWork : orcidWorks) {
                if (orcidWork.getWorkExternalIdentifiers() != null) {
                    for (WorkExternalIdentifier workExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                        /**
                         * Creates a map that contains all different
                         * external identifiers for the current work
                         */
                        if (nullSafeCheckForWorkExternalIdentifier(workExternalIdentifier)) {
                            WorkExternalIdentifierType type = workExternalIdentifier.getWorkExternalIdentifierType();
                            if (!allExternalIdentifiers.containsKey(type)) {
                                List<String> content = new ArrayList<String>();
                                content.add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                                allExternalIdentifiers.put(type, content);
                            } else {
                                allExternalIdentifiers.get(type).add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                            }
                        }
                    }
                }
                if (orcidWork.getWorkTitle() != null) {
                    Title workMainTitle = orcidWork.getWorkTitle().getTitle();
                    Subtitle worksubTitle = orcidWork.getWorkTitle().getSubtitle();
                    TranslatedTitle translatedTitle = orcidWork.getWorkTitle().getTranslatedTitle();
                    if (workMainTitle != null && !StringUtils.isBlank(workMainTitle.getContent())) {
                        workTitles.add(workMainTitle.getContent());
                    }
                    if (worksubTitle != null && !StringUtils.isBlank(worksubTitle.getContent())) {
                        workTitles.add(worksubTitle.getContent());
                    }
                    if (translatedTitle != null && !StringUtils.isBlank(translatedTitle.getContent())) {
                        workTitles.add(translatedTitle.getContent());
                    }
                }
            }
            profileIndexDocument.setWorkTitles(workTitles);
            // Set the list of external identifiers to the document list
            addExternalIdentifiersToIndexDocument(profileIndexDocument, allExternalIdentifiers);
        }
        List<Funding> orcidFundings = filteredProfile.retrieveFundings() != null ? filteredProfile.retrieveFundings().getFundings() : null;
        if (orcidFundings != null) {
            List<String> fundingTitle = new ArrayList<String>();
            for (Funding orcidFunding : orcidFundings) {
                FundingTitle title = orcidFunding.getTitle();
                if (title != null) {
                    if (title.getTitle() != null && !StringUtils.isBlank(title.getTitle().getContent())) {
                        fundingTitle.add(title.getTitle().getContent());
                    }
                    if (title.getTranslatedTitle() != null && StringUtils.isBlank(title.getTranslatedTitle().getContent())) {
                        fundingTitle.add(title.getTranslatedTitle().getContent());
                    }
                }
            }
            profileIndexDocument.setFundingTitles(fundingTitle);
        }
    }
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    orcidMessage.setOrcidProfile(filteredProfile);
    OrcidHistory orcidHistory = filteredProfile.getOrcidHistory();
    if (orcidHistory != null) {
        LastModifiedDate lastModifiedDate = orcidHistory.getLastModifiedDate();
        if (lastModifiedDate != null) {
            profileIndexDocument.setProfileLastModifiedDate(lastModifiedDate.getValue().toGregorianCalendar().getTime());
        }
        SubmissionDate submissionDate = orcidHistory.getSubmissionDate();
        if (submissionDate != null) {
            profileIndexDocument.setProfileSubmissionDate(submissionDate.getValue().toGregorianCalendar().getTime());
        }
    }
    if (indexPublicProfile) {
        profileIndexDocument.setPublicProfileMessage(orcidMessage.toXmlString());
    }
    solrDao.persist(profileIndexDocument);
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) HashMap(java.util.HashMap) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) ArrayList(java.util.ArrayList) List(java.util.List) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) WorkExternalIdentifierType(org.orcid.jaxb.model.message.WorkExternalIdentifierType) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherName(org.orcid.jaxb.model.message.OtherName) Title(org.orcid.jaxb.model.message.Title) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Subtitle(org.orcid.jaxb.model.message.Subtitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated)

Aggregations

OrcidWork (org.orcid.jaxb.model.message.OrcidWork)81 Test (org.junit.Test)44 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)42 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)32 Transactional (org.springframework.transaction.annotation.Transactional)26 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)24 Title (org.orcid.jaxb.model.message.Title)23 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)20 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)18 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)16 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)16 Source (org.orcid.jaxb.model.message.Source)14 Rollback (org.springframework.test.annotation.Rollback)13 ArrayList (java.util.ArrayList)12 Funding (org.orcid.jaxb.model.message.Funding)12 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)12 BaseTest (org.orcid.core.BaseTest)11 Contributor (org.orcid.jaxb.model.message.Contributor)11 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)11 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)10