Search in sources :

Example 96 with OrcidProfile

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

the class OrcidSearchManagerImplTest method oneOrcidInDbOtherMissing.

@Test
@Rollback
public void oneOrcidInDbOtherMissing() {
    when(mockSolrDao.findByDocumentCriteria("rndQuery", null, null)).thenReturn(multipleResultsForQuery());
    when(mockOrcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(getOrcidProfile5678MandatoryOnly());
    when(mockOrcidProfileCacheManager.retrievePublicBio("6789")).thenReturn(null);
    OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidsByQuery("rndQuery");
    assertNotNull(retrievedOrcidMessage);
    assertTrue(retrievedOrcidMessage.getOrcidSearchResults() != null && retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
    OrcidSearchResult searchResult = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
    OrcidProfile profileReturnedFromSearch = searchResult.getOrcidProfile();
    assertEquals("5678", profileReturnedFromSearch.getOrcidIdentifier().getPath());
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 97 with OrcidProfile

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

the class OrcidSearchManagerImpl method buildSearchResultsFromPublicProfile.

private List<OrcidSearchResult> buildSearchResultsFromPublicProfile(List<OrcidSolrResult> solrResults) {
    List<OrcidSearchResult> orcidSearchResults = new ArrayList<OrcidSearchResult>();
    for (OrcidSolrResult solrResult : solrResults) {
        OrcidMessage orcidMessage = null;
        String orcid = solrResult.getOrcid();
        try {
            orcidSecurityManager.checkProfile(orcid);
        } catch (DeactivatedException | LockedException | OrcidDeprecatedException x) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidProfile orcidProfile = new OrcidProfile();
            orcidProfile.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
            OrcidHistory history = new OrcidHistory();
            Date recordLastModified = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
            history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(recordLastModified)));
            orcidProfile.setOrcidHistory(history);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
            continue;
        }
        if (cachingSource.equals(SOLR)) {
            try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
                if (reader != null) {
                    BufferedReader br = new BufferedReader(reader);
                    orcidMessage = OrcidMessage.unmarshall(br);
                }
            } catch (IOException e) {
                throw new OrcidSearchException("Error closing record stream from solr search results for orcid: " + orcid, e);
            }
        }
        OrcidProfile orcidProfile = null;
        if (orcidMessage == null) {
            // Fall back to DB
            orcidProfile = orcidProfileCacheManager.retrievePublicBio(orcid);
        } else {
            orcidProfile = orcidMessage.getOrcidProfile();
        }
        if (orcidProfile != null) {
            OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
            RelevancyScore relevancyScore = new RelevancyScore();
            relevancyScore.setValue(solrResult.getRelevancyScore());
            orcidSearchResult.setRelevancyScore(relevancyScore);
            OrcidWorks orcidWorksTitlesOnly = new OrcidWorks();
            OrcidWorks fullOrcidWorks = orcidProfile.retrieveOrcidWorks();
            if (fullOrcidWorks != null && !fullOrcidWorks.getOrcidWork().isEmpty()) {
                for (OrcidWork fullOrcidWork : fullOrcidWorks.getOrcidWork()) {
                    OrcidWork orcidWorkSubset = new OrcidWork();
                    orcidWorkSubset.setVisibility(fullOrcidWork.getVisibility());
                    orcidWorkSubset.setWorkTitle(fullOrcidWork.getWorkTitle());
                    orcidWorkSubset.setWorkExternalIdentifiers(fullOrcidWork.getWorkExternalIdentifiers());
                    orcidWorksTitlesOnly.getOrcidWork().add(orcidWorkSubset);
                }
            }
            FundingList reducedFundings = new FundingList();
            FundingList fullOrcidFundings = orcidProfile.retrieveFundings();
            if (fullOrcidFundings != null && !fullOrcidFundings.getFundings().isEmpty()) {
                for (Funding fullOrcidFunding : fullOrcidFundings.getFundings()) {
                    Funding reducedFunding = new Funding();
                    reducedFunding.setVisibility(fullOrcidFunding.getVisibility());
                    reducedFunding.setDescription(fullOrcidFunding.getDescription());
                    reducedFunding.setTitle(fullOrcidFunding.getTitle());
                    reducedFundings.getFundings().add(reducedFunding);
                }
            }
            orcidProfile.setOrcidWorks(orcidWorksTitlesOnly);
            orcidProfile.setFundings(reducedFundings);
            orcidSearchResult.setOrcidProfile(orcidProfile);
            orcidSearchResults.add(orcidSearchResult);
        }
    }
    return orcidSearchResults;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) LockedException(org.orcid.core.security.aop.LockedException) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Date(java.util.Date) LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) DeactivatedException(org.orcid.core.exception.DeactivatedException) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) RelevancyScore(org.orcid.jaxb.model.message.RelevancyScore) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) FundingList(org.orcid.jaxb.model.message.FundingList) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) BufferedReader(java.io.BufferedReader)

