//setting locale, formats, profile, parameters, startDate, endDate
setGeneralVariables(requestContainer);
if (obj == null) {
logger.error("The input object is null.");
throw new EMFUserError(EMFErrorSeverity.ERROR, "100", messageBundle);
}
if (!obj.getBiObjectTypeCode().equalsIgnoreCase("KPI")) {
logger.error("The input object is not a KPI.");
throw new EMFUserError(EMFErrorSeverity.ERROR, "1001", messageBundle);
}
String userId = null;
if(profile!=null){
userId=(String) ((UserProfile) profile).getUserId();
}
else{
userId=userIdField;
}
String documentId = obj.getId().toString();
logger.debug("Loaded documentId:" + documentId);
ModelInstanceNode mI = null;
try {
// **************get the template*****************
SourceBean content = getTemplate(documentId);
logger.debug("Got the template.");
// Date for which we want to see the KpiValues
this.dateOfKPI = new Date();
this.parametersObject = readParameters(obj.getBiObjectParameters());
addBIParameterDescriptions(obj, this.parametersObject);
if(!parametersObject.containsKey("ParKpiDate")){
String dateForDataset = getDateForDataset(dateOfKPI);
parametersObject.put("ParKpiDate", dateForDataset);
}
logger.debug("Got the date for which the KpiValues have to be calculated. Date:" + this.dateOfKPI);
// **************take informations on the modelInstance and its KpiValues*****************
String modelNodeInstance = (String) content.getAttribute("model_node_instance");
logger.info("ModelNodeInstance : " + modelNodeInstance);
if (modelNodeInstance == null) {
logger.error("The modelNodeInstance specified in the template is null");
throw new EMFUserError(EMFErrorSeverity.ERROR, "10106", messageBundle);
}
String periodInstanceID = (String) content.getAttribute("periodicity_id");
logger.debug("PeriodInstanceID : " + (periodInstanceID!=null ? periodInstanceID : "null"));
if (periodInstanceID == null) {
logger.debug("No periodInstID specified will use default one");
}else{
periodInstID = new Integer(periodInstanceID);
}
getSetConf(content);
logger.debug("Setted the configuration of the template");
List kpiRBlocks = new ArrayList();// List of KpiValues Trees for each Resource: it will be sent to the jsp
// gets the ModelInstanceNode
mI = DAOFactory.getModelInstanceDAO().loadModelInstanceByLabel(modelNodeInstance, this.dateOfKPI);
if (mI==null) {
logger.error("MODEL INSTANCE IS NULL, CHECK model_node_instance IN DOCUMENT TEMPLATE.!!!!!!!!!!!!!!");
}else {
logger.debug("ModelInstanceNode, ID=" + (mI.getModelInstanceNodeId()!=null ? mI.getModelInstanceNodeId().toString():"null"));
modelInstanceRootId = (mI.getModelInstanceNodeId()!=null ? mI.getModelInstanceNodeId() : null );
logger.debug("Loaded the modelInstanceNode with LABEL " + modelNodeInstance);
}
if(dataset_multires){//if datasets return a value for each resource
this.resources = mI.getResources(); //Set all the Resources for the Model Instance
logger.info("Dataset multiresource");
calculateAndInsertKpiValueWithResources(mI.getModelInstanceNodeId(),this.resources);
logger.info("Inserted all values!!");
return;
}
// I set the list of resources of that specific ModelInstance
if (this.resources == null || this.resources.isEmpty()) {
this.resources = mI.getResources();
}
logger.debug("Setted the List of Resources related to the specified Model Instance");
KpiLineVisibilityOptions options = setVisibilityOptions();
//sets up register values
ModelInstanceNode modI = DAOFactory.getModelInstanceDAO().loadModelInstanceById(mI.getModelInstanceNodeId(), dateOfKPI);
logger.debug("Setted the List of Kpis that does not need to be persisted in db");
if (this.resources == null || this.resources.isEmpty()) {
logger.debug("There are no resources assigned to the Model Instance");
KpiResourceBlock block = new KpiResourceBlock();
block.setD(this.dateOfKPI);
block.setParMap(this.parametersObject);
KpiLine line = getBlock(mI.getModelInstanceNodeId(), null);
block.setRoot(line);
block.setTitle(name);
block.setSubtitle(subName);
block.setOptions(options);
logger.debug("Setted the tree Root.");
kpiRBlocks.add(block);
}else {
Iterator resourcesIt = this.resources.iterator();
while (resourcesIt.hasNext()) {
Resource r = (Resource) resourcesIt.next();
logger.info("Resource: " + r.getName());
KpiResourceBlock block = new KpiResourceBlock();
block.setR(r);
block.setD(dateOfKPI);
block.setParMap(this.parametersObject);
KpiLine line = getBlock(mI.getModelInstanceNodeId(), r);
block.setRoot(line);
block.setOptions(options);
logger.debug("Setted the tree Root.");
kpiRBlocks.add(block);
}
}
try {
logger.debug("Successfull kpis creation");
response.setAttribute(ObjectsTreeConstants.SESSION_OBJ_ATTR, obj);
response.setAttribute(SpagoBIConstants.PUBLISHER_NAME, publisher_Name);
response.setAttribute("metadata_publisher_Name", metadata_publisher_Name);
response.setAttribute("trend_publisher_Name", trend_publisher_Name);
if (name != null) {
response.setAttribute("title", name);
response.setAttribute("styleTitle", styleTitle);
}
if (subName != null) {
response.setAttribute("subName", subName);
response.setAttribute("styleSubTitle", styleSubTitle);
}
response.setAttribute("kpiRBlocks", kpiRBlocks);
response.setAttribute(AuditManager.AUDIT_ID, auditId);
kpiResultsList = kpiRBlocks;
} catch (Exception eex) {
EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 10107);
userError.setBundle("messages");
throw userError;
}
logger.debug("OUT");
} catch (EMFUserError e) {
logger.error("User Error", e);
errorHandler.addError(e);
if(auditId!=null){
auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()), "EXECUTION_FAILED", e
.getMessage(), null);
}
}
catch (Exception e) {
EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 101);
logger.error("Generic Error", e);
errorHandler.addError(userError);
if(auditId!=null){
auditManager.updateAudit(auditId, null, new Long(System.currentTimeMillis()), "EXECUTION_FAILED", e
.getMessage(), null);