use of org.orcid.jaxb.model.record_v2.FundingTitle 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;
}
use of org.orcid.jaxb.model.record_v2.FundingTitle in project ORCID-Source by ORCID.
the class ActivitiesGroupGenerator_GroupingFundingsTest method generateFundings.
/**
* funding-1 -> A, B, C
* funding-2 -> C, D, E
* funding-3 -> X, Y, Z
* funding-4 -> Y, B, 1
* funding-5 -> M, N, O
* funding-6 -> O, P, Q
* funding-7 -> 1, 2, B
* funding-8 -> No external identifiers
* funding-9 -> No external identifiers
* */
private Map<String, FundingSummary> generateFundings() {
Map<String, FundingSummary> result = new HashMap<String, FundingSummary>();
for (int i = 1; i < 10; i++) {
String name = "funding-" + i;
FundingSummary funding = new FundingSummary();
FundingTitle title = new FundingTitle();
title.setTitle(new Title(name));
funding.setTitle(title);
ExternalIDs fei = new ExternalIDs();
switch(i) {
case 1:
ExternalID f1 = new ExternalID();
f1.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f1.setValue("A");
ExternalID f2 = new ExternalID();
f2.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f2.setValue("B");
ExternalID f3 = new ExternalID();
f3.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f3.setValue("C");
fei.getExternalIdentifier().add(f1);
fei.getExternalIdentifier().add(f2);
fei.getExternalIdentifier().add(f3);
break;
case 2:
ExternalID f4 = new ExternalID();
f4.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f4.setValue("C");
ExternalID f5 = new ExternalID();
f5.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f5.setValue("D");
ExternalID f6 = new ExternalID();
f6.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f6.setValue("E");
fei.getExternalIdentifier().add(f4);
fei.getExternalIdentifier().add(f5);
fei.getExternalIdentifier().add(f6);
break;
case 3:
ExternalID f7 = new ExternalID();
f7.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f7.setValue("X");
ExternalID f8 = new ExternalID();
f8.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f8.setValue("Y");
ExternalID f9 = new ExternalID();
f9.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f9.setValue("Z");
fei.getExternalIdentifier().add(f7);
fei.getExternalIdentifier().add(f8);
fei.getExternalIdentifier().add(f9);
break;
case 4:
ExternalID f10 = new ExternalID();
f10.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f10.setValue("Y");
ExternalID f11 = new ExternalID();
f11.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f11.setValue("B");
ExternalID f12 = new ExternalID();
f12.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f12.setValue("1");
fei.getExternalIdentifier().add(f10);
fei.getExternalIdentifier().add(f11);
fei.getExternalIdentifier().add(f12);
break;
case 5:
ExternalID f13 = new ExternalID();
f13.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f13.setValue("M");
ExternalID f14 = new ExternalID();
f14.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f14.setValue("N");
ExternalID f15 = new ExternalID();
f15.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f15.setValue("O");
fei.getExternalIdentifier().add(f13);
fei.getExternalIdentifier().add(f14);
fei.getExternalIdentifier().add(f15);
break;
case 6:
ExternalID f16 = new ExternalID();
f16.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f16.setValue("O");
ExternalID f17 = new ExternalID();
f17.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f17.setValue("P");
ExternalID f18 = new ExternalID();
f18.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f18.setValue("Q");
fei.getExternalIdentifier().add(f16);
fei.getExternalIdentifier().add(f17);
fei.getExternalIdentifier().add(f18);
break;
case 7:
ExternalID f19 = new ExternalID();
f19.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f19.setValue("1");
ExternalID f20 = new ExternalID();
f20.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f20.setValue("2");
ExternalID f21 = new ExternalID();
f21.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
f21.setValue("B");
fei.getExternalIdentifier().add(f19);
fei.getExternalIdentifier().add(f20);
fei.getExternalIdentifier().add(f21);
break;
}
funding.setExternalIdentifiers(fei);
result.put(name, funding);
}
return result;
}
use of org.orcid.jaxb.model.record_v2.FundingTitle in project ORCID-Source by ORCID.
the class SourceInActivitiesTest method getFundingWithoutExtIdentifiers.
private ProfileFundingEntity getFundingWithoutExtIdentifiers(String userOrcid) {
Funding funding = new Funding();
funding.setOrganization(getOrganization());
FundingTitle title = new FundingTitle();
title.setTitle(new Title("Title " + System.currentTimeMillis()));
funding.setTitle(title);
funding.setType(org.orcid.jaxb.model.record_v2.FundingType.AWARD);
funding = profileFundingManager.createFunding(userOrcid, funding, true);
return profileFundingManager.getProfileFundingEntity(funding.getPutCode());
}
use of org.orcid.jaxb.model.record_v2.FundingTitle in project ORCID-Source by ORCID.
the class SourceInActivitiesTest method getFunding.
private Funding getFunding(String userOrcid) {
Funding funding = new Funding();
funding.setOrganization(getOrganization());
FundingTitle title = new FundingTitle();
title.setTitle(new Title("Title " + System.currentTimeMillis()));
funding.setTitle(title);
funding.setType(org.orcid.jaxb.model.record_v2.FundingType.AWARD);
ExternalID extId = new ExternalID();
extId.setValue("111");
extId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
extId.setUrl(new Url("http://test.com"));
extId.setRelationship(Relationship.PART_OF);
ExternalIDs extIdentifiers = new ExternalIDs();
extIdentifiers.getExternalIdentifier().add(extId);
funding.setExternalIdentifiers(extIdentifiers);
funding = profileFundingManager.createFunding(userOrcid, funding, true);
return profileFundingManager.getFunding(userOrcid, funding.getPutCode());
}
use of org.orcid.jaxb.model.record_v2.FundingTitle in project ORCID-Source by ORCID.
the class FundingForm method valueOf.
public static FundingForm valueOf(Funding funding) {
FundingForm result = new FundingForm();
result.setDateSortString(PojoUtil.createDateSortString(funding.getStartDate(), funding.getEndDate()));
if (funding.getPutCode() != null)
result.setPutCode(Text.valueOf(funding.getPutCode()));
if (funding.getAmount() != null) {
if (StringUtils.isNotEmpty(funding.getAmount().getContent())) {
String cleanNumber = funding.getAmount().getContent().trim();
result.setAmount(Text.valueOf(cleanNumber));
}
if (funding.getAmount().getCurrencyCode() != null)
result.setCurrencyCode(Text.valueOf(funding.getAmount().getCurrencyCode()));
else
result.setCurrencyCode(new Text());
} else {
result.setAmount(new Text());
result.setCurrencyCode(new Text());
}
if (StringUtils.isNotEmpty(funding.getDescription()))
result.setDescription(Text.valueOf(funding.getDescription()));
else
result.setDescription(new Text());
if (funding.getStartDate() != null)
result.setStartDate(Date.valueOf(funding.getStartDate()));
if (funding.getEndDate() != null)
result.setEndDate(Date.valueOf(funding.getEndDate()));
if (funding.getType() != null)
result.setFundingType(Text.valueOf(funding.getType().value()));
else
result.setFundingType(new Text());
if (funding.getOrganizationDefinedType() != null) {
OrgDefinedFundingSubType OrgDefinedFundingSubType = new OrgDefinedFundingSubType();
OrgDefinedFundingSubType.setSubtype(Text.valueOf(funding.getOrganizationDefinedType().getContent()));
OrgDefinedFundingSubType.setAlreadyIndexed(false);
result.setOrganizationDefinedFundingSubType(OrgDefinedFundingSubType);
}
Source source = funding.getSource();
if (source != null) {
result.setSource(source.retrieveSourcePath());
if (source.getSourceName() != null) {
result.setSourceName(source.getSourceName().getContent());
}
}
if (funding.getTitle() != null) {
FundingTitleForm fundingTitle = new FundingTitleForm();
if (funding.getTitle().getTitle() != null)
fundingTitle.setTitle(Text.valueOf(funding.getTitle().getTitle().getContent()));
else
fundingTitle.setTitle(new Text());
if (funding.getTitle().getTranslatedTitle() != null) {
TranslatedTitleForm translatedTitle = new TranslatedTitleForm();
translatedTitle.setContent(funding.getTitle().getTranslatedTitle().getContent());
translatedTitle.setLanguageCode(funding.getTitle().getTranslatedTitle().getLanguageCode());
fundingTitle.setTranslatedTitle(translatedTitle);
}
result.setFundingTitle(fundingTitle);
} else {
FundingTitleForm fundingTitle = new FundingTitleForm();
fundingTitle.setTitle(new Text());
result.setFundingTitle(fundingTitle);
}
if (funding.getUrl() != null)
result.setUrl(Text.valueOf(funding.getUrl().getValue()));
else
result.setUrl(new Text());
if (funding.getVisibility() != null)
result.setVisibility(Visibility.valueOf(funding.getVisibility()));
// Set the disambiguated organization
Organization organization = funding.getOrganization();
result.setFundingName(Text.valueOf(organization.getName()));
DisambiguatedOrganization disambiguatedOrganization = organization.getDisambiguatedOrganization();
if (disambiguatedOrganization != null) {
if (StringUtils.isNotEmpty(disambiguatedOrganization.getDisambiguatedOrganizationIdentifier())) {
result.setDisambiguatedFundingSourceId(Text.valueOf(disambiguatedOrganization.getDisambiguatedOrganizationIdentifier()));
result.setDisambiguationSource(Text.valueOf(disambiguatedOrganization.getDisambiguationSource()));
}
}
OrganizationAddress organizationAddress = organization.getAddress();
if (organizationAddress != null) {
if (!PojoUtil.isEmpty(organizationAddress.getCity()))
result.setCity(Text.valueOf(organizationAddress.getCity()));
else
result.setCity(new Text());
if (!PojoUtil.isEmpty(organizationAddress.getRegion()))
result.setRegion(Text.valueOf(organizationAddress.getRegion()));
else
result.setRegion(new Text());
if (organizationAddress.getCountry() != null)
result.setCountry(Text.valueOf(organizationAddress.getCountry().value()));
else
result.setCountry(new Text());
} else {
result.setCountry(new Text());
result.setCity(new Text());
result.setRegion(new Text());
}
// Set contributors
if (funding.getContributors() != null) {
List<Contributor> contributors = new ArrayList<Contributor>();
for (FundingContributor fContributor : funding.getContributors().getContributor()) {
Contributor contributor = Contributor.valueOf(fContributor);
contributors.add(contributor);
}
result.setContributors(contributors);
}
List<FundingExternalIdentifierForm> externalIdentifiersList = new ArrayList<FundingExternalIdentifierForm>();
// Set external identifiers
if (funding.getExternalIdentifiers() != null) {
for (ExternalID fExternalIdentifier : funding.getExternalIdentifiers().getExternalIdentifier()) {
FundingExternalIdentifierForm fundingExternalIdentifierForm = FundingExternalIdentifierForm.valueOf(fExternalIdentifier);
externalIdentifiersList.add(fundingExternalIdentifierForm);
}
}
result.setExternalIdentifiers(externalIdentifiersList);
result.setCreatedDate(Date.valueOf(funding.getCreatedDate()));
result.setLastModified(Date.valueOf(funding.getLastModifiedDate()));
return result;
}
Aggregations