Search in sources :

Example 1 with BiocacheQuery

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

the class ExportSpeciesExternalComposer method onFinish.

@Override
public boolean onFinish() {
    List<Query> list = getAllSelectedSpecies();
    List<Map> maps = new ArrayList<>();
    for (Query q : list) {
        Map m = new HashMap();
        m.put("name", q.getName());
        m.put("query", "qid:" + ((BiocacheQuery) q).getQid());
        m.put("url", q.getBS());
        maps.add(m);
    }
    Map container = new HashMap();
    container.put("data", maps);
    String json = JSONObject.toJSONString(container);
    getMapComposer().getOpenLayersJavascript().execute("postToExternal('" + CommonData.getSettings().getProperty("bccvl.post.url") + "', " + json + ");");
    login(null);
    loggingIn = false;
    return true;
}
Also used : BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Query(au.org.ala.spatial.util.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with BiocacheQuery

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

the class ClassificationLegend method getSelectionFacet.

String getSelectionFacet() {
    StringBuilder values = new StringBuilder();
    boolean unknown = false;
    for (Object selectedItem : selectedList) {
        String v = (String) selectedItem;
        v = displayToActualLabel(v);
        if (legendFacets != null && !StringConstants.UNKNOWN.equals(v) && !v.contains(StringConstants.OCCURRENCE_YEAR) && !v.contains(StringConstants.UNCERTAINTY) && !v.contains(StringConstants.COORDINATE_UNCERTAINTY)) {
            v = legendFacets.get(v);
        }
        if (v.length() == 0 || ((query instanceof BiocacheQuery || divContinous.isVisible()) && StringConstants.UNKNOWN.equals(v))) {
            unknown = true;
        } else {
            if (values.length() > 0) {
                values.append(" OR ");
            }
            if (legendFacets != null) {
                values.append(v);
            } else {
                values.append(colourmode).append(":\"");
                values.append(v).append("\"");
            }
        }
    }
    String unknownSearch = divContinous.isVisible() ? ":[* TO *]" : ":*";
    if (unknown) {
        if (values.length() > 0) {
            String newValues = "-(" + colourmode + unknownSearch + " AND -" + values.toString().replace(" OR ", " AND -") + ")";
            values = new StringBuilder();
            values.append(newValues);
        } else {
            values.append("-").append(colourmode).append(unknownSearch);
        }
    }
    if (values.length() == 0 && (minValue != gMinValue || maxValue != gMaxValue || !dunknown.isChecked())) {
        if (dunknown.isChecked()) {
            if (intContinous) {
                values.append(String.format("-(%s:[* TO *] AND -%s:[%d TO %d])", colourmode, colourmode, (int) minValue, (int) maxValue));
            } else {
                values.append(String.format("-(%s:[* TO *] AND -%s:[%f TO %f])", colourmode, colourmode, minValue, maxValue));
            }
        } else {
            if (intContinous) {
                values.append(String.format("%s:[%d TO %d]", colourmode, (int) minValue, (int) maxValue));
            } else {
                values.append(String.format("%s:[%f TO %f]", colourmode, minValue, maxValue));
            }
        }
    }
    if (values.length() > 0) {
        facet = Facet.parseFacet(values.toString());
        return facet.toString();
    } else {
        facet = null;
        return "";
    }
}
Also used : LegendObject(au.org.ala.legend.LegendObject) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery)

Example 3 with BiocacheQuery

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

the class SandboxPasteController method gotDrUid.

