use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class GDMComposer method rungdm.
public boolean rungdm() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/gdm/step2?");
sbProcessUrl.append("&pid=").append(pid);
sbProcessUrl.append("&cutpoint=").append(cutpoint.getSelectedItem().getValue());
sbProcessUrl.append("&useDistance=").append(rgdistance.getSelectedItem().getValue());
sbProcessUrl.append("&weighting=").append(weighting.getSelectedItem().getValue());
sbProcessUrl.append("&useSubSample=").append(useSubSample.isChecked() ? "1" : "0");
sbProcessUrl.append("&sitePairsSize=").append(sitePairsSize.getValue());
sbProcessUrl.append("&name=").append(query.getName());
HttpClient client = new HttpClient();
PostMethod get = new PostMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
LOGGER.debug("calling gdm ws: " + sbProcessUrl.toString());
client.executeMethod(get);
step2Id = get.getResponseBodyAsString();
getFellow("runningMsg2").setVisible(true);
statusMsg = ((Label) getFellow("runningMsg2")).getValue();
startTime = System.currentTimeMillis();
Events.echoEvent("step2Status", this, null);
return false;
} catch (Exception e) {
LOGGER.error("error finalizing GDM", e);
}
return false;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class GDMComposer method runGDMStep1.
public boolean runGDMStep1() {
try {
SelectedArea sa = getSelectedArea();
query = QueryUtil.queryFromSelectedArea(getSelectedSpecies(), sa, false, getGeospatialKosher());
query = query.newFacet(new Facet("occurrence_status_s", "absent", false), false);
sbenvsel = getSelectedLayersWithDisplayNames();
if (query.getSpeciesCount() < 2) {
getMapComposer().showMessage("An list of species with multiple occurrences for each species is required by GDM.", this);
return false;
}
HttpClient client = new HttpClient();
PostMethod get = new PostMethod(CommonData.getSatServer() + "/ws/gdm/step1?" + "envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8) + "&taxacount=" + query.getSpeciesCount() + "&speciesq=" + URLEncoder.encode(QueryUtil.queryFromSelectedArea(query, sa, false, getGeospatialKosher()).getQ(), StringConstants.UTF_8) + "&bs=" + URLEncoder.encode(query.getBS(), StringConstants.UTF_8));
if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
} else {
area = sa.getWkt();
}
if (getSelectedArea() != null) {
get.addParameter(StringConstants.AREA, area);
}
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
LOGGER.debug("calling gdm ws step 1");
client.executeMethod(get);
step1Id = get.getResponseBodyAsString();
//wait for step 1
LOGGER.debug(step1Id);
getFellow("runningMsg1").setVisible(true);
statusMsg = ((Label) getFellow("runningMsg1")).getValue();
startTime = System.currentTimeMillis();
Events.echoEvent("step1Status", this, null);
btnOk.setDisabled(true);
return true;
} catch (Exception e) {
LOGGER.error("GDM error: ", e);
getMapComposer().showMessage("Unknown error.", this);
}
return false;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class ALOCComposer method getJob.
String getJob() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/jobs/").append("inputs").append("?pid=").append(pid);
LOGGER.debug(sbProcessUrl.toString());
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
client.executeMethod(get);
String slist = get.getResponseBodyAsString();
LOGGER.debug(slist);
return slist;
} catch (Exception e) {
LOGGER.error("error getting gob info pid=" + pid, e);
}
return "";
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class ALOCComposer method getEstimate.
@Override
public long getEstimate() {
try {
String sbenvsel = getSelectedLayers();
if (sbenvsel.split(":").length > 50) {
getMapComposer().showMessage(sbenvsel.split(":").length + " layers selected. Please select fewer than 50 environmental layers in step 1.");
return -1;
}
if (groupCount.getValue() <= 1 || groupCount.getValue() > 200) {
getMapComposer().showMessage("Please enter the number of groups to generate (2 to 200) in step 2.");
//highlight step 2
return -1;
}
SelectedArea sa = getSelectedArea();
//estimate analysis size in bytes
double[][] bbox = null;
List<Double> bb;
if (sa.getMapLayer() != null) {
bb = sa.getMapLayer().getMapLayerMetadata().getBbox();
} else {
bb = Util.getBoundingBox(sa.getWkt());
}
bbox = new double[][] { { bb.get(0), bb.get(1) }, { bb.get(2), bb.get(3) } };
long cellsInBBox = (long) ((bbox[1][0] - bbox[0][0]) / 0.01 * (bbox[1][1] - bbox[0][1]) / 0.01);
long size = (groupCount.getValue() + sbenvsel.split(":").length + 2) * cellsInBBox * 4;
LOGGER.debug("ALOC estimate size in MB, cells=" + cellsInBBox + ", bbox=" + bbox[0][0] + "," + bbox[0][1] + "," + bbox[1][0] + "," + bbox[1][1] + ", groups=" + groupCount.getValue() + ", layers=" + sbenvsel.split(":").length + ", size=" + size / 1024 / 1024 + ", max size=" + CommonData.getSettings().getProperty("aloc_size_limit_in_mb"));
if (size / 1024 / 1024 > Integer.parseInt(CommonData.getSettings().getProperty("aloc_size_limit_in_mb"))) {
getMapComposer().showMessage("Analysis is too large. Reduce the number of groups, number of layers or area.", this);
return -1;
}
HttpClient client = new HttpClient();
PostMethod get = new PostMethod((CommonData.getSatServer() + "/ws/aloc/estimate?") + "gc=" + URLEncoder.encode(String.valueOf(groupCount.getValue()), StringConstants.UTF_8) + "&envlist=" + URLEncoder.encode(sbenvsel, StringConstants.UTF_8));
String area;
if (sa.getMapLayer() != null && sa.getMapLayer().getEnvelope() != null) {
area = StringConstants.ENVELOPE + "(" + sa.getMapLayer().getEnvelope() + ")";
} else {
area = sa.getWkt();
}
get.addParameter(StringConstants.AREA, area);
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.TEXT_PLAIN);
client.executeMethod(get);
String estimate = get.getResponseBodyAsString();
return Long.valueOf(estimate);
} catch (Exception e) {
LOGGER.error("Unable to get estimates", e);
}
return -1;
}
use of org.apache.commons.httpclient.HttpClient in project spatial-portal by AtlasOfLivingAustralia.
the class LayerLegendScatterplotController method onSelect$cbHighlightArea.
public void onSelect$cbHighlightArea(Event event) {
if (cbHighlightArea.getSelectedItem() != null) {
if (cbHighlightArea.getSelectedItem().getValue() instanceof MapLayer) {
MapLayer ml = cbHighlightArea.getSelectedItem().getValue();
SelectedArea sa = new SelectedArea(ml, ml.getFacets() == null ? ml.getWKT() : null);
data.setHighlightSa(sa);
} else {
String wkt = cbHighlightArea.getSelectedItem().getValue();
SelectedArea sa = new SelectedArea(null, wkt);
data.setHighlightSa(sa);
}
} else {
data.setHighlightSa(null);
}
try {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(CommonData.getSatServer() + "/ws/scatterplot/style/" + data.getId());
//add style parameters (highlight area)
if (data.getHighlightSa() != null) {
post.addParameter(StringConstants.HIGHLIGHT_WKT, data.getHighlightSa().getWkt());
} else {
post.addParameter(StringConstants.HIGHLIGHT_WKT, "");
}
post.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.executeMethod(post);
} catch (Exception e) {
LOGGER.error("error getting a new scatterplot id", e);
}
data.setImagePath(null);
redraw();
}
Aggregations