Search in sources :

Example 1 with DateOnly

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

the class DateOnlyFieldValidator method validate.

/**
 * The RulesEngine will invoke this method to perform the field validation.
 * @throws ValidationException if any validation rule fails.
 * @throws FrameworkException if any framework error occurs.
 */
public void validate() throws ValidationException, FrameworkException {
    Object value = getValue();
    if (value != null) {
        DateOnlyFieldMetaData meta = new DateOnlyFieldMetaData(null, getLabelToken(), null, getLayout(), getMinValue(), getMaxValue());
        if (value instanceof DateOnly)
            FieldValidator.validate((DateOnly) value, meta, false);
        else if (value instanceof Date)
            FieldValidator.validate(new DateOnly((Date) value), meta, false);
        else
            FieldValidator.validateData(value.toString(), meta);
    }
}
Also used : DateOnlyFieldMetaData(org.jaffa.metadata.DateOnlyFieldMetaData) DateOnly(org.jaffa.datatypes.DateOnly) Date(java.util.Date)

Example 2 with DateOnly

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

the class DateOnlyCriteriaField method getDateOnlyCriteriaField.

/**
 * This will generate a CriteriaField object based on the input parameters.
 * @param operator The operator of the criteria.
 * @param value The value for the criteria. Multiple values should be separated by comma.
 * @param meta The FieldMetaData object to obtain the layout for parsing.
 * @return a CriteriaField object based on the input parameters.
 * @throws FormatDateOnlyException if the value is incorrectly formatted.
 */
public static DateOnlyCriteriaField getDateOnlyCriteriaField(String operator, String value, DateOnlyFieldMetaData meta) throws FormatDateOnlyException {
    DateOnlyCriteriaField criteriaField = null;
    DateOnly nullValue = null;
    if (value != null)
        value = value.trim();
    if (value != null && value.length() > 0) {
        List values = new ArrayList();
        if (RELATIONAL_BETWEEN.equals(operator) || RELATIONAL_IN.equals(operator)) {
            // replace ",," with ", ,"
            value = StringHelper.replace(value, CONSECUTIVE_SEPARATORS, CONSECUTIVE_SEPARATORS_WITH_SPACE);
            if (value.startsWith(SEPARATOR_FOR_IN_BETWEEN_OPERATORS))
                values.add(null);
            StringTokenizer tknzr = new StringTokenizer(value, SEPARATOR_FOR_IN_BETWEEN_OPERATORS);
            while (tknzr.hasMoreTokens()) parseAndAdd(tknzr.nextToken().trim(), meta, values);
            if (value.endsWith(SEPARATOR_FOR_IN_BETWEEN_OPERATORS))
                values.add(null);
        } else {
            parseAndAdd(value, meta, values);
        }
        if (values.size() > 0)
            criteriaField = new DateOnlyCriteriaField(operator, (DateOnly[]) values.toArray(new DateOnly[0]));
        else
            criteriaField = new DateOnlyCriteriaField(operator, nullValue);
    } else
        criteriaField = new DateOnlyCriteriaField(operator, nullValue);
    return criteriaField;
}
Also used : DateOnly(org.jaffa.datatypes.DateOnly)

Example 3 with DateOnly

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

the class InvoiceDataBean method populate.

