Search in sources :

Example 1 with Taxon

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);
}
Also used : Distribution(eu.etaxonomy.cdm.model.description.Distribution) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList)

Example 2 with Taxon

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
}
Also used : Color(java.awt.Color) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) Language(eu.etaxonomy.cdm.model.common.Language) Distribution(eu.etaxonomy.cdm.model.description.Distribution) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) PresenceAbsenceTerm(eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with Taxon

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);
    }
}
Also used : CdmApplicationAwareDefaultExport(eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultExport) Cookie(javax.servlet.http.Cookie) MatchingTaxonConfigurator(eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) InputStreamReader(java.io.InputStreamReader) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) ByteArrayInputStream(java.io.ByteArrayInputStream) Classification(eu.etaxonomy.cdm.model.taxon.Classification) CsvTaxExportConfiguratorRedlist(eu.etaxonomy.cdm.io.csv.redlist.out.CsvTaxExportConfiguratorRedlist) UUID(java.util.UUID) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Taxon

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>&#x002F;{datasource-name}&#x002F;geo&#x002F;map&#x002F;distribution&#x002F;{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;
}
Also used : Color(java.awt.Color) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Controller(org.springframework.stereotype.Controller) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) IOccurrenceService(eu.etaxonomy.cdm.api.service.IOccurrenceService) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) HttpServletRequest(javax.servlet.http.HttpServletRequest) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) Map(java.util.Map) BaseController(eu.etaxonomy.cdm.remote.controller.BaseController) Api(io.swagger.annotations.Api) INameService(eu.etaxonomy.cdm.api.service.INameService) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) HttpServletResponse(javax.servlet.http.HttpServletResponse) OptionsController(eu.etaxonomy.cdm.remote.controller.OptionsController) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) IEditGeoService(eu.etaxonomy.cdm.ext.geo.IEditGeoService) SortOrder(eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ITaxonService(eu.etaxonomy.cdm.api.service.ITaxonService) TaxonRelationshipEdge(eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge) UuidList(eu.etaxonomy.cdm.remote.editor.UuidList) ControllerUtils(eu.etaxonomy.cdm.remote.controller.util.ControllerUtils) DefinedTermBaseList(eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList) UpdatableRoutingDataSource(eu.etaxonomy.cdm.database.UpdatableRoutingDataSource) TermBaseListPropertyEditor(eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor) WebDataBinder(org.springframework.web.bind.WebDataBinder) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) ResponseEntity(org.springframework.http.ResponseEntity) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) InitBinder(org.springframework.web.bind.annotation.InitBinder) ITermService(eu.etaxonomy.cdm.api.service.ITermService) UUIDListPropertyEditor(eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor) Color(java.awt.Color) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Taxon

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;
    }
}
Also used : OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)522 Test (org.junit.Test)203 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)147 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)141 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)126 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)124 DataSet (org.unitils.dbunit.annotation.DataSet)110 Reference (eu.etaxonomy.cdm.model.reference.Reference)108 ArrayList (java.util.ArrayList)99 UUID (java.util.UUID)98 Classification (eu.etaxonomy.cdm.model.taxon.Classification)88 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)88 HashSet (java.util.HashSet)54 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)53 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)53 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)52 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)50 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)48 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)38 TaxonRelationship (eu.etaxonomy.cdm.model.taxon.TaxonRelationship)36