Search in sources :

Example 6 with IVoucherGenerator

use of org.jaffa.components.voucher.IVoucherGenerator in project jaffa-framework by jaffa-projects.

the class BusinessEventLog method validate.

// .//GEN-END:performPreDeleteReferentialIntegrity_1_be
// All the custom code goes here//GEN-FIRST:custom
/**
 * {@inheritDoc}
 */
@Override
public void validate() throws ApplicationExceptions, FrameworkException {
    // Generate the technical-key, if required
    if (getLogId() == null) {
        try {
            IVoucherGenerator vg = VoucherGeneratorFactory.instance();
            vg.setUow(getUOW());
            vg.setDomainClassName(getClass().getName());
            vg.setFieldName(BusinessEventLogMeta.LOG_ID);
            vg.setLabelToken(BusinessEventLogMeta.META_LOG_ID.getLabelToken());
            setLogId(vg.generate());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(e);
        }
    }
    super.validate();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) IVoucherGenerator(org.jaffa.components.voucher.IVoucherGenerator)

Example 7 with IVoucherGenerator

use of org.jaffa.components.voucher.IVoucherGenerator in project jaffa-framework by jaffa-projects.

the class AuditTransaction method generateKey.

/**
 * Generate the technical-key, if required.
 */
public void generateKey() throws ApplicationExceptions, FrameworkException {
    if (getTransactionId() == null) {
        try {
            IVoucherGenerator vg = VoucherGeneratorFactory.instance();
            vg.setUow(getUOW());
            vg.setDomainClassName(getClass().getName());
            vg.setFieldName(AuditTransactionMeta.TRANSACTION_ID);
            vg.setLabelToken(AuditTransactionMeta.META_TRANSACTION_ID.getLabelToken());
            setTransactionId(vg.generate());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(e);
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) IVoucherGenerator(org.jaffa.components.voucher.IVoucherGenerator)

Example 8 with IVoucherGenerator

use of org.jaffa.components.voucher.IVoucherGenerator in project jaffa-framework by jaffa-projects.

the class AuditTransactionField method generateKey.

/**
 * Generate the technical-key, if required.
 */
public void generateKey() throws ApplicationExceptions, FrameworkException {
    if (getFieldId() == null) {
        try {
            IVoucherGenerator vg = VoucherGeneratorFactory.instance();
            vg.setUow(getUOW());
            vg.setDomainClassName(getClass().getName());
            vg.setFieldName(AuditTransactionFieldMeta.FIELD_ID);
            vg.setLabelToken(AuditTransactionFieldMeta.META_FIELD_ID.getLabelToken());
            setFieldId(vg.generate());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(e);
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) IVoucherGenerator(org.jaffa.components.voucher.IVoucherGenerator)

Example 9 with IVoucherGenerator

use of org.jaffa.components.voucher.IVoucherGenerator in project jaffa-framework by jaffa-projects.

the class QuartzSchedulerHelper method addTask.

/**
 * Adds the Task to the Scheduler.
 *
 * @param task the Task.
 * @throws FrameworkException    in case any internal error occurs.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public void addTask(ScheduledTask task) throws FrameworkException, ApplicationExceptions {
    // Ensure that the Scheduler is available
    checkScheduler();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Adding " + task);
    // Validate the Task
    prevalidate(task);
    // Voucher the technical key
    if (task.getScheduledTaskId() == null || task.getScheduledTaskId().length() == 0) {
        IVoucherGenerator vg = VoucherGeneratorFactory.instance();
        vg.setDomainClassName(ScheduledTask.class.getName());
        vg.setFieldName(BusinessEventLogMeta.SCHEDULED_TASK_ID);
        vg.setLabelToken(BusinessEventLogMeta.META_SCHEDULED_TASK_ID.getLabelToken());
        task.setScheduledTaskId(vg.generate());
    }
    // Stamp CreatedBy and CreatedOn
    if (task.getCreatedBy() == null && SecurityManager.getPrincipal() != null)
        task.setCreatedBy(SecurityManager.getPrincipal().getName());
    if (task.getCreatedOn() == null)
        task.setCreatedOn(new DateTime());
    // Create the Job and Trigger
    final JobDetail job = taskToJob(task);
    final Trigger trigger = TriggerHelper.taskToTrigger(task);
    // Schedule the Task
    try {
        final Date ft = scheduler.scheduleJob(job, trigger);
        if (LOGGER.isInfoEnabled())
            LOGGER.info(task.getScheduledTaskId() + " has been scheduled to run at: " + ft + (trigger instanceof CronTrigger ? " and repeat based on expression: " + ((CronTrigger) trigger).getCronExpression() : ""));
    } catch (SchedulerException e) {
        LOGGER.error("Error adding task in scheduler " + task.getScheduledTaskId(), e);
        // else
        throw new JaffaSchedulerFrameworkException(JaffaSchedulerFrameworkException.ADD_TASK_ERROR, new Object[] { task.getScheduledTaskId() }, e);
    }
}
Also used : IVoucherGenerator(org.jaffa.components.voucher.IVoucherGenerator) DateTime(org.jaffa.datatypes.DateTime) Date(java.util.Date)

Example 10 with IVoucherGenerator

use of org.jaffa.components.voucher.IVoucherGenerator in project jaffa-framework by jaffa-projects.

the class Transaction method generateKey.

/**
 * Generate the technical-key, if required.
 */
public void generateKey() throws ApplicationExceptions, FrameworkException {
    if (getId() == null) {
        try {
            IVoucherGenerator vg = VoucherGeneratorFactory.instance();
            vg.setUow(getUOW());
            vg.setDomainClassName(getClass().getName());
            vg.setFieldName(TransactionMeta.ID);
            vg.setLabelToken(TransactionMeta.META_ID.getLabelToken());
            setId(vg.generate());
        } catch (ValidationException e) {
            throw new ApplicationExceptions(e);
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) IVoucherGenerator(org.jaffa.components.voucher.IVoucherGenerator)

Aggregations

IVoucherGenerator (org.jaffa.components.voucher.IVoucherGenerator)11 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)9 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Blob (java.sql.Blob)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 List (java.util.List)1 JDBCColumnHandler (org.apache.log4j.jdbcplus.JDBCColumnHandler)1 JDBCIDHandler (org.apache.log4j.jdbcplus.JDBCIDHandler)1 JDBCLogColumn (org.apache.log4j.jdbcplus.JDBCLogColumn)1 IAttachmentData (org.jaffa.components.attachment.apis.IAttachmentData)1 DateTime (org.jaffa.datatypes.DateTime)1 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)1