use of org.orcid.utils.solr.entities.OrcidSolrDocument 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);
}
use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.
the class SolrDaoTest method queryFieldWithBoostAndExclusions.
@Test
public void queryFieldWithBoostAndExclusions() throws Exception {
OrcidSolrDocument firstOrcidDoc = buildFirstOrcid();
firstOrcidDoc.setOrcid(firstOrcid);
firstOrcidDoc.setFamilyName("James");
OrcidSolrDocument secondOrcidDoc = buildSupplementaryOrcid();
secondOrcidDoc.setOrcid(secondOrcid);
secondOrcidDoc.setGivenNames("James");
OrcidSolrDocument thirdOrcidDoc = buildSupplementaryOrcid();
thirdOrcidDoc.setFamilyName("James");
thirdOrcidDoc.setOrcid(RandomStringUtils.randomAlphabetic(9));
persistOrcid(firstOrcidDoc);
persistOrcid(secondOrcidDoc);
persistOrcid(thirdOrcidDoc);
String familyNameGivenNameQuery = "{!edismax qf='family-name^1.0 given-names^2.0'}James";
List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameGivenNameQuery, null, null).getResults();
assertTrue(solrResults.size() == 3);
OrcidSolrResult givenNameMatch = solrResults.get(0);
assertTrue(secondOrcid.equals(givenNameMatch.getOrcid()) && givenNameMatch.getRelevancyScore() > 1);
OrcidSolrResult familyNameMatch1 = solrResults.get(1);
OrcidSolrResult familyNameMatch2 = solrResults.get(2);
assertTrue(familyNameMatch1.getRelevancyScore() < 1.0);
assertTrue(familyNameMatch2.getRelevancyScore() < 1.0);
String familyNameGivenNameQueryWithExclude = familyNameGivenNameQuery + " -orcid:" + thirdOrcidDoc.getOrcid();
solrResults = solrDao.findByDocumentCriteria(familyNameGivenNameQueryWithExclude, null, null).getResults();
assertTrue(solrResults.size() == 2);
givenNameMatch = solrResults.get(0);
assertTrue(givenNameMatch.getOrcid().equals(secondOrcid));
assertTrue(givenNameMatch.getRelevancyScore() > 1);
familyNameMatch1 = solrResults.get(1);
assertTrue(familyNameMatch1.getOrcid().equals(firstOrcid));
assertTrue(familyNameMatch1.getRelevancyScore() < 1);
}
use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.
the class SolrDaoTest method queryStringSearchFamilyNameGivenNameTenRows.
@Test
public void queryStringSearchFamilyNameGivenNameTenRows() throws Exception {
int numRecordsToCreate = 10;
List<String> orcidsToGetStored = new ArrayList<String>();
for (int i = 0; i < numRecordsToCreate; i++) {
OrcidSolrDocument orcidSolrDocument = buildSupplementaryOrcid();
orcidSolrDocument.setGivenNames(RandomStringUtils.randomAscii(20));
// format of orcid irrelevant to solr - just need to make them
// different
orcidSolrDocument.setOrcid(RandomStringUtils.randomAscii(20));
orcidsToGetStored.add(orcidSolrDocument.getOrcid());
persistOrcid(orcidSolrDocument);
}
String familyNameOnlyQuery = "family-name:Family Name";
List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameOnlyQuery, null, null).getResults();
assertTrue(solrResults.size() == 10);
familyNameOnlyQuery = "{!start=0 rows=5} family-name:Family Name";
solrResults = solrDao.findByDocumentCriteria(familyNameOnlyQuery, null, null).getResults();
assertTrue(solrResults.size() == 5);
}
use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.
the class SolrDaoTest method buildAndPersistSecondOrcid.
private OrcidSolrDocument buildAndPersistSecondOrcid() {
OrcidSolrDocument secondDoc = buildSupplementaryOrcid();
secondDoc.setOrcid(secondOrcid);
persistOrcid(secondDoc);
return secondDoc;
}
use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.
the class SolrDaoTest method buildFirstOrcid.
private OrcidSolrDocument buildFirstOrcid() {
OrcidSolrDocument testDoc = new OrcidSolrDocument();
testDoc.setOrcid(firstOrcid);
testDoc.setGivenNames("Given Name of Person");
testDoc.setFamilyName("Smith");
testDoc.setPatentNumbers(Arrays.asList(new String[] { "Elec-hammer01X:" }));
return testDoc;
}
Aggregations