Search in sources :

Example 6 with OrcidSolrDocument

use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.

the class OrcidIndexManagerImplTest method visibilityConstraintsAppliedToSolr.

@Test
@Rollback
@Ignore
public void visibilityConstraintsAppliedToSolr() throws Exception {
    OrcidProfile hiddenNamesOrcid = orcidProfileLimitedVisiblityCreditNameAndOtherNames();
    orcidIndexManager.persistProfileInformationForIndexing(hiddenNamesOrcid);
    // check that limited fields are hidden from solr indexing
    OrcidSolrDocument namesHiddenSolrDoc = solrDocFilteredByNameVisibility();
    verify(solrDao).persist(eq(namesHiddenSolrDoc));
    // reset orcid test data and check affilations
    OrcidProfile limitedOrcid = orcidProfileLimitedVisiblityAffiliations();
    orcidIndexManager.persistProfileInformationForIndexing(limitedOrcid);
    OrcidSolrDocument hiddenPastAffiliations = solrDocFilteredByAffilliationVisibility();
    verify(solrDao).persist(eq(hiddenPastAffiliations));
    OrcidProfile orcidAllWorksPrivate = orcidProfileAllLimitedVisibilityWorks();
    orcidIndexManager.persistProfileInformationForIndexing(orcidAllWorksPrivate);
    OrcidSolrDocument hiddenWorks = solrDocFilteredByAffilliationVisibility();
    verify(solrDao).persist(eq(hiddenWorks));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 7 with OrcidSolrDocument

use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.

the class OrcidIndexManagerImplTest method solrDocFilteredByNameVisibility.

private OrcidSolrDocument solrDocFilteredByNameVisibility() {
    OrcidSolrDocument orcidSolrDocument = fullyPopulatedSolrDocumentForPersistence();
    orcidSolrDocument.setCreditName(null);
    orcidSolrDocument.setOtherNames(null);
    orcidSolrDocument.setGivenNames(null);
    orcidSolrDocument.setFamilyName(null);
    orcidSolrDocument.setGivenAndFamilyNames(null);
    OrcidProfile orcidProfile = orcidProfileLimitedVisiblityCreditNameAndOtherNames();
    OrcidMessage orcidMessage = createFilteredOrcidMessage(orcidProfile);
    orcidSolrDocument.setPublicProfileMessage(orcidMessage.toString());
    return orcidSolrDocument;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage)

Example 8 with OrcidSolrDocument

use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.

the class OrcidIndexManagerImplTest method onlyDoiPersistedFromOrcidWorks.

@Test
@Rollback
public void onlyDoiPersistedFromOrcidWorks() {
    OrcidProfile orcidProfileWithDOI = getStandardOrcidWithDoiInformation();
    OrcidSolrDocument doiListings = solrDocumentLimitedtoVisibleDoi();
    // check that the limited profiles or non doi identifiers aren't
    // included
    orcidIndexManager.persistProfileInformationForIndexing(orcidProfileWithDOI);
    verify(solrDao).persist(eq(doiListings));
    // now check null values aren't persisted when either the type or value
    // are missing
    OrcidWork orcidWork1 = orcidProfileWithDOI.retrieveOrcidWorks().getOrcidWork().get(0);
    orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).setWorkExternalIdentifierType(null);
    OrcidWork orcidWork2 = orcidProfileWithDOI.retrieveOrcidWorks().getOrcidWork().get(1);
    orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).setWorkExternalIdentifierId(null);
    // so this should leave only the second doi
    doiListings.setDigitalObjectIds(Arrays.asList(new String[] { "work2-doi2" }));
    OrcidMessage orcidMessage = createFilteredOrcidMessage(orcidProfileWithDOI);
    doiListings.setPublicProfileMessage(orcidMessage.toString());
    orcidIndexManager.persistProfileInformationForIndexing(orcidProfileWithDOI);
    verify(solrDao).persist(eq(doiListings));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 9 with OrcidSolrDocument

use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.

the class OrcidRecordToSolrDocument method convert.

