/** * Sends a notification and increments a topic sequence number. * * @param dto notification * @return saved notification */ public NotificationDto saveNotificationAndIncTopicSecNum(NotificationDto dto) { NotificationDto notificationDto = null; Topic topic = topicDao.getNextSeqNumber(dto.getTopicId()); if (topic != null) { dto.setSecNum(topic.getSequenceNumber()); Notification savedDto = notificationDao.save(dto); notificationDto = savedDto != null ? savedDto.toDto() : null; } else { LOG.warn("Can't find topic by id."); } return notificationDto; }
protected List<NotificationDto> generateNotifications(String topicId, String appId, String schemaId, int count, NotificationTypeDto type) { List<NotificationDto> notifications = new ArrayList<>(count); NotificationDto notification; for (int i = 0; i < count; i++) { notification = new NotificationDto(); notification.setApplicationId(appId != null ? appId : UUID.randomUUID().toString()); notification.setSchemaId(schemaId != null ? schemaId : UUID.randomUUID().toString()); notification.setTopicId(topicId != null ? topicId : UUID.randomUUID().toString()); notification.setType(type != null ? type : NotificationTypeDto.USER); notification.setSecNum(i); notification.setBody(UUID.randomUUID().toString().getBytes()); notification.setLastTimeModify(new Date(System.currentTimeMillis())); notification.setNfVersion(1); notification.setExpiredAt(new Date(System.currentTimeMillis() + 7 * 24 * 3600 * 1000)); notifications.add(notificationDao.save(notification).toDto()); } return notifications; }
class OrderManager { private OrderDAO oDao; private NotificationDao nDao; public saveOrder(OrderDTO o) { Long orderId = oDao.save(o); NotificationDTO n = new NotificationDTO(); n.setType(NotificationType.ORDER_CREATED); n.setEntityId(orderId); nDao.save(n); } }