use of org.jaffa.datatypes.DateOnly in project jaffa-framework by jaffa-projects.
the class JaffaDateConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// Error out if an unsupported class is passed
if (!(data instanceof DateOnly) && !(data instanceof DateTime)) {
log.warn("Unsupported input. Class=" + data.getClass() + ", data=" + data);
throw new MarshallException(data.getClass());
}
// Create a javascipt Date object.
// When using server time, Pass the individual date elements. This will ensure that a similar date will be constructed in the client's timezone.
// When not using server time, pass the millisecond since 1970 value. This will result in a date adjusted to the client's timezone.
StringBuilder jsDateConstructor = new StringBuilder("new Date(");
Boolean useServerTime = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(RULE_NAME_USE_SERVER_TIME));
if (data instanceof DateOnly) {
DateOnly d = (DateOnly) data;
if (useServerTime != null && useServerTime)
jsDateConstructor.append(d.year()).append(',').append(d.month()).append(',').append(d.day());
else
jsDateConstructor.append(d.timeInMillis());
} else {
DateTime d = (DateTime) data;
if (useServerTime != null && useServerTime)
jsDateConstructor.append(d.year()).append(',').append(d.month()).append(',').append(d.day()).append(',').append(d.hourOfDay()).append(',').append(d.minute()).append(',').append(d.second()).append(',').append(d.milli());
else
jsDateConstructor.append(d.timeInMillis());
}
String output = jsDateConstructor.append(')').toString();
if (log.isDebugEnabled())
log.debug("Outbound '" + data + "' converted to '" + output + '\'');
return new SimpleOutboundVariable(output, outctx, true);
}
use of org.jaffa.datatypes.DateOnly in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testMinAndMaxValue.
/*
Commenting out until AOP interceptors are finished
public void testLabelAtObjectLevel() {
log.debug("testLabelAtObjectLevel");
try {
// This will obtain the label for the condition 'field1 == null'
Extension1 obj = new Extension1();
obj.setField1(null);
IObjectRuleIntrospector w = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(obj.getClass().getName(), obj);
assertEquals("object label to use when field1 is null", w.getLabel());
// This will obtain the label for the condition 'field1 != null'
obj.setField1("value2");
w = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(obj.getClass().getName(), obj);
assertEquals("object label to use when field1 is not null", w.getLabel());
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
public void testMinAndMaxValue() {
log.debug("testMinAndMaxValue");
try {
IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field4", null);
assertEquals(1d, w.getMinValue());
assertEquals(100d, w.getMaxValue());
w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field5", null);
assertEquals(1L, w.getMinValue());
assertEquals(100L, w.getMaxValue());
// Note: This test may fail if it is executed on the stroke of midnight
w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field6", null);
assertEquals(DateOnly.addDay(new DateOnly(), -10), w.getMinValue());
assertEquals(new DateOnly(), w.getMaxValue());
w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field7", null);
assertEquals(1, w.getMinValue());
assertEquals(100, w.getMaxValue());
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
Aggregations