Search in sources :

Example 21 with DateTime

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

the class ExcelExportService method registerCustomDateMorpher.

/**
 * Registers a custom Morpher to handle, based on the input flag, either a DateTime or DateOnly class.
 */
private static void registerCustomDateMorpher(boolean dateTime) {
    final Class targetType = dateTime ? DateTime.class : DateOnly.class;
    Morpher targetMorpher = JSONUtils.getMorpherRegistry().getMorpherFor(targetType);
    if (targetMorpher == null || targetMorpher == IdentityObjectMorpher.getInstance()) {
        synchronized (JSONUtils.getMorpherRegistry()) {
            targetMorpher = JSONUtils.getMorpherRegistry().getMorpherFor(targetType);
            if (targetMorpher == null || targetMorpher == IdentityObjectMorpher.getInstance()) {
                // Create a custom Morpher
                targetMorpher = new ObjectMorpher() {

                    /**
                     * Returns the target Class (DateTime.class or DateOnly.class) for conversion.
                     */
                    public Class morphsTo() {
                        return targetType;
                    }

                    /**
                     * Returns true if the Morpher supports conversion from this Class. Only the String class is supported currently.
                     */
                    public boolean supports(Class clazz) {
                        return clazz == String.class;
                    }

                    /**
                     * Morphs the input object into an output object of the supported type.
                     */
                    public Object morph(Object value) {
                        try {
                            String layout = "yyyy-MM-dd'T'HH:mm:ss";
                            return targetType == DateTime.class ? Parser.parseDateTime((String) value, layout) : Parser.parseDateOnly((String) value, layout);
                        } catch (Exception e) {
                            if (log.isDebugEnabled())
                                log.debug("Error in converting '" + value + "' to " + (targetType == DateTime.class ? "DateTime" : "DateOnly"), e);
                            return value;
                        }
                    }
                };
                JSONUtils.getMorpherRegistry().registerMorpher(targetMorpher);
            }
        }
    }
}
Also used : Morpher(net.sf.ezmorph.Morpher) ObjectMorpher(net.sf.ezmorph.ObjectMorpher) IdentityObjectMorpher(net.sf.ezmorph.object.IdentityObjectMorpher) ObjectMorpher(net.sf.ezmorph.ObjectMorpher) IdentityObjectMorpher(net.sf.ezmorph.object.IdentityObjectMorpher) FlexClass(org.jaffa.flexfields.FlexClass) JSONObject(net.sf.json.JSONObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) DateTime(org.jaffa.datatypes.DateTime)

Example 22 with DateTime

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

the class AttachmentGraph method setLastChangedOn.

/**
 * Setter for property lastChangedOn.
 *
 * @param lastChangedOn Value of property lastChangedOn.
 */
