agave-notifications/notifications-core/src/main/java/org/iplantc/service/notification/dao/NotificationDao.java
/**
	 * Adds new {@link Notification} records for all the provided <code>events</code> that
	 * do not already have existing subscriptions. Tenancy and ownership are preserved.
	 * 
	 * @param associatedUuid
	 * @param createdBy
	 * @param events
	 * @param callbackUrl
	 * @throws NotificationException
	 */
Adds new  Notification records for all the provided events that
do not already have existing subscriptions. Tenancy and ownership are preserved.


Adds new Notification records for all the provided events that do not already have existing subscriptions . Tenancy and ownership are preserved .
@SuppressWarnings("unchecked")
	public List<Notification> addUniqueNotificationForEvents(
			String associatedUuid, String createdBy, List<String> events, String callbackUrl, boolean isPersistent) 
	throws NotificationException
	{
		List<Notification> newNotifications = new ArrayList<Notification>();
		if (events == null || events.isEmpty()) {
			return newNotifications;
		}
		try
		{
			HibernateUtil.beginTransaction();
			Session session = HibernateUtil.getSession();
			session.clear();
			session.disableFilter("notificationTenantFilter");
			String sql = "SELECT distinct n.event "
					+ "FROM Notification n \n"
					+ "WHERE n.status = :status and \n "
					+ "		 n.visible = :visible and \n "
					+ "		 n.owner = :owner and \n"
					+ "		 ( n.event in (:events) or n.event = :wildcard ) and \n"
					+ "		 ( associatedUuid = :uuid or n.associatedUuid = :wildcard ) \n";
			List<String> existingSubscriptions = (List<String>)session.createQuery(sql)
					.setString("status",NotificationStatusType.ACTIVE.name())
					.setString("uuid", associatedUuid)
					.setBoolean("visible",true)
					.setString("owner", createdBy)
					.setString("wildcard", "*")
					.setString("events", "'" + StringUtils.join(events,"','") + "'")
					.list();
			if (existingSubscriptions == null) {
				existingSubscriptions = new ArrayList<String>();
			}
			if (!existingSubscriptions.contains("*")) {
				for (String event: events) {
					if (!existingSubscriptions.contains(event)) {
						Notification notification = new Notification(associatedUuid, createdBy, event, callbackUrl, isPersistent);
						try {
							persist(notification);
							newNotifications.add(notification);
						}
						catch (Exception ignored) {}
					}
				}
			}
			session.flush();
			return newNotifications;
		}
		catch (HibernateException ex)
		{
			try
			{
				if (HibernateUtil.getSession().isOpen()) {
					HibernateUtil.rollbackTransaction();
				}
			}
			catch (Exception ignored) {}
			throw new NotificationException(ex);
		}
		finally {
			try { HibernateUtil.commitTransaction(); } catch (Exception ignored) {}
		}
	}
@ SuppressWarnings ( "unchecked" ) public List < Notification > addUniqueNotificationForEvents ( String associatedUuid , String createdBy , List < String > events , String callbackUrl , boolean isPersistent ) throws NotificationException { List < Notification > newNotifications = new ArrayList < Notification > ( ) ; if ( events == null || events . isEmpty ( ) ) { return newNotifications ; } try { HibernateUtil . beginTransaction ( ) ; Session session = HibernateUtil . getSession ( ) ; session . clear ( ) ; session . disableFilter ( "notificationTenantFilter" ) ; String sql = "SELECT distinct n.event " + "FROM Notification n \n" + "WHERE n.status = :status and \n " + "		 n.visible = :visible and \n " + "		 n.owner = :owner and \n" + "		 ( n.event in (:events) or n.event = :wildcard ) and \n" + "		 ( associatedUuid = :uuid or n.associatedUuid = :wildcard ) \n" ; List < String > existingSubscriptions = ( List < String > ) session . createQuery ( sql ) . setString ( "status" , NotificationStatusType . ACTIVE . name ( ) ) . setString ( "uuid" , associatedUuid ) . setBoolean ( "visible" , true ) . setString ( "owner" , createdBy ) . setString ( "wildcard" , "*" ) . setString ( "events" , "'" + StringUtils . join ( events , "','" ) + "'" ) . list ( ) ; if ( existingSubscriptions == null ) { existingSubscriptions = new ArrayList < String > ( ) ; } if ( ! existingSubscriptions . contains ( "*" ) ) { for ( String event : events ) { if ( ! existingSubscriptions . contains ( event ) ) { Notification notification = new Notification ( associatedUuid , createdBy , event , callbackUrl , isPersistent ) ; try { persist ( notification ) ; newNotifications . add ( notification ) ; } catch ( Exception ignored ) { } } } } session . flush ( ) ; return newNotifications ; } catch ( HibernateException ex ) { try { if ( HibernateUtil . getSession ( ) . isOpen ( ) ) { HibernateUtil . rollbackTransaction ( ) ; } } catch ( Exception ignored ) { } throw new NotificationException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } }
Adds new {@link Notification} records for all the provided <code>events</code> that
 do not already have existing subscriptions.
Adds new { @link Notification } records for all the provided <code > events< / code > that do not already have existing subscriptions .
// add all missing notifications. wildcard excludes everything // save the flush until here so we can do bulk insert the previous transactions