use of au.org.ala.spatial.dto.ScatterplotDataDTO in project spatial-portal by AtlasOfLivingAustralia.
the class LayerLegendScatterplotController method onCheck$chkSelectMissingRecords.
public void onCheck$chkSelectMissingRecords(Event event) {
try {
registerScatterPlotSelection();
ScatterplotDataDTO d = getScatterplotData();
d.setEnabled(true);
Facet f = getFacetIn();
if (f == null) {
mapLayer.setHighlight(null);
} else {
mapLayer.setHighlight(f.toString());
}
getMapComposer().applyChange(mapLayer);
tbxChartSelection.setText("");
data.setImagePath(null);
data.setMissingDataChecked(chkSelectMissingRecords.isChecked());
redraw();
} catch (Exception e) {
LOGGER.error("error toggling missing records checkbox", e);
clearSelection();
getMapComposer().applyChange(mapLayer);
}
}
use of au.org.ala.spatial.dto.ScatterplotDataDTO 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;
}
use of au.org.ala.spatial.dto.ScatterplotDataDTO 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.dto.ScatterplotDataDTO 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");
}
}
use of au.org.ala.spatial.dto.ScatterplotDataDTO in project spatial-portal by AtlasOfLivingAustralia.
the class MapComposer method loadUserSession.
public void loadUserSession(String sessionid) {
onClick$removeAllLayers();
Scanner scanner = null;
try {
String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + sessionid;
File sessfolder = new File(sfld);
if (!sessfolder.exists()) {
showMessage("Session information does not exist. Please provide a valid session id");
return;
}
scanner = new Scanner(new File(sfld + "/details.txt"));
// first grab the zoom level and bounding box
String[] mapdetails = scanner.nextLine().split(",");
BoundingBox bb = new BoundingBox();
bb.setMinLongitude(Float.parseFloat(mapdetails[1]));
bb.setMinLatitude(Float.parseFloat(mapdetails[2]));
bb.setMaxLongitude(Float.parseFloat(mapdetails[3]));
bb.setMaxLatitude(Float.parseFloat(mapdetails[4]));
openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true));
String[] scatterplotNames = null;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("scatterplotNames")) {
scatterplotNames = line.substring(17).split("___");
}
}
ArrayUtils.reverse(scatterplotNames);
// ignore fields not found
XStream xstream = new XStream(new DomDriver()) {
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
public boolean shouldSerializeMember(Class definedIn, String fieldName) {
if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName))
System.out.println("faled to read: " + definedIn + ", " + fieldName);
return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
}
};
}
@Override
public Object unmarshal(HierarchicalStreamReader reader) {
Object o = super.unmarshal(reader);
if (o instanceof BiocacheQuery)
((BiocacheQuery) o).getFullQ(false);
return o;
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, Object root) {
Object o = super.unmarshal(reader, root);
if (o instanceof BiocacheQuery)
((BiocacheQuery) o).getFullQ(false);
return o;
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
Object o = super.unmarshal(reader, root, dataHolder);
if (o instanceof BiocacheQuery)
((BiocacheQuery) o).getFullQ(false);
return o;
}
};
PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream);
List list = new XmlArrayList(strategy);
ListIterator it = list.listIterator(list.size());
int scatterplotIndex = 0;
while (it.hasPrevious()) {
Object o = it.previous();
MapLayer ml = null;
if (o instanceof MapLayer) {
ml = (MapLayer) o;
LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed());
addUserDefinedLayerToMenu(ml, false);
} else if (o instanceof ScatterplotDataDTO) {
ScatterplotDataDTO spdata = (ScatterplotDataDTO) o;
loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++);
}
if (ml != null) {
addUserDefinedLayerToMenu(ml, true);
}
}
} catch (Exception e) {
try {
File f = new File("/data/sessions/" + sessionid + ".txt");
PrintWriter pw = new PrintWriter(f);
e.printStackTrace(pw);
pw.close();
} catch (Exception ex) {
}
LOGGER.error("Unable to load session data", e);
showMessage("Unable to load session data");
} finally {
if (scanner != null) {
scanner.close();
}
try {
File f = new File("/data/sessions/ok/" + sessionid + ".txt");
FileUtils.writeStringToFile(f, "ok");
} catch (Exception ex) {
}
}
}
Aggregations