Search in sources :

Example 16 with DateTime

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

the class DateTimeCriteriaField method parseAndAdd.

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

Example 17 with DateTime

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

the class DateTimeCriteriaField method getDateTimeCriteriaField.

/**
 * 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 FormatDateTimeException if the value is incorrectly formatted.
 */
public static DateTimeCriteriaField getDateTimeCriteriaField(String operator, String value, DateTimeFieldMetaData meta) throws FormatDateTimeException {
    DateTimeCriteriaField criteriaField = null;
    DateTime 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 DateTimeCriteriaField(operator, (DateTime[]) values.toArray(new DateTime[0]));
        else
            criteriaField = new DateTimeCriteriaField(operator, nullValue);
    } else
        criteriaField = new DateTimeCriteriaField(operator, nullValue);
    return criteriaField;
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 18 with DateTime

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

the class FinderTx method addCriteria.

/**
 * This method will update the input criteria, based on the 'field' and 'name' inputs.
 * It is invoked by the concrete class while building a Criteria object to query the database.
 * @param field The criteria field which will have the operator and value(s).
 * @param name The name of the field for which the criteria has been passed.
 * @param criteria The Criteria object being built for the query, and which will be updated based on the 'field' and 'name' inputs.
 */
public static void addCriteria(DateTimeCriteriaField field, String name, Criteria criteria) {
    if (field != null) {
        // validate the criteria
        field.validate();
        String operator = field.getOperator();
        // @todo
        // if(!field.isOperatorValid()) {
        // throw new IllegalArgumentException(MessageHelper.findToken("error.jaffa.finder.criteriaField",new String[] {name,operator}));
        // }
        Object[] values = field.returnValuesAsObjectArray();
        if (operator != null && operator.equals(CriteriaField.RELATIONAL_IS_NULL))
            criteria.addCriteria(name, Criteria.RELATIONAL_IS_NULL);
        else if (operator != null && operator.equals(CriteriaField.RELATIONAL_IS_NOT_NULL))
            criteria.addCriteria(name, Criteria.RELATIONAL_IS_NOT_NULL);
        else if (values != null && values.length > 0) {
            if (operator != null && operator.length() == 0) {
                // A non-Jaffa tool may pass empty operator and value, even when they didn't intend to pass them. Bail out!
                if (values[0] == null)
                    return;
                // A non-empty value has been passed. So treat the operator like an Equals type
                operator = null;
            }
            if (operator == null || operator.equals(CriteriaField.RELATIONAL_EQUALS))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_EQUALS, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_NOT_EQUALS))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_NOT_EQUALS, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_GREATER_THAN))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_GREATER_THAN, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_SMALLER_THAN))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_SMALLER_THAN, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_GREATER_THAN_EQUAL_TO))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_GREATER_THAN_EQUAL_TO, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_SMALLER_THAN_EQUAL_TO))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_SMALLER_THAN_EQUAL_TO, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_BEGINS_WITH))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_BEGINS_WITH, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_ENDS_WITH))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_ENDS_WITH, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_LIKE))
                criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_LIKE, (DateTime) values[0]));
            else if (operator.equals(CriteriaField.RELATIONAL_BETWEEN)) {
                if (values.length > 0 && values[0] != null)
                    criteria.addCriteria(name, Criteria.RELATIONAL_GREATER_THAN_EQUAL_TO, determineDateTimeLimit((DateTime) values[0], true));
                if (values.length > 1 && values[1] != null)
                    criteria.addCriteria(name, Criteria.RELATIONAL_SMALLER_THAN_EQUAL_TO, determineDateTimeLimit((DateTime) values[1], false));
            } else if (operator.equals(CriteriaField.RELATIONAL_IN)) {
                if (values.length == 1) {
                    if (values[0] == null)
                        criteria.addCriteria(name, Criteria.RELATIONAL_IS_NULL);
                    else
                        criteria.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_EQUALS, (DateTime) values[0]));
                } else {
                    AtomicCriteria atomic = new AtomicCriteria();
                    if (values[0] == null)
                        atomic.addCriteria(name, Criteria.RELATIONAL_IS_NULL);
                    else
                        atomic.addAtomic(interpretDateTime(name, Criteria.RELATIONAL_EQUALS, (DateTime) values[0]));
                    for (int i = 1; i < values.length; i++) {
                        if (values[i] == null)
                            atomic.addOrCriteria(name, Criteria.RELATIONAL_IS_NULL);
                        else
                            atomic.addOrAtomic(interpretDateTime(name, Criteria.RELATIONAL_EQUALS, (DateTime) values[i]));
                    }
                    criteria.addAtomic(atomic);
                }
            }
        }
    }
}
Also used : AtomicCriteria(org.jaffa.persistence.AtomicCriteria) DateTime(org.jaffa.datatypes.DateTime)

