Search in sources :

Example 1 with BelowMinimumException

use of org.jaffa.datatypes.exceptions.BelowMinimumException in project jaffa-framework by jaffa-projects.

the class OutputCommand method validate.

// .//GEN-END:preUpdate_2_be
// All the custom code goes here//GEN-FIRST:custom
/**
 * {@inheritDoc}
 */
@Override
public void validate() throws ApplicationExceptions, FrameworkException {
    // Do not perform the sequenceNo related validations if this instance is being resequenced
    if (!m_isBeingResequenced) {
        // The sequenceNo should be at least 1
        if (isModified(OutputCommandMeta.SEQUENCE_NO)) {
            if (getSequenceNo() == null || getSequenceNo().longValue() < 1)
                throw new ApplicationExceptions(new BelowMinimumException(OutputCommandMeta.META_SEQUENCE_NO.getLabelToken(), new Object[] { new Long(1) }));
        }
        // The sequenceNo should not exceed the total number of records for a given outputType by more than 1
        if (isModified(OutputCommandMeta.OUTPUT_TYPE) || isModified(OutputCommandMeta.SEQUENCE_NO)) {
            long count = 0;
            Criteria criteria = new Criteria();
            criteria.setTable(OutputCommandMeta.getName());
            if (getOutputCommandId() != null)
                criteria.addCriteria(OutputCommandMeta.OUTPUT_COMMAND_ID, Criteria.RELATIONAL_NOT_EQUALS, getOutputCommandId());
            criteria.addCriteria(OutputCommandMeta.OUTPUT_TYPE, getOutputType());
            criteria.addFunction(Criteria.FUNCTION_COUNT, null, "f1");
            Iterator itr = getUOW().query(criteria).iterator();
            if (itr.hasNext()) {
                Map row = (Map) itr.next();
                if (row.get("f1") != null)
                    count = ((Number) row.get("f1")).longValue();
            }
            if ((getSequenceNo().longValue() - count) > 1) {
                log.error("The sequenceNo " + getSequenceNo() + " is much greater than the number of rows " + count);
                throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.OutputCommandMaintenance.ValidSequenceNo") {
                });
            }
        }
    }
    super.validate();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) BelowMinimumException(org.jaffa.datatypes.exceptions.BelowMinimumException)

Aggregations

BelowMinimumException (org.jaffa.datatypes.exceptions.BelowMinimumException)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1