use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class QuartzSchedulerHelper method jobAndTriggerToTask.
/**
* Molds the input Job and Trigger into a Task.
*/
private ScheduledTask jobAndTriggerToTask(final JobDetail jobDetail, final List<? extends Trigger> triggers) throws FrameworkException {
// Obtain the Task from the JobDataMap of the Job
ScheduledTask task = jobDataMapToTask(jobDetail.getJobDataMap());
// Obtain the Trigger Details
if (triggers != null && 0 < triggers.size()) {
final Trigger trigger = triggers.get(0);
task.setNextDue(trigger.getNextFireTime() != null ? new DateTime(trigger.getNextFireTime()) : null);
task.setLastRunOn(trigger.getPreviousFireTime() != null ? new DateTime(trigger.getPreviousFireTime()) : null);
}
// Determine the Status
ScheduledTask.TaskStatusEnumeration status;
try {
final TriggerState triggerState = scheduler.getTriggerState(TriggerKey.triggerKey(task.getScheduledTaskId(), JOB_GROUP));
switch(triggerState) {
case BLOCKED:
status = ScheduledTask.TaskStatusEnumeration.BLOCKED;
break;
case COMPLETE:
status = ScheduledTask.TaskStatusEnumeration.COMPLETE;
break;
case ERROR:
status = ScheduledTask.TaskStatusEnumeration.ERROR;
break;
case NORMAL:
status = ScheduledTask.TaskStatusEnumeration.NORMAL;
break;
case PAUSED:
status = ScheduledTask.TaskStatusEnumeration.PAUSED;
break;
default:
status = ScheduledTask.TaskStatusEnumeration.UNKNOWN;
break;
}
} catch (SchedulerException e) {
LOGGER.error("Error in determing the trigger state. Will assume UNKNOWN status for " + task.getScheduledTaskId(), e);
status = ScheduledTask.TaskStatusEnumeration.UNKNOWN;
}
task.setStatus(status);
return task;
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class QuartzSchedulerHelper method updateTask.
/**
* Updates the Task in the Scheduler.
*
* @param task the Task.
* @throws FrameworkException in case any internal error occurs.
* @throws ApplicationExceptions Indicates application error(s).
*/
public void updateTask(ScheduledTask task) throws FrameworkException, ApplicationExceptions {
// Ensure that the Scheduler is available
checkScheduler();
// Most of the validations happen during Trigger creation.
if (LOGGER.isDebugEnabled())
LOGGER.debug("Validating " + task + " before updating it");
prevalidate(task);
// Stamp LastChangedBy and LastChangedOn
if (SecurityManager.getPrincipal() != null)
task.setLastChangedBy(SecurityManager.getPrincipal().getName());
task.setLastChangedOn(new DateTime());
TriggerHelper.taskToTrigger(task);
// Get the existing Task, in case we need to revert after the delete
if (LOGGER.isDebugEnabled())
LOGGER.debug("Get existing values for " + task.getScheduledTaskId() + " before updating it");
ScheduledTask existingTask = getTask(task.getScheduledTaskId());
if (LOGGER.isDebugEnabled())
LOGGER.debug("Updating " + task.getScheduledTaskId() + " by deleting and then adding it");
deleteTask(task.getScheduledTaskId());
try {
addTask(task);
} catch (Exception e) {
// revert to original values
if (LOGGER.isDebugEnabled())
LOGGER.debug("Updating " + task.getScheduledTaskId() + " has failed. Will now add the original values for the Task");
addTask(existingTask);
ExceptionHelper.throwAFR(e);
}
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class QuartzSchedulerHelper method getExecutionDates.
/**
* Returns an array of execution dates for the given task, after the given
* date.
*
* @param task the Task.
* @param after the date after which the execution dates are to be computed.
* @param count the number of execution dates to compute.
* @return an array of execution dates for the given task, after the given
* date.
* @throws FrameworkException in case any internal error occurs.
* @throws ApplicationExceptions Indicates application error(s).
*/
public DateTime[] getExecutionDates(ScheduledTask task, DateTime after, Integer count) throws FrameworkException, ApplicationExceptions {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Computing the next valid times for " + task + " after " + after + ' ' + count + " times");
final Collection<DateTime> output = new LinkedList<DateTime>();
Trigger trigger = TriggerHelper.taskToTrigger(task);
Date d = after.getUtilDate();
for (int i = 0; i < count; i++) {
d = trigger.getFireTimeAfter(d);
if (d == null)
break;
output.add(new DateTime(d));
}
if (LOGGER.isDebugEnabled()) {
StringBuilder buf = new StringBuilder("Valid times are:");
if (0 < output.size()) {
for (DateTime dt : output) buf.append(' ').append(dt);
}
LOGGER.debug(buf.toString());
}
return 0 < output.size() ? output.toArray(new DateTime[output.size()]) : null;
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class TransactionGraph method setCreatedOn.
/**
* Setter for property createdOn.
*
* @param createdOn Value of property createdOn.
*/
public void setCreatedOn(DateTime createdOn) {
DateTime oldCreatedOn = this.createdOn;
this.createdOn = createdOn;
propertyChangeSupport.firePropertyChange("createdOn", oldCreatedOn, createdOn);
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method doesTransactionFailFilterCheck.
/**
* Check the Transaction fields against the input criteria to see if it fails any of the checks.
* Return true if anything defined in the criteria does not match the Transaction.
*
* @param transaction the Transaction to check the fields of
* @param criteria the criteria to check the values against the Transaction
* @return true if the Transaction fails the criteria check, false otherwise
*/
private boolean doesTransactionFailFilterCheck(Transaction transaction, MessageCriteria criteria) {
String messageId = getMessageCriteriaId(criteria);
if ((messageId != null) && (transaction.getId() != null)) {
if (!transaction.getId().equals(messageId)) {
return true;
}
}
String direction = getMessageCriteriaDirection(criteria);
if ((direction != null) && (transaction.getDirection() != null)) {
if (!transaction.getDirection().equals(direction)) {
return true;
}
}
List<String> statusValues = getMessageCriteriaStatus(criteria);
if ((statusValues != null) && !statusValues.isEmpty()) {
List<String> convertedValues = new ArrayList<String>();
for (String value : statusValues) {
convertedValues.add(messageToTransactionStatus(value).name());
}
if ((transaction.getStatus() == null) || !convertedValues.contains(transaction.getStatus())) {
return true;
}
}
DateTime createdOn = getMessageCriteriaCreatedOn(criteria);
if ((createdOn != null) && (transaction.getCreatedOn() != null)) {
if (!transaction.getCreatedOn().equals(createdOn)) {
return true;
}
}
String createdBy = getMessageCriteriaCreatedBy(criteria);
if ((createdBy != null) && (transaction.getCreatedBy() != null)) {
if (!transaction.getCreatedBy().equals(createdBy)) {
return true;
}
}
DateTime lastChangedOn = getMessageCriteriaLastChangedOn(criteria);
if ((lastChangedOn != null) && (transaction.getLastChangedOn() != null)) {
if (!transaction.getLastChangedOn().equals(lastChangedOn)) {
return true;
}
}
String lastChangedby = getMessageCriteriaLastChangedBy(criteria);
if ((lastChangedby != null) && (transaction.getLastChangedBy() != null)) {
if (!transaction.getLastChangedBy().equals(lastChangedby)) {
return true;
}
}
String errorMessage = getMessageCriteriaErrorMessage(criteria);
if ((errorMessage != null) && (transaction.getErrorMessage() != null)) {
if (!transaction.getErrorMessage().equals(errorMessage)) {
return true;
}
}
return false;
}
Aggregations