public OrcidSolrDocument convert(Record record, List<Funding> fundings) {
    OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
    profileIndexDocument.setOrcid(record.getOrcidIdentifier().getPath());
    if (record.getHistory() != null) {
        if (record.getHistory().getLastModifiedDate() != null) {
            profileIndexDocument.setProfileLastModifiedDate(record.getHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime());
        }
        if (record.getHistory().getSubmissionDate() != null) {
            profileIndexDocument.setProfileSubmissionDate(record.getHistory().getSubmissionDate().getValue().toGregorianCalendar().getTime());
        }
    }
    if (record.getDeprecated() != null) {
        profileIndexDocument.setPrimaryRecord(record.getDeprecated().getPrimaryRecord() != null ? record.getDeprecated().getPrimaryRecord().getOrcidIdentifier().getPath() : null);
    }
    if (record.getPerson() != null) {
        if (record.getPerson().getName() != null) {
            profileIndexDocument.setFamilyName(record.getPerson().getName().getFamilyName() != null ? record.getPerson().getName().getFamilyName().getContent() : null);
            profileIndexDocument.setGivenNames(record.getPerson().getName().getGivenNames() != null ? record.getPerson().getName().getGivenNames().getContent() : null);
            profileIndexDocument.setCreditName(record.getPerson().getName().getCreditName() != null ? record.getPerson().getName().getCreditName().getContent() : null);
        }
        if (record.getPerson().getOtherNames() != null) {
            if (record.getPerson().getOtherNames().getOtherNames() != null && !record.getPerson().getOtherNames().getOtherNames().isEmpty()) {
                List<String> names = new ArrayList<String>();
                for (org.orcid.jaxb.model.record_v2.OtherName on : record.getPerson().getOtherNames().getOtherNames()) {
                    names.add(on.getContent());
                }
                profileIndexDocument.setOtherNames(names);
            }
        }
        if (record.getPerson().getEmails() != null && record.getPerson().getEmails().getEmails() != null) {
            for (org.orcid.jaxb.model.record_v2.Email e : record.getPerson().getEmails().getEmails()) {
                profileIndexDocument.addEmailAddress(e.getEmail());
            }
        }
        //weird, the type is not indexed...!
        if (record.getPerson().getExternalIdentifiers() != null && record.getPerson().getExternalIdentifiers().getExternalIdentifiers() != null) {
            List<String> extIdOrcids = new ArrayList<String>();
            List<String> extIdRefs = new ArrayList<String>();
            List<String> extIdOrcidsAndRefs = new ArrayList<String>();
            for (PersonExternalIdentifier externalIdentifier : record.getPerson().getExternalIdentifiers().getExternalIdentifiers()) {
                String sourcePath = null;
                if (externalIdentifier.getSource() != null && externalIdentifier.getSource().retrieveSourcePath() != null) {
                    sourcePath = externalIdentifier.getSource().retrieveSourcePath();
                    extIdOrcids.add(sourcePath);
                }
                if (externalIdentifier.getValue() != null) {
                    //weird, the type is not indexed...!
                    extIdRefs.add(externalIdentifier.getValue());
                }
                if (NullUtils.noneNull(sourcePath, externalIdentifier.getValue())) {
                    extIdOrcidsAndRefs.add(sourcePath + "=" + externalIdentifier.getValue());
                }
            }
            if (!extIdOrcids.isEmpty()) {
                profileIndexDocument.setExternalIdSources(extIdOrcids);
            }
            if (!extIdRefs.isEmpty()) {
                profileIndexDocument.setExternalIdReferences(extIdRefs);
            }
            if (!extIdOrcidsAndRefs.isEmpty()) {
                profileIndexDocument.setExternalIdSourcesAndReferences(extIdOrcidsAndRefs);
            }
        }
        //weird, we only index keywords if activities exist...!
        if (record.getActivitiesSummary() != null) {
            if (record.getPerson().getKeywords() != null && record.getPerson().getKeywords().getKeywords() != null) {
                List<String> keywordValues = new ArrayList<String>();
                for (org.orcid.jaxb.model.record_v2.Keyword keyword : record.getPerson().getKeywords().getKeywords()) {
                    keywordValues.add(keyword.getContent());
                }
                profileIndexDocument.setKeywords(keywordValues);
            }
        }
        if (record.getActivitiesSummary() != null && record.getActivitiesSummary().getWorks() != null && record.getActivitiesSummary().getWorks().getWorkGroup() != null) {
            //work ids
            Map<String, List<String>> allExternalIdentifiers = new HashMap<String, List<String>>();
            Map<String, List<String>> partOf = new HashMap<String, List<String>>();
            Map<String, List<String>> self = new HashMap<String, List<String>>();
            Set<String> workTitles = new HashSet<String>();
            for (WorkGroup wg : record.getActivitiesSummary().getWorks().getWorkGroup()) {
                if (wg.getWorkSummary() != null) {
                    for (WorkSummary w : wg.getWorkSummary()) {
                        // have to use summaries here as group does not include part-of
                        if (w.getExternalIdentifiers() != null && w.getExternalIdentifiers().getExternalIdentifier() != null) {
                            for (ExternalID id : w.getExternalIdentifiers().getExternalIdentifier()) {
                                //old way
                                if (!allExternalIdentifiers.containsKey(id.getType())) {
                                    allExternalIdentifiers.put(id.getType(), new ArrayList<String>());
                                }
                                if (!allExternalIdentifiers.get(id.getType()).contains(id.getValue())) {
                                    allExternalIdentifiers.get(id.getType()).add(id.getValue());
                                }
                                //new way
                                if (Relationship.SELF.equals(id.getRelationship())) {
                                    if (!self.containsKey(id.getType() + SolrConstants.DYNAMIC_SELF)) {
                                        self.put(id.getType() + SolrConstants.DYNAMIC_SELF, new ArrayList<String>());
                                    }
                                    if (!self.get(id.getType() + SolrConstants.DYNAMIC_SELF).contains(id.getValue())) {
                                        self.get(id.getType() + SolrConstants.DYNAMIC_SELF).add(id.getValue());
                                    }
                                }
                                if (Relationship.PART_OF.equals(id.getRelationship())) {
                                    if (!partOf.containsKey(id.getType() + SolrConstants.DYNAMIC_PART_OF)) {
                                        partOf.put(id.getType() + SolrConstants.DYNAMIC_PART_OF, new ArrayList<String>());
                                    }
                                    if (!partOf.get(id.getType() + SolrConstants.DYNAMIC_PART_OF).contains(id.getValue())) {
                                        partOf.get(id.getType() + SolrConstants.DYNAMIC_PART_OF).add(id.getValue());
                                    }
                                }
                            }
                        }
                        if (w.getTitle() != null) {
                            if (w.getTitle().getTitle() != null && StringUtils.isNotEmpty(w.getTitle().getTitle().getContent())) {
                                workTitles.add(w.getTitle().getTitle().getContent());
                            }
                            if (w.getTitle().getSubtitle() != null && StringUtils.isNotEmpty(w.getTitle().getSubtitle().getContent())) {
                                workTitles.add(w.getTitle().getSubtitle().getContent());
                            }
                            if (w.getTitle().getTranslatedTitle() != null && StringUtils.isNotEmpty(w.getTitle().getTranslatedTitle().getContent())) {
                                workTitles.add(w.getTitle().getTranslatedTitle().getContent());
                            }
                        }
                    }
                }
            }
            profileIndexDocument.setSelfIds(self);
            profileIndexDocument.setPartOfIds(partOf);
            //now add them to the doc, the old way
            addExternalIdentifiersToIndexDocument(profileIndexDocument, allExternalIdentifiers);
            profileIndexDocument.setWorkTitles(new ArrayList<String>(workTitles));
        }
        Map<String, List<String>> organisationIds = new HashMap<String, List<String>>();
        organisationIds.put(SolrConstants.FUNDREF_ORGANISATION_ID, new ArrayList<String>());
        organisationIds.put(SolrConstants.RINGGOLD_ORGANISATION_ID, new ArrayList<String>());
        Map<String, List<String>> organisationNames = new HashMap<String, List<String>>();
        organisationNames.put(SolrConstants.AFFILIATION_ORGANISATION_NAME, new ArrayList<String>());
        organisationNames.put(SolrConstants.FUNDING_ORGANISATION_NAME, new ArrayList<String>());
        if (!fundings.isEmpty()) {
            Set<String> fundingTitle = new HashSet<String>();
            Set<String> fundingGrantNumbers = new HashSet<String>();
            for (Funding f : fundings) {
                if (f.getTitle() != null) {
                    if (f.getTitle().getTitle() != null && StringUtils.isNotEmpty(f.getTitle().getTitle().getContent())) {
                        fundingTitle.add(f.getTitle().getTitle().getContent());
                    }
                    if (f.getTitle().getTranslatedTitle() != null && StringUtils.isNotEmpty(f.getTitle().getTranslatedTitle().getContent())) {
                        fundingTitle.add(f.getTitle().getTranslatedTitle().getContent());
                    }
                }
                if (f.getExternalIdentifiers() != null && f.getExternalIdentifiers().getExternalIdentifier() != null) {
                    for (ExternalID id : f.getExternalIdentifiers().getExternalIdentifier()) {
                        if (id.getType().equals("grant_number")) {
                            fundingGrantNumbers.add(id.getValue());
                        }
                    }
                }
                if (f.getOrganization() != null) {
                    organisationNames.get(SolrConstants.FUNDING_ORGANISATION_NAME).add(f.getOrganization().getName());
                    if (f.getOrganization().getDisambiguatedOrganization() != null)
                        organisationIds.get(SolrConstants.FUNDREF_ORGANISATION_ID).add(f.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier());
                }
            }
            profileIndexDocument.setFundingTitles(new ArrayList<String>(fundingTitle));
            profileIndexDocument.setGrantNumbers(new ArrayList<String>(fundingGrantNumbers));
        }
        //now do affiliations
        if (record.getActivitiesSummary() != null && record.getActivitiesSummary().getEducations() != null && record.getActivitiesSummary().getEducations().getSummaries() != null) {
            for (EducationSummary e : record.getActivitiesSummary().getEducations().getSummaries()) {
                if (e.getOrganization() != null) {
                    organisationNames.get(SolrConstants.AFFILIATION_ORGANISATION_NAME).add(e.getOrganization().getName());
                    if (e.getOrganization().getDisambiguatedOrganization() != null)
                        organisationIds.get(SolrConstants.RINGGOLD_ORGANISATION_ID).add(e.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier());
                }
            }
        }
        if (record.getActivitiesSummary() != null && record.getActivitiesSummary().getEmployments() != null && record.getActivitiesSummary().getEmployments().getSummaries() != null) {
            for (EmploymentSummary e : record.getActivitiesSummary().getEmployments().getSummaries()) {
                if (e.getOrganization() != null) {
                    organisationNames.get(SolrConstants.AFFILIATION_ORGANISATION_NAME).add(e.getOrganization().getName());
                    if (e.getOrganization().getDisambiguatedOrganization() != null)
                        organisationIds.get(SolrConstants.RINGGOLD_ORGANISATION_ID).add(e.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier());
                }
            }
        }
        profileIndexDocument.setOrganisationIds(organisationIds);
        profileIndexDocument.setOrganisationNames(organisationNames);
    }
    if (indexProfile) {
        try {
            StringWriter sw = new StringWriter();
            jaxbContext_2_0_api.createMarshaller().marshal(record, sw);
            profileIndexDocument.setPublicProfileMessage(sw.getBuffer().toString());
        } catch (JAXBException e) {
            LOG.error("problem marshalling xml", e);
        }
    }
    LOG.debug(profileIndexDocument.toString());
    return profileIndexDocument;
}
Also used : HashMap(java.util.HashMap) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) ArrayList(java.util.ArrayList) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) StringWriter(java.io.StringWriter) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) JAXBException(javax.xml.bind.JAXBException) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) EducationSummary(org.orcid.jaxb.model.record.summary_v2.EducationSummary) EmploymentSummary(org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)

