Search in sources :

Example 6 with BiocacheQuery

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

the class SpeciesListListbox method extractQueryFromSelectedLists.

/**
 * Returns a query object that represents a query for all species on the selected lists.
 *
 * @param geospatialKosher
 * @return
 */
public BiocacheQuery extractQueryFromSelectedLists(boolean[] geospatialKosher) {
    StringBuilder sb = new StringBuilder();
    List<String> names = new ArrayList<String>();
    int maxOrTerms = Integer.parseInt(CommonData.getSettings().getProperty("solr.maxOrTerms", "200"));
    int count = 0;
    for (String list : selectedLists) {
        // get the speciesListItems
        Collection<SpeciesListItemDTO> items = SpeciesListUtil.getListItems(list);
        for (SpeciesListItemDTO item : items) {
            count = count + 1;
            if (item.getLsid() != null && count <= maxOrTerms) {
                if (sb.length() > 0) {
                    sb.append(",");
                }
                sb.append(item.getLsid());
            } else {
                names.add(item.getName());
            }
        }
    }
    String[] unmatchedNames = !names.isEmpty() ? names.toArray(new String[names.size()]) : null;
    String lsids = sb.length() > 0 ? sb.toString() : null;
    // ignore unmatchedNames
    return new BiocacheQuery(lsids, null, null, null, null, false, geospatialKosher);
}
Also used : SpeciesListItemDTO(au.org.ala.spatial.dto.SpeciesListItemDTO) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery)

Example 7 with BiocacheQuery

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

the class OpenLayersJavascriptImpl method defineWMSMapLayer.

/**
 * create an instance of OpenLayers.Layer.WMS.
 * <p/>
 * Base layers will be rendered differently and stored in the baseLayers
 * associative array instead of the mapLayers associative array
 *
 * @param layer
 * @return
 */
