Search in sources :

Example 21 with OrcidWorks

use of org.orcid.jaxb.model.message.OrcidWorks 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 22 with OrcidWorks

use of org.orcid.jaxb.model.message.OrcidWorks 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 23 with OrcidWorks

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

the class OrcidProfileManagerImpl method updateOrcidWorks.

/**
 * Updates the ORCID works only
 *
 * @param updatedOrcidProfile
 * @return
 */
@Override
public OrcidProfile updateOrcidWorks(OrcidProfile updatedOrcidProfile) {
    OrcidProfile existingProfile = retrieveOrcidProfile(updatedOrcidProfile.getOrcidIdentifier().getPath());
    if (existingProfile == null) {
        return null;
    }
    OrcidActivities updatedActivities = updatedOrcidProfile.getOrcidActivities();
    if (updatedActivities == null) {
        return null;
    }
    OrcidWorks updatedOrcidWorks = updatedActivities.getOrcidWorks();
    if (updatedOrcidWorks == null) {
        return null;
    }
    OrcidActivities existingActivities = existingProfile.getOrcidActivities();
    if (existingActivities == null) {
        existingActivities = new OrcidActivities();
        existingProfile.setOrcidActivities(existingActivities);
    }
    OrcidWorks existingOrcidWorks = existingActivities.getOrcidWorks();
    if (existingOrcidWorks == null) {
        existingOrcidWorks = new OrcidWorks();
        existingActivities.setOrcidWorks(existingOrcidWorks);
    }
    checkUserCanHoldMoreElement(existingProfile.retrieveOrcidWorks(), updatedOrcidProfile.retrieveOrcidWorks());
    orcidJaxbCopyManager.copyUpdatedWorksPreservingVisbility(existingProfile.retrieveOrcidWorks(), updatedOrcidProfile.retrieveOrcidWorks());
    OrcidProfile profileToReturn = updateOrcidProfile(existingProfile);
    notificationManager.sendAmendEmail(updatedOrcidProfile.getOrcidIdentifier().getPath(), AmendedSection.WORK, null);
    return profileToReturn;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 24 with OrcidWorks

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorks_duplicatedShouldFail.

@Test(expected = IllegalArgumentException.class)
public void testAddWorks_duplicatedShouldFail() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    profile2.setOrcidActivities(new OrcidActivities());
    profile2.getOrcidActivities().setOrcidWorks(new OrcidWorks());
    profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
    OrcidWorks orcidWorks = profile2.getOrcidActivities().getOrcidWorks();
    OrcidWork work1 = createWork1();
    work1.getWorkTitle().getTitle().setContent("Updated title");
    orcidWorks.getOrcidWork().add(work1);
    OrcidWork work2 = createWork2();
    orcidWorks.getOrcidWork().add(work2);
    OrcidWork work3 = createWork3();
    orcidWorks.getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile2);
    fail("Must not allow different works with same ext ids from the same source");
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test)

Example 25 with OrcidWorks

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testDedupeWorks.

@Test
public void testDedupeWorks() {
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidWorks.getOrcidWork().add(createWork1());
    orcidWorks.getOrcidWork().add(createWork1());
    assertEquals(2, orcidWorks.getOrcidWork().size());
    OrcidWorks dedupedOrcidWorks = orcidProfileManager.dedupeWorks(orcidWorks);
    assertEquals(1, dedupedOrcidWorks.getOrcidWork().size());
}
Also used : OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test)

Aggregations

OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)46 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)35 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)32 Test (org.junit.Test)24 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)19 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)15 Title (org.orcid.jaxb.model.message.Title)15 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)13 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)13 Transactional (org.springframework.transaction.annotation.Transactional)12 FundingList (org.orcid.jaxb.model.message.FundingList)9 Funding (org.orcid.jaxb.model.message.Funding)8 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)8 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)8 DBUnitTest (org.orcid.test.DBUnitTest)8 Rollback (org.springframework.test.annotation.Rollback)8 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)7 Date (java.util.Date)6 Affiliations (org.orcid.jaxb.model.message.Affiliations)6 Subtitle (org.orcid.jaxb.model.message.Subtitle)6