use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class ScatterplotListComposer method onFinish.
@Override
public boolean onFinish() {
LOGGER.debug("Area: " + getSelectedArea());
LOGGER.debug("Species: " + getSelectedSpecies());
Query lsid = getSelectedSpecies();
if (lsid == null) {
getMapComposer().showMessage("There was a problem selecting the species. Try to select the species again", this);
return false;
}
lsid = lsid.newFacet(new Facet("occurrence_status_s", "absent", false), false);
SelectedArea filterSa = getSelectedArea();
SelectedArea highlightSa = getSelectedAreaHighlight();
Query lsidQuery = QueryUtil.queryFromSelectedArea(lsid, filterSa, false, getGeospatialKosher());
if (lsidQuery == null || lsidQuery.getOccurrenceCount() == 0) {
getMapComposer().showMessage("No occurrences found for the selected species in the selected area.");
return false;
}
String pid = "";
Query backgroundLsid = getSelectedSpeciesBk();
backgroundLsid = backgroundLsid.newFacet(new Facet("occurrence_status_s", "absent", false), false);
if (bgSearchSpeciesACComp.hasValidAnnotatedItemSelected()) {
backgroundLsid = bgSearchSpeciesACComp.getQuery((Map) getMapComposer().getSession().getAttribute(StringConstants.USERPOINTS), false, getGeospatialKosher());
}
boolean envGrid = chkShowEnvIntersection.isChecked();
Query backgroundLsidQuery = null;
if (backgroundLsid != null) {
backgroundLsidQuery = QueryUtil.queryFromSelectedArea(backgroundLsid, filterSa, false, getGeospatialKosherBk());
}
String sbenvsel = getSelectedLayersWithDisplayNames();
String[] layers = sbenvsel.split(":");
if (layers.length > 20) {
getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected. Please select fewer than 20 environmental layers in step 1.");
return false;
}
StringBuilder layernames = new StringBuilder();
String layerunits = "";
for (int i = 0; i < layers.length; i++) {
String[] split = layers[i].split("\\|");
if (layernames.length() > 0) {
layernames.append(",");
layerunits += ",";
}
layers[i] = split[0];
String layerDisplayName = split[1];
layernames.append("\"").append(layerDisplayName.replace("\"", "\"\"").replace("\\", "\\\\")).append("\"");
String units = "";
try {
units = String.valueOf(((JSONObject) CommonData.getLayer(layers[i]).get("layer")).get("environmentalvalueunits"));
} catch (Exception e) {
}
layerunits += units;
}
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplotlist");
//add data parameters
post.addParameter("layers", getSelectedLayers());
post.addParameter("layernames", layernames.toString());
post.addParameter("layerunits", layerunits);
post.addParameter("foregroundOccurrencesQs", lsidQuery.getQ());
post.addParameter("foregroundOccurrencesBs", lsidQuery.getBS());
post.addParameter("foregroundName", lsidQuery.getName());
if (backgroundLsidQuery != null) {
post.addParameter("backgroundOccurrencesQs", backgroundLsidQuery.getQ());
post.addParameter("backgroundOccurrencesBs", backgroundLsidQuery.getBS());
post.addParameter("backgroundName", backgroundLsidQuery.getName());
}
if (envGrid) {
post.addParameter("gridDivisions", "20");
}
if (filterSa != null) {
post.addParameter("filterWkt", filterSa.getWkt());
}
//add style parameters (highlight area)
if (highlightSa != null) {
post.addParameter(StringConstants.HIGHLIGHT_WKT, highlightSa.getWkt());
}
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(post);
String hasId = post.getResponseBodyAsString();
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(hasId);
String htmlUrl = null;
String downloadUrl = null;
if (jo.containsKey(StringConstants.ID)) {
pid = jo.get(StringConstants.ID).toString();
}
if (jo.containsKey("htmlUrl")) {
htmlUrl = jo.get("htmlUrl").toString();
}
if (jo.containsKey("downloadUrl")) {
downloadUrl = jo.get("downloadUrl").toString();
}
if (htmlUrl != null && downloadUrl != null) {
Events.echoEvent(StringConstants.OPEN_URL, getMapComposer(), htmlUrl);
try {
Filedownload.save(new URL(downloadUrl).openStream(), "application/zip", tToolName.getValue().replaceAll(" ", "_") + ".zip");
} catch (Exception e) {
LOGGER.error("error preparing download for scatterplot data", e);
}
try {
String extras = "";
if (highlightSa != null) {
extras += "highlight=" + highlightSa.getWkt();
}
if (backgroundLsid instanceof BiocacheQuery) {
extras += "background=" + ((BiocacheQuery) backgroundLsid).getLsids();
} else if (backgroundLsid instanceof UserDataQuery) {
extras += "background=" + backgroundLsid.getQ();
} else {
extras += "background=none";
}
if (lsidQuery instanceof BiocacheQuery) {
BiocacheQuery bq = (BiocacheQuery) lsidQuery;
extras = bq.getWS() + "|" + bq.getBS() + "|" + bq.getFullQ(false) + "|" + extras;
remoteLogger.logMapAnalysis(tToolName.getValue(), "Tool - Scatterplot List", filterSa.getWkt(), bq.getLsids(), sbenvsel, pid, extras, StringConstants.SUCCESSFUL);
} else if (lsidQuery instanceof UserDataQuery) {
remoteLogger.logMapAnalysis(tToolName.getValue(), "Tool - Scatterplot List", filterSa.getWkt(), lsidQuery.getQ(), sbenvsel, pid, extras, StringConstants.SUCCESSFUL);
} else {
remoteLogger.logMapAnalysis(tToolName.getValue(), "Tool - Scatterplot List", filterSa.getWkt(), "", sbenvsel, pid, extras, StringConstants.SUCCESSFUL);
}
} catch (Exception e) {
LOGGER.error("failed to produce a scatterplot list.", e);
}
} else {
LOGGER.error("failed to produce a scatterplot list. response: " + jo);
}
} catch (Exception e) {
LOGGER.error("error getting a new scatterplot id", e);
}
this.detach();
return true;
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method updateEndemicCheckBox.
private void updateEndemicCheckBox() {
if (rAreaSelected == null) {
return;
}
// check to see if the area is within the required size...
boolean showEndemic = false;
String value = rAreaSelected.getValue();
if (!StringConstants.AUSTRALIA.equals(value) && !StringConstants.WORLD.equals(value) && !"custom".equals(value)) {
String areaName = rAreaSelected.getLabel();
MapLayer ml = getMapComposer().getMapLayer(areaName);
String sarea = "";
if (StringConstants.CURRENT.equals(value)) {
// check to see if the current extent is within the maximum
// area
SelectedArea sa = getSelectedArea();
sarea = sa.getKm2Area();
} else if (ml != null) {
sarea = ml.getAreaSqKm();
if (sarea == null) {
sarea = ml.calculateAndStoreArea();
}
}
try {
Float area = Float.parseFloat(sarea.replaceAll(",", ""));
showEndemic = (area <= CommonData.getMaxEndemicArea());
} catch (NumberFormatException e) {
LOGGER.error("failed to parse endemic area from: " + sarea);
}
}
chkEndemicSpecies.setDisabled(!showEndemic);
chkEndemicSpecies.setChecked(false);
if (lendemicNote != null) {
if (showEndemic) {
lendemicNote.setValue("Please note this may take several minutes depending on the area selected.");
} else {
lendemicNote.setValue("The selected area is too large to be considered for endemic species.");
}
}
}
use of au.org.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListComposer method onClick$btnDownload.
public void onClick$btnDownload() {
SelectedArea sa = getSelectedArea();
Map<String, Object> hm = new HashMap<String, Object>();
hm.put("selectedarea", sa);
hm.put("geospatialKosher", getGeospatialKosher());
hm.put(StringConstants.CHOOSEENDEMIC, chkEndemicSpecies.isChecked());
if (extraParams != null) {
hm.put(StringConstants.EXTRAPARAMS, extraParams);
}
SpeciesListResults window = (SpeciesListResults) Executions.createComponents("WEB-INF/zul/results/AnalysisSpeciesListResults.zul", getMapComposer(), hm);
try {
window.setParent(getMapComposer());
window.doModal();
} catch (Exception e) {
LOGGER.error("error opening analysisspecieslistresults.zul", e);
}
detach();
}
use of au.org.emii.portal.menu.SelectedArea 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.emii.portal.menu.SelectedArea in project spatial-portal by AtlasOfLivingAustralia.
the class ScatterplotComposer method onFinish.
@Override
public boolean onFinish() {
LOGGER.debug("Area: " + getSelectedArea());
LOGGER.debug("Species: " + getSelectedSpecies());
Query lsid = getSelectedSpecies();
if (lsid == null) {
getMapComposer().showMessage("There was a problem selecting the species. Try to select the species again", this);
return false;
}
lsid = lsid.newFacet(new Facet("occurrence_status_s", "absent", false), false);
String name = getSelectedSpeciesName();
String sbenvsel = getSelectedLayersWithDisplayNames();
String[] layers = sbenvsel.split(":");
if (layers.length > 2 || layers.length < 2) {
getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected. Please select 2 environmental layers in step 4.");
return false;
}
String[] layerNames = new String[2];
String[] layerValues = new String[2];
for (int i = 0; i < layers.length; i++) {
String[] split = layers[i].split("\\|");
layerValues[i] = split[0];
layerNames[i] = split[1];
}
String pid = "";
Query backgroundLsid = getSelectedSpeciesBk();
if (backgroundLsid != null)
backgroundLsid = backgroundLsid.newFacet(new Facet("occurrence_status_s", "absent", false), false);
if (bgSearchSpeciesACComp.hasValidAnnotatedItemSelected()) {
backgroundLsid = bgSearchSpeciesACComp.getQuery((Map) getMapComposer().getSession().getAttribute(StringConstants.USERPOINTS), false, getGeospatialKosher());
}
SelectedArea filterSa = getSelectedArea();
if (filterSa == null) {
LOGGER.error("scatterplot area is null");
return false;
}
SelectedArea highlightSa = getSelectedAreaHighlight();
boolean envGrid = chkShowEnvIntersection.isChecked();
Query lsidQuery = QueryUtil.queryFromSelectedArea(lsid, filterSa, false, getGeospatialKosher());
Query backgroundLsidQuery = null;
if (backgroundLsid != null) {
backgroundLsidQuery = QueryUtil.queryFromSelectedArea(backgroundLsid, filterSa, false, getGeospatialKosherBk());
}
ScatterplotDataDTO d = new ScatterplotDataDTO(lsidQuery, name, layerValues[0], layerNames[0], layerValues[1], layerNames[1], pid, null, true, highlightSa);
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplot/new");
//add data parameters
String layerunits = "";
try {
String envUnits1 = ((JSONObject) CommonData.getLayer(layerValues[0]).get("layer")).get("environmentalvalueunits").toString();
String envUnits2 = ((JSONObject) CommonData.getLayer(layerValues[1]).get("layer")).get("environmentalvalueunits").toString();
layerunits = envUnits1 + "," + envUnits2;
} catch (Exception e) {
}
//colon delimited
post.addParameter("layers", layerValues[0] + ":" + layerValues[1]);
//CSV format
post.addParameter("layernames", "\"" + layerNames[0].replace("\"", "\"\"").replace("\\", "\\\\") + "\",\"" + layerNames[1].replace("\"", "\"\"").replace("\\", "\\\\") + "\"");
post.addParameter("layerunits", layerunits);
post.addParameter("foregroundOccurrencesQs", lsidQuery.getQ());
post.addParameter("foregroundOccurrencesBs", lsidQuery.getBS());
post.addParameter("foregroundName", lsidQuery.getName());
if (backgroundLsidQuery != null) {
post.addParameter("backgroundOccurrencesQs", backgroundLsidQuery.getQ());
post.addParameter("backgroundOccurrencesBs", backgroundLsidQuery.getBS());
post.addParameter("backgroundName", backgroundLsidQuery.getName());
}
if (envGrid) {
post.addParameter("gridDivisions", "20");
}
post.addParameter("filterWkt", filterSa.getWkt());
//add style parameters (highlight area)
if (highlightSa != null) {
post.addParameter(StringConstants.HIGHLIGHT_WKT, highlightSa.getWkt());
}
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(post);
String str = post.getResponseBodyAsString();
JSONParser jp = new JSONParser();
JSONObject jsonObject = (JSONObject) jp.parse(str);
if (jsonObject != null && jsonObject.containsKey(StringConstants.ID)) {
d.setId(jsonObject.get(StringConstants.ID).toString());
d.setMissingCount(Integer.parseInt(jsonObject.get("missingCount").toString()));
} else {
LOGGER.error("error parsing scatterplot id from: " + str);
}
} catch (Exception e) {
LOGGER.error("error getting a new scatterplot id", e);
}
getMapComposer().loadScatterplot(d, tToolName.getValue());
this.detach();
try {
String extras = "";
if (lsidQuery instanceof BiocacheQuery) {
BiocacheQuery bq = (BiocacheQuery) lsidQuery;
extras = bq.getWS() + "|" + bq.getBS() + "|" + bq.getFullQ(false) + "|" + extras;
remoteLogger.logMapAnalysis(tToolName.getValue(), StringConstants.TOOL_SCATTERPLOT, filterSa.getWkt(), bq.getLsids(), layerValues[0] + ":" + layerValues[1], pid, extras, StringConstants.SUCCESSFUL);
} else if (lsidQuery instanceof UserDataQuery) {
remoteLogger.logMapAnalysis(tToolName.getValue(), StringConstants.TOOL_SCATTERPLOT, filterSa.getWkt(), lsidQuery.getQ(), "", pid, extras, StringConstants.SUCCESSFUL);
} else {
remoteLogger.logMapAnalysis(tToolName.getValue(), StringConstants.TOOL_SCATTERPLOT, filterSa.getWkt(), "", "", pid, extras, StringConstants.SUCCESSFUL);
}
} catch (Exception e) {
LOGGER.error("logging error", e);
}
return true;
}
Aggregations