@Override public CitationType unmarshal(String v) throws Exception { try { return CitationType.fromValue(v); } catch (IllegalArgumentException e) { throw new IllegalEnumValueException(CitationType.class, v); } }
@Override public String marshal(CitationType v) throws Exception { try { return v.value(); } catch (Exception e) { throw new IllegalEnumValueException(CitationType.class, String.valueOf(v)); } } }
public static CitationType fromValue(String v) { for (CitationType c : CitationType.values()) { if (c.value.equals(v)) { return c; } } throw new IllegalArgumentException(v); }
/** * 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); }
@Override public int hashCode() { int result = citationType != null ? citationType.hashCode() : 0; result = 31 * result + (citation != null ? citation.hashCode() : 0); return result; } }
@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); }
citation.setWorkCitationType(CitationType.fromValue(this.getCitation().getCitationType().getValue()));
citation.setCitationType(Text.valueOf(work.getWorkCitation().getWorkCitationType().value()));