public void gotDrUid(Event event) {
    dataResourceUid = ((String) event.getData());
    sandboxReady.setVisible(true);
    sandboxFrame.setVisible(false);
    List<Facet> facetList = new ArrayList<Facet>();
    facetList.add(new Facet("data_resource_uid", dataResourceUid, true));
    query = new BiocacheQuery(null, null, null, facetList, true, null, CommonData.getSettings().getProperty("sandbox.biocache.url"), CommonData.getSettings().getProperty("sandbox.biocache.ws.url"), true);
    if (addtoMap) {
        getMapComposer().mapSpecies(query, query.getSolrName(), StringConstants.SPECIES, query.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
    }
    // call reset window on caller to perform refresh'
    if (callback != null) {
        try {
            callback.onEvent(new ForwardEvent("", null, null, new String[] { dataResourceUid, "normal" }));
        } catch (Exception e) {
            LOGGER.error("failed to cancel species points upload", e);
        }
    }
    onClick$btnOk(null);
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Facet(au.org.ala.legend.Facet)

Example 4 with BiocacheQuery

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

the class SamplingComposer method download.

public boolean download(Event event) {
    try {
        SelectedArea sa = getSelectedArea();
        Query query = QueryUtil.queryFromSelectedArea(getSelectedSpecies(), sa, false, getGeospatialKosher());
        // test size
        if (query.getOccurrenceCount() <= 0) {
            getMapComposer().showMessage("No occurrences selected. Please try again", this);
            return false;
        }
        // translate layer names
        String[] layers = null;
        String[] layersDisplaynames = null;
        String envlayers = getSelectedLayersWithDisplayNames();
        if (envlayers.length() > 0) {
            layers = envlayers.split(":");
            layersDisplaynames = new String[layers.length];
            for (int i = 0; i < layers.length; i++) {
                String[] l = layers[i].split("\\|");
                String newName = CommonData.getLayerFacetName(l[0]);
                layers[i] = newName;
                layersDisplaynames[i] = l[1];
            }
        }
        if (query instanceof BiocacheQuery) {
            String[] inBiocache = null;
            String[] outBiocache;
            String[] outBiocacheDN;
            // split layers into 'in biocache' and 'out of biocache'
            Set<String> biocacheLayers = CommonData.getBiocacheLayerList();
            List<String> aInBiocache = new ArrayList<String>();
            List<String> aOutBiocache = new ArrayList<String>();
            List<String> aInBiocacheDN = new ArrayList<String>();
            List<String> aOutBiocacheDN = new ArrayList<String>();
            if (layers != null) {
                for (int i = 0; i < layers.length; i++) {
                    String s = layers[i];
                    if (biocacheLayers.contains(s)) {
                        aInBiocache.add(s);
                        aInBiocacheDN.add(layersDisplaynames[i]);
                    } else {
                        aOutBiocache.add(s);
                        aOutBiocacheDN.add(layersDisplaynames[i]);
                    }
                }
            }
            if (!aInBiocache.isEmpty()) {
                inBiocache = new String[aInBiocache.size()];
                aInBiocache.toArray(inBiocache);
            }
            if (!aOutBiocache.isEmpty()) {
                outBiocache = new String[aOutBiocache.size()];
                aOutBiocache.toArray(outBiocache);
                outBiocacheDN = new String[aOutBiocacheDN.size()];
                aOutBiocacheDN.toArray(outBiocacheDN);
                getMapComposer().setDownloadSecondQuery(query);
                getMapComposer().setDownloadSecondLayers(outBiocache, outBiocacheDN);
                SamplingAnalysisDownloadController c = (SamplingAnalysisDownloadController) Executions.createComponents("/WEB-INF/zul/output/SamplingAnalysisDownload.zul", getMapComposer(), null);
                c.setParent(getMapComposer());
                c.doModal();
            } else {
                getMapComposer().setDownloadSecondQuery(null);
                getMapComposer().setDownloadSecondLayers(null, null);
            }
            // test for URL download
            String url = query.getDownloadUrl(inBiocache);
            LOGGER.debug("Sending file to user: " + url);
            Events.echoEvent(StringConstants.OPEN_HTML, getMapComposer(), "Download\n" + url);
            try {
                remoteLogger.logMapAnalysis("species sampling", "Export - Species Sampling", sa.getWkt(), query.getName(), envlayers, pid, "", "download");
            } catch (Exception e) {
                LOGGER.error("remote logger error", e);
            }
            this.detach();
        } else {
            String fileUrl = query.getDownloadUrl(layers);
            Filedownload.save(new URL(fileUrl).openStream(), "application/zip", query.getName().replaceAll(" ", "_") + "_sample_" + ".zip");
            try {
                remoteLogger.logMapAnalysis("species sampling", "Export - Species Sampling", sa.getWkt(), query.getName(), envlayers, pid, "", "");
            } catch (Exception e) {
                LOGGER.error("remote logger error", e);
            }
            this.detach();
        }
        return true;
    } catch (Exception e) {
        LOGGER.error("Exception calling sampling.download:", e);
        getMapComposer().showMessage("Unknown error.", this);
    }
    return false;
}
Also used : SamplingAnalysisDownloadController(au.org.ala.spatial.composer.output.SamplingAnalysisDownloadController) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Query(au.org.ala.spatial.util.Query) SelectedArea(au.org.emii.portal.menu.SelectedArea) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) URL(java.net.URL)

Example 5 with BiocacheQuery

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

the class SandboxEmbeddedController method gotDrUid.

public void gotDrUid(Event event) {
    dataResourceUid = ((String) event.getData());
    sandboxReady.setVisible(true);
    sandboxFrame.setVisible(false);
    List<Facet> facetList = new ArrayList<Facet>();
    facetList.add(new Facet("data_resource_uid", dataResourceUid, true));
    query = new BiocacheQuery(null, null, null, facetList, true, null, CommonData.getSettings().getProperty("sandbox.biocache.url"), CommonData.getSettings().getProperty("sandbox.biocache.ws.url"), true);
    if (addtoMap) {
        getMapComposer().mapSpecies(query, query.getSolrName(), StringConstants.SPECIES, query.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
    }
    // call reset window on caller to perform refresh'
    if (callback != null) {
        try {
            callback.onEvent(new ForwardEvent("", null, null, new String[] { dataResourceUid, "normal" }));
        } catch (Exception e) {
            LOGGER.error("failed to cancel species points upload", e);
        }
    }
    onClick$btnOk(null);
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Facet(au.org.ala.legend.Facet)

Aggregations

BiocacheQuery (au.org.ala.spatial.util.BiocacheQuery)10 ArrayList (java.util.ArrayList)5 Query (au.org.ala.spatial.util.Query)3 Facet (au.org.ala.legend.Facet)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)2 LegendObject (au.org.ala.legend.LegendObject)1 SamplingAnalysisDownloadController (au.org.ala.spatial.composer.output.SamplingAnalysisDownloadController)1 SpeciesListItemDTO (au.org.ala.spatial.dto.SpeciesListItemDTO)1 SelectedArea (au.org.emii.portal.menu.SelectedArea)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 CheckEvent (org.zkoss.zk.ui.event.CheckEvent)1