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