agave-realtime/realtime-core/src/main/java/org/iplantc/service/realtime/dao/RealtimeChannelDao.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<RealtimeChannel> findMatching(String username, Map<SearchTerm, Object> searchCriteria, int offset, int limit) 
    throws RealtimeChannelException
    {
        try
        {
            Session session = getSession();
            session.clear();
            String hql = "FROM RealtimeChannel c left join c.observableEvents observableEvents \n";
            if (!AuthorizationHelper.isTenantAdmin(username)) {
                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 ";
            }
            hql +=  "        c.tenantId = :tenantid "; 
            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(RealtimeChannel.class))
                                 .setString("tenantid", TenancyHelper.getCurrentTenantId());
            q = q.replaceAll(":tenantid", "'" + TenancyHelper.getCurrentTenantId() + "'");
            if (!AuthorizationHelper.isTenantAdmin(username)) {
                query.setString("owner",username)
                    .setString("none",PermissionType.NONE.name());
                q = q.replaceAll(":owner", "'" + username + "'")
                    .replaceAll(":none", "'NONE'");
            }
            for (SearchTerm searchTerm: searchCriteria.keySet()) 
            {
                if (searchTerm.getOperator() == SearchTerm.Operator.BETWEEN || searchTerm.getOperator() == SearchTerm.Operator.ON) {
                    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(), "'" + String.valueOf(searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm))) + "'");
                }
            }
            log.debug(q);
            List<RealtimeChannel> realtimeChannels = query
                    .setFirstResult(offset)
                    .setMaxResults(limit)
                    .list();
            session.flush();
            return realtimeChannels;
        }
        catch (Throwable ex)
        {
            throw new RealtimeChannelException(ex);
        }
        finally {
            try { HibernateUtil.commitTransaction();} catch (Exception e) {}
        }
    }
@ SuppressWarnings ( "unchecked" ) public List < RealtimeChannel > findMatching ( String username , Map < SearchTerm , Object > searchCriteria , int offset , int limit ) throws RealtimeChannelException { try { Session session = getSession ( ) ; session . clear ( ) ; String hql = "FROM RealtimeChannel c left join c.observableEvents observableEvents \n" ; if ( ! AuthorizationHelper . isTenantAdmin ( username ) ) { 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 " ; } hql += "        c.tenantId = :tenantid " ; 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 ( RealtimeChannel . class ) ) . setString ( "tenantid" , TenancyHelper . getCurrentTenantId ( ) ) ; q = q . replaceAll ( ":tenantid" , "'" + TenancyHelper . getCurrentTenantId ( ) + "'" ) ; if ( ! AuthorizationHelper . isTenantAdmin ( username ) ) { query . setString ( "owner" , username ) . setString ( "none" , PermissionType . NONE . name ( ) ) ; q = q . replaceAll ( ":owner" , "'" + username + "'" ) . replaceAll ( ":none" , "'NONE'" ) ; } for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . BETWEEN || searchTerm . getOperator ( ) == SearchTerm . Operator . ON ) { 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 ( ) , "'" + String . valueOf ( searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ) + "'" ) ; } } log . debug ( q ) ; List < RealtimeChannel > realtimeChannels = query . setFirstResult ( offset ) . setMaxResults ( limit ) . list ( ) ; session . flush ( ) ; return realtimeChannels ; } catch ( Throwable ex ) { throw new RealtimeChannelException ( 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 .
// no public search term specified. return public and private // this was explicitly set to 'is null' or 'is not null'