use of org.jaffa.datatypes.DateTime 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.DateTime in project jaffa-framework by jaffa-projects.
the class TestConsumer method invoke.
public void invoke(UOW uow, TestMessage message) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Handling message " + message);
}
// Send an Email
if (message.getEmailAddress() != null) {
new EmailerBean().sendMail(new String[] { message.getEmailAddress() }, SUBJECT, "Jaffa Transaction Tester message - Time: " + new DateTime());
}
// Pause
Thread.sleep(message.getDelay());
// Perform DBQuery
if (message.getDbQuery() > 0) {
long count = message.getDbQuery();
Criteria c = new Criteria();
c.setTable(SOAEventMeta.getName());
for (int p = 0; p < count; p++) {
uow.query(c);
}
}
// Fail the transaction
if (message.isFail())
throw new ApplicationException("jaffa.tester.TestConsumer.fail");
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class UserMaintenanceTx method updateDomain.
// .//GEN-END:_loadUpdate_3_be
// .//GEN-BEGIN:_updateDomain_1_be
/**
* Update the domain object and add it to the UOW.
*/
private void updateDomain(UOW uow, UserMaintenanceUpdateInDto input, User domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = null;
// .//GEN-BEGIN:_updateDomain_2_be
try {
domain.updateFirstName(input.getFirstName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateLastName(input.getLastName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateStatus(input.getStatus());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateEMailAddress(input.getEMailAddress());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityQuestion(input.getSecurityQuestion());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityAnswer(input.getSecurityAnswer());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
if (!fromPrevalidate)
domain.updateLastUpdatedOn(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.updateLastUpdatedBy(input.getHeaderDto().getUserId());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// Add custom code //GEN-FIRST:_updateDomain_2
try {
if (input.getPassword1() != null)
domain.updatePassword(input.getPassword1());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
String[] userRole = null;
if (appExps == null || appExps.size() == 0) {
// Build an array of roles
userRole = new String[input.getUserRoleCount()];
UserRoleDto[] userRoleDtos = input.getUserRole();
for (int i = 0; i < userRoleDtos.length; i++) userRole[i] = userRoleDtos[i].getRoleName();
Arrays.sort(userRole);
performUserRoleValidations(userRole, domain);
}
if (!fromPrevalidate) {
// These keep track of whats added and removed
Collection rolesAdded = new ArrayList();
Collection rolesRemoved = new ArrayList();
Collection processed = new ArrayList();
if (appExps == null || appExps.size() == 0) {
// Roles can be updated only if the user has access to the maintenance function
if (hasMaintenanceAccess()) {
// Get the current roles
Criteria crit = new Criteria();
crit.setTable(UserRoleMeta.getName());
crit.addCriteria(UserRoleMeta.USER_NAME, input.getUserName());
Collection currRoles = uow.query(crit);
// if in database, add to the processed list
for (Iterator it = currRoles.iterator(); it.hasNext(); ) {
UserRole ur = (UserRole) it.next();
if (Arrays.binarySearch(userRole, ur.getRoleName()) >= 0) {
processed.add(ur.getRoleName());
if (log.isDebugEnabled())
log.debug("Keeping Role - " + ur.getRoleName());
} else {
rolesRemoved.add(ur.getRoleName());
uow.delete(ur);
if (log.isDebugEnabled())
log.debug("Deleting Role - " + ur.getRoleName());
}
}
// Now add the new ones
for (int i = 0; i < userRole.length; i++) {
String rolename = userRole[i];
if (!processed.contains(rolename)) {
try {
UserRole ur = new UserRole();
ur.updateRoleName(rolename);
ur.updateUserName(input.getUserName());
rolesAdded.add(ur.getRoleName());
uow.add(ur);
if (log.isDebugEnabled())
log.debug("Adding Role - " + ur.getRoleName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
}
}
}
}
}
if (input.getNotifyUser().booleanValue()) {
try {
EmailerBean email = new EmailerBean();
String[] to = new String[] { domain.getEMailAddress() };
StringBuffer body = new StringBuffer();
if ((oldPassword != null && !oldPassword.equals(domain.getPassword())) || (oldStatus != null && !oldStatus.equals(domain.getStatus()))) {
body.append("Your UserName is " + domain.getUserName());
if (oldPassword != null && !oldPassword.equals(domain.getPassword()))
body.append(" and your password is " + domain.getPassword() + ".");
if (oldStatus != null && !oldStatus.equals(domain.getStatus()))
body.append("Your account is currently " + domain.getStatus() + ".");
email.sendMail(to, "Account Information", body.toString());
}
} catch (javax.mail.MessagingException e) {
e.printStackTrace();
}
}
/* try {
UserRequest userRequest = UserRequest.findByPK(uow , new Long(input.getRequestId()));
userRequest.setStatus("S");
uow.update(userRequest);
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
*/
if (appExps != null && appExps.size() > 0)
throw appExps;
// .//GEN-BEGIN:_updateDomain_3_be
if (appExps != null && appExps.size() > 0)
throw appExps;
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class UserMaintenanceTx method createDomain.
// .//GEN-END:_duplicateCheck_4_be
// .//GEN-BEGIN:_createDomain_1_be
/**
* Create the domain object.
*/
private User createDomain(UOW uow, UserMaintenanceCreateInDto input, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
User domain = new User();
ApplicationExceptions appExps = null;
// Add custom code //GEN-FIRST:_createDomain_1
try {
if (input.getPassword1() != null)
domain.updatePassword(input.getPassword1());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// .//GEN-BEGIN:_createDomain_2_be
try {
domain.updateUserName(input.getUserName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateFirstName(input.getFirstName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateLastName(input.getLastName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateStatus(input.getStatus());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateEMailAddress(input.getEMailAddress());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityQuestion(input.getSecurityQuestion());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityAnswer(input.getSecurityAnswer());
} 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);
}
// .//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 addFormDefinitions.
private void addFormDefinitions(Connection connection) throws SQLException {
// 1=FORM_ID, FORM_NAME, FORM_ALTERNATE, FORM_VARIATION, OUTPUT_TYPE
// 6=FORM_TEMPLATE, FIELD_LAYOUT, DESCRIPTION, REMARKS, DOM_FACTORY
// 11=DOM_CLASS, DOM_KEY1, DOM_KEY2, DOM_KEY3, ADDITIONAL_DATA_COMPONENT
// 16=FOLLOW_ON_FORM_NAME, FOLLOW_ON_FORM_ALTERNATE, CREATED_ON, CREATED_BY, LAST_CHANGED_ON
// 21=LAST_CHANGED_BY
String sql = "insert into J_FORM_DEFINITIONS values (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?)";
PreparedStatement pstmnt = connection.prepareStatement(sql);
// Create first record
// 1-5
pstmnt.setLong(1, 1000000);
pstmnt.setString(2, FORM_NAME);
pstmnt.setString(3, null);
pstmnt.setString(4, null);
pstmnt.setString(5, "PDF");
// 6-10
pstmnt.setString(6, PDF_TEMPLATE);
pstmnt.setString(7, PDF_TEMPLATE + ".csv");
pstmnt.setString(8, "Standard Invoice Version");
pstmnt.setString(9, null);
pstmnt.setString(10, CustomDataBeanFactory.class.getName());
// 11-15
pstmnt.setString(11, InvoiceDataBean.class.getName());
pstmnt.setString(12, "orderNo");
pstmnt.setString(13, null);
pstmnt.setString(14, null);
pstmnt.setString(15, null);
// 16-21
pstmnt.setString(16, null);
pstmnt.setString(17, null);
pstmnt.setTimestamp(18, DateTime.addMonth(new DateTime(), -2).timestamp());
pstmnt.setString(19, "user2");
pstmnt.setTimestamp(20, (new DateTime()).timestamp());
pstmnt.setString(21, "user3");
pstmnt.execute();
pstmnt.clearParameters();
// Create second record
// 1-5
pstmnt.setLong(1, 1000001);
pstmnt.setString(2, FORM_NAME2);
pstmnt.setString(3, null);
pstmnt.setString(4, null);
pstmnt.setString(5, "Intermec 3400D");
// 6-10
pstmnt.setString(6, VELOCITY_TEMPLATE);
pstmnt.setString(7, null);
pstmnt.setString(8, "Standard Shipping Label");
pstmnt.setString(9, null);
pstmnt.setString(10, CustomDataBeanFactory.class.getName());
// 11-15
pstmnt.setString(11, InvoiceDataBean.class.getName());
pstmnt.setString(12, "orderNo");
pstmnt.setString(13, null);
pstmnt.setString(14, null);
pstmnt.setString(15, null);
// 16-21
pstmnt.setString(16, null);
pstmnt.setString(17, null);
pstmnt.setTimestamp(18, DateTime.addMonth(new DateTime(), -2).timestamp());
pstmnt.setString(19, "user2");
pstmnt.setTimestamp(20, null);
pstmnt.setString(21, null);
pstmnt.execute();
pstmnt.clearParameters();
// Create third record
// 1-5
pstmnt.setLong(1, 1000002);
pstmnt.setString(2, FORM_NAME3);
pstmnt.setString(3, null);
pstmnt.setString(4, null);
pstmnt.setString(5, "PDF");
// 6-10
pstmnt.setString(6, PDF_TEMPLATE3);
pstmnt.setString(7, PDF_TEMPLATE3 + ".csv");
pstmnt.setString(8, "Standard Invoice Version");
pstmnt.setString(9, null);
pstmnt.setString(10, DomainDataBeanFactory.class.getName());
// 11-15
pstmnt.setString(11, FormGroup.class.getName());
pstmnt.setString(12, "formName");
pstmnt.setString(13, null);
pstmnt.setString(14, null);
pstmnt.setString(15, null);
// 16-21
pstmnt.setString(16, null);
pstmnt.setString(17, null);
pstmnt.setTimestamp(18, DateTime.addMonth(new DateTime(), -2).timestamp());
pstmnt.setString(19, "user2");
pstmnt.setTimestamp(20, (new DateTime()).timestamp());
pstmnt.setString(21, "user3");
pstmnt.execute();
pstmnt.clearParameters();
pstmnt.close();
}
Aggregations