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;
}
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;
}
}
}
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);
}
}
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;
}
}
}
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;
}
Aggregations