*
* @throws EMFUserError the EMF user error
*/
public SbiKpi insertKpiNorelations(Integer kpiId, Session session) throws EMFUserError {
logger.debug("IN");
SbiKpi hibKpi = null;
try {
Query hibQuery = session.createQuery(" from SbiKpi where kpiId = " + kpiId);
List hibList = hibQuery.list();
if(!hibList.isEmpty()) {
return null;
}
// get the Kpi BO from id
IKpiDAO kpiDao=DAOFactory.getKpiDAO();
Kpi kpi=kpiDao.loadKpiById(kpiId);
// main attributes
hibKpi = new SbiKpi();
hibKpi.setKpiId(kpi.getKpiId());
hibKpi.setCode(kpi.getCode());
hibKpi.setDescription(kpi.getDescription());
hibKpi.setInterpretation(kpi.getInterpretation());
hibKpi.setName(kpi.getKpiName());
// Weight??? hibKpi.setWeight(kpi.get)
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();