Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of GeoInstance class");
Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created a MapProvider into GeoInstance object");
try {
maps = getGeoEngineInstance().getMapProvider().getMapNamesByFeature(featureName);
if(maps == null) throw new SpagoBIEngineServiceException(getActionName(),"The map list returned by the map provider is NULL");
} catch (Exception e) {
logger.error("Impossible to get a list of map containing layer [" + featureName + "] ");
throw new SpagoBIEngineServiceException(getActionName(),"Impossible to get a list of map containing layer [" + featureName + "] ", e);
}
if(maps.size() == 0) {
logger.warn("The list of map containing layer [" + featureName + "] is empty");
}
JSONObject responseJSON = new JSONObject();
JSONArray mapsJSON = new JSONArray();
for(int i = 0; i < maps.size(); i++) {
String mapName = (String)maps.get(i);
JSONObject mapJSON = new JSONObject();
mapJSON.put("id", mapName);
mapJSON.put("name", mapName);
mapJSON.put("description", mapName);
List features = getGeoEngineInstance().getMapProvider().getFeatureNamesInMap(mapName);
JSONArray featuresJSON = new JSONArray();
for(int j = 0; j < features.size(); j++) {
String layerName = (String)features.get(j);
JSONObject featureJSON = new JSONObject();
featureJSON.put("id", layerName);
featureJSON.put("name", layerName);
featureJSON.put("description", layerName);
featureJSON.put("category", "undefined");
featuresJSON.put(featureJSON);
}
JSONObject featureJSON= null;
// grafici
featureJSON = new JSONObject();
featureJSON.put("id", "grafici");
featureJSON.put("name", "grafici");
featureJSON.put("description", "grafici");
featureJSON.put("category", "undefined");
featuresJSON.put(featureJSON);
// valori
featureJSON = new JSONObject();
featureJSON.put("id", "valori");
featureJSON.put("name", "valori");
featureJSON.put("description", "valori");
featureJSON.put("category", "undefined");
featuresJSON.put(featureJSON);
mapJSON.put("features", featuresJSON);
mapsJSON.put(mapJSON);
}
responseJSON.put("maps", mapsJSON);
logger.debug( "Generated service response: " + responseJSON.toString() );
try {
writeBackToClient( new JSONSuccess(responseJSON) );
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
} catch (Throwable t) {
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
} finally {
// no resources need to be released