long elapsedTimeInMillis = upTilNow + elapsedTime.getMillis();
//**
// log.warn("Elapsed time since last calculation + prev elapsed time" + elapsedTimeInMillis);
if (slaLastCalculated.hasValue(issue)) {
slaLastCalculated.updateValue(null, issue, new ModifiedValue(slaLastCalculatedVal, calculationTime), new DefaultIssueChangeHolder());
//**
// log.warn("Updating last calculated time" + calculationTime);
} else {
slaLastCalculated.createValue(issue, calculationTime);
}
//**
// log.debug("Updated sla last calculated time");
final Duration duration = new Duration(elapsedTimeInMillis);
final Period period = duration.toPeriodTo(new DateTime());
if (timeElapsed.hasValue(issue)) {
//**
// log.warn("Updating total elapsed time to" + period);
timeElapsed.updateValue(null, issue, new ModifiedValue(timeElapsedVal, period), new DefaultIssueChangeHolder());
} else {
timeElapsed.createValue(issue, period);
}
//**
// log.debug("Updated elapsed time");
ComponentManager componentManager = ComponentManager.getInstance();
final IssueManager issueManager = componentManager.getIssueManager();
final CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
// response SLA handling
if (dateRespondedVal == null) {
// breached
if (elapsedTimeInMillis > responseTime) {
if (!ObjectUtils.equals(BREACHED, responseSlaStateVal))
{
responseSlaState.updateValue(null, issue, new ModifiedValue(responseSlaStateVal, BREACHED), new DefaultIssueChangeHolder());
log.debug("Dispatching breached SLA event.");
dispatchEvent(issue, user, issueManager, customFieldManager, SLA_BREACHED_EVENT_ID);
}
}
// warn at 50% response SLA elapsed
else if (elapsedTimeInMillis > responseTime / 2)
{
if (!ObjectUtils.equals(WARN, responseSlaStateVal))
{
responseSlaState.updateValue(null, issue, new ModifiedValue(responseSlaStateVal, WARN), new DefaultIssueChangeHolder());
log.debug("Dispatching 50% of SLA time elapsed.");
dispatchEvent(issue, user, issueManager, customFieldManager, FIFTY_PERCENT_SLA_EVENT_ID);
}
}
// SLA OK
else if (!ObjectUtils.equals(OK, responseSlaStateVal)) {
responseSlaState.updateValue(null, issue, new ModifiedValue(responseSlaStateVal, OK), new DefaultIssueChangeHolder());
}
}
// resolved KPI handling
if (dateResolvedVal == null) {
if (elapsedTimeInMillis > fixTime) {
if (!ObjectUtils.equals(BREACHED, fixKPIStateVal))
{
fixKPIState.updateValue(null, issue, new ModifiedValue(fixKPIStateVal, BREACHED), new DefaultIssueChangeHolder());
log.debug("Dispatching breached fix KPI event.");
dispatchEvent(issue, user, issueManager, customFieldManager, FIX_KPI_BREACHED_EVENT_ID);
}
} else if (elapsedTimeInMillis > fixTime / 2) {
if (!ObjectUtils.equals(WARN, fixKPIStateVal))
{
fixKPIState.updateValue(null, issue, new ModifiedValue(fixKPIStateVal, WARN), new DefaultIssueChangeHolder());
log.debug("Dispatching 50% of SLA time elapsed.");
dispatchEvent(issue, user, issueManager, customFieldManager, FIFTY_PERCENT_FIX_KPI_EVENT_ID);
}
} else if (!ObjectUtils.equals(OK, fixKPIStateVal)) {
fixKPIState.updateValue(null, issue, new ModifiedValue(responseSlaStateVal, OK), new DefaultIssueChangeHolder());
}
}
//**
log.debug("Updated response sla and fix kpi states");