Example 19 with DateTime

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

the class GridComponent method getGridChildren.

public void getGridChildren(String rowNo, String field, GridForm myForm) {
    GridModel w_model1 = (GridModel) myForm.getWidgetCache().getModel(field);
    GridModelRow row;
    System.out.println("The row number is " + rowNo);
    row = w_model1.getRowById(new Integer(rowNo).intValue());
    if ((row.getElement("isExpanded") != null) && (Boolean.TRUE.equals((Boolean) row.getElement("isExpanded")))) {
        return;
    }
    row.addElement("isExpanded", new Boolean(true));
    row.addElement("isDisplayed", new Boolean(true));
    w_model1.setTarget(row);
    row = w_model1.newRow(new Integer(rowNo).intValue() + 1);
    row.addElement("isDisplayed", new Boolean(true));
    row.addElement("isTarget", new Boolean(false));
    row.addElement("isParent", new Boolean(false));
    row.addElement("level", new Integer(4));
    row.addElement("field1", new EditBoxModel("Field91Value"));
    row.addElement("field2", new EditBoxModel("Field92Value"));
    row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
    row.addElement("field4", new CheckBoxModel(true));
    row.addElement("field5", new ImageModel(ImageComponent.getImageBytes("C:\\Sandbox\\Jaffa\\source\\httpunittest\\html\\widgets\\tests\\testimage1_up.gif")));
    row.addElement("field6", new DropDownModel("Value3"));
}
Also used : GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) DateTimeModel(org.jaffa.presentation.portlet.widgets.model.DateTimeModel) DropDownModel(org.jaffa.presentation.portlet.widgets.model.DropDownModel) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow) ImageModel(org.jaffa.presentation.portlet.widgets.model.ImageModel) DateTime(org.jaffa.datatypes.DateTime) CheckBoxModel(org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)

Example 20 with DateTime

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

the class UserGridForm method createNewModel.

private GridModel createNewModel() {
    GridModel model = new GridModel();
    GridModelRow row;
    row = model.newRow();
    row.addElement("field1", new EditBoxModel("Field11Value"));
    row.addElement("field2", new EditBoxModel("Field12Value"));
    row.addElement("field3", new DateTimeModel());
    row.addElement("field4", new CheckBoxModel(true));
    row.addElement("field5", new ImageModel(ImageComponent.getImageBytes("C:\\Sandbox\\Jaffa\\source\\httpunittest\\html\\widgets\\tests\\testimage1_up.gif")));
    row.addElement("field6", new DropDownModel("Value1"));
    row = model.newRow();
    row.addElement("field1", new EditBoxModel("Field21Value"));
    row.addElement("field2", new EditBoxModel("Field22Value"));
    row.addElement("field3", new DateTimeModel(new DateTime()));
    row.addElement("field4", new CheckBoxModel(false));
    row.addElement("field5", new ImageModel(ImageComponent.getImageBytes("C:\\Sandbox\\Jaffa\\source\\httpunittest\\html\\widgets\\tests\\testimage1_down.gif")));
    row.addElement("field6", new DropDownModel("Value2"));
    row = model.newRow();
    row.addElement("field1", new EditBoxModel("Field31Value"));
    row.addElement("field2", new EditBoxModel("Field32Value"));
    row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
    row.addElement("field4", new CheckBoxModel(true));
    row.addElement("field5", new ImageModel(ImageComponent.getImageBytes("C:\\Sandbox\\Jaffa\\source\\httpunittest\\html\\widgets\\tests\\testimage1_up.gif")));
    row.addElement("field6", new DropDownModel("Value3"));
    return model;
}
Also used : GridModel(org.jaffa.presentation.portlet.widgets.model.GridModel) DateTimeModel(org.jaffa.presentation.portlet.widgets.model.DateTimeModel) DropDownModel(org.jaffa.presentation.portlet.widgets.model.DropDownModel) EditBoxModel(org.jaffa.presentation.portlet.widgets.model.EditBoxModel) GridModelRow(org.jaffa.presentation.portlet.widgets.model.GridModelRow) ImageModel(org.jaffa.presentation.portlet.widgets.model.ImageModel) DateTime(org.jaffa.datatypes.DateTime) CheckBoxModel(org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)

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