use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.
the class DwcaReferenceExport method handleTaxonNode.
/**
* @param state
* @param node
* @throws IOException
* @throws FileNotFoundException
* @throws UnsupportedEncodingException
*/
@Override
protected void handleTaxonNode(DwcaTaxExportState state, TaxonNode node) throws IOException, FileNotFoundException, UnsupportedEncodingException {
try {
// sec
DwcaReferenceRecord record = new DwcaReferenceRecord(metaRecord, state.getConfig());
Taxon taxon = CdmBase.deproxy(node.getTaxon());
Reference sec = taxon.getSec();
if (sec != null && !state.recordExists(file, sec)) {
handleReference(state, record, sec, taxon);
PrintWriter writer = createPrintWriter(state, file);
record.write(state, writer);
state.addExistingRecord(file, sec);
}
// nomRef
record = new DwcaReferenceRecord(metaRecord, state.getConfig());
INomenclaturalReference nomRefI = taxon.getName().getNomenclaturalReference();
Reference nomRef = CdmBase.deproxy(nomRefI, Reference.class);
if (nomRef != null && !state.recordExists(file, nomRef)) {
handleReference(state, record, nomRef, taxon);
PrintWriter writer = createPrintWriter(state, file);
record.write(state, writer);
state.addExistingRecord(file, nomRef);
}
} catch (Exception e) {
String message = "Unexpected exception: " + e.getMessage();
state.getResult().addException(e, message);
} finally {
flushWriter(state, file);
}
}
use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method makeYear.
/**
* Parses the publication date part.
* @param nomRef
* @param year
* @return If the string is not parsable <code>false</code>
* is returned. <code>True</code> otherwise
*/
private boolean makeYear(INomenclaturalReference nomRef, String year) {
boolean result = true;
if (year == null) {
return false;
}
if ("".equals(year.trim())) {
return true;
}
VerbatimTimePeriod datePublished = TimePeriodParser.parseStringVerbatim(year);
if (nomRef.getType().equals(ReferenceType.BookSection)) {
handleBookSectionYear((IBookSection) nomRef, datePublished);
} else if (nomRef instanceof Reference) {
((Reference) nomRef).setDatePublished(datePublished);
} else {
throw new ClassCastException("nom Ref is not of type Reference but " + (nomRef.getClass()));
}
return result;
}
use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method parseReference.
private void parseReference(INonViralName nameToBeFilled, String strReference, boolean isInReference) {
INomenclaturalReference ref;
String originalStrReference = strReference;
// End (just delete end (e.g. '.', may be ambigous for yearPhrase, but no real information gets lost
Matcher endMatcher = getMatcher(referenceEnd + end, strReference);
if (endMatcher.find()) {
String endPart = endMatcher.group(0);
strReference = strReference.substring(0, strReference.length() - endPart.length());
}
// String pDetailYear = ".*" + detailSeparator + detail + fWs + yearSeperator + fWs + yearPhrase + fWs + end;
// Matcher detailYearMatcher = getMatcher(pDetailYear, strReference);
String strReferenceWithYear = strReference;
// year
String yearPart = null;
String pYearPhrase = yearSeperator + fWs + yearPhrase + fWs + end;
Matcher yearPhraseMatcher = getMatcher(pYearPhrase, strReference);
if (yearPhraseMatcher.find()) {
yearPart = yearPhraseMatcher.group(0);
strReference = strReference.substring(0, strReference.length() - yearPart.length());
yearPart = yearPart.replaceFirst(pStart + yearSeperator, "").trim();
} else {
if (nameToBeFilled.isZoological()) {
IZoologicalName zooName = (IZoologicalName) CdmBase.deproxy(nameToBeFilled);
yearPart = String.valueOf(zooName.getPublicationYear());
// continue
} else {
ref = makeDetailYearUnparsable(nameToBeFilled, strReference);
ref.setDatePublished(TimePeriodParser.parseStringVerbatim(yearPart));
return;
}
}
// detail
String pDetailPhrase = detailSeparator + fWs + detail + fWs + end;
Matcher detailPhraseMatcher = getMatcher(pDetailPhrase, strReference);
if (detailPhraseMatcher.find()) {
String detailPart = detailPhraseMatcher.group(0);
strReference = strReference.substring(0, strReference.length() - detailPart.length());
detailPart = detailPart.replaceFirst(pStart + detailSeparator, "").trim();
nameToBeFilled.setNomenclaturalMicroReference(detailPart);
} else {
makeDetailYearUnparsable(nameToBeFilled, strReferenceWithYear);
return;
}
// parse title and author
ref = parseReferenceTitle(strReference, yearPart, isInReference);
if (ref.hasProblem()) {
// we need to protect both caches otherwise the titleCache is incorrectly build from atomized parts
ref.setTitleCache((isInReference ? "in " : "") + originalStrReference, true);
ref.setAbbrevTitleCache((isInReference ? "in " : "") + originalStrReference, true);
}
nameToBeFilled.setNomenclaturalReference(ref);
int end = Math.min(strReference.length(), ref.getProblemEnds());
ref.setProblemEnds(end);
}
use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.
the class NonViralNameParserImplTest method assertFullRefStandard.
private void assertFullRefStandard(INonViralName name) {
assertEquals("Abies", name.getGenusOrUninomial());
assertEquals("alba", name.getSpecificEpithet());
assertEquals("Mill.", name.getAuthorshipCache());
assertEquals("455", name.getNomenclaturalMicroReference());
assertNotNull(name.getNomenclaturalReference());
INomenclaturalReference ref = name.getNomenclaturalReference();
assertEquals("1987", ref.getYear());
assertEquals("Sp. Pl.", ref.getAbbrevTitle());
}
use of eu.etaxonomy.cdm.model.reference.INomenclaturalReference in project cdmlib by cybertaxonomy.
the class ReferenceController method doGetNomenclaturalCitation.
/**
* TODO write controller documentation
*
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = { "nomenclaturalCitation" }, method = RequestMethod.GET)
public ModelAndView doGetNomenclaturalCitation(@PathVariable("uuid") UUID uuid, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "microReference", required = false) String microReference) throws IOException {
ModelAndView mv = new ModelAndView();
Reference rb = service.load(uuid, NOMENCLATURAL_CITATION_INIT_STRATEGY);
if (INomenclaturalReference.class.isAssignableFrom(rb.getClass())) {
String nomRefCit = NomenclaturalSourceFormatter.INSTANCE().format(rb, microReference);
mv.addObject(nomRefCit);
return mv;
} else {
response.sendError(400, "The supplied reference-uuid must specify a INomenclaturalReference.");
}
return mv;
}
Aggregations