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 static void populateExternalIdentifiers(Work work, WorkForm workForm) { if(work.getExternalIdentifiers() != null) { populateExternalIdentifiers(work.getExternalIdentifiers(), workForm, work.getWorkType()); } }
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); } } } } }
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;
if (work.getPutCode() != null) { w.setPutCode(Text.valueOf(work.getPutCode())); if (!PojoUtil.isEmpty(work.getLanguageCode())) { w.setLanguageCode(Text.valueOf(work.getLanguageCode())); if (work.getWorkType() != null) { w.setWorkType(Text.valueOf(work.getWorkType().value())); WorkCategory category = WorkCategory.fromWorkType(work.getWorkType()); w.setWorkCategory(Text.valueOf(category.value())); if (work.getWorkTitle() != null) { if (work.getWorkTitle().getTitle() != null) { w.setTitle(Text.valueOf(work.getWorkTitle().getTitle().getContent())); if (work.getWorkTitle().getTranslatedTitle() != null) { TranslatedTitleForm tt = new TranslatedTitleForm(); tt.setContent(work.getWorkTitle().getTranslatedTitle().getContent()); tt.setLanguageCode(work.getWorkTitle().getTranslatedTitle().getLanguageCode()); w.setTranslatedTitle(tt); if (work.getWorkTitle().getSubtitle() != null) { w.setSubtitle(Text.valueOf(work.getWorkTitle().getSubtitle().getContent())); if (work.getJournalTitle() != null ) { w.setJournalTitle(Text.valueOf(work.getJournalTitle().getContent()));
public void validateWork(Work work, Source activeSource, 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.name()).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) { 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(); if (type == null) { Map<String, String> params = new HashMap<String, String>();
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) {
public Work toWork() { Work work = new Work(); work.setPutCode(Long.valueOf(this.getPutCode().getValue())); work.setLanguageCode(this.getLanguageCode().getValue()); work.setWorkType(WorkType.fromValue(this.getWorkType().getValue())); work.setWorkTitle(workTitle); work.setJournalTitle(new org.orcid.jaxb.model.v3.rc2.common.Title(this.getJournalTitle().getValue())); work.setShortDescription(this.getShortDescription().getValue()); work.setUrl(new Url(this.getUrl().getValue())); } else { work.setUrl(new Url()); work.setVisibility(org.orcid.jaxb.model.v3.rc2.common.Visibility.fromValue(this.getVisibility().getVisibility().value())); work.setCountry(new org.orcid.jaxb.model.v3.rc2.common.Country(org.orcid.jaxb.model.common.Iso3166Country.fromValue(this.getCountryCode().getValue()))); work.setPublicationDate(new org.orcid.jaxb.model.v3.rc2.common.PublicationDate(year, month, day)); work.setWorkCitation(citation); CreatedDate createdDate = new CreatedDate(); createdDate.setValue(DateUtils.convertToXMLGregorianCalendar(this.getCreatedDate().toJavaDate())); work.setCreatedDate(createdDate);
private Work getWork(JSONObject json) throws JSONException { Work result = new Work(); Locale locale = localeManager.getLocale(); if (json.has("type")) { try { result.setWorkType(WorkType.fromValue(json.getString("type"))); } catch (IllegalArgumentException e) { result.setWorkTitle(workTitle); result.setUrl(new Url(json.getString("URL"))); result.setWorkExternalIdentifiers(new ExternalIDs()); if (json.has("DOI")) { String doi = json.getString("DOI"); result.getWorkExternalIdentifiers().getExternalIdentifier().add(extId); result.getWorkExternalIdentifiers().getExternalIdentifier().add(extId); result.getWorkExternalIdentifiers().getExternalIdentifier().add(extId); result.setShortDescription(description); result.setJournalTitle(new Title(journalTitle)); result.setPublicationDate(publicationDate); result.setLanguageCode(json.getString("language")); } catch (IllegalArgumentException e) {
switch (currentElement) { case "id": if (work.getExternalIdentifiers() == null) { work.setWorkExternalIdentifiers(new ExternalIDs()); arxiv.setValue(normalizationService.normalise("arxiv", value)); arxiv.setUrl(new Url(value)); work.getWorkExternalIdentifiers().getExternalIdentifier().add(arxiv); break; case "title": c.setTime(date); PublicationDate publicationDate = new PublicationDate(); work.setPublicationDate(publicationDate); publicationDate.setDay(new Day(c.get(Calendar.DAY_OF_MONTH))); doi.setValue(normalizationService.normalise("doi", value)); doi.setUrl(new Url(normalizationService.generateNormalisedURL("doi", value))); work.getWorkExternalIdentifiers().getExternalIdentifier().add(doi); break;
@Override @Transactional public Work updateWork(String orcid, Work work, boolean isApiRequest) { WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode()); Visibility originalVisibility = Visibility.valueOf(workEntity.getVisibility()); Source activeSource = sourceManager.retrieveActiveSource(); if (!existing.getPutCode().equals(work.getPutCode())) { activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), activeSource); 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 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; }
@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) { b.setWorkType(a.getWorkType().name()); }
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); } } } }
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 static void populateContributors(Work work, WorkForm workForm) { List<Contributor> contributorsList = new ArrayList<Contributor>(); if(work.getWorkContributors() != null) { org.orcid.jaxb.model.v3.rc2.record.WorkContributors contributors = work.getWorkContributors(); if (contributors != null) { for (org.orcid.jaxb.model.v3.rc2.common.Contributor contributor : contributors.getContributor()) { contributorsList.add(Contributor.valueOf(contributor)); } } } workForm.setContributors(contributorsList); }
/** * 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); }
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;
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), activeSource); externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());