String name = threshold.getName();
String description = threshold.getDescription();
String code = threshold.getCode();
Integer thresholdTypeId = threshold.getThresholdTypeId();
SbiThreshold sbiThreshold = (SbiThreshold) aSession.load(
SbiThreshold.class, threshold.getId());
SbiDomains newThresholdType = null;
if (thresholdTypeId != null) {
newThresholdType = (SbiDomains) aSession.load(SbiDomains.class,
thresholdTypeId);
}
SbiDomains oldThrType = sbiThreshold.getThresholdType();
if(!oldThrType.getValueCd().equalsIgnoreCase(newThresholdType.getValueCd())){
//If the type of threshold is changed all old threshold need to be deleted
Set set = sbiThreshold.getSbiThresholdValues();
ArrayList thValues=new ArrayList();
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
SbiThresholdValue sbiThValue = (SbiThresholdValue) iterator.next();
//look up for alarms
String hql = "from SbiAlarm a where a.sbiThresholdValue.idThresholdValue = :id";
Query hqlQuery = aSession.createQuery(hql);
hqlQuery.setInteger("id", sbiThValue.getIdThresholdValue());
List <SbiAlarm> alarms = hqlQuery.list();
if(alarms != null && !alarms.isEmpty()){
throw new EMFUserError(EMFErrorSeverity.ERROR, 10119);
}
aSession.delete(sbiThValue);
aSession.flush();
}
}
sbiThreshold.setName(name);
sbiThreshold.setDescription(description);
sbiThreshold.setCode(code);
sbiThreshold.setThresholdType(newThresholdType);
updateSbiCommonInfo4Update(sbiThreshold);
aSession.saveOrUpdate(sbiThreshold);
Integer thrId = threshold.getId();