Example 10 with OrcidSolrDocument

use of org.orcid.utils.solr.entities.OrcidSolrDocument in project ORCID-Source by ORCID.

the class SolrIndexUpdater method updateSolrIndexForLockedOrDeprecatedRecord.

/** Updates solr with just the ORCID and lastUpdated, blanking the record.
     * 
     * @param orcid
     * @param lastUpdated
     */
public void updateSolrIndexForLockedOrDeprecatedRecord(String orcid, Date lastUpdated) {
    OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
    profileIndexDocument.setOrcid(orcid);
    profileIndexDocument.setProfileLastModifiedDate(lastUpdated);
    this.persist(profileIndexDocument);
}
Also used : OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument)

Aggregations

OrcidSolrDocument (org.orcid.utils.solr.entities.OrcidSolrDocument)31 Test (org.junit.Test)16 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)12 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)11 OrcidSolrResult (org.orcid.utils.solr.entities.OrcidSolrResult)9 ArrayList (java.util.ArrayList)4 BaseTest (org.orcid.core.BaseTest)4 Funding (org.orcid.jaxb.model.record_v2.Funding)4 Rollback (org.springframework.test.annotation.Rollback)4 HashMap (java.util.HashMap)3 List (java.util.List)3 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)3 Record (org.orcid.jaxb.model.record_v2.Record)3 OrcidRecordToSolrDocument (org.orcid.listener.solr.OrcidRecordToSolrDocument)3 OrcidSolrResults (org.orcid.utils.solr.entities.OrcidSolrResults)3 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)2 Email (org.orcid.jaxb.model.message.Email)2 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)2 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)2 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)2