Example usage for org.hibernate.criterion Restrictions or

List of usage examples for org.hibernate.criterion Restrictions or

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions or.

Prototype

public static LogicalExpression or(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the disjuction of two expressions

Usage

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * API to fetch batch instance list by Batch name and status.
 * /* w  w w.j  a va2s  .c  om*/
 * @param batchName String
 * @param batchStatus BatchInstanceStatus
 * @param userName String
 * @param userRoles Set<String>
 * @return List<BatchInstance>
 */
@Override
public List<BatchInstance> getBatchInstanceListByBatchNameAndStatus(String batchName,
        BatchInstanceStatus batchStatus, String userName, Set<String> userRoles) {
    EphesoftCriteria criteria = criteria();
    List<BatchInstance> batchInstanceList = null;
    String batchNameLocal = batchName.replaceAll(DataAccessConstant.PERCENTAGE, REPLACEMENT_STRING);
    if (batchStatus != null) {
        criteria.add(Restrictions.like(BATCH_NAME,
                DataAccessConstant.PERCENTAGE + batchNameLocal + DataAccessConstant.PERCENTAGE));
        criteria.add(Restrictions.eq(STATUS, batchStatus));
        criteria.add(
                Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));

        Set<String> batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);

        if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
            criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
            criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
            batchInstanceList = find(criteria);
        }
    }
    return batchInstanceList;
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * An API to fetch all the batch instances by status list. Parameter firstResult set a limit upon the number of objects to be
 * retrieved. Parameter maxResults set the first result to be retrieved. Parameter orderList set the sort property and order of
 * that property. If orderList parameter is null or empty then this parameter is avoided.
 * //from w ww  . j a v a  2  s . c  o  m
 * @param statusList List<BatchInstanceStatus> status list of batch instance status.
 * @param firstResult the first result to retrieve, numbered from <tt>0</tt>
 * @param maxResults maxResults the maximum number of results
 * @param orderList List<Order> orderList set the sort property and order of that property. If orderList parameter is null or empty
 *            then this parameter is avoided.
 * @param filterClauseList List<BatchInstanceFilter> this will add the where clause to the criteria query based on the property
 *            name and value. If filterClauseList parameter is null or empty then this parameter is avoided.
 * @param batchPriorities List<BatchPriority> this will add the where clause to the criteria query based on the priority list
 *            selected. If batchPriorities parameter is null or empty then this parameter is avoided.
 * @param userName Current user name.
 * @param userRoles currentUserRoles
 * @param EphesoftUser current ephesoft-user
 * @param criteria EphesoftCriteria
 * @param searchString the searchString on which batch instances have to be fetched
 * @return List<BatchInstance> return the batch instance list.
 */
public List<BatchInstance> getBatchInstances(List<BatchInstanceStatus> statusList, final int firstResult,
        final int maxResults, final List<Order> orderList, final List<BatchInstanceFilter> filterClauseList,
        final List<BatchPriority> batchPriorities, String userName, final Set<String> userRoles,
        EphesoftUser ephesoftUser, final EphesoftCriteria criteria, final String searchString) {
    EphesoftCriteria criteriaLocal = null;
    if (criteria == null) {
        criteriaLocal = criteria();
    } else {
        criteriaLocal = criteria;
    }

    // For adding identifier as an criteria for result
    if (null != searchString && !searchString.isEmpty()) {
        String searchStringLocal = searchString.replaceAll("%", "\\\\%");
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, "%" + searchStringLocal + "%");
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, "%" + searchStringLocal + "%");

        LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
        criteriaLocal.add(searchCriteria);
    }

    if (null != statusList) {
        criteriaLocal.add(Restrictions.in(STATUS, statusList));
        // criteria.add(Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));
    }

    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteriaLocal.add(disjunction);

    }

    List<BatchInstance> batchInstaceList = new ArrayList<BatchInstance>();
    BatchInstanceFilter[] filters = null;
    Order[] orders = null;
    switch (ephesoftUser) {
    default:
        Set<String> batchClassIndentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        Set<String> batchInstanceIndentifiers = batchInstanceGroupsDao
                .getBatchInstanceIdentifierForUserRoles(userRoles);
        if ((null != batchClassIndentifiers && batchClassIndentifiers.size() > 0)
                || (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0)) {
            if (filterClauseList != null) {
                filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
            }
            if (orderList != null) {
                orders = orderList.toArray(new Order[orderList.size()]);
            }
            if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0
                    && null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                final Disjunction disjunction = Restrictions.disjunction();
                if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0) {
                    criteriaLocal.createAlias(BATCH_CLASS, BATCH_CLASS);
                    disjunction.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIndentifiers));
                }
                if (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                    disjunction.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIndentifiers));
                }
                criteriaLocal.add(disjunction);
            } else if (null != batchClassIndentifiers && batchClassIndentifiers.size() > 0) {
                criteriaLocal.createAlias(BATCH_CLASS, BATCH_CLASS);
                criteriaLocal.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIndentifiers));
            } else if (null != batchInstanceIndentifiers && batchInstanceIndentifiers.size() > 0) {
                criteriaLocal.add(Restrictions.in(BATCH_INSTANCE_IDENTIFIER, batchInstanceIndentifiers));
            }
            batchInstaceList = find(criteriaLocal, firstResult, maxResults, filters, orders);
        }
        break;
    }
    return batchInstaceList;
}

