public IUINotification createUINotification(IQueuedNotification notification) throws Exception {
    if (notification == null) throw new CodingRuntimeException("Invalid notification.");

    if (notification.getINotificationMessage() == null)
      throw new CodingRuntimeException("Notification message is null.");

    if (notification.getINotificationPriority() == null)
      throw new CodingRuntimeException("Notification priority is null.");

    NotificationVo instance = new NotificationVo();
    DomainFactory domainFactory = this.getDomainFactory();

    AppUser doUser =
        (AppUser)
            domainFactory.getDomainObject(AppUser.class, notification.getINotificationUserId());

    if (doUser == null)
      throw new DomainRuntimeException("Invalid User Id passed into createNotification.");

    instance.setUser(AppUserNotificationVoAssembler.create(doUser));
    instance.setDateTime(new DateTime());
    instance.setNotificationPriority(notification.getINotificationPriority().getId());
    instance.setMessage(notification.getINotificationMessage());
    instance.setSource(notification.getINotificationSource());
    instance.setSeen(Boolean.FALSE);

    if (notification.getINotificationEntityType() != null) {
      instance.setEntityType(notification.getINotificationEntityType());
      instance.setEntityId(notification.getINotificationEntityId());
    }

    String[] errors = instance.validate();
    if (errors != null && errors.length > 0) {
      throw new RuntimeException("Validation errors while creating a user notification.");
    }

    try {
      ims.core.admin.domain.objects.Notifications doNotification =
          NotificationVoAssembler.extractNotifications(domainFactory, instance);
      domainFactory.save(doNotification);
      instance = NotificationVoAssembler.create(doNotification);
    } catch (StaleObjectException e) {
      throw new RuntimeException(e);
    }

    return instance;
  }
  public void setUserNotified(INotification notification) {
    if (notification == null)
      throw new CodingRuntimeException("Notification passed into setUserNotified is null.");

    DomainFactory factory = getDomainFactory();

    NotificationVo notificationVo =
        NotificationVoAssembler.create(
            (Notifications)
                factory.getDomainObject(Notifications.class, notification.getINotificationId()));

    notificationVo.setUserNotified(true);

    notificationVo.validate();

    try {
      factory.save(NotificationVoAssembler.extractNotifications(factory, notificationVo));
    } catch (StaleObjectException e) {
      throw new RuntimeException(e);
    }
  }
  public void markAsSeen(IUINotification notification) {
    if (notification == null)
      throw new CodingRuntimeException("Notification passed into markAsSeen is null.");

    DomainFactory factory = getDomainFactory();

    NotificationVo notificationVo =
        NotificationVoAssembler.create(
            (Notifications)
                factory.getDomainObject(Notifications.class, notification.getINotificationId()));

    notificationVo.setSeen(Boolean.TRUE);
    notificationVo.setSeenAt(new DateTime());

    notificationVo.validate();

    try {
      factory.save(NotificationVoAssembler.extractNotifications(factory, notificationVo));
    } catch (StaleObjectException e) {
      throw new RuntimeException(e);
    }
  }