task.setEnabled(serviceResource.isEnabled());
// Need to store the enabled flag update
getNexusScheduler().updateSchedule(task);
ScheduledServiceResourceStatus resourceStatus = new ScheduledServiceResourceStatus();
resourceStatus.setResource(serviceResource);
// Just need to update the id, as the incoming data is a POST w/ no id
resourceStatus.getResource().setId(task.getId());
resourceStatus.setResourceURI(createChildReference(request, this, task.getId()).toString());
resourceStatus.setStatus(task.getTaskState().toString());
resourceStatus.setReadableStatus(getReadableState(task.getTaskState()));
resourceStatus.setCreated(task.getScheduledAt() == null ? "n/a" : task.getScheduledAt().toString());
resourceStatus.setLastRunResult(TaskState.BROKEN.equals(task.getTaskState()) ? "Error" : "Ok");
resourceStatus.setLastRunTime(task.getLastRun() == null ? "n/a" : task.getLastRun().toString());
resourceStatus.setNextRunTime(task.getNextRun() == null ? "n/a" : task.getNextRun().toString());
if (task.getScheduledAt() != null) {
resourceStatus.setCreatedInMillis(task.getScheduledAt().getTime());
}
if (task.getLastRun() != null) {
resourceStatus.setLastRunTimeInMillis(task.getLastRun().getTime());
}
if (task.getNextRun() != null) {
resourceStatus.setNextRunTimeInMillis(task.getNextRun().getTime());
}
result = new ScheduledServiceResourceStatusResponse();
result.setData(resourceStatus);
}