// load master map
try {
loadMasterMapTotalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.renderMap.loadMasterMap");
masterMap = svgMapLoader.loadMapAsDocument(getMasterMapFile(true));
} catch (IOException e) {
GeoEngineException geoException;
logger.error("Impossible to load map from file: " + getMasterMapFile(true));
String description = "Impossible to load map from file: " + getMasterMapFile(true);
geoException = new GeoEngineException("Impossible to render map", e);
geoException.setDescription(description);
throw geoException;
} finally {
if(loadMasterMapTotalTimeMonitor != null) loadMasterMapTotalTimeMonitor.stop();
}
// load target map
try {
loadTargetMapTotalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.renderMap.loadTargetMap");
targetMap = mapProvider.getSVGMapDOMDocument();
}finally {
if(loadTargetMapTotalTimeMonitor != null) loadTargetMapTotalTimeMonitor.stop();
}
// marge and decorate map
try {
margeAndDecorateMapTotalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.renderMap.margeAndDecorateMap");
addData(targetMap, dataMart);
addLink(targetMap, dataMart);
SVGMapMerger.margeMap(targetMap, masterMap, null, "targetMap");
if( includeScript ) {
includeScripts(masterMap);
} else {
importScripts(masterMap);
}
setMainMapDimension(masterMap, targetMap);
Element scriptInit = masterMap.getElementById("init");
Node scriptText = scriptInit.getFirstChild();
JSONObject conf = new JSONObject();
JSONArray measures;
try {
measures = getMeasuresConfigurationScript(dataMart);
String selectedMeasureName = getSelectedMeasureName();
logger.debug("Selected measure [" + selectedMeasureName + "]");
Assert.assertTrue(selectedMeasureName != null, "default_kpi attribute cannot be null. Please add it to MEASURES tag in your template file");
int selectedMeasureIndexIndex = -1;
for(int i = 0; i < measures.length(); i++) {
JSONObject measure = (JSONObject)measures.get(i);
logger.debug("Comparing selected measure [" + selectedMeasureName + "] with measure [" + (String)measure.get("name") + "]");
String nm = (String)measure.get("name");
if(selectedMeasureName.equalsIgnoreCase( nm)) {
logger.debug("Selected measure [" + selectedMeasureName + "] is equal to measure [" + (String)measure.get("name") + "]");
selectedMeasureIndexIndex = i;
break;
}
}
logger.debug("Selected measure index [" + selectedMeasureIndexIndex + "]");
conf.put("selected_measure_index", selectedMeasureIndexIndex);
conf.put("measures", measures);
JSONArray layers = getLayersConfigurationScript(targetMap);
String targetLayer = datamartProvider.getSelectedLevel().getFeatureName();
int targetLayerIndex = -1;
for(int i = 0; i < layers.length(); i++) {
JSONObject layer = (JSONObject)layers.get(i);
if(targetLayer.equals( layer.get("name"))) {
targetLayerIndex = i;
break;
}
}
conf.put("target_layer_index", targetLayerIndex);
conf.put("layers", layers);
JSONObject guiSettings = getGUIConfigurationScript();
guiSettings.put("includeChartLayer", getLayer("grafici")!=null);
guiSettings.put("includeValuesLayer", getLayer("valori")!=null);
conf.put("gui_settings", guiSettings);
String execId = (String)this.getEnv().get("SBI_EXECUTION_ID");
conf.put("execId", execId);
JSONObject localeJSON = new JSONObject();
Locale locale = (Locale) this.getEnv().get(EngineConstants.ENV_LOCALE);
logger.debug("Current environment locale is: " + locale);
if (locale == null) {
logger.debug("Using default english locale");
locale = Locale.ENGLISH;
}
localeJSON.put("language", locale.getLanguage());
localeJSON.put("country", locale.getCountry());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
localeJSON.put("decimalSeparator", new Character(dfs.getDecimalSeparator()).toString());
localeJSON.put("groupingSeparator", new Character(dfs.getGroupingSeparator()).toString());
conf.put("locale", localeJSON);
} catch (JSONException e1) {
GeoEngineException geoException;
logger.error("Impossible to create sbi.geo.conf", e1);
String description = "Impossible to create sbi.geo.conf";
geoException = new GeoEngineException("Impossible to create sbi.geo.conf", e1);
geoException.setDescription(description);
throw geoException;
}
scriptText.setNodeValue( "sbi = {};\n sbi.geo = {};\n sbi.geo.conf = " + conf.toString() );
try {
tmpMap = getTempFile();
} catch (IOException e) {
GeoEngineException geoException;
logger.error("Impossible to create a temporary file", e);
String description = "Impossible to create a temporary file";
geoException = new GeoEngineException("Impossible to render map", e);
geoException.setDescription(description);
throw geoException;
}catch (Throwable t) {
GeoEngineException geoException;
logger.error("Impossible to create a temporary file", t);
String description = "Impossible to create a temporary file";
geoException = new GeoEngineException("Impossible to render map", t);
geoException.setDescription(description);
throw geoException;
}
try {
SVGMapSaver.saveMap(masterMap, tmpMap);
} catch (FileNotFoundException e) {
GeoEngineException geoException;
logger.error("Impossible to save map on temporary file " + tmpMap, e);
String str = e.getMessage()!=null?e.getMessage():e.getClass().getName();
String description = "Impossible to save map on temporary file " + tmpMap + ". Root cause: " + str;
geoException = new GeoEngineException("Impossible to render map", e);
geoException.setDescription(description);
throw geoException;
} catch (TransformerException e) {
GeoEngineException geoException;
logger.error("Impossible to save map on temporary file " + tmpMap, e);
String str = e.getMessage()!=null?e.getMessage():e.getClass().getName();
String description = "Impossible to save map on temporary file " + tmpMap + ". Root cause: " + str;
geoException = new GeoEngineException("Impossible to render map", e);
geoException.setDescription(description);
throw geoException;
}catch (Throwable t) {
GeoEngineException geoException;
logger.error("Impossible to save map on temporary file " + tmpMap, t);
String str = t.getMessage()!=null?t.getMessage():t.getClass().getName();
String description = "Impossible to save map on temporary file " + tmpMap + ". Root cause: " + str;
geoException = new GeoEngineException("Impossible to render map", t);
geoException.setDescription(description);
throw geoException;
}
} finally {
if(margeAndDecorateMapTotalTimeMonitor != null) margeAndDecorateMapTotalTimeMonitor.stop();
}