String mimeType;
String responseType;
JSONArray jsonArray;
IDataSet dataSet;
IDataStore dataStore;
JSONObject dataSetJSON;
String fileExtension;
String fileName;
boolean writeBackResponseInline;
logger.debug("IN");
try {
super.service(request,response);
Assert.assertNotNull(getConsoleEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
Assert.assertNotNull(getConsoleEngineInstance().getDataSetServiceProxy(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of DatasetServiceProxy class");
dataSetLabel = getAttributeAsString( DATASET_LABEL );
logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]");
Assert.assertTrue(!StringUtilities.isEmpty( dataSetLabel ), "Parameter [" + DATASET_LABEL + "] cannot be null or empty");
mimeType = getAttributeAsString( MIME_TYPE );
logger.debug("Parameter [" + MIME_TYPE + "] is equal to [" + mimeType + "]");
if(mimeType == null) {
logger.warn("Parameter [" + MIME_TYPE + "] has not been valorized");
mimeType = DEFAULT_MIME_TYPE;
logger.debug("Parameter [" + MIME_TYPE + "] has been set equal to [" + mimeType + "]");
}
responseType = getAttributeAsString( RESPONSE_TYPE );
logger.debug("Parameter [" + RESPONSE_TYPE + "] is equal to [" + responseType + "]");
if(!RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType) && !RESPONSE_TYPE_ATTACHMENT.equalsIgnoreCase(responseType)) {
logger.warn("Value [" + responseType + "] is not a valid for parameter [" + RESPONSE_TYPE + "]");
responseType = RESPONSE_TYPE_ATTACHMENT;
logger.debug("Parameter [" + RESPONSE_TYPE + "] has been set equal to [" + responseType + "]");
}
String test = getAttributeAsString(META);
logger.debug("Parameter [" + META + "] is equal to [" + test + "]");
jsonArray = this.getAttributeAsJSONArray(META);
logger.debug("Parameter [" + META + "] is equal to [" + jsonArray.toString(4) + "]");
dataSet = null;
try {
dataSet = getConsoleEngineInstance().getDataSetServiceProxy().getDataSetByLabel( dataSetLabel );
} catch(Throwable t) {
throw new SpagoBIServiceException("Impossible to find a dataset whose label is [" + dataSetLabel + "]", t);
}
Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
Assert.assertNotNull(dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]");
Map params = getConsoleEngineInstance().getAnalyticalDrivers();
dataSet.setParamsMap(params);
dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
dataSet.loadData();
dataStore = dataSet.getDataStore();
Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
// dataStore decoration ....
Object resultNumber = dataStore.getMetaData().getProperty("resultNumber");
if(resultNumber == null) dataStore.getMetaData().setProperty("resultNumber", new Integer((int)dataStore.getRecordsCount()));
if(jsonArray != null && jsonArray.length() > 0) {
int fieldNo = dataStore.getMetaData().getFieldCount();
for(int i = 0; i < fieldNo; i++) {
dataStore.getMetaData().getFieldMeta(i).setProperty("visible", Boolean.FALSE);
}
List actionColumns = new ArrayList();
for(int i = 0; i < jsonArray.length(); i++) {
String fieldName = jsonArray.getJSONObject(i).optString("name", null);
String fieldHeader = jsonArray.getJSONObject(i).optString("header", null);
Boolean isActionColumn = jsonArray.getJSONObject(i).optBoolean("actionColumn", Boolean.FALSE);
if(isActionColumn.booleanValue() == false) {
if(StringUtilities.isEmpty(fieldName)) {
logger.warn("no name for column: " + jsonArray.getJSONObject(i).toString(4));
continue;
}
int fieldIndex = dataStore.getMetaData().getFieldIndex(fieldName);
if(fieldIndex < 0){
logger.warn("dataStore does not conatin a column named [" + fieldIndex + "]");
continue;
}
if(jsonArray.getJSONObject(i).optBoolean("hidden", true) == false) {
dataStore.getMetaData().getFieldMeta(fieldIndex).setProperty("visible", Boolean.TRUE);
dataStore.getMetaData().getFieldMeta(fieldIndex).setAlias(fieldHeader);
}
} else {
String actionConfig = jsonArray.getJSONObject(i).optString("actionConfig");
logger.debug("Parameter [actionConfig] is equal to [" + actionConfig + "]");
Assert.assertNotNull(actionConfig, "Parameter [actionConfig]connot be undefined if parameter [actionColumn] is true");
JSONObject actionConfigJson = new JSONObject(actionConfig);
actionColumns.add( actionConfigJson );
}
}
dataStore.getMetaData().setProperty("actionColumns", actionColumns);
}
params = new HashMap();