Work other = (Work) obj; if (this.getWorkTitle() == null) { if (other.getWorkTitle() != null) return false; } else if (!this.getWorkTitle().equals(other.getWorkTitle())) return false; if (this.getWorkType() == null) { if (other.getWorkType() != null) return false; } else if (!this.getWorkType().equals(other.getWorkType())) return false; if (this.getWorkExternalIdentifiers() == null) { if (other.getWorkExternalIdentifiers() != null) return false; } else if (!this.getWorkExternalIdentifiers().equals(other.getWorkExternalIdentifiers())) return false; if (this.getSource() == null) { if (other.getSource() != null) return false; } else if (!this.getSource().equals(other.getSource())) return false;
private Work getWorkFromSummary(WorkSummary summary) { Work work = new Work(); work.setWorkTitle(summary.getTitle()); work.setWorkType(summary.getType()); work.setPublicationDate(summary.getPublicationDate()); work.setWorkExternalIdentifiers(summary.getExternalIdentifiers()); work.setVisibility(summary.getVisibility()); work.setSource(getUpdatedSource(summary.getSource())); return work; }
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); } } } }
if (this.getWorkTitle() == null) { if (other.getWorkTitle() != null) return false; } else if (!this.getWorkTitle().equals(other.getWorkTitle())) return false; if (this.getWorkExternalIdentifiers() == null) { if (other.getWorkExternalIdentifiers() != null && other.getWorkExternalIdentifiers().getExternalIdentifier() != null && !other.getWorkExternalIdentifiers().getExternalIdentifier().isEmpty()) return false; } else if (other.getWorkExternalIdentifiers() == null) { if (this.getWorkExternalIdentifiers().getExternalIdentifier() != null && !this.getWorkExternalIdentifiers().getExternalIdentifier().isEmpty()) return false; } else { List<? extends GroupAble> otherExternalIdentifiers = other.getWorkExternalIdentifiers().getExternalIdentifier(); List<? extends GroupAble> thisExternalIdentifiers = this.getWorkExternalIdentifiers().getExternalIdentifier(); boolean sharedExtId = false; if (this.getSource() == null) { if (other.getSource() != null) return false; } else if (!this.getSource().equals(other.getSource())) return false; return true;
public void validateWork(Work work, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) { WorkTitle title = work.getWorkTitle(); if (title == null || title.getTitle() == null || PojoUtil.isEmpty(title.getTitle().getContent())) { throw new ActivityTitleValidationException(); if (work.getCountry() != null) { if (work.getCountry().getValue() == null) { Map<String, String> params = new HashMap<String, String>(); String values = Arrays.stream(Iso3166Country.values()).map(element -> element.value()).collect(Collectors.joining(", ")); if (work.getWorkType() == null) { Map<String, String> params = new HashMap<String, String>(); String values = Arrays.stream(WorkType.values()).map(element -> element.value()).collect(Collectors.joining(", ")); if (!PojoUtil.isEmpty(work.getLanguageCode())) { if (!Arrays.stream(LanguageCode.getValues()).anyMatch(work.getLanguageCode()::equals)) { Map<String, String> params = new HashMap<String, String>(); String values = Arrays.stream(LanguageCode.getValues()).collect(Collectors.joining(", ")); if (work.getPublicationDate() != null) { if (isApiRequest) { validateFuzzyDate(work.getPublicationDate()); PublicationDate pd = work.getPublicationDate(); Year year = pd.getYear(); Month month = pd.getMonth(); if (work.getWorkCitation() != null) { String citation = work.getWorkCitation().getCitation(); CitationType type = work.getWorkCitation().getWorkCitationType();
public String workToBibtex(Work work, String creditName){ StringBuffer out = new StringBuffer(); switch (work.getWorkType()) { case JOURNAL_ARTICLE: out.append("@article{"); out.append(escapeStringForBibtex(creditName).replace(' ', '_')+work.getPutCode()); out.append(",\ntitle={"+escapeStringForBibtex((work.getWorkTitle() != null) ? work.getWorkTitle().getTitle().getContent() : "No Title")+"}"); if (work.getJournalTitle() != null) { out.append(",\njournal={"+escapeStringForBibtex(work.getJournalTitle().getContent())+"}"); if (work.getWorkContributors() != null && work.getWorkContributors().getContributor() != null) { for (Contributor c : work.getWorkContributors().getContributor()) { if (c.getCreditName() != null && c.getCreditName().getContent() != null) { names.add(c.getCreditName().getContent()); if (work.getPublicationDate() != null) { int year = 0; try { year = Integer.parseInt(work.getPublicationDate().getYear().getValue()); } catch (Exception e) {
theTitle = this.getTitle(); strategy.appendField(locator, this, "title", buffer, theTitle); theJournalTitle = this.getJournalTitle(); strategy.appendField(locator, this, "journalTitle", buffer, theJournalTitle); theShortDescription = this.getShortDescription(); strategy.appendField(locator, this, "shortDescription", buffer, theShortDescription); theCitation = this.getCitation(); strategy.appendField(locator, this, "citation", buffer, theCitation); theType = this.getType(); strategy.appendField(locator, this, "type", buffer, theType); thePublicationDate = this.getPublicationDate(); strategy.appendField(locator, this, "publicationDate", buffer, thePublicationDate); theExternalIds = this.getExternalIds(); strategy.appendField(locator, this, "externalIds", buffer, theExternalIds); theUrl = this.getUrl(); strategy.appendField(locator, this, "url", buffer, theUrl); theContributors = this.getContributors(); strategy.appendField(locator, this, "contributors", buffer, theContributors); theLanguageCode = this.getLanguageCode(); strategy.appendField(locator, this, "languageCode", buffer, theLanguageCode);
public static void cleanEmptyFields(Work work) { if(work != null) { if(work.getWorkCitation() != null) { if(PojoUtil.isEmpty(work.getWorkCitation().getCitation())) { work.setWorkCitation(null); } } if(work.getWorkTitle() != null) { if(work.getWorkTitle().getTranslatedTitle() != null) { if(PojoUtil.isEmpty(work.getWorkTitle().getTranslatedTitle().getContent())) { work.getWorkTitle().setTranslatedTitle(null); } } } if(work.getWorkContributors() != null && work.getWorkContributors().getContributor() != null) { for(Contributor c : work.getWorkContributors().getContributor()) { if(c.getCreditName() != null && PojoUtil.isEmpty(c.getCreditName().getContent())) { c.setCreditName(null); } } } } }
@Override @Transactional public Work updateWork(String orcid, Work work, boolean isApiRequest) { WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode()); String originalVisibility = workEntity.getVisibility(); SourceEntity sourceEntity = sourceManager.retrieveSourceEntity(); if (!existing.getPutCode().equals(work.getPutCode())) { activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity); externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
@Override public String generateBibtex(String orcid, Work work){ //if we have a citation use that if (work.getWorkCitation() != null && work.getWorkCitation().getWorkCitationType() != null && work.getWorkCitation().getWorkCitationType().equals(CitationType.BIBTEX)) { return work.getWorkCitation().getCitation(); } //if we have a DOI, use that if (work.getWorkExternalIdentifiers() != null && work.getWorkExternalIdentifiers().getExternalIdentifier() != null){ String doi = extractID(work, WorkExternalIdentifierType.DOI); if (doi != null){ try{ String bibtex = doiManager.fetchDOIBibtex(doi); if (bibtex != null) return bibtex; }catch (Exception e){ //something went wrong at crossref/datacite e.g. 10.1890/1540-9295(2006)004[0244:elsdvs]2.0.co;2 //ignore and use our metadata LOGGER.warn("cannot resolve DOI to metadata:"+doi); } } } //otherwise, use whatever we can String creditName = getCreditName(orcid); return workToBibtex(work,creditName); }
/** * From model object to database object */ @Override public void mapAtoB(Work a, WorkEntity b, MappingContext context) { // Starting with 3.0_rc2 dissertation will be migrated to dissertation-thesis if(WorkType.DISSERTATION.equals(a.getWorkType())) { b.setWorkType(org.orcid.jaxb.model.common.WorkType.DISSERTATION_THESIS.name()); } else { b.setWorkType(a.getWorkType().name()); } }
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity); externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
/** * 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 sourceId * 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, String sourceId) { Set<ExternalID> existingExternalIds = new HashSet<ExternalID>(); for(Work work : existingWorks) { //If it is the same source if(work.retrieveSourcePath().equals(sourceId)) { 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; }
/** * Turn a work into Citeproc JSON. Uses bibtex citation if present, * otherwise attempts to map ORCID metadata * * @param work the work to translate * @param creditName name to use as author if no bibtex found * @param abreviate if true, will shorten bibtex derived authorship to 200 characters or 20 authors * @return the JSON as a String. */ public CSLItemData toCiteproc(Work work, String creditName, boolean abreviate) { if (work.getWorkCitation() != null && work.getWorkCitation().getWorkCitationType() != null && work.getWorkCitation().getWorkCitationType().equals(CitationType.BIBTEX)) { return translateFromBibtexCitation(work, abreviate); } return translateFromWorkMetadata(work,creditName); }
/** * Create an instance of {@link Work } * */ public Work createWork() { return new Work(); }
builder.title((work.getWorkTitle() != null) ? StringUtils.stripAccents(work.getWorkTitle().getTitle().getContent()) : "No Title"); String doi = extractID(work, WorkExternalIdentifierType.DOI); String url = extractID(work, WorkExternalIdentifierType.URI); if (work.getJournalTitle() != null) { builder.containerTitle(StringUtils.stripAccents(work.getJournalTitle().getContent())); if (work.getWorkContributors() != null && work.getWorkContributors().getContributor() != null) { for (Contributor c : work.getWorkContributors().getContributor()) { if (c.getCreditName() != null && c.getCreditName().getContent() != null) { names.add(StringUtils.stripAccents(c.getCreditName().getContent())); if (work.getPublicationDate() != null) { int year = 0; int month = 0; int day = 0; try { year = Integer.parseInt(work.getPublicationDate().getYear().getValue()); month = Integer.parseInt(work.getPublicationDate().getMonth().getValue()); day = Integer.parseInt(work.getPublicationDate().getDay().getValue()); } catch (Exception e) { switch (work.getWorkType()) { case ARTISTIC_PERFORMANCE: break;
/** * From model object to database object */ @Override public void mapAtoB(Work a, MinimizedWorkEntity b, MappingContext context) { //Starting with 3.0_rc2 dissertation will be migrated to dissertation-thesis if(WorkType.DISSERTATION.equals(a.getWorkType())) { b.setWorkType(org.orcid.jaxb.model.common.WorkType.DISSERTATION_THESIS.name()); } else { b.setWorkType(a.getWorkType().name()); } }
try { BibTeXConverter conv = new BibTeXConverter(); String ascii = Normalizer.normalize(work.getWorkCitation().getCitation(), Normalizer.Form.NFKD); ascii = ascii.replaceAll("[^\\x00-\\x7F]", ""); BibTeXDatabase db = conv.loadDatabase(IOUtils.toInputStream(ascii));
/** * 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; }