Search in sources :

Example 1 with Taxon

use of org.powo.model.Taxon in project powop by RBGKew.

the class DescriptionParsingTest method testRead.

/**
 * @throws Exception if there is a problem accessing the file
 */
@Test
public final void testRead() throws Exception {
    expect(conversionService.convert(isA(String.class), isA(TypeDescriptor.class), isA(TypeDescriptor.class))).andReturn(new TreeSet<>(Arrays.asList(DescriptionType.general)));
    expect(conversionService.convert(isA(String.class), eq(DateTime.class))).andReturn(new DateTime()).anyTimes();
    expect(taxonService.find(isA(String.class))).andReturn(new Taxon()).anyTimes();
    expect(taxonService.find(isA(String.class), eq("taxon-with-content"))).andReturn(new Taxon()).anyTimes();
    replay(taxonService, conversionService);
    flatFileItemReader.open(new ExecutionContext());
    flatFileItemReader.read();
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Taxon(org.powo.model.Taxon) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with Taxon

use of org.powo.model.Taxon in project powop by RBGKew.

the class ReferenceParsingTest method testRead.

/**
 * @throws Exception if there is a problem accessing the file
 */
@Test
public final void testRead() throws Exception {
    EasyMock.expect(taxonService.find(EasyMock.isA(String.class))).andReturn(new Taxon()).anyTimes();
    EasyMock.replay(taxonService);
    flatFileItemReader.open(new ExecutionContext());
    flatFileItemReader.read();
}
Also used : ExecutionContext(org.springframework.batch.item.ExecutionContext) Taxon(org.powo.model.Taxon) Test(org.junit.Test)

Example 3 with Taxon

use of org.powo.model.Taxon in project powop by RBGKew.

the class FieldSetMapper method mapField.

/**
 * @param object the object to map onto
 * @param fieldName the name of the field
 * @param value the value to map
 * @throws BindException if there is a problem mapping
 *         the value to the object
 */
@Override
public final void mapField(final Taxon object, final String fieldName, final String value) throws BindException {
    super.mapField(object, fieldName, value);
    Term term = TermFactory.findTerm(fieldName);
    logger.debug("Mapping " + fieldName + " " + " " + value + " to " + object);
    if (term instanceof DcTerm) {
        DcTerm dcTerm = (DcTerm) term;
        switch(dcTerm) {
            case bibliographicCitation:
                object.setBibliographicCitation(value);
                break;
            case references:
                object.setUri(value);
                break;
            case source:
                object.setSource(value);
                break;
            default:
                break;
        }
    }
    // DwcTerms
    if (term instanceof DwcTerm) {
        DwcTerm dwcTerm = (DwcTerm) term;
        switch(dwcTerm) {
            case acceptedNameUsageID:
                if (value != null && value.trim().length() != 0) {
                    if (object.getAcceptedNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setAcceptedNameUsage(taxon);
                    }
                    object.getAcceptedNameUsage().setIdentifier(value);
                }
                break;
            case acceptedNameUsage:
                if (value != null && value.trim().length() != 0) {
                    if (object.getAcceptedNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setAcceptedNameUsage(taxon);
                    }
                    object.getAcceptedNameUsage().setScientificName(value);
                }
                break;
            case class_:
                object.setClazz(value);
                break;
            case family:
                object.setFamily(value);
                break;
            case genus:
                object.setGenus(value);
                break;
            case infraspecificEpithet:
                object.setInfraspecificEpithet(value);
                break;
            case kingdom:
                object.setKingdom(value);
                break;
            case nameAccordingToID:
                // not mapped
                break;
            case namePublishedInID:
                // not mapped
                break;
            case namePublishedIn:
                object.setNamePublishedInString(value);
                break;
            case namePublishedInYear:
                object.setNamePublishedInYear(conversionService.convert(value, Integer.class));
                break;
            case nomenclaturalCode:
                object.setNomenclaturalCode(conversionService.convert(value, NomenclaturalCode.class));
                break;
            case nomenclaturalStatus:
                object.setNomenclaturalStatus(conversionService.convert(value, NomenclaturalStatus.class));
                break;
            case order:
                object.setOrder(value);
                break;
            case originalNameUsageID:
                if (value != null && value.trim().length() != 0) {
                    if (object.getOriginalNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setOriginalNameUsage(taxon);
                    }
                    object.getOriginalNameUsage().setIdentifier(value);
                }
                break;
            case originalNameUsage:
                if (value != null && value.trim().length() != 0) {
                    if (object.getOriginalNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setOriginalNameUsage(taxon);
                    }
                    object.getOriginalNameUsage().setScientificName(value);
                }
                break;
            case parentNameUsageID:
                if (value != null && value.trim().length() != 0) {
                    if (object.getParentNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setParentNameUsage(taxon);
                    }
                    object.getParentNameUsage().setIdentifier(value);
                }
                break;
            case parentNameUsage:
                if (value != null && value.trim().length() != 0) {
                    if (object.getParentNameUsage() == null) {
                        Taxon taxon = new Taxon();
                        object.setParentNameUsage(taxon);
                    }
                    object.getParentNameUsage().setScientificName(value);
                }
                break;
            case phylum:
                object.setPhylum(value);
                break;
            case scientificName:
                object.setScientificName(value);
                break;
            case scientificNameAuthorship:
                object.setScientificNameAuthorship(value);
                break;
            case scientificNameID:
                object.setScientificNameID(value);
                break;
            case specificEpithet:
                object.setSpecificEpithet(value);
                break;
            case subgenus:
                object.setSubgenus(value);
                break;
            case taxonID:
                object.setIdentifier(value);
                break;
            case taxonomicStatus:
                try {
                    object.setTaxonomicStatus(conversionService.convert(value, TaxonomicStatus.class));
                } catch (ConversionException ce) {
                    logger.error(ce.getMessage());
                }
                break;
            case taxonRank:
                try {
                    object.setTaxonRank(conversionService.convert(value, Rank.class));
                } catch (ConversionException ce) {
                    logger.error(ce.getMessage());
                }
                break;
            case taxonRemarks:
                object.setTaxonRemarks(value);
                break;
            case verbatimTaxonRank:
                object.setVerbatimTaxonRank(value);
                break;
            default:
                break;
        }
    }
    // eMonocot Terms
    if (term instanceof EmonocotTerm) {
        EmonocotTerm eMonocotTerm = (EmonocotTerm) term;
        switch(eMonocotTerm) {
            case subfamily:
                object.setSubfamily(value);
                break;
            case subtribe:
                object.setSubtribe(value);
                break;
            case tribe:
                object.setTribe(value);
                break;
            default:
                break;
        }
    }
}
Also used : NomenclaturalCode(org.gbif.ecat.voc.NomenclaturalCode) ConversionException(org.springframework.core.convert.ConversionException) NomenclaturalStatus(org.gbif.ecat.voc.NomenclaturalStatus) TaxonomicStatus(org.powo.model.constants.TaxonomicStatus) Taxon(org.powo.model.Taxon) Rank(org.gbif.ecat.voc.Rank) EmonocotTerm(org.powo.api.job.EmonocotTerm) DcTerm(org.gbif.dwc.terms.DcTerm) DwcTerm(org.gbif.dwc.terms.DwcTerm) Term(org.gbif.dwc.terms.Term) EmonocotTerm(org.powo.api.job.EmonocotTerm) DcTerm(org.gbif.dwc.terms.DcTerm) DwcTerm(org.gbif.dwc.terms.DwcTerm)

Example 4 with Taxon

use of org.powo.model.Taxon in project powop by RBGKew.

the class Processor method doProcess.

public Taxon doProcess(Taxon t) throws Exception {
    logger.debug("Processing {}", t.getIdentifier());
    if (t.getIdentifier() == null) {
        throw new NoIdentifierException(t);
    }
    Taxon persisted = getTaxonService().find(t.getIdentifier());
    if (persisted == null) {
        // Taxon is new
        validate(t);
        chunkAnnotations.add(createAnnotation(t, RecordType.Taxon, AnnotationCode.Create, AnnotationType.Info));
        t.setAuthority(getSource());
        t.setResource(getResource());
        // don't try saving any linked taxa. This must be done by the linking processor
        t.setParentNameUsage(null);
        t.setAcceptedNameUsage(null);
        t.setOriginalNameUsage(null);
        logger.debug("Adding taxon {}", t);
        return t;
    } else {
        checkAuthority(RecordType.Taxon, t, persisted.getAuthority());
        if (skipUnmodified && ((persisted.getModified() != null && t.getModified() != null) && !persisted.getModified().isBefore(t.getModified()))) {
            replaceAnnotation(persisted, AnnotationType.Info, AnnotationCode.Skipped);
        } else {
            persisted.setAccessRights(t.getAccessRights());
            persisted.setCreated(t.getCreated());
            persisted.setLicense(t.getLicense());
            persisted.setModified(t.getModified());
            persisted.setRights(t.getRights());
            persisted.setRightsHolder(t.getRightsHolder());
            persisted.setBibliographicCitation(t.getBibliographicCitation());
            persisted.setClazz(t.getClazz());
            persisted.setFamily(t.getFamily());
            persisted.setGenus(t.getGenus());
            persisted.setInfraspecificEpithet(t.getInfraspecificEpithet());
            persisted.setKingdom(t.getKingdom());
            persisted.setNamePublishedInString(t.getNamePublishedInString());
            persisted.setNamePublishedInYear(t.getNamePublishedInYear());
            persisted.setNomenclaturalCode(t.getNomenclaturalCode());
            persisted.setNomenclaturalStatus(t.getNomenclaturalStatus());
            persisted.setOrder(t.getOrder());
            persisted.setPhylum(t.getPhylum());
            persisted.setScientificName(t.getScientificName());
            persisted.setScientificNameAuthorship(t.getScientificNameAuthorship());
            persisted.setScientificNameID(t.getScientificNameID());
            persisted.setSource(t.getSource());
            persisted.setSpecificEpithet(t.getSpecificEpithet());
            persisted.setSubfamily(t.getSubfamily());
            persisted.setSubgenus(t.getSubgenus());
            persisted.setSubtribe(t.getSubtribe());
            persisted.setTaxonomicStatus(t.getTaxonomicStatus());
            persisted.setTaxonRemarks(t.getTaxonRemarks());
            persisted.setTribe(t.getTribe());
            persisted.setTaxonRank(t.getTaxonRank());
            persisted.setUri(t.getUri());
            validate(t);
            replaceAnnotation(persisted, AnnotationType.Info, AnnotationCode.Update);
        }
        logger.debug("Overwriting taxon {}", persisted);
        return persisted;
    }
}
Also used : NoIdentifierException(org.powo.job.dwc.exception.NoIdentifierException) Taxon(org.powo.model.Taxon)

Example 5 with Taxon

use of org.powo.model.Taxon in project powop by RBGKew.

the class SkippingProcessor method process.

/**
 * @param taxon a taxon object
 * @throws Exception if something goes wrong
 * @return Taxon a taxon object
 */
public final Annotation process(final Taxon taxon) throws Exception {
    logger.debug("Processing " + taxon.getIdentifier());
    if (taxon.getIdentifier() == null) {
        throw new NoIdentifierException(taxon);
    }
    Taxon persistedTaxon = taxonService.find(taxon.getIdentifier());
    if (persistedTaxon == null) {
        throw new CannotFindRecordException(taxon.getIdentifier(), taxon.toString());
    }
    Annotation annotation = resolveAnnotation(RecordType.Taxon, persistedTaxon.getId(), getStepExecution().getJobExecutionId());
    if (annotation == null) {
        annotation = this.createAnnotation(persistedTaxon, RecordType.Taxon, AnnotationCode.Skipped, AnnotationType.Info);
        bindAnnotation(annotation);
    } else {
        if (annotation.getCode().equals(AnnotationCode.Skipped)) {
            throw new TaxonAlreadyProcessedException(taxon);
        }
        annotation.setType(AnnotationType.Info);
        annotation.setCode(AnnotationCode.Skipped);
        logger.debug(persistedTaxon.getIdentifier() + " was skipped");
    }
    return annotation;
}
Also used : CannotFindRecordException(org.powo.job.dwc.exception.CannotFindRecordException) NoIdentifierException(org.powo.job.dwc.exception.NoIdentifierException) Taxon(org.powo.model.Taxon) TaxonAlreadyProcessedException(org.powo.job.dwc.exception.TaxonAlreadyProcessedException) Annotation(org.powo.model.Annotation)

Aggregations

Taxon (org.powo.model.Taxon)80 Test (org.junit.Test)42 SolrInputDocument (org.apache.solr.common.SolrInputDocument)16 TaxonSolrInputDocument (org.powo.model.solr.TaxonSolrInputDocument)16 Before (org.junit.Before)11 Reference (org.powo.model.Reference)9 ArrayList (java.util.ArrayList)7 Distribution (org.powo.model.Distribution)7 Image (org.powo.model.Image)7 Description (org.powo.model.Description)6 List (java.util.List)5 Term (org.gbif.dwc.terms.Term)4 CannotFindRecordException (org.powo.job.dwc.exception.CannotFindRecordException)4 TaxonomicStatus (org.powo.model.constants.TaxonomicStatus)4 DwcTerm (org.gbif.dwc.terms.DwcTerm)3 Session (org.hibernate.Session)3 Transaction (org.hibernate.Transaction)3 Annotation (org.powo.model.Annotation)3 VernacularName (org.powo.model.VernacularName)3 ExecutionContext (org.springframework.batch.item.ExecutionContext)3