Search in sources :

Example 31 with DateTime

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;
}
Also used : TriggerState(org.quartz.Trigger.TriggerState) DateTime(org.jaffa.datatypes.DateTime)

Example 32 with DateTime

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);
    }
}
Also used : DateTime(org.jaffa.datatypes.DateTime) FrameworkException(org.jaffa.exceptions.FrameworkException) JAXBException(javax.xml.bind.JAXBException) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException)

Example 33 with DateTime

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;
}
Also used : DateTime(org.jaffa.datatypes.DateTime) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 34 with DateTime

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);
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 35 with DateTime

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;
}
Also used : ArrayList(java.util.ArrayList) DateTime(org.jaffa.datatypes.DateTime)

Aggregations

DateTime (org.jaffa.datatypes.DateTime)74 Criteria (org.jaffa.persistence.Criteria)16 UOW (org.jaffa.persistence.UOW)11 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)9 PreparedStatement (java.sql.PreparedStatement)8 ValidationException (org.jaffa.datatypes.ValidationException)8 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)8 Iterator (java.util.Iterator)7 Map (java.util.Map)5 Date (java.util.Date)4 FrameworkException (org.jaffa.exceptions.FrameworkException)4 LinkedHashMap (java.util.LinkedHashMap)3 JMSException (javax.jms.JMSException)3 MarshallException (org.directwebremoting.extend.MarshallException)3 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)3 DateTimeModel (org.jaffa.presentation.portlet.widgets.model.DateTimeModel)3 DropDownModel (org.jaffa.presentation.portlet.widgets.model.DropDownModel)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Enumeration (java.util.Enumeration)2 LinkedList (java.util.LinkedList)2