Search in sources :

Example 11 with Query

use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.

the class ActiveLayersInfoEventListener method onEvent.

@Override
public void onEvent(Event event) throws Exception {
    MapComposer mapComposer = getMapComposer(event);
    if (mapComposer != null && mapComposer.safeToPerformMapAction()) {
        // get reference to the label/image the user clicked on
        Component target = event.getTarget();
        Listitem listItem = (Listitem) target.getParent().getParent();
        MapLayer activeLayer = listItem.getValue();
        if (activeLayer != null) {
            if (activeLayer.getSpeciesQuery() != null) {
                Query q = activeLayer.getSpeciesQuery();
                Events.echoEvent(StringConstants.OPEN_HTML, mapComposer, q.getMetadataHtml());
            } else if (activeLayer.getMapLayerMetadata().getMoreInfo() != null && activeLayer.getMapLayerMetadata().getMoreInfo().startsWith("http://")) {
                String infourl = activeLayer.getMapLayerMetadata().getMoreInfo().replace("__", ".");
                if (activeLayer.getSubType() == LayerUtilitiesImpl.SCATTERPLOT) {
                    ScatterplotDataDTO data = activeLayer.getScatterplotDataDTO();
                    infourl += "?dparam=X-Layer:" + data.getLayer1Name();
                    infourl += "&dparam=Y-Layer:" + data.getLayer2Name();
                }
                // send the user to the BIE page for the species
                LOGGER.debug("opening the following url " + infourl);
                Events.echoEvent(StringConstants.OPEN_URL, mapComposer, activeLayer.getMapLayerMetadata().getMoreInfo().replace("__", "."));
            } else if (activeLayer.getMapLayerMetadata().getMoreInfo() != null && activeLayer.getMapLayerMetadata().getMoreInfo().length() > 0) {
                LOGGER.debug("performing a MapComposer.showMessage for following content " + activeLayer.getMapLayerMetadata().getMoreInfo());
                String metadata = activeLayer.getMapLayerMetadata().getMoreInfo();
                Events.echoEvent(StringConstants.OPEN_HTML, mapComposer, metadata);
            } else if (activeLayer.getType() == LayerUtilitiesImpl.MAP) {
                String metaurl = "http://www.google.com/intl/en_au/help/terms_maps.html";
                if ("outline".equalsIgnoreCase(mapComposer.getPortalSession().getBaseLayer())) {
                    metaurl = "openstreetmap_metadata.html";
                } else if ("minimal".equalsIgnoreCase(mapComposer.getPortalSession().getBaseLayer())) {
                    metaurl = "http://www.naturalearthdata.com/about/terms-of-use";
                }
                LOGGER.debug("opening base map metadata for: " + mapComposer.getPortalSession().getBaseLayer() + ", url:" + metaurl);
                Events.echoEvent(StringConstants.OPEN_URL, mapComposer, metaurl);
            } else {
                LOGGER.debug("no metadata is available for current layer");
                mapComposer.showMessage("Metadata currently unavailable");
            }
        }
    } else {
        LOGGER.debug("MapController reports unsafe to perform action");
    }
}
Also used : ScatterplotDataDTO(au.org.ala.spatial.dto.ScatterplotDataDTO) MapComposer(au.org.emii.portal.composer.MapComposer) Query(au.org.ala.spatial.util.Query) MapLayer(au.org.emii.portal.menu.MapLayer) Listitem(org.zkoss.zul.Listitem) Component(org.zkoss.zk.ui.Component)

Example 12 with Query

use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.

the class SpeciesListResults method populateList.

public void populateList() {
    if (selectedArea == null) {
        selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
    }
    try {
        Query sq = QueryUtil.queryFromSelectedArea(null, selectedArea, extraParams, false, geospatialKosher);
        sq = sq.newFacet(new Facet("occurrence_status_s", "absent", false), false);
        if (sq.getSpeciesCount() <= 0) {
            getMapComposer().showMessage("No species records in the active area.");
            results = null;
            popupListboxResults.setVisible(false);
            resultsLabel.setVisible(false);
            this.detach();
            return;
        }
        // remove header
        String speciesList = chooseEndemic ? sq.endemicSpeciesList() : sq.speciesList();
        results = speciesList.substring(speciesList.indexOf('\n') + 1).split("\n");
        java.util.Arrays.sort(results);
        // results should already be sorted
        String[] tmp = results;
        if (results.length > 200) {
            tmp = java.util.Arrays.copyOf(results, 200);
            resultsLabel.setValue("preview of first 200 of " + results.length + " species found");
        } else {
            resultsLabel.setValue("preview of all " + results.length + " species found");
        }
        popupListboxResults.setModel(new ListModelArray(tmp, false));
        popupListboxResults.setItemRenderer(new ListitemRenderer() {

            public void render(Listitem li, Object data, int itemIdx) {
                String s = (String) data;
                CSVReader reader = new CSVReader(new StringReader(s));
                String[] ss;
                try {
                    ss = reader.readNext();
                } catch (Exception e) {
                    ss = new String[0];
                }
                if (ss == null || ss.length == 0) {
                    return;
                }
                Listcell lc = new Listcell(ss[0]);
                lc.setParent(li);
                int col = 1;
                while (col < ss.length) {
                    lc = new Listcell(ss[col]);
                    lc.setParent(li);
                    col++;
                }
                try {
                    reader.close();
                } catch (IOException e) {
                    LOGGER.error("error closing after reading species list", e);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("error reading species list data", e);
    }
}
Also used : Query(au.org.ala.spatial.util.Query) CSVReader(au.com.bytecode.opencsv.CSVReader) SelectedArea(au.org.emii.portal.menu.SelectedArea) IOException(java.io.IOException) IOException(java.io.IOException) StringReader(java.io.StringReader) Facet(au.org.ala.legend.Facet)

Aggregations

Query (au.org.ala.spatial.util.Query)12 Facet (au.org.ala.legend.Facet)5 SelectedArea (au.org.emii.portal.menu.SelectedArea)5 BiocacheQuery (au.org.ala.spatial.util.BiocacheQuery)4 MapLayer (au.org.emii.portal.menu.MapLayer)4 CSVReader (au.com.bytecode.opencsv.CSVReader)3 StringReader (java.io.StringReader)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.simple.JSONObject)3 ScatterplotDataDTO (au.org.ala.spatial.dto.ScatterplotDataDTO)2 MapComposer (au.org.emii.portal.composer.MapComposer)2 HashMap (java.util.HashMap)2 JSONArray (org.json.simple.JSONArray)2 JSONParser (org.json.simple.parser.JSONParser)2 ParseException (org.json.simple.parser.ParseException)2 Event (org.zkoss.zk.ui.event.Event)2 LegendObject (au.org.ala.legend.LegendObject)1 SamplingAnalysisDownloadController (au.org.ala.spatial.composer.output.SamplingAnalysisDownloadController)1 PhylogeneticDiversityListResults (au.org.ala.spatial.composer.results.PhylogeneticDiversityListResults)1 Geometry (com.vividsolutions.jts.geom.Geometry)1