public String defineWMSMapLayer(MapLayer layer) {
    String associativeArray;
    String gutter = "0";
    String params = "";
    if (layer.isBaseLayer()) {
        associativeArray = StringConstants.BASE_LAYERS;
    } else {
        associativeArray = StringConstants.MAP_LAYERS;
    }
    if (!Validate.empty(layer.getCql())) {
        params = "CQL_FILTER: '" + layer.getCqlJS() + "' ";
        params += ", ";
    }
    if (!Validate.empty(layer.getEnvParams())) {
        try {
            params += "env: '" + URLEncoder.encode(layer.getEnvParams(), StringConstants.UTF_8) + "', ";
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("failed to encode env params : " + layer.getEnvParams().replace("'", "\\'"), e);
        }
    }
    String dynamicStyle = "";
    if (layer.isPolygonLayer()) {
        String colour = Integer.toHexString((0xFF0000 & (layer.getRedVal() << 16)) | (0x00FF00 & layer.getGreenVal() << 8) | (0x0000FF & layer.getBlueVal()));
        while (colour.length() < 6) {
            colour = "0" + colour;
        }
        String filter;
        /*
                two types of areas are displayed as WMS.
                1. environmental envelopes. these are backed by a grid file.
                2. layerdb, objects table, areas referenced by a pid.  these are geometries.
             */
        if (layer.getUri().contains("ALA:envelope")) {
            filter = "";
            if (!layer.getUri().contains("sld_body")) {
                filter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\">" + "<NamedLayer><Name>" + layerUtilities.getLayer(layer.getUri()) + "</Name>" + "<UserStyle><FeatureTypeStyle><Rule><RasterSymbolizer><Geometry></Geometry>" + "<ColorMap>" + "<ColorMapEntry color=\"#ffffff\" opacity=\"0\" quantity=\"0\"/>" + "<ColorMapEntry color=\"#" + colour + "\" opacity=\"1\" quantity=\"1\" />" + "</ColorMap></RasterSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>";
            }
        } else if (layer.getUri() != null && layer.getUri().contains("ColorMapEntry")) {
            // area from grid as contextual layer
            String uri = layer.getUri();
            // replace with current colour
            String str = "ColorMapEntry+color%3D%220x";
            int p = uri.indexOf(str);
            while (p > 0 && p + str.length() + 6 < uri.length()) {
                uri = uri.substring(0, p + str.length()) + colour + uri.substring(p + str.length() + 6);
                p = uri.indexOf(str, p + 1);
            }
            layer.setUri(uri);
            filter = "";
        } else {
            filter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><StyledLayerDescriptor version=\"1.0.0\" xmlns=\"http://www.opengis.net/sld\">" + "<NamedLayer><Name>" + layerUtilities.getLayer(layer.getUri()) + "</Name>" + "<UserStyle><FeatureTypeStyle><Rule><Title>Polygon</Title><PolygonSymbolizer><Fill>" + "<CssParameter name=\"fill\">#" + colour + "</CssParameter></Fill>" + "</PolygonSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>";
        }
        try {
            if (filter.length() == 0) {
                dynamicStyle = "";
            } else {
                dynamicStyle = "&sld_body=" + URLEncoder.encode(filter, StringConstants.UTF_8);
            }
        } catch (Exception e) {
            LOGGER.debug("invalid filter sld", e);
        }
    }
    String script = " " + associativeArray + "['" + layer.getUniqueIdJS() + "'] = new OpenLayers.Layer.WMS(" + "  '" + layer.getNameJS() + "', " + "  '" + layer.getUriJS().replace("wms?service=WMS&version=1.1.0&request=GetMap&", "wms\\/reflect?") + dynamicStyle + "', " + "  {" + ((StringConstants.DEFAULT.equals(layer.getSelectedStyleNameJS())) ? "" : "   styles: '" + layer.getSelectedStyleNameJS() + "', ") + "   layers: '" + layer.getLayerJS() + "', " + "   format: '" + layer.getImageFormat() + "', " + "         srs: 'epsg:3857', " + "   transparent: " + (!layer.isBaseLayer()) + ", " + "   " + params + wmsVersionDeclaration(layer) + "  }, " + "  { " + "   isBaseLayer: " + layer.isBaseLayer() + ", " + "   opacity: " + layer.getOpacity() + ", " + "   queryable: true, " + "   gutter: " + gutter + ", " + "   wrapDateLine: true, displayname: '" + StringEscapeUtils.escapeJavaScript(layer.getDisplayName()) + "'" + "  }  " + " ); " + // tiles around the viewport!!
    associativeArray + "['" + layer.getUniqueIdJS() + "']" + ".getFeatureInfoBuffer =" + CommonData.getSettings().getProperty("get_feature_info_buffer") + "; ";
    // add ws and bs urls for species layers
    if (layer.getSpeciesQuery() != null) {
        Query q = layer.getSpeciesQuery();
        if (q instanceof BiocacheQuery) {
            BiocacheQuery bq = (BiocacheQuery) q;
            try {
                script += associativeArray + "['" + layer.getUniqueIdJS() + "']" + ".ws ='" + StringEscapeUtils.escapeJavaScript(bq.getWS()) + "'; " + associativeArray + "['" + layer.getUniqueIdJS() + "']" + ".bs ='" + StringEscapeUtils.escapeJavaScript(bq.getBS()) + "'; ";
            } catch (Exception e) {
                LOGGER.error("error escaping for JS: " + bq.getBS(), e);
            }
        }
        if (q.flagRecordCount() > 0) {
            script += "parent.addFlaggedRecords('" + layer.getNameJS() + "','" + StringEscapeUtils.escapeJavaScript(q.getFlaggedRecords()) + "'); ";
        }
    }
    if (!layer.isBaseLayer()) {
        script += " " + associativeArray + "['" + layer.getUniqueIdJS() + "']" + ".featureInfoResponseType=" + layer.getType() + "; ";
    }
    // register for loading images...
    script += "registerLayer(" + associativeArray + "['" + layer.getUniqueIdJS() + "']);";
    return wrapWithSafeToProceed(script);
}
Also used : BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Query(au.org.ala.spatial.util.Query) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with BiocacheQuery

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

the class AddSpeciesController method addTolMultiple.

