Transaction tx = null;
try {
aSession = getSession();
tx = aSession.beginTransaction();
SbiKpiInstance hibSbiKpiInstance = (SbiKpiInstance) aSession
.load(SbiKpiInstance.class, kpiInstID);
Set alarms = hibSbiKpiInstance.getSbiAlarms();
if (!alarms.isEmpty()) {
Iterator itAl = alarms.iterator();
while (itAl.hasNext()) {
boolean isAlarming = false;
SbiAlarm alarm = (SbiAlarm) itAl.next();
SbiThresholdValue threshold = alarm
.getSbiThresholdValue();
String type = threshold.getSbiThreshold()
.getThresholdType().getValueCd();
double min;
double max;
String thresholdValue = "";
logger.debug("Threshold Type: " + type);
if (type.equals("RANGE")) {
min = threshold.getMinValue();
max = threshold.getMaxValue();
logger.debug("Threshold Min: " + min);
logger.debug("Threshold Max: " + max);
// if the value is in the interval, then there
// should be
// an alarm
if (kpiVal.doubleValue() >= min
&& kpiVal.doubleValue() <= max) {
isAlarming = true;
thresholdValue = "Min:" + min + "-Max:" + max;
logger.debug("The value "
+ kpiVal.doubleValue()
+ " is in the RANGE " + thresholdValue
+ " and so an Alarm will be scheduled");
}
} else if (type.equals("MINIMUM")) {
min = threshold.getMinValue();
logger.debug("Threshold Min: " + min);
// if the value is smaller than the min value
if (kpiVal.doubleValue() <= min) {
isAlarming = true;
thresholdValue = "Min:" + min;
logger.debug("The value "
+ kpiVal.doubleValue()
+ " is lower than " + thresholdValue
+ " and so an Alarm will be scheduled");
}
} else if (type.equals("MAXIMUM")) {
max = threshold.getMaxValue();
logger.debug("Threshold Max: " + max);
// if the value is higher than the max value
if (kpiVal.doubleValue() >= max) {
isAlarming = true;
thresholdValue = "Max:" + max;
logger.debug("The value "
+ kpiVal.doubleValue()
+ " is higher than " + thresholdValue
+ " and so an Alarm will be scheduled");
}
}
if (isAlarming) {
SbiAlarmEvent alarmEv = new SbiAlarmEvent();
String kpiName = hibSbiKpiInstance.getSbiKpi()
.getName();
logger.debug("Kpi Name: " + kpiName);
String resources = null;
if (value.getR() != null) {
resources = value.getR().getName();