logger.debug("Creating engine instance ...");
try {
qbeEngineInstance = QbeEngine.createInstance(getTemplateAsSourceBean(), getEnv() );
} catch(Throwable t) {
SpagoBIEngineStartupException serviceException;
String msg = "Impossible to create engine instance for document [" + getDocumentId() + "].";
Throwable rootException = t;
while(rootException.getCause() != null) {
rootException = rootException.getCause();
}
String str = rootException.getMessage()!=null? rootException.getMessage(): rootException.getClass().getName();
msg += "\nThe root cause of the error is: " + str;
serviceException = new SpagoBIEngineStartupException(ENGINE_NAME, msg, t);
if(rootException instanceof QbeTemplateParseException) {
QbeTemplateParseException e = (QbeTemplateParseException)rootException;
serviceException.setDescription( e.getDescription());
serviceException.setHints( e.getHints() );
}
throw serviceException;
}
logger.debug("Engine instance succesfully created");
qbeEngineInstance.setAnalysisMetadata( getAnalysisMetadata() );
// initializes form state, if not already initialized (starting a new form definition)
FormState formState = qbeEngineInstance.getFormState();
if (formState == null) {
logger.debug("Initializing a new form state object...");
formState = new FormState();
formState.setConf(new JSONObject());
qbeEngineInstance.setFormState(formState);
}
//Integer subObjectId = getAttributeAsInteger("subobjectId");
//get the form values saved (if the user has loaded a subobject)
analysisFormState = new SmartFilterAnalysisState();
analysisFormState.load( getAnalysisStateRowData() );
formState.setFormStateValues(analysisFormState.getFormValues());
//save the map id-->field name
formState.setIdNameMap();
qbeEngineInstance.getEnv().put("TEMPLATE", getTemplateAsSourceBean());
String docId = this.getAttributeAsString("formDocumentId");
if(docId != null) qbeEngineInstance.getEnv().put("DOCUMENT", docId);
else {
qbeEngineInstance.getEnv().put("DOCUMENT", this.getDocumentId());
}
locale = (Locale)qbeEngineInstance.getEnv().get(EngineConstants.ENV_LOCALE);
setAttributeInSession( ENGINE_INSTANCE, qbeEngineInstance);
setAttribute(ENGINE_INSTANCE, qbeEngineInstance);
setAttribute(LANGUAGE, locale.getLanguage());
setAttribute(COUNTRY, locale.getCountry());
String publisherName = "VIEW_FORM_ENGINE_PUBLISHER";
String modality = this.getAttributeAsString(PARAM_MODALITY);
logger.debug("Input " + PARAM_MODALITY + " parameter is " + modality);
if (modality != null && modality.trim().equalsIgnoreCase("EDIT")) {
// edit template
publisherName = "EDIT_FORM_ENGINE_PUBLISHER";
}
serviceResponse.setAttribute(DynamicPublisher.PUBLISHER_NAME, publisherName);
} catch (Throwable e) {
SpagoBIEngineStartupException serviceException = null;
if(e instanceof SpagoBIEngineStartupException) {
serviceException = (SpagoBIEngineStartupException)e;
} else {
Throwable rootException = e;
while(rootException.getCause() != null) {
rootException = rootException.getCause();
}
String str = rootException.getMessage()!=null? rootException.getMessage(): rootException.getClass().getName();
String message = "An unpredicted error occurred while executing " + getEngineName() + " service."
+ "\nThe root cause of the error is: " + str;
serviceException = new SpagoBIEngineStartupException(getEngineName(), message, e);
}
throw serviceException;
//throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), qbeEngineInstance, e);