private void addTolMultiple(String lsid, String sciname, String family, String kingdom, boolean insertAtBeginning) {
    for (Listitem li : lMultiple.getItems()) {
        Listcell lsidCell = (Listcell) li.getLastChild();
        Listcell scinameCell = (Listcell) li.getFirstChild().getNextSibling();
        if ((lsidCell.getLabel().equals(lsid)) || (scinameCell.getLabel().replace("(not found)", "").trim().equals(sciname))) {
            return;
        }
    }
    Listitem li = new Listitem();
    // remove button
    Listcell lc = new Listcell("x");
    lc.setSclass("xRemove");
    lc.addEventListener(StringConstants.ONCLICK, new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            Listitem li = (Listitem) event.getTarget().getParent();
            li.detach();
            refreshBtnOkDisabled();
            if (multipleSpeciesUploadName == null) {
                multipleSpeciesUploadName = "";
            }
            if (loadedAssemblage && !multipleSpeciesUploadName.contains("subset")) {
                multipleSpeciesUploadName += " - subset";
            }
        }
    });
    lc.setParent(li);
    // sci name
    if (lsid == null) {
        lc = new Listcell(sciname + " (not found)");
        lc.setSclass("notFoundSciname");
    } else {
        lc = new Listcell(sciname);
    }
    lc.setParent(li);
    // family
    if (lsid == null && !sciname.matches(".*[0-9].*")) {
        lc = new Listcell("click to search");
        lc.setSclass("notFoundFamily");
        lc.addEventListener(StringConstants.ONCLICK, new EventListener() {

            @Override
            public void onEvent(Event event) throws Exception {
                Listitem li = (Listitem) event.getTarget().getParent();
                Listcell scinameCell = (Listcell) li.getFirstChild().getNextSibling();
                String sciname = scinameCell.getLabel().replace("(not found)", "").trim();
                mSearchSpeciesACComponent.getAutoComplete().refresh(sciname);
                mSearchSpeciesACComponent.getAutoComplete().open();
                mSearchSpeciesACComponent.getAutoComplete().setText(sciname + " ");
                li.detach();
            }
        });
    } else {
        lc = new Listcell(family);
    }
    lc.setParent(li);
    // kingdom
    lc = new Listcell(kingdom);
    lc.setParent(li);
    // count
    if (lsid != null) {
        int count = new BiocacheQuery(lsid, null, null, null, false, getGeospatialKosher()).getOccurrenceCount();
        if (count > 0) {
            lc = new Listcell(String.valueOf(count));
        } else {
            lc = new Listcell(kingdom);
        }
    } else {
        int count = new BiocacheQuery(null, null, "raw_name:\"" + sciname + "\"", null, false, getGeospatialKosher()).getOccurrenceCount();
        if (count > 0) {
            lc = new Listcell(String.valueOf(count));
        } else {
            lc = new Listcell(kingdom);
        }
    }
    lc.setParent(li);
    // lsid
    lc = new Listcell(lsid);
    lc.setParent(li);
    if (insertAtBeginning && !lMultiple.getChildren().isEmpty()) {
        lMultiple.insertBefore(li, lMultiple.getFirstChild());
    } else {
        li.setParent(lMultiple);
    }
}
Also used : BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) IOException(java.io.IOException)

Example 9 with BiocacheQuery

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

the class AddSpeciesController method onClick$btnOk.

