}
private KpiValue toKpiValue(SbiKpiValue value, Date d) throws EMFUserError {
logger.debug("IN");
KpiValue toReturn = new KpiValue();
Date beginDate = value.getBeginDt();
logger
.debug("SbiKpiValue begin date: "
+ (beginDate != null ? beginDate.toString()
: "Begin date null"));
Date endDate = value.getEndDt();
logger.debug("SbiKpiValue end date: "
+ (endDate != null ? endDate.toString() : "End date null"));
String val = value.getValue();
logger
.debug("SbiKpiValue value: "
+ (val != null ? val : "Value null"));
String valueDescr = value.getDescription();
logger.debug("SbiKpiValue description: "
+ (valueDescr != null ? valueDescr : "Value description null"));
Integer kpiInstanceID = null;
Double weight = null;
Double target = null;
String scaleCode = null;
String scaleName = null;
SbiResources res = value.getSbiResources();
Resource r = null;
IResourceDAO resDao=DAOFactory.getResourceDAO();
if (res != null) {
r = resDao.toResource(res);
logger.debug("SbiKpiValue resource: "
+ (r.getColumn_name() != null ? r.getColumn_name()
: "resource name null"));
}
kpiInstanceID = value.getSbiKpiInstance().getIdKpiInstance();
logger.debug("SbiKpiValue kpiInstanceID: "
+ (kpiInstanceID != null ? kpiInstanceID.toString()
: "kpiInstanceID null"));
SbiKpiInstance kpiInst = value.getSbiKpiInstance();
List thresholdValues = new ArrayList();
Date kpiInstBegDt = kpiInst.getBeginDt();
logger.debug("kpiInstBegDt begin date: "
+ (kpiInstBegDt != null ? kpiInstBegDt.toString()
: "Begin date null"));
// in case the current threshold is correct
if (((d.before(endDate) || d.equals(endDate))
&& (d.after(beginDate) || d.equals(beginDate))
&& (d.after(kpiInstBegDt) || d.equals(kpiInstBegDt)))|| kpiInst.getSbiKpiInstanceHistories().isEmpty()) {
weight = kpiInst.getWeight();
logger.debug("SbiKpiValue weight: "
+ (weight != null ? weight.toString() : "weight null"));
target = kpiInst.getTarget();
logger.debug("SbiKpiValue target: "
+ (target != null ? target.toString() : "target null"));
if (kpiInst.getSbiMeasureUnit() != null) {
scaleCode = kpiInst.getSbiMeasureUnit().getScaleCd();
logger.debug("SbiKpiValue scaleCode: "
+ (scaleCode != null ? scaleCode : "scaleCode null"));
scaleName = kpiInst.getSbiMeasureUnit().getScaleNm();
logger.debug("SbiKpiValue scaleName: "
+ (scaleName != null ? scaleName : "scaleName null"));
}
logger.debug("Requested date d: " + d.toString()
+ " in between beginDate and EndDate");
SbiThreshold t = kpiInst.getSbiThreshold();
if(t!=null){
Set ts = t.getSbiThresholdValues();
Iterator i = ts.iterator();
while (i.hasNext()) {
SbiThresholdValue tls = (SbiThresholdValue) i.next();
IThresholdValueDAO thDao=(IThresholdValueDAO)DAOFactory.getThresholdValueDAO();
ThresholdValue tr = thDao.toThresholdValue(tls);
thresholdValues.add(tr);
}
}
} else {// in case older thresholds have to be retrieved
Set kpiInstHist = kpiInst.getSbiKpiInstanceHistories();
Iterator i = kpiInstHist.iterator();
while (i.hasNext()) {
SbiKpiInstanceHistory ih = (SbiKpiInstanceHistory) i.next();
Date ihBegDt = ih.getBeginDt();
Date ihEndDt = ih.getEndDt();
if ((d.after(ihBegDt) || d.equals(ihBegDt))
&& (d.before(ihEndDt) || d.equals(ihEndDt))) {
weight = ih.getWeight();
logger.debug("SbiKpiValue weight: "
+ (weight != null ? weight.toString()
: "weight null"));
target = ih.getTarget();
logger.debug("SbiKpiValue target: "
+ (target != null ? target.toString()
: "target null"));
if (ih.getSbiMeasureUnit() != null) {
scaleCode = ih.getSbiMeasureUnit().getScaleCd();
logger.debug("SbiKpiValue scaleCode: "
+ (scaleCode != null ? scaleCode
: "scaleCode null"));
scaleName = ih.getSbiMeasureUnit().getScaleNm();
logger.debug("SbiKpiValue scaleName: "
+ (scaleName != null ? scaleName
: "scaleName null"));
}
SbiThreshold t = ih.getSbiThreshold();
if(t!=null){
Set ts = t.getSbiThresholdValues();
Iterator it = ts.iterator();
while (it.hasNext()) {
SbiThresholdValue tls = (SbiThresholdValue) it.next();
IThresholdValueDAO thDao=(IThresholdValueDAO)DAOFactory.getThresholdValueDAO();
ThresholdValue tr = thDao.toThresholdValue(tls);
thresholdValues.add(tr);
}
}
}
}
}
toReturn.setValueDescr(valueDescr);
logger.debug("Kpi value descritpion setted");
toReturn.setTarget(target);
logger.debug("Kpi value target setted");
toReturn.setBeginDate(beginDate);
logger.debug("Kpi value begin date setted");
toReturn.setEndDate(endDate);
logger.debug("Kpi value end date setted");
toReturn.setValue(val);
logger.debug("Kpi value setted");
toReturn.setKpiInstanceId(kpiInstanceID);
logger.debug("Kpi value Instance ID setted");
toReturn.setWeight(weight);
logger.debug("Kpi value weight setted");
toReturn.setR(r);
logger.debug("Kpi value resource setted");
toReturn.setScaleCode(scaleCode);
logger.debug("Kpi value scale Code setted");
toReturn.setScaleName(scaleName);
logger.debug("Kpi value scale Name setted");
toReturn.setThresholdValues(thresholdValues);
logger.debug("Kpi value Thresholds setted");
toReturn.setKpiValueId(value.getIdKpiInstanceValue());
logger.debug("Kpi value ID setted");
toReturn.setValueXml(value.getXmlData());
logger.debug("Kpi value XML setted");
OrganizationalUnitGrantNode grantNode = new OrganizationalUnitGrantNode();
OrganizationalUnitNode node = new OrganizationalUnitNode();
if(value.getSbiOrgUnit() != null){
OrganizationalUnit ou = DAOFactory.getOrganizationalUnitDAO().getOrganizationalUnit(value.getSbiOrgUnit().getId());
node.setOu(ou);
}
if(value.getSbiOrgUnitHierarchies() != null){
OrganizationalUnitHierarchy hierarchy = DAOFactory.getOrganizationalUnitDAO().getHierarchy(value.getSbiOrgUnitHierarchies().getId());
node.setHierarchy(hierarchy);
}
if(value.getSbiOrgUnit() != null && value.getSbiOrgUnitHierarchies() != null){
grantNode.setOuNode(node);
toReturn.setGrantNodeOU(grantNode);
}
logger.debug("Kpi value organizational unit grant node setted");
logger.debug("OUT");