use of eu.etaxonomy.cdm.model.occurrence.GatheringEvent in project cdmlib by cybertaxonomy.
the class DerivedUnitFacade method distanceToGroundToString.
// distance to ground
/**
* Returns the correctly formatted <code>distance to ground</code> information.
* If distanceToGroundText is not blank, it will be returned,
* otherwise distanceToGround will be returned, followed by distanceToGroundMax
* if existing, separated by " - "
* @return
*/
@Transient
public String distanceToGroundToString() {
if (!hasGatheringEvent()) {
return null;
} else {
GatheringEvent ev = getGatheringEvent(true);
String text = ev.getDistanceToGroundText();
Double min = getDistanceToGround();
Double max = getDistanceToGroundMax();
return DistanceStringFormatter.distanceString(min, max, text, METER);
}
}
use of eu.etaxonomy.cdm.model.occurrence.GatheringEvent in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleSpecimen.
private void handleSpecimen(CdmLightExportState state, SpecimenOrObservationBase<?> specimen) {
try {
state.addSpecimenToStore(specimen);
CdmLightExportTable table = CdmLightExportTable.SPECIMEN;
String specimenId = getId(state, specimen);
String[] csvLine = new String[table.getSize()];
/*
* SpecimenCitation = “El Salvador, Municipio La Libertad, San
* Diego, El Amatal, 14.4.1993, González 159” [Auch ohne Punkt] ->
* FieldUnit TitleCache HerbariumAbbrev = “B” [wie gehabt]
* HerbariumCode
*
*/
csvLine[table.getIndex(CdmLightExportTable.SPECIMEN_ID)] = specimenId;
csvLine[table.getIndex(CdmLightExportTable.SPECIMEN_CITATION)] = specimen.getTitleCache();
Collection<FieldUnit> fieldUnits = this.getOccurrenceService().findFieldUnits(specimen.getUuid(), null);
if (fieldUnits.size() == 1) {
Iterator<FieldUnit> iterator = fieldUnits.iterator();
if (iterator.hasNext()) {
FieldUnit fieldUnit = iterator.next();
csvLine[table.getIndex(CdmLightExportTable.FIELDUNIT_CITATION)] = fieldUnit.getTitleCache();
}
}
if (specimen.isInstanceOf(DerivedUnit.class)) {
DerivedUnit derivedUnit = (DerivedUnit) specimen;
if (!StringUtils.isBlank(derivedUnit.getBarcode())) {
csvLine[table.getIndex(CdmLightExportTable.BARCODE)] = derivedUnit.getBarcode();
}
if (!StringUtils.isBlank(derivedUnit.getAccessionNumber())) {
csvLine[table.getIndex(CdmLightExportTable.ACCESSION_NUMBER)] = derivedUnit.getAccessionNumber();
}
if (!StringUtils.isBlank(derivedUnit.getCatalogNumber())) {
csvLine[table.getIndex(CdmLightExportTable.CATALOGUE_NUMBER)] = derivedUnit.getCatalogNumber();
}
}
csvLine[table.getIndex(CdmLightExportTable.PREFERREDSTABLE_ID)] = specimen.getPreferredStableUri() != null ? specimen.getPreferredStableUri().toString() : null;
csvLine[table.getIndex(CdmLightExportTable.SPECIMEN_IMAGE_URIS)] = extractMediaURIs(state, specimen.getDescriptions(), Feature.IMAGE());
if (specimen instanceof DerivedUnit) {
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
if (derivedUnit.getCollection() != null) {
csvLine[table.getIndex(CdmLightExportTable.HERBARIUM_ABBREV)] = derivedUnit.getCollection().getCode();
}
if (specimen instanceof MediaSpecimen) {
MediaSpecimen mediaSpecimen = (MediaSpecimen) specimen;
Iterator<MediaRepresentation> it = mediaSpecimen.getMediaSpecimen().getRepresentations().iterator();
String mediaUris = extractMediaUris(it);
csvLine[table.getIndex(CdmLightExportTable.MEDIA_SPECIMEN_URL)] = mediaUris;
}
if (derivedUnit.getDerivedFrom() != null) {
for (SpecimenOrObservationBase<?> original : derivedUnit.getDerivedFrom().getOriginals()) {
// FieldUnit??
if (original instanceof FieldUnit) {
FieldUnit fieldUnit = (FieldUnit) original;
csvLine[table.getIndex(CdmLightExportTable.COLLECTOR_NUMBER)] = fieldUnit.getFieldNumber();
GatheringEvent gathering = fieldUnit.getGatheringEvent();
if (gathering != null) {
if (gathering.getLocality() != null) {
csvLine[table.getIndex(CdmLightExportTable.LOCALITY)] = gathering.getLocality().getText();
}
if (gathering.getCountry() != null) {
csvLine[table.getIndex(CdmLightExportTable.COUNTRY)] = gathering.getCountry().getLabel();
}
csvLine[table.getIndex(CdmLightExportTable.COLLECTOR_STRING)] = createCollectorString(state, gathering, fieldUnit);
if (gathering.getGatheringDate() != null) {
csvLine[table.getIndex(CdmLightExportTable.COLLECTION_DATE)] = gathering.getGatheringDate().toString();
}
if (!gathering.getCollectingAreas().isEmpty()) {
int index = 0;
csvLine[table.getIndex(CdmLightExportTable.FURTHER_AREAS)] = "0";
for (NamedArea area : gathering.getCollectingAreas()) {
if (index == 0) {
csvLine[table.getIndex(CdmLightExportTable.AREA_CATEGORY1)] = area.getLevel() != null ? area.getLevel().getLabel() : "";
csvLine[table.getIndex(CdmLightExportTable.AREA_NAME1)] = area.getLabel();
}
if (index == 1) {
csvLine[table.getIndex(CdmLightExportTable.AREA_CATEGORY2)] = area.getLevel() != null ? area.getLevel().getLabel() : "";
csvLine[table.getIndex(CdmLightExportTable.AREA_NAME2)] = area.getLabel();
}
if (index == 2) {
csvLine[table.getIndex(CdmLightExportTable.AREA_CATEGORY3)] = area.getLevel() != null ? area.getLevel().getLabel() : "";
csvLine[table.getIndex(CdmLightExportTable.AREA_NAME3)] = area.getLabel();
}
if (index == 3) {
csvLine[table.getIndex(CdmLightExportTable.FURTHER_AREAS)] = "1";
break;
}
index++;
}
}
}
}
}
} else {
state.getResult().addWarning("The specimen with uuid " + specimen.getUuid() + " is not an DerivedUnit.");
}
}
state.getProcessor().put(table, specimen, csvLine);
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling specimen " + cdmBaseStr(specimen) + ": " + e.getMessage());
}
}
use of eu.etaxonomy.cdm.model.occurrence.GatheringEvent in project cdmlib by cybertaxonomy.
the class SpecimenSythesysExcelImport method start.
/*
* Store the unit with it's Gathering informations in the CDM
*/
public boolean start(SpecimenSynthesysExcelImportConfigurator config) {
boolean result = true;
// refreshTransaction();
try {
/**
* SPECIMEN OR OBSERVATION OR LIVING
*/
DerivedUnitFacade derivedUnitFacade = getFacade();
derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
// set catalogue number (unitID)
derivedUnitFacade.setCatalogNumber(unitID);
derivedUnitFacade.setAccessionNumber(accessionNumber);
if (!originalsource.isEmpty()) {
Reference reference = ReferenceFactory.newGeneric();
reference.setTitleCache(originalsource, true);
derivedUnitBase.addSource(OriginalSourceType.Import, originalsource, "", reference, "");
} else {
derivedUnitBase.addSource(OriginalSourceType.Import, unitID, "", ref, ref.getCitation());
}
// manage institution
if (!institutionCode.isEmpty()) {
Institution institution = getInstitution(config);
// manage collection
if (!collectionCode.isEmpty()) {
Collection collection = getCollection(institution, config);
// link specimen & collection
derivedUnitFacade.setCollection(collection);
}
}
/**
* GATHERING EVENT
*/
// gathering event
UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(getTermService(), locality, languageIso, longitude, latitude, gatheringAgent, gatheringTeam, config);
// country
UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
unitsGatheringArea.useTDWGareas(this.useTDWGarea);
// unitsGatheringArea.setConfig(config, getOccurrenceService(),getTermService());
unitsGatheringArea.setParams(isocountry, country, config, getTermService(), getVocabularyService());
DefinedTermBase areaCountry = unitsGatheringArea.getCountry();
// copy gathering event to facade
GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
// join gatheringEvent to fieldObservation
derivedUnitFacade.setGatheringEvent(gatheringEvent);
derivedUnitFacade.setLocality(gatheringEvent.getLocality());
derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
// derivedUnitFacade.setCollector(gatheringEvent.getCollector());
derivedUnitFacade.setCountry((NamedArea) areaCountry);
for (DefinedTermBase<?> area : unitsGatheringArea.getAreas()) {
derivedUnitFacade.addCollectingArea((NamedArea) area);
}
if (gatheringNotes != null && !gatheringNotes.isEmpty()) {
derivedUnitFacade.setFieldNotes(gatheringNotes);
}
/*
* merge AND STORE DATA
*/
// getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
getTermService().saveLanguageData(unitsGatheringEvent.getLocality());
// add gathering date
if (keepAtomisedDate && (!gatheringYear.isEmpty() || !gatheringMonth.isEmpty() || !gatheringDay.isEmpty())) {
Calendar calendar = Calendar.getInstance();
if (!gatheringYear.isEmpty()) {
TimePeriod tp = TimePeriod.NewInstance(Integer.parseInt(gatheringYear));
if (!gatheringMonth.isEmpty()) {
tp.setStartMonth(Integer.parseInt(gatheringMonth));
if (!gatheringDay.isEmpty()) {
tp.setStartDay(Integer.parseInt(gatheringDay));
}
}
unitsGatheringEvent.setGatheringDate(tp);
}
} else {
if (!gatheringDate.isEmpty()) {
TimePeriod tp = TimePeriodParser.parseString(gatheringDate);
unitsGatheringEvent.setGatheringDate(tp);
}
}
// add fieldNumber
derivedUnitFacade.setFieldNumber(fieldNumber);
// add Multimedia URLs
if (multimediaObjects.size() > 0) {
for (String multimediaObject : multimediaObjects) {
Media media;
try {
media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
derivedUnitFacade.addDerivedUnitMedia(media);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
getOccurrenceService().saveOrUpdate(derivedUnitBase);
setTaxonName(config);
// refreshTransaction();
if (DEBUG) {
logger.info("saved new specimen ...");
}
} catch (Exception e) {
logger.warn("Error when reading record!!");
e.printStackTrace();
result = false;
}
if (DEBUG) {
logger.info("commit done");
}
// app.close();
return result;
}
use of eu.etaxonomy.cdm.model.occurrence.GatheringEvent in project cdmlib by cybertaxonomy.
the class TestSpecimen method testSpecimen.
public void testSpecimen() {
logger.info("Create test taxon ...");
Reference sec = ReferenceFactory.newDatabase();
String fullNameString = "Acanthostyles saucechicoensis (Hieron.) R.M. King & H. Rob.";
INonViralName name = NonViralNameParserImpl.NewInstance().parseFullName(fullNameString);
TaxonName botanicalName = TaxonName.castAndDeproxy(name);
Taxon taxon = Taxon.NewInstance(botanicalName, sec);
Collection collection = Collection.NewInstance();
String collectionCode = "ABCDE";
collection.setCode(collectionCode);
Institution institution = Institution.NewInstance();
String institutionCode = "Inst444";
institution.setCode(institutionCode);
collection.setInstitute(institution);
logger.info("Create determination event");
DeterminationEvent determinationEvent = DeterminationEvent.NewInstance();
determinationEvent.setTaxon(taxon);
Person actor = Person.NewTitledInstance("J. M�ller (JE)");
determinationEvent.setActor(actor);
logger.info("Create gathering event");
GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
AgentBase<?> gatherer = Person.NewTitledInstance("Lorentz,P.G. s.n.");
gatheringEvent.setActor(gatherer);
Calendar gatheringDate = Calendar.getInstance();
int year = 1922;
int month = 10;
int date = 05;
gatheringDate.set(year, month, date);
gatheringEvent.setGatheringDate(gatheringDate);
logger.info("Create locality");
NamedArea namedArea = NamedArea.NewInstance();
Country country = Country.ARGENTINAARGENTINEREPUBLIC();
namedArea.addCountry(country);
namedArea.setType(NamedAreaType.ADMINISTRATION_AREA());
// XX
gatheringEvent.addCollectingArea(namedArea);
String localityString = "Sierras Pampeanas, Sauce Chico";
LanguageString locality = LanguageString.NewInstance(localityString, Language.DEFAULT());
gatheringEvent.setLocality(locality);
logger.info("Create new specimen ...");
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
specimen.setCatalogNumber("JE 00004506");
// ??
specimen.setStoredUnder(botanicalName);
specimen.setCollection(collection);
String annotation = "originally designated as type specimen 2000, but corrected 2005-11";
specimen.addAnnotation(Annotation.NewDefaultLanguageInstance(annotation));
Media media = Media.NewInstance();
URI uri = null;
try {
uri = new URI("http://131.130.131.9/database/img/imgBrowser.php?ID=50599");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
String mimeType = null;
Integer size = null;
MediaRepresentation mediaRepresentation = MediaRepresentation.NewInstance(mimeType, "jpg");
media.addRepresentation(mediaRepresentation);
MediaRepresentationPart mediaRepresentationPart = MediaRepresentationPart.NewInstance(uri, size);
mediaRepresentation.addRepresentationPart(mediaRepresentationPart);
// specimen.addMedia(media); #3597
// Original ID
String id = "22";
IdentifiableSource source = IdentifiableSource.NewDataImportInstance(id);
specimen.addSource(source);
FieldUnit fieldUnit = FieldUnit.NewInstance();
DerivationEvent derivationEvent = DerivationEvent.NewInstance(DerivationEventType.GATHERING_IN_SITU());
derivationEvent.addDerivative(specimen);
fieldUnit.addDerivationEvent(derivationEvent);
fieldUnit.setGatheringEvent(gatheringEvent);
// type information
// typified by
logger.warn("Specimen: " + specimen);
DerivationEvent dEvent = specimen.getDerivedFrom();
logger.warn("DerivationEvent: " + dEvent);
Set<SpecimenOrObservationBase> originals = dEvent.getOriginals();
logger.warn("Originals: " + originals);
for (SpecimenOrObservationBase<?> original : originals) {
if (original instanceof FieldUnit) {
FieldUnit fieldUnit2 = (FieldUnit) original;
logger.warn("FieldUnit: " + fieldUnit2);
GatheringEvent gatheringEvent2 = fieldUnit2.getGatheringEvent();
logger.warn("GatheringEvent: " + gatheringEvent2);
AgentBase<?> gatherer2 = gatheringEvent2.getCollector();
logger.warn("Gatherer: " + gatherer2);
}
}
}
use of eu.etaxonomy.cdm.model.occurrence.GatheringEvent in project cdmlib by cybertaxonomy.
the class SpecimenTest method testUnmarshalSpecimen.
@Test
public void testUnmarshalSpecimen() throws Exception {
CdmDocumentBuilder cdmDocumentBuilder = new CdmDocumentBuilder();
URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)), uri.toString());
// List<SpecimenOrObservationBase> occurrences = dataSet.getOccurrences();
DerivedUnit specimen = (DerivedUnit) dataSet.getOccurrences().get(0);
assertNotNull("Specimen must not be null", specimen);
Institution institution = (Institution) dataSet.getAgents().get(0);
assertNotNull("Institution must not be null", institution);
Person person = (Person) dataSet.getAgents().get(1);
assertNotNull("Person must not be null", person);
Taxon taxon = (Taxon) dataSet.getTaxonBases().get(0);
assertNotNull("Taxon must not be null", taxon);
TaxonName name = dataSet.getTaxonomicNames().get(0);
assertNotNull("TaxonName must not be null", name);
DefinedTerm sex = (DefinedTerm) dataSet.getTerms().get(1);
Collection collection = dataSet.getCollections().get(0);
assertNotNull("Collection must not be null", collection);
FieldUnit fieldUnit = (FieldUnit) dataSet.getOccurrences().get(1);
assertNotNull("FieldUnit must not be null", fieldUnit);
assertEquals("Specimen.collection must equal Collection", collection, specimen.getCollection());
assertEquals("Collection.institute must equal Institution", institution, collection.getInstitute());
assertEquals("TaxonName must equal Specimen.storedUnder", name, specimen.getStoredUnder());
assertEquals("Sex must equal Specimen.sex", sex, specimen.getSex());
assertNotNull("Specimen.determinations must not be null", specimen.getDeterminations());
assertFalse("Specimen.determinations must not be empty", specimen.getDeterminations().isEmpty());
DeterminationEvent determination = specimen.getDeterminations().iterator().next();
assertEquals("Person must equal Determination.actor", person, determination.getActor());
GatheringEvent gatheringEvent = (GatheringEvent) dataSet.getEventBases().get(0);
assertNotNull("GatheringEvent must not be null", gatheringEvent);
DerivationEvent derivationEvent = (DerivationEvent) dataSet.getEventBases().get(1);
assertNotNull("DerivationEvent must not be null", derivationEvent);
assertEquals("GatheringEvent must be equal to FieldUnit.getGatheringEvent()", gatheringEvent, fieldUnit.getGatheringEvent());
assertTrue("DerivationEvent.derivatives must contain Specimen", derivationEvent.getDerivatives().contains(specimen));
assertEquals("DerivationEvent must equal Specimen.derivedFrom", derivationEvent, specimen.getDerivedFrom());
}
Aggregations