class HibernateSystemMessageDAO extends HibernatePersistentObjectDAO<SystemMessage> implements SystemMessageDAO {

	@Override
	public boolean store(SystemMessage message) throws PersistenceException {
		long originalId = message.getId();

		// Do standard processing
		boolean stored = super.store(message);

		/**
		 * Store a new event for the recipient, in case this is a new system
		 * message
		 */
		if (stored && originalId == 0L && message.getType() == SystemMessage.TYPE_SYSTEM) {
			UserHistoryDAO hDao = (UserHistoryDAO) Context.get().getBean(UserHistoryDAO.class);
			UserDAO uDao = (UserDAO) Context.get().getBean(UserDAO.class);
			for (Recipient rec : message.getRecipients()) {
				if (rec.getType() == Recipient.TYPE_EMAIL)
					continue;

				UserHistory history = new UserHistory();
				history.setTenantId(message.getTenantId());
				history.setComment(message.getMessageText());
				history.setEvent(UserEvent.MESSAGE_RECEIVED.toString());
				history.setAuthor(message.getAuthor());
				history.setNotifyEvent(message.isNotify());

				User recipient = uDao.findByUsername(rec.getName());
				if (recipient != null)
					history.setUser(recipient);

				User author = uDao.findByUsername(message.getAuthor());
				if (author != null)
					history.setAuthor(author.getFullName());

				hDao.store(history);
			}
		}

		return stored;
	}

	public  HibernateSystemMessageDAO();

}