use of au.org.ala.spatial.composer.output.SamplingAnalysisDownloadController 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;
}
Aggregations