Search in sources :

Example 1 with INomenclaturalReference

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);
    }
}
Also used : INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 2 with INomenclaturalReference

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;
}
Also used : VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Reference(eu.etaxonomy.cdm.model.reference.Reference) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IVolumeReference(eu.etaxonomy.cdm.model.reference.IVolumeReference)

Example 3 with INomenclaturalReference

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);
}
Also used : Matcher(java.util.regex.Matcher) INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 4 with INomenclaturalReference

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());
}
Also used : INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference)

Example 5 with INomenclaturalReference

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;
}
Also used : INomenclaturalReference(eu.etaxonomy.cdm.model.reference.INomenclaturalReference) Reference(eu.etaxonomy.cdm.model.reference.Reference) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)10 Reference (eu.etaxonomy.cdm.model.reference.Reference)5 IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)2 IVolumeReference (eu.etaxonomy.cdm.model.reference.IVolumeReference)2 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)2 Test (org.junit.Test)2 URI (eu.etaxonomy.cdm.common.URI)1 LSID (eu.etaxonomy.cdm.model.common.LSID)1 Language (eu.etaxonomy.cdm.model.common.Language)1 VerbatimTimePeriod (eu.etaxonomy.cdm.model.common.VerbatimTimePeriod)1 Distribution (eu.etaxonomy.cdm.model.description.Distribution)1 TextData (eu.etaxonomy.cdm.model.description.TextData)1 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)1 Rank (eu.etaxonomy.cdm.model.name.Rank)1 IArticle (eu.etaxonomy.cdm.model.reference.IArticle)1 IBook (eu.etaxonomy.cdm.model.reference.IBook)1 IBookSection (eu.etaxonomy.cdm.model.reference.IBookSection)1 IJournal (eu.etaxonomy.cdm.model.reference.IJournal)1