Example 98 with OrcidProfile

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

the class OrcidProfileManagerImpl method updateOrcidBio.

/**
 * Updates the ORCID bio data
 *
 * @param updatedOrcidProfile
 * @return
 */
@Deprecated
@Override
public OrcidProfile updateOrcidBio(OrcidProfile updatedOrcidProfile) {
    addSourceToBioElements(updatedOrcidProfile);
    OrcidProfile existingProfile = retrieveOrcidProfile(updatedOrcidProfile.getOrcidIdentifier().getPath());
    if (existingProfile == null) {
        return null;
    }
    // preserve the visibility settings
    orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingProfile.getOrcidBio(), updatedOrcidProfile.getOrcidBio());
    OrcidProfile profileToReturn = updateOrcidProfile(existingProfile, UpdateOptions.NO_ACTIVITIES);
    notificationManager.sendAmendEmail(updatedOrcidProfile.getOrcidIdentifier().getPath(), AmendedSection.BIO, null);
    return profileToReturn;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile)

Example 99 with OrcidProfile

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

the class OrcidProfileManagerImpl method addOrcidWorks.

@Override
@Transactional
public void addOrcidWorks(OrcidProfile updatedOrcidProfile) {
    String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
    OrcidProfile existingProfile = null;
    List<OrcidWork> updatedOrcidWorksList = null;
    try {
        synchronized (getLock(orcid)) {
            existingProfile = retrieveOrcidProfile(orcid);
            if (existingProfile == null) {
                throw new IllegalArgumentException("No record found for " + orcid);
            }
            OrcidWorks existingOrcidWorks = existingProfile.retrieveOrcidWorks();
            OrcidWorks updatedOrcidWorks = updatedOrcidProfile.retrieveOrcidWorks();
            Visibility workVisibilityDefault = existingProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
            Boolean claimed = existingProfile.getOrcidHistory().isClaimed();
            setWorkPrivacy(updatedOrcidWorks, workVisibilityDefault, claimed == null ? false : claimed);
            if (updatedOrcidWorks != null) {
                addSourceToWorks(updatedOrcidWorks, getSource());
            }
            updatedOrcidWorks = dedupeWorks(updatedOrcidWorks);
            updatedOrcidWorksList = updatedOrcidWorks.getOrcidWork();
            checkUserCanHoldMoreElement(existingProfile.retrieveOrcidWorks(), updatedOrcidProfile.retrieveOrcidWorks());
            if (compareWorksUsingScopusWay) {
                checkForAlreadyExistingWorks(orcid, existingOrcidWorks, updatedOrcidWorksList);
                if (existingOrcidWorks != null)
                    checkWorkExternalIdentifiersAreNotDuplicated(updatedOrcidWorksList, existingOrcidWorks.getOrcidWork());
                else
                    checkWorkExternalIdentifiersAreNotDuplicated(updatedOrcidWorksList, null);
            } else {
                checkForAlreadyExistingWorksLegacyMode(existingOrcidWorks, updatedOrcidWorksList);
            }
            persistAddedWorks(orcid, updatedOrcidWorksList);
            profileDao.flush();
        }
    } finally {
        releaseLock(orcid);
    }
    boolean notificationsEnabled = existingProfile.getOrcidInternal().getPreferences().getNotificationsEnabled();
    if (notificationsEnabled && updatedOrcidWorksList != null) {
        List<Item> activities = new ArrayList<>();
        for (OrcidWork updatedWork : updatedOrcidWorksList) {
            Item activity = new Item();
            activity.setItemName(updatedWork.getWorkTitle().getTitle().getContent());
            activity.setItemType(ItemType.WORK);
            activity.setPutCode(updatedWork.getPutCode());
            activities.add(activity);
        }
        notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, activities);
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Item(org.orcid.jaxb.model.notification.permission_v2.Item) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) Visibility(org.orcid.jaxb.model.message.Visibility) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with OrcidProfile

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