public void onClick$btnOk(Event event) {
    Map params = new HashMap();
    params.put(StringConstants.POLYGON_LAYERS, getMapComposer().getPolygonLayers());
    if (btnOk.isDisabled()) {
        return;
    }
    loadedAssemblage = false;
    if (rAllSpecies.isSelected()) {
        AddSpeciesInArea window = (AddSpeciesInArea) Executions.createComponents("WEB-INF/zul/add/AddSpeciesInArea.zul", getMapComposer(), params);
        window.setGeospatialKosher(getGeospatialKosher());
        window.setExpertDistributions(chkExpertDistributions.isChecked());
        window.setAllSpecies(true);
        window.loadAreaLayers();
        try {
            window.setParent(getMapComposer());
            window.doModal();
        } catch (Exception e) {
            LOGGER.error("error opening AddSpeciesInArea.zul", e);
        }
    } else if (chkArea.isChecked()) {
        getFromAutocomplete();
        if (rSearch.isSelected()) {
            AddSpeciesInArea window = (AddSpeciesInArea) Executions.createComponents("WEB-INF/zul/add/AddSpeciesInArea.zul", getMapComposer(), params);
            window.setSpeciesParams(query, rank, taxon);
            window.setExpertDistributions(chkExpertDistributions.isChecked());
            window.loadAreaLayers();
            try {
                window.setParent(getMapComposer());
                window.doModal();
            } catch (Exception e) {
                LOGGER.error("error opening AddSpeciesInArea.zul", e);
            }
        } else if (rMultiple.isSelected()) {
            // when next is pressed we want to export the list to the species list
            if (Util.getUserEmail() != null && !"guest@ala.org.au".equals(Util.getUserEmail())) {
                showExportSpeciesListDialog();
                loadedAssemblage = true;
            } else {
                AddSpeciesInArea window = (AddSpeciesInArea) Executions.createComponents("WEB-INF/zul/add/AddSpeciesInArea.zul", getMapComposer(), params);
                window.setExpertDistributions(chkExpertDistributions.isChecked());
                // extract all lsids
                StringBuilder sb = new StringBuilder();
                for (Listitem li : lMultiple.getItems()) {
                    Listcell lsidCell = (Listcell) li.getLastChild();
                    if (!lsidCell.getLabel().contains("not found")) {
                        if (sb.length() > 0) {
                            sb.append(",");
                        }
                        sb.append(lsidCell.getLabel());
                    }
                }
                query = new BiocacheQuery(sb.toString(), null, null, null, null, false, getGeospatialKosher());
                window.setSpeciesParams(query, rank, taxon);
                window.setMultipleSpeciesUploadName(CommonData.lang("uploaded_species_list_layer_name"));
                window.loadAreaLayers();
                try {
                    window.setParent(getMapComposer());
                    window.doModal();
                } catch (Exception e) {
                    LOGGER.error("error opening AddSpeciesInArea.zul", e);
                }
            }
        } else if (rUploadLSIDs.isSelected()) {
            // we need to populate the "create assemblage" with the values from the species list
            AddSpeciesInArea window = (AddSpeciesInArea) Executions.createComponents("WEB-INF/zul/add/AddSpeciesInArea.zul", getMapComposer(), params);
            // extract all the items for selected species lists
            query = speciesListListbox.extractQueryFromSelectedLists(getGeospatialKosher());
            window.setSpeciesParams(query, rank, taxon);
            window.setMultipleSpeciesUploadName(CommonData.lang("uploaded_species_list_layer_name"));
            window.loadAreaLayers();
            try {
                window.setParent(getMapComposer());
                window.doModal();
            } catch (Exception e) {
                LOGGER.error("error opening AddSpeciesInArea.zul", e);
            }
        } else {
            onClick$btnUpload(event);
        }
    } else {
        if (rSearch.isSelected()) {
            getMapComposer().mapSpeciesFromAutocompleteComponent(searchSpeciesACComponent, null, getGeospatialKosher(), chkExpertDistributions.isChecked());
        } else if (rUploadLSIDs.isSelected()) {
            // we need to populate the "create assemblage" with the values from the species list
            loadedAssemblage = true;
        } else {
            onClick$btnUpload(event);
        }
    }
    if (!loadedAssemblage) {
        this.detach();
    }
}
Also used : HashMap(java.util.HashMap) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 10 with BiocacheQuery

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

the class SpeciesAutoCompleteComponent method onCheck$chkUseRawName.

/**
 * The use "supplied" name check box has been either selected or deselected,
 * take the appropriate action on the combo box
 *
 * @param event
 */
public void onCheck$chkUseRawName(Event event) {
    boolean checked = ((CheckEvent) event).isChecked();
    BiocacheQuery q = checked ? new BiocacheQuery(null, null, null, null, false, new boolean[] { true, true, false }) : null;
    autoComplete.setBiocacheQuery(q);
}
Also used : BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) CheckEvent(org.zkoss.zk.ui.event.CheckEvent)

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