Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

In this page you can find the example usage for org.hibernate Query setParameterList.

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

From source file:edu.ur.hibernate.ir.security.db.HbIrAclDAO.java

License:Apache License

/**
 * Return sepcified sids who have the specified permission
 * /*from w w  w  . j av a2  s  .co  m*/
 * @see edu.ur.ir.security.IrAclDAO#hasPermission(java.lang.Long, java.lang.String, java.lang.String)
 */
@SuppressWarnings("unchecked")
public Set<Sid> getSidsWithPermissionForObject(Long objectId, String className, String permission,
        List<Sid> specificSids) {
    HashSet<Sid> sids = new HashSet<Sid>();
    Set<Long> userIds = new HashSet<Long>();
    Set<Long> groupIds = new HashSet<Long>();

    for (Sid sid : specificSids) {
        if (sid.getSidType().equals(IrUser.USER_SID_TYPE)) {
            userIds.add(((IrUser) sid).getId());
        } else if (sid.getSidType().equals(IrUserGroup.GROUP_SID_TYPE)) {
            groupIds.add(((IrUserGroup) sid).getId());
        } else {
            throw new IllegalStateException("Unknown sid type " + sid.getSidType());
        }
    }

    if (userIds.size() > 0) {
        Query q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("specifiedUsersWithPermission");

        q.setParameter("objectId", objectId);
        q.setParameter("className", className);
        q.setParameter("permissionName", permission);
        q.setParameterList("userIds", userIds);

        List<Sid> userSids = (List<Sid>) q.list();
        sids.addAll(userSids);
    }

    if (groupIds.size() > 0) {
        Query q = hbCrudDAO.getSessionFactory().getCurrentSession()
                .getNamedQuery("specifiedGroupsWithPermission");

        q.setParameter("objectId", objectId);
        q.setParameter("className", className);
        q.setParameter("permissionName", permission);
        q.setParameterList("groupIds", groupIds);

        List<Sid> groupSids = (List<Sid>) q.list();
        sids.addAll(groupSids);
    }

    return sids;
}

From source file:edu.ur.hibernate.ir.security.db.HbIrUserAccessControlEntryDAO.java

License:Apache License

/**
 * Get the list of users for the given access control list.
 * /*from  w w w .  j a v a2  s .c  o  m*/
 * @param acl - acl to the the access control entries for
 * @param users - list of users to get for the acl
 * 
 * @return - list of users found.
 */
@SuppressWarnings("unchecked")
public List<IrUserAccessControlEntry> getUserControlEntriesForUsers(IrAcl acl, List<IrUser> users) {
    LinkedList<Long> userIds = new LinkedList<Long>();
    for (IrUser user : users) {
        userIds.add(user.getId());
    }

    Query q = hbCrudDAO.getSessionFactory().getCurrentSession().getNamedQuery("userControlEntriesForUsers");
    q.setLong("aclId", acl.getId());
    q.setParameterList("userIds", userIds);
    return q.list();
}

From source file:edu.utah.further.fqe.ds.model.further.service.results.ResultDataServiceImpl.java

License:Apache License

@Override
public <T> T getQueryResultsInList(final String hql, final String parameterName, final List<Object> queryIds) {
    final Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setParameterList(parameterName, queryIds);
    return (T) query.list();
}

From source file:edu.utah.further.fqe.mpi.impl.service.IdentifierServiceImpl.java

License:Apache License

@Override
@Transactional(value = "identifierTransactionManager")
public List<Identifier> getUnresolvedIdentifiers(final List<String> queryIds) {
    Validate.notNull(queryIds, "queryId is required for identity resolution");

    // get all identifiers that have a null federated id so we can fill them in
    final Query identifierQuery = identifierSessionFactory.getCurrentSession()
            .createQuery("from IdentifierEntity as identifier where " + "identifier.commonId is null "
                    + "and identifier.queryId IN (:queryIds)");
    identifierQuery.setParameterList("queryIds", queryIds);

    return identifierQuery.list();
}

From source file:edu.utah.further.fqe.mpi.impl.service.IdentifierServiceImpl.java

License:Apache License

