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;
}
}
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;
}
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);
}
}
}
}
}
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"));
}
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;
}
Aggregations