agave-notifications/notifications-core/src/main/java/org/iplantc/service/notification/dao/NotificationAttemptDao.java
/**
     * Searches for software by the given user who matches the given set of 
     * parameters. Permissions are honored in this query as in pagination
     *
     * @param username
     * @param searchCriteria
     * @param offset
     * @param limit
     * @return
     * @throws SoftwareException
     */
Searches for software by the given user who matches the given set of
parameters. Permissions are honored in this query as in pagination


Searches for software by the given user who matches the given set of parameters . Permissions are honored in this query as in pagination
@SuppressWarnings("unchecked")
    public List<NotificationAttempt> findMatching(String notificationId, String username, Map<SearchTerm, Object> searchCriteria, int offset, int limit) 
    throws NotificationException
    {
        try
        {
            Session session = getSession();
            session.clear();
if (!AuthorizationHelper.isTenantAdmin(username)) {
    // no public search term specified. return public and private
    hql +=  " WHERE ( \n" +
            "       c.owner = :owner OR \n" +
            "       c.id in ( \n" + 
            "               SELECT cp.resourceId FROM RealtimeChannelPermission cp \n" +
            "               WHERE cp.username = :owner AND cp.permission <> :none \n" +
            "              ) \n" +
            "      ) AND \n";
} else {
    hql += " WHERE ";
}
            String hql = "FROM NotificationAttempt c "; 
            hql += "\n WHERE c.tenantId = :tenantid ";
            hql += "\n       AND       c.notificationId = :notificationId ";
            if (!AuthorizationHelper.isTenantAdmin(username)) {
				hql +=   "    AND c.owner = :username \n";
			}
            for (SearchTerm searchTerm: searchCriteria.keySet()) 
            {
                if (searchCriteria.get(searchTerm) == null 
                        || StringUtils.equalsIgnoreCase(searchCriteria.get(searchTerm).toString(), "null")) 
                {
                    if (searchTerm.getOperator() == SearchTerm.Operator.NEQ ) {
                        hql += "\n       AND       " + String.format(searchTerm.getMappedField(), searchTerm.getPrefix()) + " is not null ";
                    } else if (searchTerm.getOperator() == SearchTerm.Operator.EQ ) {
                        hql += "\n       AND       " + String.format(searchTerm.getMappedField(), searchTerm.getPrefix()) + " is null ";
                    } else {
                        hql += "\n       AND       " + searchTerm.getExpression();
                    }
                } else {
                    hql += "\n       AND       " + searchTerm.getExpression();
                }
            }
            hql +=  " ORDER BY c.name ASC\n";
            String q = hql;
            Query query = session.createQuery(hql)
                                 .setResultTransformer(Transformers.aliasToBean(NotificationAttempt.class))
                                 .setString("tenantid", TenancyHelper.getCurrentTenantId())
                                 .setString("notificationId", notificationId);
            q = q.replaceAll(":tenantid", "'" + TenancyHelper.getCurrentTenantId() + "'");
            q = q.replaceAll(":notificationId", "'" + notificationId + "'");
            if (!AuthorizationHelper.isTenantAdmin(username)) {
                query.setString("owner",username);
                q = q.replaceAll(":owner", "'" + username + "'");
            }
            for (SearchTerm searchTerm: searchCriteria.keySet()) 
            {
                if (searchTerm.getOperator() == SearchTerm.Operator.BETWEEN) {
                    List<String> formattedDates = (List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm));
                    for(int i=0;i<formattedDates.size(); i++) {
                        query.setString(searchTerm.getSafeSearchField()+i, formattedDates.get(i));
                        q = q.replaceAll(":" + searchTerm.getSafeSearchField(), "'" + formattedDates.get(i) + "'");
                    }
                }
                else if (searchTerm.getOperator().isSetOperator()) 
                {
                    query.setParameterList(searchTerm.getSafeSearchField(), (List<Object>)searchCriteria.get(searchTerm));
                    q = q.replaceAll(":" + searchTerm.getSafeSearchField(), "('" + StringUtils.join((List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)), "','") + "')" );
                }
                else if (searchCriteria.get(searchTerm) == null 
                        || StringUtils.equalsIgnoreCase(searchCriteria.get(searchTerm).toString(), "null")
                        && (searchTerm.getOperator() == SearchTerm.Operator.NEQ || searchTerm.getOperator() == SearchTerm.Operator.EQ )) {
                }
                else 
                {
                    query.setParameter(searchTerm.getSafeSearchField(), 
                            searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)));
                    q = q.replaceAll(":" + searchTerm.getSafeSearchField(), "'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'");
                }
            }
            log.debug(q);
            List<NotificationAttempt> attempts = query
                    .setFirstResult(offset)
                    .setMaxResults(limit)
                    .list();
            session.flush();
            return attempts;
        }
        catch (Throwable ex)
        {
            throw new NotificationException(ex);
        }
        finally {
            try { HibernateUtil.commitTransaction();} catch (Exception e) {}
        }
    }
