SbiKpiModel sbiKpiModel = (SbiKpiModel) aSession.load(
SbiKpiModel.class, aModel.getId());
sbiKpiModelInst.setSbiKpiModel(sbiKpiModel);
// set the sbiKpiInstance
KpiInstance kpiInst = toCreate.getKpiInstance();
//if already present
if(kpiInst != null){
SbiKpiInstance sbiKpiInstance = new SbiKpiInstance();
if(kpiInst.getKpi() != null){
SbiKpi sbiKpi = (SbiKpi) aSession.load(SbiKpi.class, kpiInst.getKpi());
sbiKpiInstance.setSbiKpi(sbiKpi);
if(kpiInst.getThresholdId() != null){
SbiThreshold sbiThr = (SbiThreshold) aSession.load(SbiThreshold.class, kpiInst.getThresholdId());
sbiKpiInstance.setSbiThreshold(sbiThr);
}
sbiKpiInstance.setWeight(kpiInst.getWeight());
sbiKpiInstance.setTarget(kpiInst.getTarget());
//if periodicity exists then set it
if(kpiInst.getPeriodicityId() != null){
Set periods = new HashSet<SbiKpiInstPeriod>();
SbiKpiPeriodicity sbiPeriodicity = (SbiKpiPeriodicity) aSession.load(SbiKpiPeriodicity.class, kpiInst.getPeriodicityId());
if(sbiPeriodicity != null){
periods.add(sbiPeriodicity);
sbiKpiInstance.setSbiKpiInstPeriods(periods);
}
}
if(kpiInst.getChartTypeId() != null){
SbiDomains chartType = (SbiDomains) aSession.load(SbiDomains.class, kpiInst.getChartTypeId());
sbiKpiInstance.setChartType(chartType);
}
Calendar now = Calendar.getInstance();
sbiKpiInstance.setBeginDt(now.getTime());
updateSbiCommonInfo4Insert(sbiKpiInstance);