Search in sources :

Example 1 with CannotFindRecordException

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

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

the class NonOwnedFieldSetMapper method mapField.

@Override
public void mapField(T object, String fieldName, String value) throws BindException {
    super.mapField(object, fieldName, value);
    Term term = getTermFactory().findTerm(fieldName);
    // DwcTerms
    if (term instanceof DwcTerm) {
        DwcTerm dwcTerm = (DwcTerm) term;
        switch(dwcTerm) {
            case taxonID:
                if (value != null && !value.isEmpty()) {
                    Taxon taxon = taxonService.find(value);
                    if (taxon == null) {
                        logger.error("Cannot find record " + value);
                        throw new CannotFindRecordException(value, value);
                    } else {
                        taxon = new Taxon();
                        taxon.setIdentifier(value);
                        ((NonOwned) object).getTaxa().add(taxon);
                    }
                }
                break;
            default:
                break;
        }
    }
}
Also used : CannotFindRecordException(org.powo.job.dwc.exception.CannotFindRecordException) Taxon(org.powo.model.Taxon) DwcTerm(org.gbif.dwc.terms.DwcTerm) Term(org.gbif.dwc.terms.Term) DwcTerm(org.gbif.dwc.terms.DwcTerm)

Example 3 with CannotFindRecordException

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

the class DwCProcessingExceptionProcessListener method onReadError.

public final void onReadError(final Exception e) {
    logger.error("Read Error " + e.getMessage());
    if (e instanceof FlatFileParseException) {
        FlatFileParseException ffpe = (FlatFileParseException) e;
        StringBuffer message = new StringBuffer();
        message.append(ffpe.getMessage());
        final Annotation annotation = new Annotation();
        if (ffpe.getCause() != null) {
            message.append(" " + ffpe.getCause().getMessage());
            logger.debug("FlatFileParseException | " + ffpe.getMessage() + " Cause " + ffpe.getCause().getMessage());
            if (ffpe.getCause().getClass().equals(CannotFindRecordException.class)) {
                annotation.setCode(AnnotationCode.BadIdentifier);
                CannotFindRecordException cfre = (CannotFindRecordException) ffpe.getCause();
                annotation.setValue(cfre.getValue());
            } else if (ffpe.getCause().getClass().equals(BindException.class)) {
                annotation.setCode(AnnotationCode.BadField);
                BindException be = (BindException) ffpe.getCause();
                annotation.setValue(be.getFieldError().getField());
            } else {
                annotation.setCode(AnnotationCode.BadRecord);
            }
        } else {
            logger.debug("FlatFileParseException | " + ffpe.getMessage());
        }
        annotation.setJobId(stepExecution.getJobExecutionId());
        annotation.setRecordType(getRecordType());
        annotation.setType(AnnotationType.Error);
        annotation.setText(message.toString());
        super.annotate(annotation);
    }
}
Also used : FlatFileParseException(org.springframework.batch.item.file.FlatFileParseException) CannotFindRecordException(org.powo.job.dwc.exception.CannotFindRecordException) BindException(org.springframework.validation.BindException) Annotation(org.powo.model.Annotation)

Example 4 with CannotFindRecordException

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

the class OwnedEntityFieldSetMapper method mapField.

@Override
public void mapField(T object, String fieldName, String value) throws BindException {
    super.mapField(object, fieldName, value);
    Term term = TermFactory.findTerm(fieldName);
    // DwcTerms
    if (term instanceof DwcTerm) {
        DwcTerm dwcTerm = (DwcTerm) term;
        switch(dwcTerm) {
            case taxonID:
                if (value != null && !value.isEmpty()) {
                    Taxon taxon = taxonService.find(value);
                    if (taxon == null) {
                        logger.error("Cannot find record " + value);
                        throw new CannotFindRecordException(value, value);
                    } else {
                        taxon = new Taxon();
                        taxon.setIdentifier(value);
                        object.setTaxon(taxon);
                    }
                }
                break;
            default:
                break;
        }
    }
}
Also used : CannotFindRecordException(org.powo.job.dwc.exception.CannotFindRecordException) Taxon(org.powo.model.Taxon) DwcTerm(org.gbif.dwc.terms.DwcTerm) Term(org.gbif.dwc.terms.Term) DwcTerm(org.gbif.dwc.terms.DwcTerm)

Example 5 with CannotFindRecordException

use of org.powo.job.dwc.exception.CannotFindRecordException 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)5 Taxon (org.powo.model.Taxon)4 Annotation (org.powo.model.Annotation)3 DwcTerm (org.gbif.dwc.terms.DwcTerm)2 Term (org.gbif.dwc.terms.Term)2 NoIdentifierException (org.powo.job.dwc.exception.NoIdentifierException)2 TaxonAlreadyProcessedException (org.powo.job.dwc.exception.TaxonAlreadyProcessedException)2 UnexpectedTaxonException (org.powo.job.dwc.exception.UnexpectedTaxonException)1 FlatFileParseException (org.springframework.batch.item.file.FlatFileParseException)1 BindException (org.springframework.validation.BindException)1