if(hibList!=null && !hibList.isEmpty()) {
return;
}
// get the Kpi BO from id
IKpiDAO kpiDao=DAOFactory.getKpiDAO();
Kpi kpi=kpiDao.loadKpiById(kpiId);
// main attributes
SbiKpi hibKpi = new SbiKpi();
hibKpi.setKpiId(kpi.getKpiId());
hibKpi.setCode(kpi.getCode());
hibKpi.setDescription(kpi.getDescription());
hibKpi.setInterpretation(kpi.getInterpretation());
hibKpi.setName(kpi.getKpiName());
hibKpi.setWeight(kpi.getStandardWeight());
char isFather=kpi.getIsParent().equals(true)? 'T' : 'F';
hibKpi.setFlgIsFather(new Character(isFather));
hibKpi.setInterpretation(kpi.getInterpretation());
hibKpi.setInputAttributes(kpi.getInputAttribute());
hibKpi.setModelReference(kpi.getModelReference());
hibKpi.setTargetAudience(kpi.getTargetAudience());
hibKpi.setIsAdditive(kpi.getIsAdditive());
if(kpi.getMeasureTypeId()!=null){
SbiDomains measureType=(SbiDomains)session.load(SbiDomains.class, kpi.getMeasureTypeId());
hibKpi.setSbiDomainsByMeasureType(measureType);
}
if(kpi.getKpiTypeId()!=null){
SbiDomains kpiType=(SbiDomains)session.load(SbiDomains.class, kpi.getKpiTypeId());
hibKpi.setSbiDomainsByKpiType(kpiType);
}
if(kpi.getMetricScaleId()!=null){
SbiDomains metricScaleType=(SbiDomains)session.load(SbiDomains.class, kpi.getMetricScaleId());
hibKpi.setSbiDomainsByMetricScaleType(metricScaleType);
}
// load dataset
if (kpi.getKpiDsId() != null) {
Integer dsID = kpi.getKpiDsId();
GuiGenericDataSet guiGenericDataSet = DAOFactory.getDataSetDAO().loadDataSetById(dsID);
if(guiGenericDataSet!=null){
insertDataSet(guiGenericDataSet, session);
SbiDataSetConfig sbiDs= (SbiDataSetConfig) session.load(SbiDataSetConfig.class, guiGenericDataSet.getDsId());
hibKpi.setSbiDataSet(sbiDs);
}
}
// load threshold
if (kpi.getThreshold() != null) {
Threshold th=kpi.getThreshold();
insertThreshold(th, session);
SbiThreshold sbiTh= (SbiThreshold) session.load(SbiThreshold.class, th.getId());
hibKpi.setSbiThreshold(sbiTh);
}
// Measure Unit ???
if(kpi.getScaleCode()!=null && !kpi.getScaleCode().equalsIgnoreCase("")){
IMeasureUnitDAO muDao=DAOFactory.getMeasureUnitDAO();
MeasureUnit mu=muDao.loadMeasureUnitByCd(kpi.getScaleCode());
insertMeasureUnit(mu, session);
SbiMeasureUnit sbiMu= (SbiMeasureUnit) session.load(SbiMeasureUnit.class, mu.getId());
hibKpi.setSbiMeasureUnit(sbiMu);
}
Transaction tx = session.beginTransaction();
Integer kpiIdReturned = (Integer)session.save(hibKpi);
tx.commit();
List kpiDocsList = kpi.getSbiKpiDocuments();
Iterator i = kpiDocsList.iterator();
while (i.hasNext()) {
KpiDocuments doc = (KpiDocuments) i.next();
String label = doc.getBiObjLabel();
IBIObjectDAO biobjDAO = DAOFactory.getBIObjectDAO();
BIObject biobj = biobjDAO.loadBIObjectByLabel(label);
if(biobj!=null){
insertBIObject(biobj, session, true);
doc.setBiObjId(biobj.getId());
}
Integer origDocId = doc.getBiObjId();
Criterion labelCriterrion = Expression.eq("label",label);
Criteria criteria = session.createCriteria(SbiObjects.class);
criteria.add(labelCriterrion);
SbiObjects hibObject = (SbiObjects) criteria.uniqueResult();
if(hibObject!=null){
SbiKpiDocument temp = new SbiKpiDocument();
temp.setSbiKpi(hibKpi);
temp.setSbiObjects(hibObject);
KpiDocuments docK = kpiDao.loadKpiDocByKpiIdAndDocId(kpiId, origDocId);
if(docK!=null && docK.getKpiDocId()!=null){
temp.setIdKpiDoc(docK.getKpiDocId());
Transaction tx2 = session.beginTransaction();
session.save(temp);
tx2.commit();
}
}
}
//manage insert of kpi relations
List<KpiRel> relations = DAOFactory.getKpiDAO().loadKpiRelListByParentId(kpi.getKpiId());
if(relations != null && !relations.isEmpty()){
for (int j = 0; j < relations.size(); j++) {
KpiRel kpiRel = (KpiRel)relations.get(j);
//insert child kpi first
insertKpi(kpiRel.getKpiChildId(), session);