From source file:com.ephesoft.dcma.da.dao.hibernate.ConnectionDaoImpl.java

License:Open Source License

@Override
public List<Connections> getAllConnectionsExcludingDeleted() {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.DocumentTypeMappingConfigDaoImpl.java

License:Open Source License

@Override
public List<DocumentTypeMappingConfig> getDocumentTypeMappingConfigByConnectionId(long connectionID) {
    LOG.info(EphesoftStringUtil.concatenate("connection id is :", connectionID));
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.or(Restrictions.eq(FUZZY_CONNECTION_ID, connectionID),
            Restrictions.eq(DB_EXPORT_CONNECTION_ID, connectionID)));
    return this.find(criteria);
}

From source file:com.eryansky.modules.sys.web.OrganController.java

License:Apache License

/**
 * combogrid/*from  www.jav  a  2  s  .c o m*/
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "combogrid" })
@ResponseBody
public Datagrid<Organ> combogrid(String nameOrCode,
        @RequestParam(value = "ids", required = false) List<Long> ids, Integer rows) throws Exception {
    Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
    Criterion[] criterions = new Criterion[0];
    criterions = ArrayUtils.add(criterions, 0, statusCriterion);
    Criterion criterion = null;
    if (Collections3.isNotEmpty(ids)) {
        //in?
        Criterion inCriterion = Restrictions.in("id", ids);

        if (StringUtils.isNotBlank(nameOrCode)) {
            Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
            Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
            Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion);
            criterion = Restrictions.or(inCriterion, criterion1);
        } else {
            criterion = inCriterion;
        }
        //??
        criterions = ArrayUtils.add(criterions, 0, criterion);
    } else {
        if (StringUtils.isNotBlank(nameOrCode)) {
            Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
            Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
            criterion = Restrictions.or(nameCriterion, codeCriterion);
            //??
            criterions = ArrayUtils.add(criterions, 0, criterion);
        }
    }

    //
    Page<Organ> p = new Page<Organ>(rows);//
    p = organManager.findPageByCriteria(p, criterions);
    Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult());
    return dg;
}

From source file:com.eryansky.web.base.OrganAction.java

License:Apache License

/**
 * combogrid//from   ww w .  j a va2s  .  co  m
 * @return
 * @throws Exception
 */
public String combogrid() throws Exception {
    try {
        Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
        Criterion[] criterions = new Criterion[0];
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
        Criterion criterion = null;
        if (!Collections3.isEmpty(ids)) {
            //in?
            Criterion inCriterion = Restrictions.in("id", ids);

            if (StringUtils.isNotBlank(nameOrCode)) {
                Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
                Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
                Criterion criterion1 = Restrictions.or(nameCriterion, codeCriterion);
                criterion = Restrictions.or(inCriterion, criterion1);
            } else {
                criterion = inCriterion;
            }
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        } else {
            if (StringUtils.isNotBlank(nameOrCode)) {
                Criterion nameCriterion = Restrictions.like("name", nameOrCode, MatchMode.ANYWHERE);
                Criterion codeCriterion = Restrictions.like("code", nameOrCode, MatchMode.ANYWHERE);
                criterion = Restrictions.or(nameCriterion, codeCriterion);
                //??
                criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
            }
        }

        //
        Page<Organ> p = new Page<Organ>(rows);//
        p = organManager.findByCriteria(p, criterions);
        Datagrid<Organ> dg = new Datagrid<Organ>(p.getTotalCount(), p.getResult());
        Struts2Utils.renderJson(dg);
    } catch (Exception e) {
        throw e;
    }
    return null;
}

From source file:com.eryansky.web.base.UserAction.java

License:Apache License

/**
 * combogrid/* ww w.ja  v a  2 s.c o  m*/
 * @return
 * @throws Exception
 */
public String combogrid() throws Exception {
    try {
        Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue());
        Criterion[] criterions = new Criterion[0];
        criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion);
        Criterion criterion = null;
        if (!Collections3.isEmpty(ids)) {
            //in?
            Criterion inCriterion = Restrictions.in("id", ids);

            if (StringUtils.isNotBlank(loginNameOrName)) {
                Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName,
                        MatchMode.ANYWHERE);
                Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
                Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion);
                criterion = Restrictions.or(inCriterion, criterion1);
            } else {
                criterion = inCriterion;
            }
            //??
            criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
        } else {
            if (StringUtils.isNotBlank(loginNameOrName)) {
                Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName,
                        MatchMode.ANYWHERE);
                Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE);
                criterion = Restrictions.or(loginNameCriterion, nameCriterion);
                //??
                criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion);
            }
        }

        //
        Page<User> p = new Page<User>(rows);//
        p = userManager.findByCriteria(p, criterions);
        Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult());
        Struts2Utils.renderJson(dg);
    } catch (Exception e) {
        throw e;
    }
    return null;
}

