use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.
the class SamplingComposer method fixFocus.
@Override
void fixFocus() {
switch(currentStep) {
case 1:
rgArea.setFocus(true);
break;
case 2:
if (rSpeciesSearch.isChecked()) {
searchSpeciesACComp.getAutoComplete().setFocus(true);
} else {
rgSpecies.setFocus(true);
}
break;
case 3:
lbListLayers.setFocus(true);
// tick and disable all 'DEFAULT' sampled layers
if (getSelectedSpecies() != null) {
Query q = getSelectedSpecies();
String[] defaultFields = q.getDefaultDownloadFields();
if (defaultFields.length > 0) {
lbListLayers.selectLayersAndDisable(defaultFields);
}
}
updateLayerSelectionCount();
break;
default:
LOGGER.error("invalid step for SamplingComposer: " + currentStep);
}
}
use of au.org.ala.spatial.util.Query 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;
}
use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.
the class MetadataEvent method onEvent.
@Override
public void onEvent(Event event) throws Exception {
MapComposer mc = (MapComposer) event.getPage().getFellow(StringConstants.MAPPORTALPAGE);
MapLayer mapLayer = mc.getMapLayer(layerName);
if (mapLayer != null) {
if (mapLayer.getSpeciesQuery() != null) {
// TODO: update for scatterplot layers
Query q = mapLayer.getSpeciesQuery();
Events.echoEvent(StringConstants.OPEN_HTML, mc, q.getMetadataHtml());
} else if (mapLayer.getMapLayerMetadata().getMoreInfo() != null && mapLayer.getMapLayerMetadata().getMoreInfo().startsWith("http://")) {
String infourl = mapLayer.getMapLayerMetadata().getMoreInfo().replace("__", ".");
if (mapLayer.getSubType() == LayerUtilitiesImpl.SCATTERPLOT) {
ScatterplotDataDTO data = mapLayer.getScatterplotDataDTO();
infourl += "?dparam=X-Layer:" + data.getLayer1Name();
infourl += "&dparam=Y-Layer:" + data.getLayer2Name();
}
// send the user to the BIE page for the species
Events.echoEvent(StringConstants.OPEN_URL, mc, infourl);
} else if (mapLayer.getMapLayerMetadata().getMoreInfo() != null && mapLayer.getMapLayerMetadata().getMoreInfo().length() > 0) {
Events.echoEvent(StringConstants.OPEN_HTML, mc, mapLayer.getMapLayerMetadata().getMoreInfo());
} else {
mc.showMessage("Metadata currently unavailable");
}
}
}
use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityListResults method evalArea.
private void evalArea(SelectedArea sa) {
try {
Query sq = QueryUtil.queryFromSelectedArea(selectedQuery, sa, null, false, null);
CSVReader r = new CSVReader(new StringReader(sq.speciesList()));
JSONArray ja = new JSONArray();
for (String[] s : r.readAll()) {
ja.add(s[1]);
}
// call pd with specieslist=ja.toString()
String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getPD";
NameValuePair[] params = new NameValuePair[2];
params[0] = new NameValuePair("noTreeText", StringConstants.TRUE);
params[1] = new NameValuePair("speciesList", ja.toString());
JSONParser jp = new JSONParser();
JSONArray pds = (JSONArray) jp.parse(Util.readUrlPost(url, params));
Map<String, String> pdrow = new HashMap<String, String>();
Map<String, JSONArray> speciesRow = new HashMap<String, JSONArray>();
for (int j = 0; j < pds.size(); j++) {
String tree = "" + ((JSONObject) pds.get(j)).get(StringConstants.STUDY_ID);
pdrow.put(tree, ((JSONObject) pds.get(j)).get("pd").toString());
speciesRow.put(tree, (JSONArray) ((JSONObject) pds.get(j)).get("taxaRecognised"));
// maxPD retrieval
String maxPd = ((JSONObject) pds.get(j)).get("maxPd").toString();
for (int k = 0; k < selectedTrees.size(); k++) {
if (((Map<String, String>) selectedTrees.get(k)).get(StringConstants.STUDY_ID).equals(tree)) {
((Map<String, String>) selectedTrees.get(k)).put("maxPd", maxPd);
}
}
}
areaPds.add(pdrow);
areaSpeciesMatches.add(speciesRow);
} catch (Exception e) {
LOGGER.error("failed processing a pd for a selected area.", e);
}
}
use of au.org.ala.spatial.util.Query 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);
}
Aggregations