Example usage for javax.transaction Status toString

List of usage examples for javax.transaction Status toString

Introduction

In this page you can find the example usage for javax.transaction Status toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.opentides.service.impl.NotificationServiceImpl.java

@Scheduled(fixedDelayString = "${notification.delay}")
@Transactional/*from ww  w .jav a2  s.c  om*/
public void executeNotification() {
    int max = StringUtil.convertToInt(limit, 20);
    for (int i = 0; i < max; i++) {
        List<Notification> notifications = notificationDao.findNewNotifications(1);
        if (notifications == null || notifications.isEmpty())
            break;
        Notification n = notifications.get(0);
        Status status = null;
        boolean processed = false;
        StringBuffer remarks = new StringBuffer();
        try {
            if ("EMAIL".equals(n.getMedium())) {
                n.setStatus(Status.IN_PROCESS.toString());
                notificationDao.saveEntityModel(n);
                // send email
                if (n.getSubject() == null)
                    n.setSubject("");
                if (StringUtil.isEmpty(n.getAttachment())) {
                    emailHandler.sendEmail(n.getRecipientReference().split(","),
                            new String[] { n.getEmailCC() }, new String[] {}, n.getEmailReplyTo(),
                            n.getSubject(), n.getMessage());
                } else {
                    // send with attachment
                    File attachment = new File(n.getAttachment());
                    emailHandler.sendEmail(n.getRecipientReference().split(","),
                            new String[] { n.getEmailCC() }, new String[] {}, n.getEmailReplyTo(),
                            n.getSubject(), n.getMessage(), new File[] { attachment });
                }

                status = Status.PROCESSED;
                processed = true;
                remarks.append("Email successfully sent to " + n.getRecipientReference() + ".\n");
            }
            if ("SMS".equals(n.getMedium())) {
                n.setStatus(Status.IN_PROCESS.toString());
                notificationDao.saveEntityModel(n);
                // send SMS
                //               processed = smsService.send(n.getRecipientReference(), n.getMessage());
                //               if(processed) {
                //                  status = Status.PROCESSED;
                //                  remarks.append("SMS sent to " + n.getRecipientReference() + "\n");
                //               } else {
                //                  status = Status.FAILED;
                //               }
            }
            if (processed) {
                if (status != null)
                    n.setStatus(status.toString());
                n.setRemarks(remarks.toString());
                notificationDao.saveEntityModel(n);
            }
        } catch (Exception e) {
            _log.error("Error encountered while sending notification", e);
            remarks.append(e.getMessage());
            if (remarks.length() > 3999)
                n.setRemarks(remarks.substring(0, 3999));
            else
                n.setRemarks(remarks.toString() + "\n");
            n.setStatus(Status.FAILED.toString());
            notificationDao.saveEntityModel(n);
        }
    }
}