Search in sources :

Example 6 with DateTime

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

the class DateTimeTag method getHtml.

private String getHtml(String idPrefix, SimpleWidgetModel model, IPropertyRuleIntrospector propertyRuleIntrospector) {
    StringBuffer sb = new StringBuffer(getValidateScript(idPrefix));
    // ensure a valid value for the interval-size
    if (!checkValidInterval(m_minInterval))
        m_minInterval = DEFAULT_MINUTE_INTERVAL;
    // set the value & meta
    DateTime value = getRoundedDateTime(model, m_minInterval);
    // Format just the Date portion
    String formattedDate = value == null ? "" : Formatter.format(DateTime.toDateOnly(value), propertyRuleIntrospector.getLayout());
    if (formattedDate.indexOf(":") != -1) {
        formattedDate = formattedDate.substring(0, formattedDate.length() - 8);
    }
    sb.append("<A id=\"" + idPrefix + "_anchor\" name=\"" + idPrefix + "_anchor\">");
    sb.append("<INPUT");
    sb.append(" TYPE=\"text\"");
    sb.append(" ID=\"" + idPrefix + "_date\"");
    sb.append(" VALUE=\"" + formattedDate + "\"" + (propertyRuleIntrospector.isMandatory() ? " class=\"datetimeMandatory\" " : ""));
    sb.append(" SIZE=\"" + m_columns + "\"");
    sb.append(" MAXLENGTH=\"" + propertyRuleIntrospector.getMaxLength() + "\"");
    sb.append(getStyle());
    sb.append(" onBlur=\"javascript:" + getValidateCall(idPrefix) + "\"");
    sb.append(" onFocus=\"javascript:" + idPrefix + "_tmp = this.value;\"");
    // sb.append("</A><A id=\"" + m_name + "_lookup\" onclick=\"setTextField('" + idPrefix + "') ;");
    sb.append("</A><A id=\"" + idPrefix + "_lookup\" onclick=\"setTextField('" + idPrefix + "') ;");
    sb.append("setCurrentDate('" + idPrefix + "_date') ; document.getElementById('calendardd').disabled = false ;  cal2.showCalendar('" + idPrefix + "_anchor'); ");
    sb.append("return false;\" name=\"anchor6\" href=\"javascript:void(0);\">");
    sb.append("<img src=\"jaffa/imgs/datetime/calendar_32b.gif\" width=\"20\" height=\"20\" valign=\"middle\" align=\"absbottom\" border=\"0\"> </A>");
    sb.append("<DIV id=\"testdiv1\" style=\"VISIBILITY: hidden; background-color: #FFFFFF; layer-background-color: #FFFFFF; POSITION: absolute; z-index:100\"></DIV>\n");
    // add hidden fields if only the date is to be displayed.. else add dropdowns
    if (getDateOnly()) {
        sb.append(" <input type=\"HIDDEN\" id=\"" + idPrefix + "_hours\" value=\"0\"/>");
        sb.append(" <input type=\"HIDDEN\" id=\"" + idPrefix + "_mins\" value=\"0\"/>");
    } else {
        sb.append(" <select id=\"" + idPrefix + "_hours\" class=\"dd\" onChange=\"javascript:datetime_updateHidden('" + idPrefix + "');\">");
        // sb.append("<option value=\"\"> </option>");
        for (int i = 0; i < 24; i++) {
            if (i < 10) {
                sb.append("<option value=\"0" + i + "\"" + (value != null && value.hourOfDay() == i ? "SELECTED" : "") + ">0" + i + "</option>\n");
            } else {
                sb.append("<option value=\"" + i + "\"" + (value != null && value.hourOfDay() == i ? "SELECTED" : "") + ">" + i + "</option>\n");
            }
        }
        sb.append("</select>\n");
        sb.append(" : <select id=\"" + idPrefix + "_mins\"  class=\"dd\" onChange=\"javascript:datetime_updateHidden('" + idPrefix + "')\";>");
        // sb.append("<option value=\"\"> </option>");
        for (int i = 0; i < 60; i = i + m_minInterval) {
            if (i < 10) {
                sb.append("<option value=\"0" + i + "\"" + (value != null && value.minute() == i ? "SELECTED" : "") + ">0" + i + "</option>\n");
            } else {
                sb.append("<option value=\"" + i + "\"" + (value != null && value.minute() == i ? "SELECTED" : "") + ">" + i + "</option>\n");
            }
        }
        sb.append("</select>\n");
    }
    sb.append("<input type=\"HIDDEN\" ");
    sb.append("id=\"" + idPrefix + "\"");
    if (!TagHelper.isEnclosed(pageContext))
        sb.append(" NAME=\"" + m_field + "WV\" ");
    sb.append(" CLASS=\"WidgetDateTime\" ");
    String formattedDateTime = "";
    if (value != null)
        formattedDateTime = formattedDate + " " + value.hourOfDay() + ":" + value.minute();
    sb.append(" VALUE=\"" + formattedDateTime + "\"\n>");
    sb.append(getWidgetRegistrationScript(idPrefix, false));
    return sb.toString();
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 7 with DateTime

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

the class DateTimeTag method getRoundedDateTime.

/**
 * Get the DateTime whose minute portion is a multiple of the intervalSize
 * Update the model, in case the DateTime is changed
 */
private DateTime getRoundedDateTime(SimpleWidgetModel model, int intervalSize) {
    DateTime value = model.getDateTimeValue();
    if (value != null) {
        if (getDateOnly()) {
            if (value.hourOfDay() > 0 || value.minute() > 0 || value.second() > 0 || value.milli() > 0) {
                // create a dateOnly
                value = new DateTime(value.year(), value.month(), value.day());
                // update the model too !!!
                model.setWidgetValue(value);
            }
        } else {
            int minute = value.minute();
            int roundedMinute = ((minute + (intervalSize / 2)) / intervalSize) * intervalSize;
            if (roundedMinute > 59) {
                roundedMinute = 0;
                value = DateTime.addHour(value, 1);
            }
            if (roundedMinute != minute || value.second() > 0 || value.milli() > 0) {
                value = new DateTime(value.year(), value.month(), value.day(), value.hourOfDay(), roundedMinute, 0, 0);
                if (log.isDebugEnabled())
                    log.debug("Updating the SimpleWidgetModel from " + model.getStringValue() + " to " + value.toString());
                // update the model too !!!
                model.setWidgetValue(value);
            }
        }
    }
    return value;
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 8 with DateTime

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

the class AddTest method testAddDateTime.

/**
 * Inserts a record into ITEM using the query:
 * insert into ITEM(ITEM_ID, CREATED_DATETIME) values('Z-TESTITEM-04', to_date('2003-09-10 20:30:40', 'yyyy-MM-dd hh24:mi:ss')).
 * It then checks if the record was added. Finally the record is deleted
 */
public void testAddDateTime() {
    try {
        String itemId = "Z-TESTITEM-04";
        DateTime datetime = new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0);
        Item obj = (Item) m_uow.newPersistentInstance(Item.class);
        obj.updateItemId(itemId);
        obj.updateCreatedDatetime(datetime);
        m_uow.add(obj);
        m_uow.commit();
        // Now retrieve the added record & check if it was correctly added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(ItemMeta.getName());
        c.addCriteria(ItemMeta.ITEM_ID, itemId);
        Iterator i = m_uow.query(c).iterator();
        Item item = (Item) i.next();
        assertEquals(itemId, item.getItemId());
        assertEquals(datetime, item.getCreatedDatetime());
        // Now delete the bugger
        m_uow.delete(item);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW) DateTime(org.jaffa.datatypes.DateTime)

Example 9 with DateTime

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

the class AddTest method testAddWithAutoKey.

/**
 * Inserts a record into ASSET, which has a database generated key
 * It then checks if the record was added. Finally the record is deleted
 */
public void testAddWithAutoKey() {
    try {
        String assetId = "Z-TESTASSET-01";
        DateTime datetime = new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0);
        Asset obj = (Asset) m_uow.newPersistentInstance(Asset.class);
        obj.updateAssetId(assetId);
        obj.updateCreatedDatetime(datetime);
        m_uow.add(obj);
        m_uow.commit();
        // Now retrieve the added record & check if it was correctly added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(AssetMeta.getName());
        c.addCriteria(AssetMeta.ASSET_ID, assetId);
        Iterator i = m_uow.query(c).iterator();
        Asset asset = (Asset) i.next();
        assertNotNull(asset.getAssetTk());
        assertEquals(assetId, asset.getAssetId());
        assertEquals(datetime, asset.getCreatedDatetime());
        // Now delete the bugger
        m_uow.delete(asset);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW) DateTime(org.jaffa.datatypes.DateTime)

Example 10 with DateTime

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

the class FunctionTest method testMax.

/**
 * Tests the max() function
 * select max(CREATED_DATETIME) from item;
 */
public void testMax() {
    try {
        Criteria c = new Criteria();
        c.setTable(ItemMeta.getName());
        c.addFunction(Criteria.FUNCTION_MAX, ItemMeta.CREATED_DATETIME, "max");
        Map m = (Map) m_uow.query(c).iterator().next();
        assertEquals("max(CREATED_DATETIME)", new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0), m.get("max"));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Criteria(org.jaffa.persistence.Criteria) Map(java.util.Map) DateTime(org.jaffa.datatypes.DateTime)

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