From source file:com.eucalyptus.auth.DatabaseAccountProxy.java

License:Open Source License

@Override
public List<Authorization> lookupAccountGlobalAuthorizations(String resourceType) throws AuthException {
    String accountId = this.delegate.getAccountNumber();
    if (resourceType == null) {
        throw new AuthException("Empty resource type");
    }/*  w w  w .  j av  a  2s .  c  o  m*/
    EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class);
    try {
        @SuppressWarnings("unchecked")
        List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db
                .createCriteria(AuthorizationEntity.class).setCacheable(true)
                .add(Restrictions.and(Restrictions.eq("type", resourceType),
                        Restrictions.or(Restrictions.eq("effect", EffectType.Allow),
                                Restrictions.eq("effect", EffectType.Deny))))
                .createCriteria("statement").setCacheable(true).createCriteria("policy").setCacheable(true)
                .createCriteria("group").setCacheable(true)
                .add(Restrictions.eq("name", DatabaseAuthUtils.getUserGroupName(User.ACCOUNT_ADMIN)))
                .createCriteria("account").setCacheable(true).add(Restrictions.eq("accountNumber", accountId))
                .list();
        db.commit();
        List<Authorization> results = Lists.newArrayList();
        for (AuthorizationEntity auth : authorizations) {
            results.add(new DatabaseAuthorizationProxy(auth));
        }
        return results;
    } catch (Exception e) {
        db.rollback();
        Debugging.logError(LOG, e,
                "Failed to lookup global authorization for account " + accountId + ", type=" + resourceType);
        throw new AuthException("Failed to lookup account global auth", e);
    }
}

From source file:com.eucalyptus.auth.DatabaseRoleProxy.java

License:Open Source License

@Override
public List<Authorization> lookupAuthorizations(final String resourceType) throws AuthException {
    if (resourceType == null) {
        throw new AuthException("Empty resource type");
    }/*from   ww w . j  a  va  2s.c  o  m*/
    final EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class);
    try {
        @SuppressWarnings("unchecked")
        final List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db
                .createCriteria(AuthorizationEntity.class)
                .add(Restrictions.and(
                        Restrictions.or(Restrictions.eq("type", resourceType), Restrictions.eq("type", "*")),
                        Restrictions.in("effect",
                                EnumSet.of(Authorization.EffectType.Allow, Authorization.EffectType.Deny))))
                .createCriteria("statement").createCriteria("policy").createCriteria("role")
                .add(Restrictions.eq("roleId", getRoleId())).setCacheable(true).list();
        final List<Authorization> results = Lists.newArrayList();
        for (final AuthorizationEntity auth : authorizations) {
            results.add(new DatabaseAuthorizationProxy(auth));
        }
        return results;
    } catch (Exception e) {
        Debugging.logError(LOG, e,
                "Failed to lookup authorization for user with ID " + getRoleId() + ", type=" + resourceType);
        throw new AuthException("Failed to lookup auth", e);
    } finally {
        if (db.isActive())
            db.rollback();
    }
}

From source file:com.eucalyptus.auth.DatabaseUserProxy.java

License:Open Source License

@Override
public List<Authorization> lookupAuthorizations(String resourceType) throws AuthException {
    String userId = this.delegate.getUserId();
    if (resourceType == null) {
        throw new AuthException("Empty resource type");
    }//from  w ww.  ja v a 2 s .  com
    EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class);
    try {
        @SuppressWarnings("unchecked")
        List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db
                .createCriteria(AuthorizationEntity.class).setCacheable(true)
                .add(Restrictions.and(Restrictions.eq("type", resourceType),
                        Restrictions.or(Restrictions.eq("effect", EffectType.Allow),
                                Restrictions.eq("effect", EffectType.Deny))))
                .createCriteria("statement").setCacheable(true).createCriteria("policy").setCacheable(true)
                .createCriteria("group").setCacheable(true).createCriteria("users").setCacheable(true)
                .add(Restrictions.eq("userId", userId)).list();
        db.commit();
        List<Authorization> results = Lists.newArrayList();
        for (AuthorizationEntity auth : authorizations) {
            results.add(new DatabaseAuthorizationProxy(auth));
        }
        return results;
    } catch (Exception e) {
        db.rollback();
        Debugging.logError(LOG, e,
                "Failed to lookup authorization for user with ID " + userId + ", type=" + resourceType);
        throw new AuthException("Failed to lookup auth", e);
    }
}