Search in sources :

Example 6 with DateOnly

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);
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) DateOnly(org.jaffa.datatypes.DateOnly) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) DateTime(org.jaffa.datatypes.DateTime)

Example 7 with DateOnly

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();
    }
}
Also used : DateOnly(org.jaffa.datatypes.DateOnly) Extension1(org.jaffa.rules.testmodels.Extension1) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

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