return options;
}
public void calculateAndInsertKpiValueWithResources(Integer miId,List resources)throws EMFUserError, EMFInternalError, SourceBeanException {
logger.debug("IN");
ModelInstanceNode modI = DAOFactory.getModelInstanceDAO().loadModelInstanceById(miId, dateOfKPI);
if (modI != null) {
logger.info("Loaded Model Instance Node with id: " + modI.getModelInstanceNodeId());
}
List childrenIds = modI.getChildrenIds();
if (!childrenIds.isEmpty()) {
Iterator childrenIt = childrenIds.iterator();
while (childrenIt.hasNext()) {
Integer id = (Integer) childrenIt.next();
calculateAndInsertKpiValueWithResources(id, resources);
}
}
KpiInstance kpiI = modI.getKpiInstanceAssociated();
if (kpiI != null) {
KpiValue kVal = new KpiValue();
logger.info("Got KpiInstance with ID: " + kpiI.getKpiInstanceId().toString());
IDataSet dataSet = DAOFactory.getKpiDAO().getDsFromKpiId(kpiI.getKpi());
logger.info("Retrieved the Dataset to be calculated: " + (dataSet!=null ? dataSet.getId():"null"));
Integer kpiInstanceID = kpiI.getKpiInstanceId();
Date kpiInstBegDt = kpiI.getD();
kVal = setTimeAttributes(kVal, kpiI);
kVal.setKpiInstanceId(kpiInstanceID);
logger.debug("Setted the KpiValue Instance ID:"+kpiInstanceID);
if ( (dateOfKPI.after(kpiInstBegDt)||dateOfKPI.equals(kpiInstBegDt))) {
//kpiInstance doesn't change
}else{
KpiInstance tempKIn = DAOFactory.getKpiInstanceDAO().loadKpiInstanceByIdFromHistory(kpiInstanceID,dateOfKPI);
if(tempKIn==null){//kpiInstance doesn't change
}else{
// in case older thresholds have to be retrieved
kpiI = tempKIn;
}
}
kVal = getFromKpiInstAndSetKpiValueAttributes(kpiI,kVal);
// If it has to be calculated for a Resource. The resource will be set as parameter
HashMap temp = (HashMap) this.parametersObject.clone();
temp.put("ParModelInstance", miId);
temp.put("ParKpiInstance", kpiInstanceID.toString());
// If not, the dataset will be calculated without the parameter Resource
// and the DataSet won't expect a parameter of type resource
//if(dataSet.hasBehaviour( QuerableBehaviour.class.getName()) ) {
if(dataSet!=null){
Kpi kpi = DAOFactory.getKpiDAO().loadKpiById(kpiI.getKpi());
//if parameter exists and OU is abilitaded for Model Instance, than calculate as dataset parameter
String parKpiOuLabel = (String)this.parametersObject.get("ParKpiOU");
logger.info("Got ParKpiOU: " + parKpiOuLabel);
String paramLabelHierarchy = (String)this.parametersObject.get("ParKpiHierarchy");
logger.info("Got ParKpiHierarchy: " + paramLabelHierarchy);
setOUAbilitated(miId, parKpiOuLabel, paramLabelHierarchy);
if(ouList != null && !ouList.isEmpty()){
if(use_ou){
for(int i = 0; i<ouList.size(); i++){
OrganizationalUnitGrantNode grantNode = ouList.get(i);
String ouLabel = grantNode.getOuNode().getOu().getLabel();
String hierLabel = grantNode.getOuNode().getHierarchy().getLabel();
if(parKpiOuLabel == null){
this.parametersObject.put("ParKpiOU", ouLabel);
this.parametersObject.put("ParKpiHierarchy", hierLabel);
}
kVal.setGrantNodeOU(grantNode);
kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
if(ouWarning != null && kVal.getValue() == null){
kVal.setValueDescr(ouWarning);
}
if(parKpiOuLabel == null){
this.parametersObject.remove("ParKpiOU");
this.parametersObject.remove("ParKpiHierarchy");
}
}
}else{
kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
}
}else{
if(use_ou){
kVal = new KpiValue();
kVal.setValueDescr(ouWarning);
kVal.setKpiInstanceId(kpiI.getKpiInstanceId());
if(dateIntervalFrom!=null && dateIntervalTo!=null){
kVal.setBeginDate(dateIntervalFrom);
kVal.setEndDate(dateIntervalTo);
} else{
kVal.setBeginDate(dateOfKPI);
kVal.setEndDate(dateOfKPI);
}
kVal.setValue(null);
}else{
kVal = recursiveGetKpiValueFromKpiRel(kpi,dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), modI.getModelInstanceNodeId());
kVal = getKpiValueFromDataset(dataSet,temp,kVal,dateOfKPI,kVal.getEndDate(), true, modI.getModelInstanceNodeId());
}
}
/* if(ouList != null && !ouList.isEmpty()){