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