agave-systems/systems-core/src/main/java/org/iplantc/service/transfer/dao/TransferTaskDao.java
/**
     * Searches for {@link TransferTask}s by the given user who matches the given set of 
     * parameters. Permissions are honored in this query.
     *
     * @param username
     * @param searchCriteria
     * @param offset
     * @param limit
     * @return
     * @throws TransferException
     */
Searches for  TransferTasks by the given user who matches the given set of
parameters. Permissions are honored in this query.


Searches for TransferTasks by the given user who matches the given set of parameters . Permissions are honored in this query .
@SuppressWarnings("unchecked")
    public static List<TransferTask> findMatching(String username, Map<SearchTerm, Object> searchCriteria, int limit, int offset) 
    throws TransferException
    {
        try
        {
            Session session = getSession();
            session.clear();
            StringBuilder sql = new StringBuilder(" SELECT j FROM TransferTask as t \n");
            if (!ServiceUtils.isAdmin(username)) {
                sql.append(" WHERE ( \n" + "       t.owner = :owner OR \n" + "       t.id in ( \n" + "               SELECT pm.transferTaskId FROM TransferTaskPermission as pm \n" + "               WHERE pm.username = :owner AND pm.permission <> :none \n" + "              ) \n" + "      ) AND \n");
            } else {
                sql.append(" WHERE ");
            }
            sql.append("        j.tenantId = :tenantid ");
            for (SearchTerm searchTerm: searchCriteria.keySet()) 
            {
                sql.append("\n       AND       ").append(searchTerm.getExpression());
            }
            if (!sql.toString().contains("j.visible")) {
                sql.append("\n       AND j.visible = :visiblebydefault \n");
            }
            sql.append(" ORDER BY j.lastUpdated DESC\n");
            String q = sql.toString();
            Query query = session.createQuery(sql.toString())
                                 .setString("tenantid", TenancyHelper.getCurrentTenantId());
            q = q.replaceAll(":tenantid", "'" + TenancyHelper.getCurrentTenantId() + "'");
            if (sql.toString().contains(":visiblebydefault") ) {
                query.setBoolean("visiblebydefault", Boolean.TRUE);
                q = q.replaceAll(":visiblebydefault", "1");
            }
            if (!ServiceUtils.isAdmin(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) {
                    List<String> formattedDates = (List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm));
                    for(int i=0;i<formattedDates.size(); i++) {
                        query.setString(searchTerm.getSearchField()+i, formattedDates.get(i));
                        q = q.replaceAll(":" + searchTerm.getSearchField(), "'" + formattedDates.get(i) + "'");
                    }
                }
                else if (searchTerm.getOperator().isSetOperator()) 
                {
                    query.setParameterList(searchTerm.getSearchField(), (List<Object>)searchCriteria.get(searchTerm));
                    q = q.replaceAll(":" + searchTerm.getSearchField(), "('" + StringUtils.join((List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)), "','") + "')" );
                }
                else 
                {
                    query.setParameter(searchTerm.getSearchField(), 
                            searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)));
                    q = q.replaceAll(":" + searchTerm.getSearchField(), "'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'");
                }
            }
            List<TransferTask> transferTasks = query
                    .setFirstResult(offset)
                    .setMaxResults(limit)
                    .list();
            session.flush();
            return transferTasks;
        }
        catch (Throwable ex)
        {
            throw new TransferException(ex);
        }
        finally {
            try { HibernateUtil.commitTransaction();} catch (Exception ignored) {}
        }
    }
@ SuppressWarnings ( "unchecked" ) public static List < TransferTask > findMatching ( String username , Map < SearchTerm , Object > searchCriteria , int limit , int offset ) throws TransferException { try { Session session = getSession ( ) ; session . clear ( ) ; StringBuilder sql = new StringBuilder ( " SELECT j FROM TransferTask as t \n" ) ; if ( ! ServiceUtils . isAdmin ( username ) ) { sql . append ( " WHERE ( \n" + "       t.owner = :owner OR \n" + "       t.id in ( \n" + "               SELECT pm.transferTaskId FROM TransferTaskPermission as pm \n" + "               WHERE pm.username = :owner AND pm.permission <> :none \n" + "              ) \n" + "      ) AND \n" ) ; } else { sql . append ( " WHERE " ) ; } sql . append ( "        j.tenantId = :tenantid " ) ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { sql . append ( "\n       AND       " ) . append ( searchTerm . getExpression ( ) ) ; } if ( ! sql . toString ( ) . contains ( "j.visible" ) ) { sql . append ( "\n       AND j.visible = :visiblebydefault \n" ) ; } sql . append ( " ORDER BY j.lastUpdated DESC\n" ) ; String q = sql . toString ( ) ; Query query = session . createQuery ( sql . toString ( ) ) . setString ( "tenantid" , TenancyHelper . getCurrentTenantId ( ) ) ; q = q . replaceAll ( ":tenantid" , "'" + TenancyHelper . getCurrentTenantId ( ) + "'" ) ; if ( sql . toString ( ) . contains ( ":visiblebydefault" ) ) { query . setBoolean ( "visiblebydefault" , Boolean . TRUE ) ; q = q . replaceAll ( ":visiblebydefault" , "1" ) ; } if ( ! ServiceUtils . isAdmin ( 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 ) { List < String > formattedDates = ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ; for ( int i = 0 ; i < formattedDates . size ( ) ; i ++ ) { query . setString ( searchTerm . getSearchField ( ) + i , formattedDates . get ( i ) ) ; q = q . replaceAll ( ":" + searchTerm . getSearchField ( ) , "'" + formattedDates . get ( i ) + "'" ) ; } } else if ( searchTerm . getOperator ( ) . isSetOperator ( ) ) { query . setParameterList ( searchTerm . getSearchField ( ) , ( List < Object > ) searchCriteria . get ( searchTerm ) ) ; q = q . replaceAll ( ":" + searchTerm . getSearchField ( ) , "('" + StringUtils . join ( ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) , "','" ) + "')" ) ; } else { query . setParameter ( searchTerm . getSearchField ( ) , searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ) ; q = q . replaceAll ( ":" + searchTerm . getSearchField ( ) , "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ; } } List < TransferTask > transferTasks = query . setFirstResult ( offset ) . setMaxResults ( limit ) . list ( ) ; session . flush ( ) ; return transferTasks ; } catch ( Throwable ex ) { throw new TransferException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } }
Searches for {@link TransferTask}s by the given user who matches the given set of
 parameters.
Searches for { @link TransferTask } s by the given user who matches the given set of parameters .
// log.debug(q);