use of org.orcid.jaxb.model.record_v2.PersonExternalIdentifier 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.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method testUnmarshallPerson.
@Test
public void testUnmarshallPerson() throws SAXException, URISyntaxException {
Person person = (Person) unmarshallFromPath("/record_2.0/samples/read_samples/person-2.0.xml", Person.class, "/record_2.0/person-2.0.xsd");
assertNotNull(person);
assertNotNull(person.getName());
assertEquals("give-names", person.getName().getGivenNames().getContent());
assertEquals("family-name", person.getName().getFamilyName().getContent());
assertEquals("credit-name", person.getName().getCreditName().getContent());
assertEquals(Visibility.PUBLIC, person.getName().getVisibility());
assertNotNull(person.getOtherNames());
assertNotNull(person.getOtherNames().getOtherNames());
assertEquals(1, person.getOtherNames().getOtherNames().size());
OtherName otherName = person.getOtherNames().getOtherNames().get(0);
assertEquals("other-name-1", otherName.getContent());
assertNotNull(otherName.getCreatedDate());
assertNotNull(otherName.getCreatedDate().getValue());
assertEquals(2001, otherName.getCreatedDate().getValue().getYear());
assertEquals(12, otherName.getCreatedDate().getValue().getMonth());
assertEquals(31, otherName.getCreatedDate().getValue().getDay());
assertNotNull(otherName.getLastModifiedDate().getValue());
assertEquals(2001, otherName.getLastModifiedDate().getValue().getYear());
assertEquals(12, otherName.getLastModifiedDate().getValue().getMonth());
assertEquals(31, otherName.getLastModifiedDate().getValue().getDay());
assertNotNull(otherName.getSource());
assertEquals("8888-8888-8888-8880", otherName.getSource().retrieveSourcePath());
assertNotNull(person.getBiography());
assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility());
assertEquals("biography", person.getBiography().getContent());
assertNotNull(person.getResearcherUrls());
assertNotNull(person.getResearcherUrls().getResearcherUrls());
assertEquals(1, person.getResearcherUrls().getResearcherUrls().size());
ResearcherUrl rUrl = person.getResearcherUrls().getResearcherUrls().get(0);
assertEquals(Visibility.PUBLIC, rUrl.getVisibility());
assertEquals(Long.valueOf(1248), rUrl.getPutCode());
assertEquals("url-name-1", rUrl.getUrlName());
assertNotNull(rUrl.getUrl());
assertEquals("http://url.com/", rUrl.getUrl().getValue());
assertNotNull(rUrl.getCreatedDate());
assertEquals(2001, rUrl.getCreatedDate().getValue().getYear());
assertEquals(12, rUrl.getCreatedDate().getValue().getMonth());
assertEquals(31, rUrl.getCreatedDate().getValue().getDay());
assertNotNull(rUrl.getLastModifiedDate());
assertEquals(2001, rUrl.getLastModifiedDate().getValue().getYear());
assertEquals(12, rUrl.getLastModifiedDate().getValue().getMonth());
assertEquals(31, rUrl.getLastModifiedDate().getValue().getDay());
assertNotNull(rUrl.getSource());
assertEquals("8888-8888-8888-8880", rUrl.getSource().retrieveSourcePath());
assertNotNull(person.getEmails());
assertNotNull(person.getEmails().getEmails());
assertEquals(1, person.getEmails().getEmails().size());
Email email = person.getEmails().getEmails().get(0);
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("user1@email.com", email.getEmail());
assertNotNull(email.getCreatedDate());
assertNotNull(email.getCreatedDate().getValue());
assertEquals(2001, email.getCreatedDate().getValue().getYear());
assertEquals(12, email.getCreatedDate().getValue().getMonth());
assertEquals(31, email.getCreatedDate().getValue().getDay());
assertNotNull(email.getLastModifiedDate());
assertNotNull(email.getLastModifiedDate().getValue());
assertEquals(2001, email.getLastModifiedDate().getValue().getYear());
assertEquals(12, email.getLastModifiedDate().getValue().getMonth());
assertEquals(31, email.getLastModifiedDate().getValue().getDay());
assertNotNull(email.getSource());
assertEquals("8888-8888-8888-8880", email.retrieveSourcePath());
assertNotNull(person.getAddresses());
assertNotNull(person.getAddresses().getAddress());
assertEquals(1, person.getAddresses().getAddress().size());
Address address = person.getAddresses().getAddress().get(0);
assertEquals(Visibility.PUBLIC, address.getVisibility());
assertEquals(Long.valueOf(1), address.getPutCode());
assertNotNull(address.getCountry());
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getCreatedDate().getValue());
assertEquals(2001, address.getCreatedDate().getValue().getYear());
assertEquals(12, address.getCreatedDate().getValue().getMonth());
assertEquals(31, address.getCreatedDate().getValue().getDay());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getLastModifiedDate().getValue());
assertEquals(2001, address.getLastModifiedDate().getValue().getYear());
assertEquals(12, address.getLastModifiedDate().getValue().getMonth());
assertEquals(31, address.getLastModifiedDate().getValue().getDay());
assertNotNull(address.getSource());
assertEquals("8888-8888-8888-8880", address.getSource().retrieveSourcePath());
assertNotNull(person.getKeywords());
assertNotNull(person.getKeywords().getKeywords());
assertEquals(1, person.getKeywords().getKeywords().size());
Keyword keyword = person.getKeywords().getKeywords().get(0);
assertEquals(Visibility.PUBLIC, keyword.getVisibility());
assertEquals(Long.valueOf(1), keyword.getPutCode());
assertEquals("keyword1", keyword.getContent());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getCreatedDate().getValue());
assertEquals(2001, keyword.getCreatedDate().getValue().getYear());
assertEquals(12, keyword.getCreatedDate().getValue().getMonth());
assertEquals(31, keyword.getCreatedDate().getValue().getDay());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getLastModifiedDate().getValue());
assertEquals(2001, keyword.getLastModifiedDate().getValue().getYear());
assertEquals(12, keyword.getLastModifiedDate().getValue().getMonth());
assertEquals(31, keyword.getLastModifiedDate().getValue().getDay());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
assertNotNull(person.getExternalIdentifiers());
assertNotNull(person.getExternalIdentifiers().getExternalIdentifiers());
assertEquals(1, person.getExternalIdentifiers().getExternalIdentifiers().size());
PersonExternalIdentifier extId = person.getExternalIdentifiers().getExternalIdentifiers().get(0);
assertEquals(Visibility.PUBLIC, extId.getVisibility());
assertEquals(Long.valueOf(1), extId.getPutCode());
assertEquals("type-1", extId.getType());
assertEquals("value-1", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://url.com/1", extId.getUrl().getValue());
assertNotNull(extId.getCreatedDate());
assertNotNull(extId.getCreatedDate().getValue());
assertEquals(2001, extId.getCreatedDate().getValue().getYear());
assertEquals(12, extId.getCreatedDate().getValue().getMonth());
assertEquals(31, extId.getCreatedDate().getValue().getDay());
assertNotNull(extId.getLastModifiedDate());
assertNotNull(extId.getLastModifiedDate().getValue());
assertEquals(2001, extId.getLastModifiedDate().getValue().getYear());
assertEquals(12, extId.getLastModifiedDate().getValue().getMonth());
assertEquals(31, extId.getLastModifiedDate().getValue().getDay());
assertNotNull(extId.getSource());
assertEquals("8888-8888-8888-8880", extId.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_v2.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method unmarshallFromPath.
private Object unmarshallFromPath(String path, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type, schemaPath);
Object result = null;
if (ResearcherUrls.class.equals(type)) {
result = (ResearcherUrls) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (PersonExternalIdentifiers.class.equals(type)) {
result = (PersonExternalIdentifiers) obj;
} else if (Biography.class.equals(type)) {
result = (Biography) obj;
} else if (Name.class.equals(type)) {
result = (Name) obj;
} else if (CreditName.class.equals(type)) {
result = (CreditName) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (OtherNames.class.equals(type)) {
result = (OtherNames) obj;
} else if (Keywords.class.equals(type)) {
result = (Keywords) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Addresses.class.equals(type)) {
result = (Addresses) obj;
} else if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Emails.class.equals(type)) {
result = (Emails) obj;
} else if (Email.class.equals(type)) {
result = (Email) obj;
} else if (Person.class.equals(type)) {
result = (Person) obj;
} else if (Deprecated.class.equals(type)) {
result = (Deprecated) obj;
} else if (Preferences.class.equals(type)) {
result = (Preferences) obj;
} else if (History.class.equals(type)) {
result = (History) obj;
} else if (Record.class.equals(type)) {
result = (Record) obj;
} else if (ActivitiesSummary.class.equals(type)) {
result = (ActivitiesSummary) obj;
} else if (Works.class.equals(type)) {
result = (Works) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
use of org.orcid.jaxb.model.record_v2.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method testUnmarshallExternalIdentifiers.
@Test
public void testUnmarshallExternalIdentifiers() throws SAXException, URISyntaxException {
PersonExternalIdentifiers externalIdentifiers = (PersonExternalIdentifiers) unmarshallFromPath("/record_2.0/samples/read_samples/external-identifiers-2.0.xml", PersonExternalIdentifiers.class, "/record_2.0/person-external-identifier-2.0.xsd");
assertNotNull(externalIdentifiers);
assertNotNull(externalIdentifiers.getExternalIdentifiers());
assertEquals(2, externalIdentifiers.getExternalIdentifiers().size());
for (PersonExternalIdentifier extId : externalIdentifiers.getExternalIdentifiers()) {
assertThat(extId.getPutCode(), anyOf(is(1L), is(2L)));
assertThat(extId.getType(), anyOf(is("common-name-1"), is("common-name-2")));
assertThat(extId.getValue(), anyOf(is("id-reference-1"), is("id-reference-2")));
assertNotNull(extId.getUrl());
assertThat(extId.getUrl().getValue(), anyOf(is("http://url/1"), is("http://url/2")));
assertNotNull(extId.getCreatedDate());
assertNotNull(extId.getLastModifiedDate());
assertNotNull(extId.getSource());
assertEquals("8888-8888-8888-8880", extId.getSource().retrieveSourcePath());
}
PersonExternalIdentifier extId = (PersonExternalIdentifier) unmarshallFromPath("/record_2.0/samples/read_samples/external-identifier-2.0.xml", PersonExternalIdentifier.class);
assertNotNull(extId);
assertEquals("A-0003", extId.getType());
assertEquals(Long.valueOf(1), extId.getPutCode());
assertEquals("A-0003", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://ext-id/A-0003", extId.getUrl().getValue());
assertEquals(Visibility.PUBLIC.value(), extId.getVisibility().value());
assertNotNull(extId.getCreatedDate());
assertNotNull(extId.getLastModifiedDate());
assertNotNull(extId.getSource());
assertEquals("8888-8888-8888-8880", extId.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_v2.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class OrcidInfo method publicPreview.
@RequestMapping(value = { "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}", "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/print" })
public ModelAndView publicPreview(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") int pageNo, @RequestParam(value = "v", defaultValue = "0") int v, @RequestParam(value = "maxResults", defaultValue = "15") int maxResults, @PathVariable("orcid") String orcid) {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (Exception e) {
return new ModelAndView("error-404");
}
try {
// Check if the profile is deprecated, non claimed or locked
orcidSecurityManager.checkProfile(orcid);
} catch (OrcidDeprecatedException | OrcidNotClaimedException | LockedException e) {
ModelAndView mav = new ModelAndView("public_profile_unavailable");
mav.addObject("effectiveUserOrcid", orcid);
String displayName = "";
if (e instanceof OrcidDeprecatedException) {
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
mav.addObject("deprecated", true);
mav.addObject("primaryRecord", profile.getPrimaryRecord().getId());
} else if (e instanceof OrcidNotClaimedException) {
displayName = localeManager.resolveMessage("orcid.reserved_for_claim");
} else {
mav.addObject("locked", true);
mav.addObject("isPublicProfile", true);
displayName = localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name");
}
if (!PojoUtil.isEmpty(displayName)) {
mav.addObject("title", getMessage("layout.public-layout.title", displayName, orcid));
mav.addObject("displayName", displayName);
}
return mav;
}
long lastModifiedTime = getLastModifiedTime(orcid);
ModelAndView mav = null;
if (request.getRequestURI().contains("/print")) {
mav = new ModelAndView("print_public_record");
mav.addObject("hideUserVoiceScript", true);
} else {
mav = new ModelAndView("public_profile_v3");
}
mav.addObject("isPublicProfile", true);
mav.addObject("effectiveUserOrcid", orcid);
mav.addObject("lastModifiedTime", lastModifiedTime);
boolean isProfileEmtpy = true;
HttpSession session = request.getSession(false);
if (session != null) {
session.removeAttribute(PUBLIC_WORKS_RESULTS_ATTRIBUTE);
}
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
// Fill personal details
if (publicPersonalDetails != null) {
// Get display name
String displayName = "";
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
if (!PojoUtil.isEmpty(displayName)) {
// <Published Name> (<ORCID iD>) - ORCID | Connecting Research
// and Researchers
mav.addObject("title", getMessage("layout.public-layout.title", displayName.trim(), orcid));
mav.addObject("displayName", displayName);
}
// Get biography
if (publicPersonalDetails.getBiography() != null) {
Biography bio = publicPersonalDetails.getBiography();
if (org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.equals(bio.getVisibility()) && !PojoUtil.isEmpty(bio.getContent())) {
isProfileEmtpy = false;
mav.addObject("biography", bio);
}
}
// Fill other names
OtherNames publicOtherNames = publicPersonalDetails.getOtherNames();
if (publicOtherNames != null && publicOtherNames.getOtherNames() != null) {
Iterator<OtherName> it = publicOtherNames.getOtherNames().iterator();
while (it.hasNext()) {
OtherName otherName = it.next();
if (!org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.equals(otherName.getVisibility())) {
it.remove();
}
}
}
Map<String, List<OtherName>> groupedOtherNames = groupOtherNames(publicOtherNames);
mav.addObject("publicGroupedOtherNames", groupedOtherNames);
}
// Fill biography elements
// Fill country
Addresses publicAddresses = addressManager.getPublicAddresses(orcid, lastModifiedTime);
Map<String, String> countryNames = new HashMap<String, String>();
if (publicAddresses != null && publicAddresses.getAddress() != null) {
Address publicAddress = null;
// The primary address will be the one with the lowest display index
for (Address address : publicAddresses.getAddress()) {
countryNames.put(address.getCountry().getValue().value(), getcountryName(address.getCountry().getValue().value()));
if (publicAddress == null) {
publicAddress = address;
}
}
if (publicAddress != null) {
mav.addObject("publicAddress", publicAddress);
mav.addObject("countryNames", countryNames);
Map<String, List<Address>> groupedAddresses = groupAddresses(publicAddresses);
mav.addObject("publicGroupedAddresses", groupedAddresses);
}
}
// Fill keywords
Keywords publicKeywords = keywordManager.getPublicKeywords(orcid, lastModifiedTime);
Map<String, List<Keyword>> groupedKeywords = groupKeywords(publicKeywords);
mav.addObject("publicGroupedKeywords", groupedKeywords);
// Fill researcher urls
ResearcherUrls publicResearcherUrls = researcherUrlManager.getPublicResearcherUrls(orcid, lastModifiedTime);
Map<String, List<ResearcherUrl>> groupedResearcherUrls = groupResearcherUrls(publicResearcherUrls);
mav.addObject("publicGroupedResearcherUrls", groupedResearcherUrls);
// Fill emails
Emails publicEmails = emailManager.getPublicEmails(orcid, lastModifiedTime);
Map<String, List<Email>> groupedEmails = groupEmails(publicEmails);
mav.addObject("publicGroupedEmails", groupedEmails);
// Fill external identifiers
PersonExternalIdentifiers publicPersonExternalIdentifiers = externalIdentifierManager.getPublicExternalIdentifiers(orcid, lastModifiedTime);
Map<String, List<PersonExternalIdentifier>> groupedExternalIdentifiers = groupExternalIdentifiers(publicPersonExternalIdentifiers);
mav.addObject("publicGroupedPersonExternalIdentifiers", groupedExternalIdentifiers);
LinkedHashMap<Long, WorkForm> minimizedWorksMap = new LinkedHashMap<>();
LinkedHashMap<Long, Affiliation> affiliationMap = new LinkedHashMap<>();
LinkedHashMap<Long, Funding> fundingMap = new LinkedHashMap<>();
LinkedHashMap<Long, PeerReview> peerReviewMap = new LinkedHashMap<>();
minimizedWorksMap = activityCacheManager.pubMinWorksMap(orcid, lastModifiedTime);
if (minimizedWorksMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("worksEmpty", true);
}
affiliationMap = affiliationMap(orcid, lastModifiedTime);
if (affiliationMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("affiliationsEmpty", true);
}
fundingMap = fundingMap(orcid, lastModifiedTime);
if (fundingMap.size() > 0)
isProfileEmtpy = false;
else {
mav.addObject("fundingEmpty", true);
}
peerReviewMap = peerReviewMap(orcid, lastModifiedTime);
if (peerReviewMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("peerReviewsEmpty", true);
}
ObjectMapper mapper = new ObjectMapper();
try {
String worksIdsJson = mapper.writeValueAsString(minimizedWorksMap.keySet());
String affiliationIdsJson = mapper.writeValueAsString(affiliationMap.keySet());
String fundingIdsJson = mapper.writeValueAsString(fundingMap.keySet());
String peerReviewIdsJson = mapper.writeValueAsString(peerReviewMap.keySet());
mav.addObject("workIdsJson", StringEscapeUtils.escapeEcmaScript(worksIdsJson));
mav.addObject("affiliationIdsJson", StringEscapeUtils.escapeEcmaScript(affiliationIdsJson));
mav.addObject("fundingIdsJson", StringEscapeUtils.escapeEcmaScript(fundingIdsJson));
mav.addObject("peerReviewIdsJson", StringEscapeUtils.escapeEcmaScript(peerReviewIdsJson));
mav.addObject("isProfileEmpty", isProfileEmtpy);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (!profile.isReviewed()) {
if (isProfileValidForIndex(profile)) {
int countTokens = orcidOauth2TokenService.findCountByUserName(orcid, lastModifiedTime);
if (!profile.isAccountNonLocked() || countTokens == 0 || (!CreationMethod.WEBSITE.value().equals(profile.getCreationMethod()) && !CreationMethod.DIRECT.value().equals(profile.getCreationMethod()))) {
mav.addObject("noIndex", true);
}
} else {
mav.addObject("noIndex", true);
}
}
return mav;
}
Aggregations