public void populate() throws FrameworkException, ApplicationExceptions {
    if (PENDING_ORDER_NO.equals(orderNo))
        throw new ApplicationExceptions(new DataNotReadyException(new String[] { "OrderNo", PENDING_ORDER_NO }));
    int lines = 1;
    if (VALID_ORDER_NO.equals(orderNo))
        lines = 20;
    else if (VALID_ORDER_NO2.equals(orderNo) || VALID_LABEL.equals(orderNo))
        lines = 2;
    else
        throw new ApplicationExceptions(new DataNotFoundException(new String[] { "OrderNo", VALID_ORDER_NO }));
    this.orderTotal = 0;
    // this.orderNo="PO0019657-A";
    // this.shippingAddress="A building 2building 3building 4building\nSome Road 2SomeRoad 3SomeRoad 4SomeRoad\nSome City 1SomeCity 2SomeCity 3SomeCity\nUtah 1Utah 2Utah 3Utah 4Utah 5Utah 6Utah 7Utah\nUT 98765 123412353tew5tgwe523451235125125";
    this.shippingAddress = "A building\nSome Road\nSome City\nUtah\nUT 98765";
    this.vendorAddress = "Acme Road\nAcmeville\nUtah\nUT 98765";
    this.vendorCode = "AM001-2";
    this.vendorName = "ACME Inc.";
    this.orderDate = DateOnly.addDay(new DateOnly(), -7);
    this.needDate = DateOnly.addDay(new DateOnly(), 2);
    this.remarks = "See additional pages";
    this.item = new ArrayList();
    for (int i = 0; i < lines && i < partList.length; i++) {
        InvoiceLineItem it = new InvoiceLineItem();
        this.item.add(it);
        it.setItemNo(i + 1);
        long qty = quantityList[i];
        double price = priceList[i];
        it.setQuantity(new Long(qty));
        it.setDescription(partList[i]);
        it.setUnitPrice(new Double(price));
        it.setExtendedPrice(new Double(price * qty));
        this.orderTotal += price * qty;
        System.out.println(it.toString());
    }
}
Also used : DataNotReadyException(org.jaffa.modules.printing.services.exceptions.DataNotReadyException) DataNotFoundException(org.jaffa.modules.printing.services.exceptions.DataNotFoundException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ArrayList(java.util.ArrayList) DateOnly(org.jaffa.datatypes.DateOnly)

Example 4 with DateOnly

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

the class DateOnlyCriteriaField method parseAndAdd.

private static void parseAndAdd(String str, DateOnlyFieldMetaData meta, List values) throws FormatDateOnlyException {
    try {
        DateOnly parsedValue = null;
        if (str != null && str.length() > 0) {
            if (meta != null)
                parsedValue = Parser.parseDateOnly(str, meta.getLayout());
            else
                parsedValue = Parser.parseDateOnly(str);
        }
        values.add(parsedValue);
    } catch (FormatDateOnlyException e) {
        e.setField(meta != null ? meta.getLabelToken() : "");
        throw e;
    }
}
Also used : DateOnly(org.jaffa.datatypes.DateOnly) FormatDateOnlyException(org.jaffa.datatypes.exceptions.FormatDateOnlyException)

Example 5 with DateOnly

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

the class JaffaDateConverter method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
    // Error out if an unsupported class is passed
    if (paramType != DateOnly.class && paramType != DateTime.class) {
        log.warn("Unsupported input. Class=" + paramType);
        throw new MarshallException(paramType);
    }
    // Extract Char Encoding from the Web Context
    String charEncoding = null;
    WebContext context = WebContextFactory.get();
    if (context != null) {
        HttpServletRequest req = context.getHttpServletRequest();
        if (req != null)
            charEncoding = req.getCharacterEncoding();
    }
    if (charEncoding == null)
        charEncoding = CHAR_ENCODER;
    String value = iv.getValue();
    // If the text is null then the whole bean is null
    if (value.trim().equals(ProtocolConstants.INBOUND_NULL))
        return null;
    Object output;
    try {
        // Handle a millisecond input
        long millis = 0;
        if (value.length() > 0)
            millis = Long.parseLong(value);
        // DWR returns null dates as '0', so we must return a null in this case
        if (millis == 0)
            return null;
        Boolean useServerTime = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(RULE_NAME_USE_SERVER_TIME));
        if (useServerTime != null && useServerTime) {
            if (log.isInfoEnabled())
                log.info("A String representation of a date should be posted by the client, since the application rule '" + RULE_NAME_USE_SERVER_TIME + "' is set");
        }
        output = paramType == DateOnly.class ? new DateOnly(millis) : new DateTime(millis);
    } catch (NumberFormatException e) {
        try {
            // Handle a String input
            if (log.isDebugEnabled())
                log.debug("Error in parsing '" + value + "' as milliseconds since 1970. Will attempt to parse it as a String representation of a date");
            output = paramType == DateOnly.class ? DateTime.toDateOnly(Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME)) : Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME);
        } catch (FormatDateTimeException e1) {
            if (log.isDebugEnabled())
                log.debug("Error in parsing Date '" + value + "' using the format '" + FORMAT_DATE_TIME + '\'', e1);
            throw new MarshallException(DateOnly.class, e1);
        } catch (UnsupportedEncodingException e1) {
            if (log.isDebugEnabled())
                log.debug("Error in encoding Date '" + value + "' using the format '" + charEncoding + '\'', e1);
            throw new MarshallException(DateOnly.class, e1);
        }
    }
    if (log.isDebugEnabled())
        log.debug("Inbound '" + value + "' converted to '" + output + '\'');
    return output;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebContext(org.directwebremoting.WebContext) MarshallException(org.directwebremoting.extend.MarshallException) DateOnly(org.jaffa.datatypes.DateOnly) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DateTime(org.jaffa.datatypes.DateTime) FormatDateTimeException(org.jaffa.datatypes.exceptions.FormatDateTimeException)

Aggregations

DateOnly (org.jaffa.datatypes.DateOnly)7 MarshallException (org.directwebremoting.extend.MarshallException)2 DateTime (org.jaffa.datatypes.DateTime)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 WebContext (org.directwebremoting.WebContext)1 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)1 FormatDateOnlyException (org.jaffa.datatypes.exceptions.FormatDateOnlyException)1 FormatDateTimeException (org.jaffa.datatypes.exceptions.FormatDateTimeException)1 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 DateOnlyFieldMetaData (org.jaffa.metadata.DateOnlyFieldMetaData)1 DataNotFoundException (org.jaffa.modules.printing.services.exceptions.DataNotFoundException)1 DataNotReadyException (org.jaffa.modules.printing.services.exceptions.DataNotReadyException)1 Extension1 (org.jaffa.rules.testmodels.Extension1)1