if (kpi.getThreshold() != null) {
Integer thresholdId = kpi.getThreshold().getId();
sbiThreshold = (SbiThreshold) aSession.load(SbiThreshold.class, thresholdId);
}
SbiKpi sbiKpi = (SbiKpi) aSession.load(SbiKpi.class, kpi.getKpiId());
SbiDomains kpiType = null;
if (kpi.getKpiTypeId() != null) {
Integer kpiTypeId = kpi.getKpiTypeId();
kpiType = (SbiDomains) aSession.load(SbiDomains.class, kpiTypeId);
}
SbiDomains metricScaleType = null;
if (kpi.getMetricScaleId() != null) {
Integer metricScaleId = kpi.getMetricScaleId();
metricScaleType = (SbiDomains) aSession.load(SbiDomains.class, metricScaleId);
}
SbiDomains measureType = null;
if (kpi.getMeasureTypeId() != null) {
Integer measureTypeId = kpi.getMeasureTypeId();
measureType = (SbiDomains) aSession.load(SbiDomains.class, measureTypeId);
}
//Loading all old sbiObjects
Criterion kpiCriter = Expression.eq("sbiKpi",sbiKpi);
Criteria crite = aSession.createCriteria(SbiKpiDocument.class);
crite.add(kpiCriter);
List existingDocs = crite.list();
List kpiDocsList = kpi.getSbiKpiDocuments();
Set sbiKpiDocuments = new HashSet(0);
Iterator i = kpiDocsList.iterator();
while (i.hasNext()) {
KpiDocuments doc = (KpiDocuments) i.next();
String label = doc.getBiObjLabel();
Criterion labelCriterrion = Expression.eq("label",label);
Criteria criteria = aSession.createCriteria(SbiObjects.class);
criteria.add(labelCriterrion);
SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();
Integer kpiId = kpi.getKpiId();
Criterion kpiCriterrion = Expression.eq("sbiKpi",sbiKpi);
Criterion sbiObjCriterrion = Expression.eq("sbiObjects",hibObject);
Criteria crit = aSession.createCriteria(SbiKpiDocument.class);
crit.add(kpiCriterrion);
crit.add(sbiObjCriterrion);
SbiKpiDocument kpiDoc = (SbiKpiDocument) crit.uniqueResult();
if(existingDocs!=null && !existingDocs.isEmpty() && kpiDoc!=null){
if(existingDocs.contains(kpiDoc)){
existingDocs.remove(kpiDoc);
}
}
if(kpiDoc==null){
SbiKpiDocument temp = new SbiKpiDocument();
temp.setSbiKpi(sbiKpi);
temp.setSbiObjects(hibObject);
updateSbiCommonInfo4Update(temp);
aSession.saveOrUpdate(temp);
}
}
if(existingDocs!=null && !existingDocs.isEmpty() ){
Iterator it2 = existingDocs.iterator();
while(it2.hasNext()){
SbiKpiDocument kpiDoc = (SbiKpiDocument) it2.next();
aSession.delete(kpiDoc);
}
}
sbiKpi.setInterpretation(interpretation);
sbiKpi.setInputAttributes(inputAttribute);
sbiKpi.setModelReference(modelReference);
sbiKpi.setTargetAudience(targetAudience);
sbiKpi.setSbiDomainsByKpiType(kpiType);
sbiKpi.setSbiDomainsByMeasureType(measureType);
sbiKpi.setSbiDomainsByMetricScaleType(metricScaleType);
sbiKpi.setName(name);
sbiKpi.setDescription(description);
sbiKpi.setCode(code);
sbiKpi.setMetric(metric);
sbiKpi.setWeight(weight);
sbiKpi.setIsAdditive(kpi.getIsAdditive());
//sbiKpi.setSbiKpiDocumentses(sbiKpiDocuments);
sbiKpi.setSbiDataSet(ds);
sbiKpi.setSbiThreshold(sbiThreshold);
updateSbiCommonInfo4Update(sbiKpi);
aSession.saveOrUpdate(sbiKpi);
IUdpValueDAO dao=DAOFactory.getUdpDAOValue();
dao.setUserProfile(getUserProfile());
dao.insertOrUpdateRelatedUdpValues(kpi, sbiKpi, aSession, "KPI");