@Override public ExternalIDs getAllExternalIDs(String orcid) { List<WorkSummary> summaries = getWorksSummaryList(orcid); ExternalIDs ids = new ExternalIDs(); for (WorkSummary s:summaries){ for (ExternalID id: s.getExternalIdentifiers().getExternalIdentifier()){ if (!ids.getExternalIdentifier().contains(id)){ ids.getExternalIdentifier().add(id); } } } return ids; }
private void addExternalIdsToExistingSet(Work work, Set<ExternalID> existingExternalIDs) { if(work != null && work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null) { for(ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) { //Don't include PART_OF external ids if(!Relationship.PART_OF.equals(extId.getRelationship())) { existingExternalIDs.add(extId); } } } }
public static ExternalIDs valueOf(org.orcid.jaxb.model.message.WorkExternalIdentifiers messageWorkExternalIdentifiers) { ExternalIDs ids = new ExternalIDs(); for (WorkExternalIdentifier id : messageWorkExternalIdentifiers.getWorkExternalIdentifier()){ ids.getExternalIdentifier().add(ExternalID.fromMessageExtId(id)); } return ids; }
/** * Merges in the DOI from a work into a CSLItemdata (if found and not * already present) * * @param work * @param item */ private String extractID(Work work, WorkExternalIdentifierType type) { if (work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null && work.getExternalIdentifiers().getExternalIdentifier().size() > 0) { for (ExternalID id : work.getExternalIdentifiers().getExternalIdentifier()) { if (id.getType().equalsIgnoreCase(type.value())) { return id.getValue(); } } } return null; }
/** * Merges in the DOI from a work into a CSLItemdata (if found and not * already present) * * @param work * @param item */ private String extractID(Work work, WorkExternalIdentifierType type) { if (work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null && work.getExternalIdentifiers().getExternalIdentifier().size() > 0) { for (ExternalID id : work.getExternalIdentifiers().getExternalIdentifier()) { if (id.getType().equalsIgnoreCase(type.value())) { return id.getValue(); } } } return null; }
public void checkFundingExternalIdentifiersForDuplicates(ExternalIDs newExtIds, ExternalIDs existingExtIds, Source existingSource, Source activeSource) { if (existingExtIds != null && newExtIds != null) { for (ExternalID existingId : existingExtIds.getExternalIdentifier()) { for (ExternalID newId : newExtIds.getExternalIdentifier()) { if (areRelationshipsSameAndSelf(existingId.getRelationship(), newId.getRelationship()) && newId.equals(existingId) && SourceEntityUtils.isTheSameForDuplicateChecking(activeSource,existingSource)) { Map<String, String> params = new HashMap<String, String>(); params.put("clientName", SourceEntityUtils.getSourceName(activeSource)); throw new OrcidDuplicatedActivityException(params); } } } } }
private Work checkWorkAndIdentifierTypes(Work work) { if (WorkType.BOOK_CHAPTER.equals(work.getWorkType())) { for (ExternalID externalID : work.getExternalIdentifiers().getExternalIdentifier()) { if ("isbn".equals(externalID.getType())) { externalID.setRelationship(Relationship.PART_OF); } } } return work; }
@Override public FindMyStuffResult find(String orcid, ExternalIDs existingIDs) { FindMyStuffResult result = new FindMyStuffResult(); result.setFinderName(getFinderName()); if (!isEnabled()) return result; try { InputStream is = cache.get(metadataEndpoint + orcid, "application/json"); ObjectMapper objectMapper = new ObjectMapper(); CrossrefSearchResult crResult = objectMapper.readValue(is, CrossrefSearchResult.class); for (CrossrefItem w : crResult.message.items) { if (!existingIDs.getExternalIdentifier().contains(w.getExternalID(norm))) { String title = (w.title!=null && !w.title.isEmpty())? w.title.get(0):""; result.getResults().add(new FindMyStuffItem(w.DOI, "doi", title)); } } result.setTotal(crResult.message.totalResults); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
/** * Return the list of existing external identifiers for the given user where the source matches the given sourceId * * @param existingWorks * The list of existing works for the current user * @param activeSource * The client id we are evaluating * @return A set of all the existing external identifiers that belongs to the given user and to the given source id * */ private Set<ExternalID> buildExistingExternalIdsSet(List<Work> existingWorks, Source activeSource) { Set<ExternalID> existingExternalIds = new HashSet<ExternalID>(); for(Work work : existingWorks) { //If it is the same source if(SourceEntityUtils.isTheSameForDuplicateChecking(activeSource, work.getSource())) { if(work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null) { for(ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) { //Don't include PART_OF external ids if(!Relationship.PART_OF.equals(extId.getRelationship())) { existingExternalIds.add(extId); } } } } } return existingExternalIds; }
public void validateFunding(ExternalIDs ids) { if (ids == null) // urgh return; List<String> errors = Lists.newArrayList(); for (ExternalID id : ids.getExternalIdentifier()) { if (id.getType() == null || !identifierTypeManager.fetchIdentifierTypesByAPITypeName(null).containsKey(id.getType())) { errors.add(id.getType()); } if(PojoUtil.isEmpty(id.getValue())) { errors.add("value"); } if(requireRelationshipOnExternalIdentifier) { if(id.getRelationship() == null) { errors.add("relationship"); } } } checkAndThrow(errors); }
@Override public FindMyStuffResult find(String orcid, ExternalIDs existingIDs) { FindMyStuffResult result = new FindMyStuffResult(); result.setFinderName(getFinderName()); if (!isEnabled()) return result; try { InputStream is = cache.get(metadataEndpoint + orcid, "application/json"); ObjectMapper objectMapper = new ObjectMapper(); DataciteSearchResult dcResult = objectMapper.readValue(is, DataciteSearchResult.class); for (DataciteSimpleWork w : dcResult.data) { if (!existingIDs.getExternalIdentifier().contains(w.attributes.getExternalID())) { result.getResults().add(new FindMyStuffItem(w.attributes.doi, "doi", w.attributes.title)); } } result.setTotal(dcResult.meta.total); } catch (MalformedURLException e) { // do nothing } catch (IOException e) { // do nothing } return result; }
public GroupPojo(List<T> summaries, int id, String orcid, ExternalIDs ids){ setGroupId(id); Long maxDisplayIndex = null; setActivities(new ArrayList<T>()); for (T summary : summaries) { getActivities().add(summary); Long displayIndex = Long.parseLong(summary.getDisplayIndex()); if (maxDisplayIndex == null || displayIndex > maxDisplayIndex) { maxDisplayIndex = displayIndex; setActivePutCode(summary.getPutCode()); setActiveVisibility(summary.getVisibility().name()); setDefaultActivity(summary); } if (summary.getSource().retrieveSourcePath().equals(orcid)) { setUserVersionPresent(true); } } if (ids != null) { for (ExternalID extId : ids.getExternalIdentifier()) { if (extId.getRelationship() == null) { extId.setRelationship(Relationship.SELF); } externalIdentifiers.add(ActivityExternalIdentifier.valueOf(extId)); } } }
public void checkExternalIdentifiersForDuplicates(ExternalIDs newExtIds, ExternalIDs existingExtIds, Source existingSource, Source activeSource) { if (existingExtIds != null && newExtIds != null) { for (ExternalID existingId : existingExtIds.getExternalIdentifier()) { for (ExternalID newId : newExtIds.getExternalIdentifier()) { // normalize the ids before checking equality newId.setNormalized(new TransientNonEmptyString(norm.normalise(newId.getType(), newId.getValue()))); if (existingId.getNormalized() == null) existingId.setNormalized(new TransientNonEmptyString(norm.normalise(existingId.getType(), existingId.getValue()))); if (areRelationshipsSameAndSelf(existingId.getRelationship(), newId.getRelationship()) && newId.equals(existingId) && SourceEntityUtils.isTheSameForDuplicateChecking(activeSource,existingSource)) { Map<String, String> params = new HashMap<String, String>(); params.put("clientName", SourceEntityUtils.getSourceName(activeSource)); throw new OrcidDuplicatedActivityException(params); } } } } }
private void addExternalIdentifier(Work work, String type, String value, Locale locale) { ExternalID extId = new ExternalID(); extId.setType(type); extId.setValue(value); extId.setRelationship(Relationship.SELF); IdentifierType idType = identifierTypeManager.fetchIdentifierTypeByDatabaseName(type.toUpperCase(), locale); if (idType != null && !PojoUtil.isEmpty(idType.getResolutionPrefix())) { extId.setUrl(new Url(idType.getResolutionPrefix() + value)); } if(work.getExternalIdentifiers() == null) { work.setWorkExternalIdentifiers(new ExternalIDs()); } work.getExternalIdentifiers().getExternalIdentifier().add(extId); } }
private SchemaOrgAffiliation createFundingOrg(FundingGroup fundingGroup) { SchemaOrgAffiliation a = new SchemaOrgAffiliation(); a.name = fundingGroup.getFundingSummary().get(0).getOrganization().getName(); a.alternateName = fundingGroup.getFundingSummary().get(0).getTitle().getTitle().getContent(); //add org ids for (FundingSummary s : fundingGroup.getFundingSummary()){ if (s.getOrganization().getDisambiguatedOrganization() !=null){ if (!StringUtils.isEmpty(s.getOrganization().getDisambiguatedOrganization().getDisambiguationSource()) && !StringUtils.isEmpty(s.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier())) addIdToAffiliation(s.getOrganization().getDisambiguatedOrganization().getDisambiguationSource(),s.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier(), a); if (s.getOrganization().getDisambiguatedOrganization().getExternalIdentifiers() != null) for (DisambiguatedOrganizationExternalIdentifier i : s.getOrganization().getDisambiguatedOrganization().getExternalIdentifiers()) { addIdToAffiliation(i.getIdentifierType(),i.getIdentifier(), a); } } } //add grant ids if (fundingGroup.getIdentifiers() != null && fundingGroup.getIdentifiers().getExternalIdentifier() != null) for (ExternalID id : fundingGroup.getIdentifiers().getExternalIdentifier()) a.identifier.add(new SchemaOrgExternalID(id.getType(), norm.normalise(id.getType(), id.getValue()))); return a; }
private static void populateExternalIdentifiers(WorkForm workForm, Work work) { ExternalIDs workExternalIds = new ExternalIDs(); if(workForm.getWorkExternalIdentifiers() != null && !workForm.getWorkExternalIdentifiers().isEmpty()) { for(ActivityExternalIdentifier wfExtId : workForm.getWorkExternalIdentifiers()) { ExternalID wExtId = new ExternalID(); if(!PojoUtil.isEmpty(wfExtId.getExternalIdentifierId())) { wExtId.setValue(wfExtId.getExternalIdentifierId().getValue()); } if(!PojoUtil.isEmpty(wfExtId.getExternalIdentifierType())) { wExtId.setType(wfExtId.getExternalIdentifierType().getValue()); } if(!PojoUtil.isEmpty(wfExtId.getRelationship())) { wExtId.setRelationship(Relationship.fromValue(wfExtId.getRelationship().getValue())); } if(!PojoUtil.isEmpty(wfExtId.getUrl())) { wExtId.setUrl(new org.orcid.jaxb.model.v3.rc2.common.Url(wfExtId.getUrl().getValue())); } workExternalIds.getExternalIdentifier().add(wExtId); } } work.setWorkExternalIdentifiers(workExternalIds); }
@Override public ExternalIDs convertFrom(String source, Type<ExternalIDs> destinationType) { JSONFundingExternalIdentifiers fundingExternalIdentifiers = JsonUtils.readObjectFromJsonString(source, JSONFundingExternalIdentifiers.class); ExternalIDs externalIDs = new ExternalIDs(); for (JSONExternalIdentifier externalIdentifier : fundingExternalIdentifiers.getFundingExternalIdentifier()) { ExternalID id = new ExternalID(); if (externalIdentifier.getType() == null) { id.setType(FundingExternalIdentifierType.GRANT_NUMBER.value()); } else { id.setType(externalIdentifier.getType().toLowerCase()); } if (externalIdentifier.getUrl() != null && !PojoUtil.isEmpty(externalIdentifier.getUrl().getValue())) { Url url = new Url(externalIdentifier.getUrl().getValue()); id.setUrl(url); } if (!PojoUtil.isEmpty(externalIdentifier.getValue())) { id.setValue(externalIdentifier.getValue()); } if (externalIdentifier.getRelationship() != null) { id.setRelationship(Relationship.fromValue(conv.convertFrom(externalIdentifier.getRelationship(), null))); } externalIDs.getExternalIdentifier().add(id); } return externalIDs; }
@Override public String convertTo(ExternalIDs source, Type<String> destinationType) { JSONFundingExternalIdentifiers jsonFundingExternalIdentifiers = new JSONFundingExternalIdentifiers(); for (ExternalID externalID : source.getExternalIdentifier()) { JSONExternalIdentifier jsonExternalIdentifier = new JSONExternalIdentifier(); if (externalID.getType() != null) { jsonExternalIdentifier.setType(conv.convertTo(externalID.getType(), null)); } if (externalID.getUrl() != null) { jsonExternalIdentifier.setUrl(new JSONUrl(externalID.getUrl().getValue())); } if (!PojoUtil.isEmpty(externalID.getValue())) { jsonExternalIdentifier.setValue(externalID.getValue()); } if (externalID.getRelationship() != null) { jsonExternalIdentifier.setRelationship(conv.convertTo(externalID.getRelationship().value(), null)); } jsonFundingExternalIdentifiers.getFundingExternalIdentifier().add(jsonExternalIdentifier); } return JsonUtils.convertToJsonString(jsonFundingExternalIdentifiers); }
@Override public String convertTo(ExternalIDs source, Type<String> destinationType) { JSONExternalIdentifiers jsonExternalIdentifiers = new JSONExternalIdentifiers(); for (ExternalID externalID : source.getExternalIdentifier()) { JSONExternalIdentifier jsonExternalIdentifier = new JSONExternalIdentifier(); if (externalID.getType() != null) { jsonExternalIdentifier.setType(conv.convertTo(externalID.getType(), null)); } if (externalID.getUrl() != null) { jsonExternalIdentifier.setUrl(new JSONUrl(externalID.getUrl().getValue())); } if (!PojoUtil.isEmpty(externalID.getValue())) { jsonExternalIdentifier.setValue(externalID.getValue()); } if (externalID.getRelationship() != null) { jsonExternalIdentifier.setRelationship(conv.convertTo(externalID.getRelationship().value(), null)); } jsonExternalIdentifiers.getExternalIdentifier().add(jsonExternalIdentifier); } return JsonUtils.convertToJsonString(jsonExternalIdentifiers); }
@Override public String convertTo(ExternalIDs source, Type<String> destinationType) { JSONWorkExternalIdentifiers jsonWorkExternalIdentifiers = new JSONWorkExternalIdentifiers(); for (ExternalID externalID : source.getExternalIdentifier()) { JSONWorkExternalIdentifier jsonWorkExternalIdentifier = new JSONWorkExternalIdentifier(); if (externalID.getType() != null) { jsonWorkExternalIdentifier.setWorkExternalIdentifierType(conv.convertTo(externalID.getType(), null)); } if (externalID.getUrl() != null) { jsonWorkExternalIdentifier.setUrl(new JSONUrl(externalID.getUrl().getValue())); } if (!PojoUtil.isEmpty(externalID.getValue())) { jsonWorkExternalIdentifier.setWorkExternalIdentifierId(new WorkExternalIdentifierId(externalID.getValue())); } if (externalID.getRelationship() != null) { jsonWorkExternalIdentifier.setRelationship(conv.convertTo(externalID.getRelationship().value(), null)); } jsonWorkExternalIdentifiers.getWorkExternalIdentifier().add(jsonWorkExternalIdentifier); } return JsonUtils.convertToJsonString(jsonWorkExternalIdentifiers); }