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;
}
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);
}
}
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;
}
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");
}
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());
}
Aggregations