@Override
@Transactional(value = "identifierTransactionManager")
public Map<Long, Set<Long>> getCommonIdToVirtualIdMap(final List<String> queryIds,
        final boolean orderedVirtualIds) {
    Validate.notNull(queryIds, "queryIds are required for create a common id to virtual id mapping");

    // get all identifiers that have a null federated id so we can fill them in
    final Query identifierQuery = identifierSessionFactory.getCurrentSession()
            .createQuery("SELECT DISTINCT "
                    + "new map(identifier.commonId as common, identifier.virtualId as virtual) "
                    + "from IdentifierEntity as identifier " + "where identifier.commonId is not null "
                    + "and identifier.queryId IN (:queryIds)");
    identifierQuery.setParameterList("queryIds", queryIds);

    final List<Map<String, Long>> results = identifierQuery.list();
    final Map<Long, Set<Long>> commonToVirtualMap = new HashMap<>();
    for (final Map<String, Long> result : results) {
        final Long common = result.get("common");
        if (commonToVirtualMap.containsKey(common)) {
            commonToVirtualMap.get(common).add(result.get("virtual"));
        } else {/*from w  w  w.ja  va2  s  .c  om*/
            Set<Long> virtuals = null;

            if (orderedVirtualIds) {
                virtuals = new TreeSet<>();
            } else {
                virtuals = new HashSet<>();
            }

            virtuals.add(result.get("virtual"));

            commonToVirtualMap.put(common, virtuals);
        }
    }

    return commonToVirtualMap;
}

From source file:es.logongas.ix3.dao.impl.GenericDAOImplHibernate.java

License:Apache License

/**
 * Pone los parmetros en una Query//w  w  w . j av  a2s.  co  m
 *
 * @param query La Query a la que se le pone los parmetros.
 * @param parameters El map debe ser del tipo Map<String,Object> o Map<Integer,Object>. Y se pondrn los parmetros por nombre o por posicin.
 */
