Search in sources :

Example 1 with NoIdentifierException

use of org.powo.job.dwc.exception.NoIdentifierException 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 2 with NoIdentifierException

use of org.powo.job.dwc.exception.NoIdentifierException 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)

Example 3 with NoIdentifierException

use of org.powo.job.dwc.exception.NoIdentifierException in project powop by RBGKew.

the class CheckingProcessor 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.info("Processing " + taxon.getIdentifier());
    if (taxon.getIdentifier() == null || taxon.getIdentifier().isEmpty()) {
        throw new NoIdentifierException(taxon);
    }
    Taxon persistedTaxon = taxonService.find(taxon.getIdentifier());
    if (persistedTaxon == null) {
        throw new CannotFindRecordException(taxon.getIdentifier(), taxon.toString());
    }
    Annotation annotation = annotationService.findAnnotation(RecordType.Taxon, persistedTaxon.getId(), getStepExecution().getJobExecutionId());
    if (annotation == null) {
        logger.warn(taxon.getIdentifier() + " was not expected");
        throw new UnexpectedTaxonException(taxon);
    } else {
        if (annotation.getCode().equals(AnnotationCode.Present)) {
            throw new TaxonAlreadyProcessedException(taxon);
        }
        annotation.setType(AnnotationType.Info);
        annotation.setCode(AnnotationCode.Present);
        logger.info(taxon.getIdentifier() + " was expected");
    }
    return annotation;
}
Also used : CannotFindRecordException(org.powo.job.dwc.exception.CannotFindRecordException) NoIdentifierException(org.powo.job.dwc.exception.NoIdentifierException) UnexpectedTaxonException(org.powo.job.dwc.exception.UnexpectedTaxonException) Taxon(org.powo.model.Taxon) TaxonAlreadyProcessedException(org.powo.job.dwc.exception.TaxonAlreadyProcessedException) Annotation(org.powo.model.Annotation)

Aggregations

NoIdentifierException (org.powo.job.dwc.exception.NoIdentifierException)3 Taxon (org.powo.model.Taxon)3 CannotFindRecordException (org.powo.job.dwc.exception.CannotFindRecordException)2 TaxonAlreadyProcessedException (org.powo.job.dwc.exception.TaxonAlreadyProcessedException)2 Annotation (org.powo.model.Annotation)2 UnexpectedTaxonException (org.powo.job.dwc.exception.UnexpectedTaxonException)1