ITransaction transaction = null;
Connection connection = null;
//HQL2SQLStatementRewriter queryRewriter = null;
String jpaQueryStr = null;
String sqlQuery = null;
SQLFieldsReader fieldsReader = null;
Vector extractedFields = null;
Map params = null;
TemplateBuilder templateBuilder = null;
String templateContent = null;
File reportFile = null;
ReportRunner runner = null;
boolean isFormEngineInstance = false;
logger.debug("IN");
try {
super.service(request, response);
mimeType = getAttributeAsString( MIME_TYPE );
logger.debug(MIME_TYPE + ": " + mimeType);
responseType = getAttributeAsString( RESPONSE_TYPE );
logger.debug(RESPONSE_TYPE + ": " + responseType);
Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
transaction = (getEngineInstance().getDataSource()).getTransaction();
transaction.open();
fileExtension = MimeUtils.getFileExtension( mimeType );
writeBackResponseInline = RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType);
isFormEngineInstance = getEngineInstance().getTemplate().getProperty("formJSONTemplate") != null;
if (!isFormEngineInstance) {
// case of standard QBE
Assert.assertNotNull(getEngineInstance().getActiveQuery(), "Query object cannot be null in oder to execute " + this.getActionName() + " service");
Assert.assertTrue(getEngineInstance().getActiveQuery().isEmpty() == false, "Query object cannot be empty in oder to execute " + this.getActionName() + " service");
Assert.assertNotNull(mimeType, "Input parameter [" + MIME_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");
Assert.assertTrue( MimeUtils.isValidMimeType( mimeType ) == true, "[" + mimeType + "] is not a valid value for " + MIME_TYPE + " parameter");
Assert.assertNotNull(responseType, "Input parameter [" + RESPONSE_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");
Assert.assertTrue( RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType) || RESPONSE_TYPE_ATTACHMENT.equalsIgnoreCase(responseType), "[" + responseType + "] is not a valid value for " + RESPONSE_TYPE + " parameter");
statement = getEngineInstance().getDataSource().createStatement( getEngineInstance().getActiveQuery() );
//logger.debug("Parametric query: [" + statement.getQueryString() + "]");
statement.setParameters( getEnv() );
jpaQueryStr = statement.getQueryString();
logger.debug("Executable HQL/JPQL query: [" + jpaQueryStr + "]");
sqlQuery = statement.getSqlQueryString();
Assert.assertNotNull(sqlQuery, "The SQL query is needed while exporting results.");
} else {
// case of FormEngine
sqlQuery = this.getAttributeFromSessionAsString(ExecuteDetailQueryAction.LAST_DETAIL_QUERY);
Assert.assertNotNull(sqlQuery, "The detail query was not found, maybe you have not execute the detail query yet.");
}
logger.debug("Executable SQL query: [" + sqlQuery + "]");
logger.debug("Exctracting fields ...");
fieldsReader = new SQLFieldsReader(sqlQuery, transaction.getSQLConnection());
try {
extractedFields = fieldsReader.readFields();
} catch (Exception e) {
logger.debug("Impossible to extract fields from query");
throw new SpagoBIEngineException("Impossible to extract fields from query: " + jpaQueryStr, e);
}
logger.debug("Fields extracted succesfully");