Search in sources :

Example 1 with TaxonAlreadyProcessedException

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

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

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