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