the class OrcidProfileManagerImpl method updateOrcidProfile.

private OrcidProfile updateOrcidProfile(OrcidProfile orcidProfile, UpdateOptions updateOptions) {
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            ProfileEntity existingProfileEntity = profileDao.find(orcidProfile.getOrcidIdentifier().getPath());
            Visibility defaultVisibility = Visibility.fromValue(existingProfileEntity.getActivitiesVisibilityDefault().value());
            if (existingProfileEntity != null) {
                // Dont delete the existing elements anymore
                // profileDao.removeChildrenWithGeneratedIds(existingProfileEntity);
                setWorkPrivacy(orcidProfile, defaultVisibility);
                setAffiliationPrivacy(orcidProfile, defaultVisibility);
                setFundingPrivacy(orcidProfile, defaultVisibility);
            }
            addSourceToNewActivities(orcidProfile.getOrcidActivities());
            dedupeWorks(orcidProfile);
            dedupeAffiliations(orcidProfile);
            dedupeFundings(orcidProfile);
            addSourceToEmails(orcidProfile, existingProfileEntity, amenderOrcid);
            Boolean claimed = orcidProfile.getOrcidHistory() != null ? orcidProfile.getOrcidHistory().isClaimed() : existingProfileEntity.getClaimed();
            if (orcidProfile.getOrcidInternal() != null && orcidProfile.getOrcidInternal().getPreferences() != null && orcidProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault() != null) {
                defaultVisibility = orcidProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
            }
            addDefaultVisibilityToBioItems(orcidProfile, defaultVisibility, claimed);
            ProfileEntity profileEntity = adapter.toProfileEntity(orcidProfile, existingProfileEntity, updateOptions);
            profileEntity.setLastModified(new Date());
            profileEntity.setIndexingStatus(IndexingStatus.PENDING);
            profileDao.flush();
            ProfileEntity updatedProfileEntity = profileDao.merge(profileEntity);
            profileDao.refresh(updatedProfileEntity);
            // Then persist the works
            if (orcidProfile.getOrcidActivities() != null && orcidProfile.getOrcidActivities().getOrcidWorks() != null) {
                adapter.setWorks(profileEntity, orcidProfile.getOrcidActivities().getOrcidWorks());
            } else {
                adapter.setWorks(profileEntity, null);
            }
        }
    });
    OrcidProfile profile = transactionTemplate.execute(new TransactionCallback<OrcidProfile>() {

        @Override
        public OrcidProfile doInTransaction(TransactionStatus status) {
            return convertToOrcidProfile(profileDao.find(orcidProfile.getOrcidIdentifier().getPath()), LoadOptions.ALL);
        }
    });
    return profile;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) TransactionStatus(org.springframework.transaction.TransactionStatus) Visibility(org.orcid.jaxb.model.message.Visibility) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Aggregations

OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)241 Test (org.junit.Test)118 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)77 Transactional (org.springframework.transaction.annotation.Transactional)50 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)45 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)43 DBUnitTest (org.orcid.test.DBUnitTest)43 Rollback (org.springframework.test.annotation.Rollback)40 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)36 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)35 Date (java.util.Date)27 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)27 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)25 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)23 Affiliations (org.orcid.jaxb.model.message.Affiliations)22 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)22 Title (org.orcid.jaxb.model.message.Title)22 Email (org.orcid.jaxb.model.message.Email)21 GivenNames (org.orcid.jaxb.model.message.GivenNames)21 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)21