private void setParameters(Query query, Map<Object, Object> parameters) {
    if (parameters != null) {
        for (Map.Entry<Object, Object> entry : parameters.entrySet()) {
            Object value = entry.getValue();
            Object parameterKey = entry.getKey();

            if (parameterKey == null) {
                throw new NullPointerException("El nombre de un parmetro no puede ser null");
            }

            if (parameterKey instanceof Number) {
                Number parameterIndex = (Number) parameterKey;
                query.setParameter(parameterIndex.intValue(), value);
            } else if (parameterKey instanceof String) {
                String parameterName = (String) parameterKey;
                if (value instanceof Object[]) {
                    query.setParameterList(parameterName, (Object[]) value);
                } else if (value instanceof Collection) {
                    query.setParameterList(parameterName, (Collection) value);
                } else {
                    query.setParameter(parameterName, value);
                }
            } else {
                throw new RuntimeException("La clave debe ser de tipo String o Number");
            }
        }
    }
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find unassigned employees by filters//from www.  j  a v a  2  s  .c o m
 *
 *
 * @param since
 * @param until
 * @param fullName
 * @param listResourcepool
 * @param idJobCategories
 */
public List<Employee> findUnassigned(Date since, Date until, String fullName,
        List<Resourcepool> listResourcepool, Integer[] idJobCategories) {

    // Add Restrictions
    //
    List<NamedRestriction> restrictions = new ArrayList<NamedRestriction>();

    MappingHql mappingHql = this.getMappingHql().setNamedQuery(EmployeeNamedQuery.FIND_UNSIGNED)
            .putRestrictions(EmployeeNamedRestriction.EXCLUDE_IN_DATES);

    if (ValidateUtil.isNotNull(fullName)) {
        mappingHql.putRestrictions(EmployeeNamedRestriction.LIKE_NAME);
    }

    if (ValidateUtil.isNotNull(listResourcepool)) {
        mappingHql.putRestrictions(EmployeeNamedRestriction.IN_POOLS);
    }

    if (ValidateUtil.isNotNull(idJobCategories)) {
        mappingHql.putRestrictions(EmployeeNamedRestriction.IN_CATEGORIES);
    }

    // Create query
    String statement = mappingHql.putOrders(GenericNamedOrder.BY_CONTACT_NAME).create();

    Query query = getSession().createQuery(statement);

    // Set parameters
    //
    if (ValidateUtil.isNotNull(listResourcepool)) {
        query.setParameterList(NamedParams.RESOURCEPOOL.name(), listResourcepool);
    }

    if (ValidateUtil.isNotNull(fullName)) {
        query.setString(NamedParams.FULLNAME.name(),
                StringPool.PERCENT + fullName.toLowerCase() + StringPool.PERCENT);
    }

    if (ValidateUtil.isNotNull(idJobCategories)) {
        query.setParameterList(NamedParams.CATEGORIES.name(), idJobCategories);
    }

    query.setDate(NamedParams.SINCE.name(), since);
    query.setDate(NamedParams.UNTIL.name(), until);
    query.setString(NamedParams.RESOURCE_ASSIGNED.name(), Constants.RESOURCE_ASSIGNED);

    return query.list();
}

From source file:es.sm2.openppm.core.dao.LearnedLessonDAO.java

License:Open Source License

/**
 * Add parameters//w  w w  .j a va2s.  co  m
 *
 * @param query
 * @param filter
 */
private void addParameters(Query query, LearnedLessonSearch filter) {

    // LearnedLesson search parameters
    //

    // Name and id
    if (ValidateUtil.isNotNull(filter.getLlaaQuery())) {
        query.setString("llaaQuery", "%" + filter.getLlaaQuery().toUpperCase() + "%");
    }

    Integer[] idsLLAA = IntegerUtil.parseStringSequence(filter.getLlaaQuery(), StringPool.COMMA);

    if (ValidateUtil.isNotNull(idsLLAA)) {
        query.setParameterList("idsLLAA", idsLLAA);
    }

    // Programs
    if (ValidateUtil.isNotNull(filter.getLlaaPrograms())) {
        query.setParameterList("llaaPrograms", filter.getLlaaPrograms());
    }

    // Customers
    if (ValidateUtil.isNotNull(filter.getLlaaCustomers())) {
        query.setParameterList("llaaCustomers", filter.getLlaaCustomers());
    }

    // Sellers
    if (ValidateUtil.isNotNull(filter.getLlaaSellers())) {
        query.setParameterList("llaaSellers", filter.getLlaaSellers());
    }

    // Geographic Areas
    if (ValidateUtil.isNotNull(filter.getLlaaGeographicAreas())) {
        query.setParameterList("llaaGeographicAreas", filter.getLlaaGeographicAreas());
    }

    // Customer types
    if (ValidateUtil.isNotNull(filter.getLlaaCustomerTypes())) {
        query.setParameterList("llaaCustomerTypes", filter.getLlaaCustomerTypes());
    }

    // Funding sources
    if (ValidateUtil.isNotNull(filter.getLlaaFundingSources())) {
        query.setParameterList("llaaFundingSources", filter.getLlaaFundingSources());
    }

    // Knowledge Area
    if (ValidateUtil.isNotNull(filter.getLlaaKnowledgeArea())) {
        query.setParameterList("llaaKnowledgeArea", filter.getLlaaKnowledgeArea());
    }

    // Owners
    if (ValidateUtil.isNotNull(filter.getLlaaOwner())) {
        query.setParameterList("llaaOwner", filter.getLlaaOwner());
    }

    // Profiles
    if (ValidateUtil.isNotNull(filter.getLlaaJobProfile())) {
        query.setParameterList("llaaJobProfile", filter.getLlaaJobProfile());
    }

    // Min impact time
    if (filter.getLlaaMinImpactTime() != null) {
        query.setBigDecimal("llaaMinImpactTime", filter.getLlaaMinImpactTime());
    }

    // Max impact time
    if (filter.getLlaaMaxImpactTime() != null) {
        query.setBigDecimal("llaaMaxImpactTime", filter.getLlaaMaxImpactTime());
    }

    // Min impact cost
    if (filter.getLlaaMinImpactCost() != null) {
        query.setBigDecimal("llaaMinImpactCost", filter.getLlaaMinImpactCost());
    }

    // Max impact cost
    if (filter.getLlaaMaxImpactCost() != null) {
        query.setBigDecimal("llaaMaxImpactCost", filter.getLlaaMaxImpactCost());
    }

    // Min ranking
    if (filter.getLlaaMinRanking() != null) {
        query.setBigDecimal("llaaMinRanking", filter.getLlaaMinRanking());
    }

    // Max ranking
    if (filter.getLlaaMaxRanking() != null) {
        query.setBigDecimal("llaaMaxRanking", filter.getLlaaMaxRanking());
    }

    // Since
    if (filter.getLlaaSince() != null) {
        query.setDate("llaaSince", filter.getLlaaSince());
    }

    // Until
    if (filter.getLlaaUntil() != null) {
        query.setDate("llaaUntil", filter.getLlaaUntil());
    }
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * Add parameters//  w  w  w.  j a v  a 2s .  com
 *
 * @param query
 * @param filter
 */
private void addParameters(Query query, ProjectSearch filter) {

    // Add parameter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority())
                || ProjectSearch.LESS_EQUAL.equals(filter.getPriority())) && filter.getLastPriority() != null) {

            query.setInteger("lastPriority", filter.getLastPriority());
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            query.setInteger("firstPriority", filter.getFirstPriority());
            query.setInteger("lastPriority", filter.getLastPriority());
        }
    }

    // Add parameter for risk rating
    if (ValidateUtil.isNotNull(filter.getRiskRating())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getRiskRating())
                || ProjectSearch.LESS_EQUAL.equals(filter.getRiskRating()))
                && filter.getLastRiskRating() != null) {

            query.setInteger("lastRiskRating", filter.getLastRiskRating());
        } else if (ProjectSearch.BETWEEN.equals(filter.getRiskRating()) && filter.getLastRiskRating() != null
                && filter.getFirstRiskRating() != null) {

            query.setInteger("firstRiskRating", filter.getFirstRiskRating());
            query.setInteger("lastRiskRating", filter.getLastRiskRating());
        }
    }

    if (filter.getIncludeDisabled() != null && !filter.getIncludeDisabled()) {
        query.setBoolean("disable", Boolean.TRUE);
    }

    if (filter.getSince() != null) {
        query.setDate("since", filter.getSince());
    }
    if (filter.getUntil() != null) {
        query.setDate("until", filter.getUntil());
    }
    if (filter.getInternalProject() != null) {
        query.setBoolean("internalProject", filter.getInternalProject());
    }
    if (filter.getIsGeoSelling() != null) {
        query.setBoolean("isGeoSelling", filter.getIsGeoSelling());
    }
    if (filter.getBudgetYear() != null) {
        query.setInteger("budgetYear", filter.getBudgetYear());
    }
    if (ValidateUtil.isNotNull(filter.getProjectName())) {
        query.setString("projectName", "%" + filter.getProjectName().toUpperCase() + "%");
    }

    Integer[] idsProject = IntegerUtil.parseStringSequence(filter.getProjectName(), StringPool.COMMA);

    if (SettingUtil.getBoolean(filter.getSettings(), VisibilityProjectSetting.PROJECT_COLUMN_IDPROJECT)
            && idsProject != null) {

        query.setParameterList("projectNameID", idsProject);
    }

    if (ValidateUtil.isNotNull(filter.getRag())) {
        query.setCharacter("rag", filter.getRag().charAt(0));
    }
    if (filter.getCompany() != null) {
        query.setEntity("company", filter.getCompany());
    }
    if (filter.getEmployeeByInvestmentManager() != null) {
        query.setEntity("employeeByInvestmentManager", filter.getEmployeeByInvestmentManager());
    }
    if (filter.getStakeholder() != null) {
        query.setEntity("stakeholder", filter.getStakeholder());
    }
    if (filter.getProgramManager() != null) {
        query.setEntity("programManager", filter.getProgramManager());
    }
    if (filter.getIsIndirectSeller() != null) {
        query.setBoolean("isIndirectSeller", filter.getIsIndirectSeller());
    }

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        query.setParameterList("performingorgs", filter.getPerformingorgs());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        query.setParameterList("employeeBySponsors", filter.getEmployeeBySponsors());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        query.setParameterList("employeeByProjectManagers", filter.getEmployeeByProjectManagers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        query.setParameterList("customers", filter.getCustomers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        query.setParameterList("customertypes", filter.getCustomertypes());
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        query.setParameterList("programs", filter.getPrograms());
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        query.setParameterList("categories", filter.getCategories());
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        query.setParameterList("sellers", filter.getSellers());
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        query.setParameterList("geography", filter.getGeography());
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        query.setParameterList("fundingsources", filter.getFundingsources());
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        query.setParameterList("projects", filter.getProjects());
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        query.setParameterList("status", filter.getStatus());
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        query.setParameterList("investmentStatus", filter.getInvestmentStatus());
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        query.setParameterList("labels", filter.getLabels());
    }
    if (ValidateUtil.isNotNull(filter.getTechnologies())) {
        query.setParameterList("technologies", filter.getTechnologies());
    }
    if (ValidateUtil.isNotNull(filter.getStageGates())) {
        query.setParameterList("stagegate", filter.getStageGates());
    }
    if (ValidateUtil.isNotNull(filter.getContractTypes())) {
        query.setParameterList("contractTypes", filter.getContractTypes());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        query.setParameterList("employeeByFunctionalManagers", filter.getEmployeeByFunctionalManagers());
    }
    if (ValidateUtil.isNotNull(filter.getClassificationsLevel())) {
        query.setParameterList("classificationsLevel", filter.getClassificationsLevel());
    }

    if (filter.getShowInactivated() != null && !filter.getShowInactivated()) {

        query.setString("hideInactivated", Constants.INVESTMENT_INACTIVATED);
    }
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * /* w  ww.  j av  a2 s .  c  o m*/
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<ProjectWrap> findProjectsForExecutiveReport(ProjectSearch filter) {

    String q = "SELECT DISTINCT NEW es.sm2.openppm.core.model.wrap.ProjectWrap(" + "p, "
            + "(SELECT CASE WHEN SUM(ch.cost) IS NULL THEN 0d ELSE SUM(ch.cost) END FROM Chargescosts ch WHERE ch.project = p AND (ch.idChargeType = 1 OR ch.idChargeType = 2 OR ch.idChargeType = 3)) "
            + ") " + "FROM Projectactivity pa " + "JOIN pa.project p " + "JOIN p.program pr "
            + "JOIN p.performingorg po " + "LEFT JOIN p.stakeholders stk "
            + "LEFT JOIN pa.activitysellers actSell " + "LEFT JOIN p.projectfundingsources fs "
            + "LEFT JOIN p.projectlabels pl " + "JOIN pa.wbsnode w ";

    String where = "";

    // Create filter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if (ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority()) && filter.getLastPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "p.priority >= :lastPriority ");
        } else if (ProjectSearch.LESS_EQUAL.equals(filter.getPriority()) && filter.getLastPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "p.priority <= :lastPriority ");
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "(p.priority BETWEEN :firstPriority AND :lastPriority) ");
        }
    }

    // Filter by since and until dates
    if (filter.getSince() != null && filter.getUntil() != null) {
        where += FilterUtil.addFilterAnd(where,
                "((p.startDate BETWEEN :since AND :until) OR (p.finishDate BETWEEN :since AND :until) OR (p.startDate <= :since AND p.finishDate >= :until))");
    } else if (filter.getSince() != null) {
        where += FilterUtil.addFilterAnd(where, "p.startDate >= :since ");
    } else if (filter.getUntil() != null) {
        where += FilterUtil.addFilterAnd(where, "p.finishDate <= :since ");
    }

    where += FilterUtil.addFilterAnd(filter.getInternalProject(), where,
            "p.internalProject = :internalProject ");
    where += FilterUtil.addFilterAnd(filter.getBudgetYear(), where, "p.budgetYear = :budgetYear ");
    where += FilterUtil.addFilterAnd(filter.getProjectName(), where,
            "(UPPER(p.projectName) LIKE :projectName OR UPPER(p.chartLabel) LIKE :projectName OR UPPER(p.accountingCode) LIKE :projectName) ");
    where += FilterUtil.addFilterAnd(filter.getRag(), where, "p.rag = :rag ");
    where += FilterUtil.addFilterAnd(filter.getCompany(), where, "po.company = :company ");
    where += FilterUtil.addFilterAnd(filter.getEmployeeByInvestmentManager(), where,
            "p.employeeByInvestmentManager = :employeeByInvestmentManager ");
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        where += FilterUtil.addFilterAnd(where,
                "p.employeeByFunctionalManager.idEmployee IN (:employeeByFunctionalManagers) ");
    }
    where += FilterUtil.addFilterAnd(filter.getStakeholder(), where, "stk.employee = :stakeholder ");
    where += FilterUtil.addFilterAnd(filter.getProgramManager(), where, "pr.employee = :programManager ");

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        where += FilterUtil.addFilterAnd(where, "po.idPerfOrg IN (:performingorgs) ");
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        where += FilterUtil.addFilterAnd(where, "p.employeeBySponsor.idEmployee IN (:employeeBySponsors) ");
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        where += FilterUtil.addFilterAnd(where,
                "p.employeeByProjectManager.idEmployee IN (:employeeByProjectManagers) ");
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        where += FilterUtil.addFilterAnd(where, "p.customer.idCustomer IN (:customers) ");
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        where += FilterUtil.addFilterAnd(where, "p.contracttype.idContractType IN (:customertypes) ");
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        where += FilterUtil.addFilterAnd(where, "p.program.idProgram IN (:programs) ");
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        where += FilterUtil.addFilterAnd(where, "p.category.idCategory IN (:categories) ");
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        where += FilterUtil.addFilterAnd(where, "actSell.seller.idSeller IN (:sellers) ");
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        where += FilterUtil.addFilterAnd(where, "p.geography.idGeography IN (:geography) ");
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        where += FilterUtil.addFilterAnd(where, "fs.fundingsource.idFundingSource IN (:fundingsources) ");
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        where += FilterUtil.addFilterAnd(where, "p.idProject IN (:projects) ");
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        where += FilterUtil.addFilterAnd(where, "p.status IN (:status) ");
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        where += FilterUtil.addFilterAnd(where, "p.investmentStatus IN (:investmentStatus) ");
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        where += FilterUtil.addFilterAnd(where, "pl.label.idLabel IN (:labels) ");
    }

    Query query = getSession().createQuery(q + where);

    // Add parameter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority())
                || ProjectSearch.LESS_EQUAL.equals(filter.getPriority())) && filter.getLastPriority() != null) {

            query.setInteger("lastPriority", filter.getLastPriority());
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            query.setInteger("firstPriority", filter.getFirstPriority());
            query.setInteger("lastPriority", filter.getLastPriority());
        }
    }

    if (filter.getSince() != null) {
        query.setDate("since", filter.getSince());
    }
    if (filter.getUntil() != null) {
        query.setDate("until", filter.getUntil());
    }
    if (filter.getInternalProject() != null) {
        query.setBoolean("internalProject", filter.getInternalProject());
    }
    if (filter.getBudgetYear() != null) {
        query.setInteger("budgetYear", filter.getBudgetYear());
    }
    if (ValidateUtil.isNotNull(filter.getProjectName())) {
        query.setString("projectName", "%" + filter.getProjectName().toUpperCase() + "%");
    }
    if (ValidateUtil.isNotNull(filter.getRag())) {
        query.setCharacter("rag", filter.getRag().charAt(0));
    }
    if (filter.getCompany() != null) {
        query.setEntity("company", filter.getCompany());
    }
    if (filter.getEmployeeByInvestmentManager() != null) {
        query.setEntity("employeeByInvestmentManager", filter.getEmployeeByInvestmentManager());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        query.setParameterList("employeeByFunctionalManagers", filter.getEmployeeByFunctionalManagers());
    }
    if (filter.getStakeholder() != null) {
        query.setEntity("stakeholder", filter.getStakeholder());
    }
    if (filter.getProgramManager() != null) {
        query.setEntity("programManager", filter.getProgramManager());
    }

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        query.setParameterList("performingorgs", filter.getPerformingorgs());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        query.setParameterList("employeeBySponsors", filter.getEmployeeBySponsors());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        query.setParameterList("employeeByProjectManagers", filter.getEmployeeByProjectManagers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        query.setParameterList("customers", filter.getCustomers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        query.setParameterList("customertypes", filter.getCustomertypes());
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        query.setParameterList("programs", filter.getPrograms());
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        query.setParameterList("categories", filter.getCategories());
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        query.setParameterList("sellers", filter.getSellers());
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        query.setParameterList("geography", filter.getGeography());
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        query.setParameterList("fundingsources", filter.getFundingsources());
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        query.setParameterList("projects", filter.getProjects());
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        query.setParameterList("status", filter.getStatus());
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        query.setParameterList("investmentStatus", filter.getInvestmentStatus());
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        query.setParameterList("labels", filter.getLabels());
    }

    return query.list();
}