public void setLastChangedOn(DateTime lastChangedOn) {
    DateTime oldLastChangedOn = this.lastChangedOn;
    this.lastChangedOn = lastChangedOn;
    propertyChangeSupport.firePropertyChange("lastChangedOn", oldLastChangedOn, lastChangedOn);
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 23 with DateTime

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

the class AttachmentMaintenanceTx method createDomain.

// .//GEN-END:_duplicateCheck_4_be
// .//GEN-BEGIN:_createDomain_1_be
/**
 * Create the domain object.
 */
private Attachment createDomain(UOW uow, AttachmentMaintenanceCreateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
    Attachment domain = new Attachment();
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_createDomain_2_be
    try {
        domain.updateAttachmentId(input.getAttachmentId());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateSerializedKey(input.getSerializedKey());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateOriginalFileName(input.getOriginalFileName());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateAttachmentType(input.getAttachmentType());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateContentType(input.getContentType());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateDescription(input.getDescription());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateRemarks(input.getRemarks());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateSupercededBy(input.getSupercededBy());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        if (!fromPrevalidate)
            domain.updateCreatedOn(new DateTime());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        if (!fromPrevalidate && input.getHeaderDto() != null && input.getHeaderDto().getUserId() != null)
            domain.updateCreatedBy(input.getHeaderDto().getUserId());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    try {
        domain.updateData(input.getData());
    } catch (ValidationException e) {
        if (appExps == null)
            appExps = new ApplicationExceptions();
        appExps.add(e);
    }
    // .//GEN-BEGIN:_createDomain_3_be
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    return domain;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) Attachment(org.jaffa.components.attachment.domain.Attachment) DateTime(org.jaffa.datatypes.DateTime)

Example 24 with DateTime

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

the class FormDataWrapper method addFormUsages.

private void addFormUsages(Connection connection) throws SQLException {
    // 1=FORM_NAME, EVENT_NAME, FORM_ALTERNATE, COPIES, CREATED_ON
    // 6=CREATED_BY, LAST_CHANGED_ON, LAST_CHANGED_BY
    String sql = "insert into J_FORM_USAGES values (?,?,?,?,?,  ?,?,?)";
    PreparedStatement pstmnt = connection.prepareStatement(sql);
    // Create first record
    pstmnt.setString(1, FORM_NAME);
    pstmnt.setString(2, "PO");
    pstmnt.setString(3, null);
    pstmnt.setLong(4, 1);
    pstmnt.setTimestamp(5, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(6, "user2");
    pstmnt.setTimestamp(7, (new DateTime()).timestamp());
    pstmnt.setString(8, "user3");
    pstmnt.execute();
    pstmnt.clearParameters();
    // Create second record
    pstmnt.setString(1, FORM_NAME2);
    pstmnt.setString(2, "Ship");
    pstmnt.setString(3, null);
    pstmnt.setLong(4, 2);
    pstmnt.setTimestamp(5, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(6, "user2");
    pstmnt.setTimestamp(7, null);
    pstmnt.setString(8, null);
    pstmnt.execute();
    pstmnt.clearParameters();
    // Create third record
    pstmnt.setString(1, FORM_NAME3);
    pstmnt.setString(2, "Form Group");
    pstmnt.setString(3, null);
    pstmnt.setLong(4, 1);
    pstmnt.setTimestamp(5, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(6, "user2");
    pstmnt.setTimestamp(7, (new DateTime()).timestamp());
    pstmnt.setString(8, "user3");
    pstmnt.execute();
    pstmnt.clearParameters();
    pstmnt.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) DateTime(org.jaffa.datatypes.DateTime)

Example 25 with DateTime

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

the class FormDataWrapper method addFormEvents.

private void addFormEvents(Connection connection) throws SQLException {
    // 1=EVENT_NAME, DESCRIPTION, CREATED_ON, CREATED_BY, LAST_CHANGED_ON,
    // 6=LAST_CHANGED_BY
    String sql = "insert into J_FORM_EVENTS values (?,?,?,?,?,  ?)";
    PreparedStatement pstmnt = connection.prepareStatement(sql);
    // Create first record
    pstmnt.setString(1, "PO");
    pstmnt.setString(2, "Create Purchase Order");
    pstmnt.setTimestamp(3, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(4, "user2");
    pstmnt.setTimestamp(5, (new DateTime()).timestamp());
    pstmnt.setString(6, "user3");
    pstmnt.execute();
    pstmnt.clearParameters();
    // Create second record
    pstmnt.setString(1, "Ship");
    pstmnt.setString(2, "Ship Material");
    pstmnt.setTimestamp(3, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(4, "user2");
    pstmnt.setTimestamp(5, null);
    pstmnt.setString(6, null);
    pstmnt.execute();
    pstmnt.clearParameters();
    // Create thrid record
    pstmnt.setString(1, "Form Group");
    pstmnt.setString(2, "Complete Group Definition");
    pstmnt.setTimestamp(3, DateTime.addMonth(new DateTime(), -2).timestamp());
    pstmnt.setString(4, "user2");
    pstmnt.setTimestamp(5, (new DateTime()).timestamp());
    pstmnt.setString(6, "user3");
    pstmnt.execute();
    pstmnt.clearParameters();
    pstmnt.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) 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