use of eu.etaxonomy.cdm.model.taxon.Taxon in project cdmlib by cybertaxonomy.
the class EditGeoServiceTest method createTestDataSet.
@Override
public // @Test
void createTestDataSet() throws FileNotFoundException {
List<TaxonDescription> taxonDescriptions = new ArrayList<>();
TaxonDescription description1 = TaxonDescription.NewInstance();
taxonDescriptions.add(description1);
Distribution distribution1 = Distribution.NewInstance(Country.POLANDPOLISHPEOPLESREPUBLIC(), null);
description1.addElement(distribution1);
Distribution distribution2 = Distribution.NewInstance(Country.SWITZERLANDSWISSCONFEDERATION(), null);
// distribution2.setFeature(Feature.COMMON_NAME());
description1.addElement(distribution2);
Taxon taxon = Taxon.NewInstance(null, null);
taxon.setTitleCache("Dummy taxon", true);
taxon.addDescription(description1);
taxon.setUuid(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
taxonService.save(taxon);
setComplete();
endTransaction();
writeDbUnitDataSetFile(new String[] { "TAXONBASE", "DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE", // IMPORTANT!!!
"HIBERNATE_SEQUENCES" }, "getDistributionServiceRequestParameterString", true);
}
use of eu.etaxonomy.cdm.model.taxon.Taxon in project cdmlib by cybertaxonomy.
the class EditGeoServiceTest method getDistributionServiceRequestParameterString.
@SuppressWarnings("deprecation")
// @Test
@DataSet(value = "EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
public // })
void getDistributionServiceRequestParameterString() {
boolean subAreaPreference = false;
boolean statusOrderPreference = false;
Set<MarkerType> hideMarkedAreas = null;
Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;
List<Language> langs = null;
List<TaxonDescription> taxonDescriptions = new ArrayList<>();
TaxonDescription description1 = TaxonDescription.NewInstance();
taxonDescriptions.add(description1);
Distribution distribution1 = Distribution.NewInstance(Country.GERMANY(), null);
description1.addElement(distribution1);
Distribution distribution2 = Distribution.NewInstance(Country.FRANCE(), null);
distribution2.setFeature(Feature.COMMON_NAME());
description1.addElement(distribution2);
Taxon taxon = (Taxon) taxonService.find(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
TaxonDescription taxDesc = taxon.getDescriptions().iterator().next();
for (DescriptionElementBase deb : taxDesc.getElements()) {
Distribution distribution = CdmBase.deproxy(deb, Distribution.class);
NamedArea area = distribution.getArea();
System.out.println(area.getTitleCache());
}
taxonDescriptions.addAll(taxon.getDescriptions());
String distributions = editGeoService.getDistributionServiceRequestParameterString(taxonDescriptions, subAreaPreference, statusOrderPreference, hideMarkedAreas, presenceAbsenceTermColors, langs);
System.out.println(distributions);
Assert.assertTrue("Distribution string should contain the non-persited distribution Germany", distributions.contains("DEU"));
Assert.assertFalse("Distribution string should contain France as it has a non-distribution feature", distributions.contains("FRA"));
// CHE,POL
}
use of eu.etaxonomy.cdm.model.taxon.Taxon in project cdmlib by cybertaxonomy.
the class CsvExportController method doExportRedlist.
/**
* Fetches data from the application context and forwards the stream to the HttpServletResponse,
* which offers a file download.
*
* @param featureUuids List of uuids to download/select {@link Feature feature}features
* @param taxonName the selected taxon name
* @param classificationUuid the uuid of the selected classification
* @param response HttpServletResponse which returns the ByteArrayOutputStream
*/
@RequestMapping(value = { "exportRedlist" }, method = { RequestMethod.POST })
public void doExportRedlist(@RequestParam(value = "features", required = false) UuidList featureUuids, @RequestParam(value = "classificationUuid", required = false) String classificationUuid, @RequestParam(value = "taxonName", required = false) String taxonName, @RequestParam(value = "area", required = false) UuidList areas, @RequestParam(value = "downloadTokenValueId", required = false) String downloadTokenValueId, HttpServletResponse response, HttpServletRequest request) {
boolean includeUnpublished = NO_UNPUBLISHED;
Classification classification = classificationService.load(UUID.fromString(classificationUuid), CLASSIFICATION_INIT_STRATEGY);
UUID taxonNodeUuid = classification.getRootNode().getUuid();
if (CdmUtils.isNotBlank(taxonName)) {
MatchingTaxonConfigurator config = new MatchingTaxonConfigurator();
config.setIncludeUnpublished(includeUnpublished);
config.setClassificationUuid(UUID.fromString(classificationUuid));
config.setTaxonNameTitle(taxonName);
List<TaxonBase> taxaByName = taxonService.findTaxaByName(config);
for (TaxonBase<?> taxonBase : taxaByName) {
if (taxonBase.isInstanceOf(Taxon.class)) {
TaxonNode taxonNode = classification.getNode(HibernateProxyHelper.deproxy(taxonService.load(taxonBase.getUuid(), TAXON_WITH_NODES_INIT_STRATEGY), Taxon.class));
if (taxonNode != null) {
taxonNodeUuid = taxonNode.getUuid();
break;
}
}
}
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
CsvTaxExportConfiguratorRedlist config = setTaxExportConfigurator(taxonNodeUuid, featureUuids, areas, byteArrayOutputStream);
CdmApplicationAwareDefaultExport<CsvTaxExportConfiguratorRedlist> defaultExport = (CdmApplicationAwareDefaultExport<CsvTaxExportConfiguratorRedlist>) appContext.getBean("defaultExport");
logger.info("Start export...");
logger.info("doExportRedlist()" + requestPathAndQuery(request));
defaultExport.invoke(config);
try {
/*
* Fetch data from the appContext and forward stream to HttpServleResponse
*
* FIXME: Large Data could be out of memory
*
* HTPP Error Break
*/
// byteArrayOutputStream.toByteArray()
ByteArrayInputStream bais = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
InputStreamReader isr = new InputStreamReader(bais);
Cookie progressCookie = new Cookie("fileDownloadToken", downloadTokenValueId);
progressCookie.setPath("/");
progressCookie.setMaxAge(60);
response.addCookie(progressCookie);
response.setContentType("text/csv; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + config.getClassificationTitleCache() + ".txt\"");
PrintWriter printWriter = response.getWriter();
int i;
while ((i = isr.read()) != -1) {
printWriter.write(i);
}
byteArrayOutputStream.flush();
isr.close();
byteArrayOutputStream.close();
printWriter.flush();
printWriter.close();
} catch (Exception e) {
logger.error("error generating feed", e);
}
}
use of eu.etaxonomy.cdm.model.taxon.Taxon in project cdmlib by cybertaxonomy.
the class KmlController method doGetTypeDesignationsKml.
/**
* Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
* {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
* an valid URI parameter String. Higher level distribution areas are expanded in order to include all
* nested sub-areas.
* <p>
* URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
*
* @param request
* @param response
* @return URI parameter Strings for the EDIT Map Service
* @throws IOException TODO write controller method documentation
*/
@RequestMapping(value = { "typeDesignations/{uuid-list}" }, method = RequestMethod.GET)
public Kml doGetTypeDesignationsKml(@PathVariable("uuid-list") UuidList uuidList, HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.info("doGetTypeDesignationsKml() " + requestPathAndQuery(request));
Map<SpecimenOrObservationType, Color> specimenOrObservationTypeColors = null;
List<TypeDesignationBase<?>> typeDesignations = nameService.loadTypeDesignations(uuidList, Arrays.asList("typeSpecimen"));
List<SpecimenOrObservationBase> specimensOrObersvations = typeDesignations.stream().filter(td -> td != null && td instanceof SpecimenTypeDesignation).map(SpecimenTypeDesignation.class::cast).map(SpecimenTypeDesignation::getTypeSpecimen).filter(s -> s != null).collect(Collectors.toList());
Kml kml = geoservice.occurrencesToKML(specimensOrObersvations, specimenOrObservationTypeColors);
return kml;
}
use of eu.etaxonomy.cdm.model.taxon.Taxon in project cdmlib by cybertaxonomy.
the class TaxonController method doListSpecimensOrObservations.
@RequestMapping(value = "specimensOrObservations", method = RequestMethod.GET)
public List<SpecimenOrObservationBase<?>> doListSpecimensOrObservations(@PathVariable("uuid") UUID uuid, HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
TaxonBase<?> tb = service.load(uuid);
List<OrderHint> orderHints = new ArrayList<>();
orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
if (tb instanceof Taxon) {
List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon) tb, null, null, null, orderHints, null);
return specimensOrObservations;
} else {
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
return null;
}
}
Aggregations