@ SuppressWarnings ( "unchecked" ) public List < NotificationAttempt > findMatching ( String notificationId , String username , Map < SearchTerm , Object > searchCriteria , int offset , int limit ) throws NotificationException { try { Session session = getSession ( ) ; session . clear ( ) ; String hql = "FROM NotificationAttempt c " ; hql += "\n WHERE c.tenantId = :tenantid " ; hql += "\n       AND       c.notificationId = :notificationId " ; if ( ! AuthorizationHelper . isTenantAdmin ( username ) ) { hql += "    AND c.owner = :username \n" ; } for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchCriteria . get ( searchTerm ) == null || StringUtils . equalsIgnoreCase ( searchCriteria . get ( searchTerm ) . toString ( ) , "null" ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . NEQ ) { hql += "\n       AND       " + String . format ( searchTerm . getMappedField ( ) , searchTerm . getPrefix ( ) ) + " is not null " ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . EQ ) { hql += "\n       AND       " + String . format ( searchTerm . getMappedField ( ) , searchTerm . getPrefix ( ) ) + " is null " ; } else { hql += "\n       AND       " + searchTerm . getExpression ( ) ; } } else { hql += "\n       AND       " + searchTerm . getExpression ( ) ; } } hql += " ORDER BY c.name ASC\n" ; String q = hql ; Query query = session . createQuery ( hql ) . setResultTransformer ( Transformers . aliasToBean ( NotificationAttempt . class ) ) . setString ( "tenantid" , TenancyHelper . getCurrentTenantId ( ) ) . setString ( "notificationId" , notificationId ) ; q = q . replaceAll ( ":tenantid" , "'" + TenancyHelper . getCurrentTenantId ( ) + "'" ) ; q = q . replaceAll ( ":notificationId" , "'" + notificationId + "'" ) ; if ( ! AuthorizationHelper . isTenantAdmin ( username ) ) { query . setString ( "owner" , username ) ; q = q . replaceAll ( ":owner" , "'" + username + "'" ) ; } for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . BETWEEN ) { List < String > formattedDates = ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ; for ( int i = 0 ; i < formattedDates . size ( ) ; i ++ ) { query . setString ( searchTerm . getSafeSearchField ( ) + i , formattedDates . get ( i ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "'" + formattedDates . get ( i ) + "'" ) ; } } else if ( searchTerm . getOperator ( ) . isSetOperator ( ) ) { query . setParameterList ( searchTerm . getSafeSearchField ( ) , ( List < Object > ) searchCriteria . get ( searchTerm ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "('" + StringUtils . join ( ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) , "','" ) + "')" ) ; } else if ( searchCriteria . get ( searchTerm ) == null || StringUtils . equalsIgnoreCase ( searchCriteria . get ( searchTerm ) . toString ( ) , "null" ) && ( searchTerm . getOperator ( ) == SearchTerm . Operator . NEQ || searchTerm . getOperator ( ) == SearchTerm . Operator . EQ ) ) { } else { query . setParameter ( searchTerm . getSafeSearchField ( ) , searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ; } } log . debug ( q ) ; List < NotificationAttempt > attempts = query . setFirstResult ( offset ) . setMaxResults ( limit ) . list ( ) ; session . flush ( ) ; return attempts ; } catch ( Throwable ex ) { throw new NotificationException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception e ) { } } }
Searches for software by the given user who matches the given set of
 parameters.
Searches for software by the given user who matches the given set of parameters .
//            String hql = "FROM NotificationAttempt c left join c.observableEvents observableEvents \n"; //             //            if (!AuthorizationHelper.isTenantAdmin(username)) { //                // no public search term specified. return public and private //                hql +=  " WHERE ( \n" + //                        "       c.owner = :owner OR \n" + //                        "       c.id in ( \n" +  //                        "               SELECT cp.resourceId FROM RealtimeChannelPermission cp \n" + //                        "               WHERE cp.username = :owner AND cp.permission <> :none \n" + //                        "              ) \n" + //                        "      ) AND \n"; //            } else { //                hql += " WHERE "; //            } // this was explicitly set to 'is null' or 'is not null'