Search in sources :

Example 1 with Conjunction

use of org.hibernate.criterion.Conjunction in project dhis2-core by dhis2.

the class HibernateMinMaxDataElementStore method parseFilter.

private Criteria parseFilter(Criteria criteria, List<String> filters) {
    Conjunction conjunction = Restrictions.conjunction();
    Schema schema = schemaService.getDynamicSchema(MinMaxDataElement.class);
    if (!filters.isEmpty()) {
        for (String filter : filters) {
            String[] split = filter.split(":");
            if (split.length != 3) {
                throw new QueryParserException("Invalid filter: " + filter);
            }
            QueryPath queryPath = queryPlanner.getQueryPath(schema, split[0]);
            Property property = queryParser.getProperty(schema, split[0]);
            Criterion restriction = getRestriction(property, queryPath.getPath(), split[1], split[2]);
            if (restriction != null) {
                conjunction.add(restriction);
                if (queryPath.haveAlias()) {
                    for (String alias : queryPath.getAlias()) {
                        criteria.createAlias(alias, alias);
                    }
                }
            }
        }
    }
    criteria.add(conjunction);
    return criteria;
}
Also used : QueryPath(org.hisp.dhis.query.planner.QueryPath) QueryParserException(org.hisp.dhis.query.QueryParserException) Criterion(org.hibernate.criterion.Criterion) Schema(org.hisp.dhis.schema.Schema) Conjunction(org.hibernate.criterion.Conjunction) Property(org.hisp.dhis.schema.Property)

Example 2 with Conjunction

use of org.hibernate.criterion.Conjunction in project openmrs-core by openmrs.

the class HibernateUtil method addAttributeCriteria.

/**
 * Adds attribute value criteria to the given criteria query
 *
 * @param criteria the criteria
 * @param serializedAttributeValues the serialized attribute values
 * @param <AT> the attribute type
 */
public static <AT extends AttributeType> void addAttributeCriteria(Criteria criteria, Map<AT, String> serializedAttributeValues) {
    Conjunction conjunction = Restrictions.conjunction();
    int a = 0;
    for (Map.Entry<AT, String> entry : serializedAttributeValues.entrySet()) {
        String alias = "attributes" + (a++);
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Location.class).setProjection(Projections.id());
        detachedCriteria.createAlias("attributes", alias);
        detachedCriteria.add(Restrictions.eq(alias + ".attributeType", entry.getKey()));
        detachedCriteria.add(Restrictions.eq(alias + ".valueReference", entry.getValue()));
        detachedCriteria.add(Restrictions.eq(alias + ".voided", false));
        conjunction.add(Property.forName("id").in(detachedCriteria));
    }
    criteria.add(conjunction);
}
Also used : Conjunction(org.hibernate.criterion.Conjunction) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Map(java.util.Map) Location(org.openmrs.Location)

Example 3 with Conjunction

use of org.hibernate.criterion.Conjunction in project openmrs-core by openmrs.

the class HibernateProviderDAO method getNameSearchExpression.

/**
 * Creates or that matches the input name with Provider-Person-Names (not voided)
 *
 * @param name
 * @return Junction
 */
private Junction getNameSearchExpression(String name) {
    MatchMode mode = MatchMode.ANYWHERE;
    Conjunction and = Restrictions.conjunction();
    and.add(Restrictions.eq("personName.voided", false));
    Disjunction or = Restrictions.disjunction();
    and.add(or);
    or.add(Restrictions.ilike("personName.givenName", name, mode));
    or.add(Restrictions.ilike("personName.middleName", name, mode));
    or.add(Restrictions.ilike("personName.familyName", name, mode));
    or.add(Restrictions.ilike("personName.familyName2", name, mode));
    return and;
}
Also used : MatchMode(org.hibernate.criterion.MatchMode) Disjunction(org.hibernate.criterion.Disjunction) Conjunction(org.hibernate.criterion.Conjunction)

Example 4 with Conjunction

use of org.hibernate.criterion.Conjunction in project candlepin by candlepin.

the class CheckJobStatusPermission method getCriteriaRestrictions.

@Override
@SuppressWarnings("checkstyle:indentation")
public Criterion getCriteriaRestrictions(Class entityClass) {
    if (!entityClass.equals(JobStatus.class)) {
        return null;
    }
    Conjunction conjunction = Restrictions.conjunction();
    // Org has to match.
    conjunction.add(Restrictions.in("ownerId", allowedOrgIds));
    conjunction.add(Restrictions.or(Restrictions.ne("targetType", JobStatus.TargetType.OWNER), Restrictions.and(Restrictions.eq("targetType", JobStatus.TargetType.OWNER), Restrictions.eqProperty("ownerId", "targetId"))));
    // If the principal is not a user, make sure to enforce a principalName match.
    if (!"user".equalsIgnoreCase(principalType)) {
        conjunction.add(Restrictions.eq("principalName", principalName));
    }
    return conjunction;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Conjunction(org.hibernate.criterion.Conjunction)

Example 5 with Conjunction

use of org.hibernate.criterion.Conjunction in project openmrs-core by openmrs.

the class HibernateProviderDAO method prepareProviderCriteria.

/**
 * Creates a Provider Criteria based on name
 *
 * @param name represents provider name
 * @param includeRetired
 * @return Criteria represents the hibernate criteria to search
 */
private Criteria prepareProviderCriteria(String name, boolean includeRetired) {
    if (StringUtils.isBlank(name)) {
        name = "%";
    }
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Provider.class).createAlias("person", "p", JoinType.LEFT_OUTER_JOIN);
    if (!includeRetired) {
        criteria.add(Restrictions.eq("retired", false));
    }
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.createAlias("p.names", "personName", JoinType.LEFT_OUTER_JOIN);
    Disjunction or = Restrictions.disjunction();
    or.add(Restrictions.ilike("identifier", name, getMatchMode()));
    or.add(Restrictions.ilike("name", name, MatchMode.ANYWHERE));
    Conjunction and = Restrictions.conjunction();
    or.add(and);
    String[] splitNames = name.split(" ");
    for (String splitName : splitNames) {
        and.add(getNameSearchExpression(splitName));
    }
    criteria.add(or);
    return criteria;
}
Also used : Disjunction(org.hibernate.criterion.Disjunction) Conjunction(org.hibernate.criterion.Conjunction) Criteria(org.hibernate.Criteria) Provider(org.openmrs.Provider)

Aggregations

Conjunction (org.hibernate.criterion.Conjunction)9 Disjunction (org.hibernate.criterion.Disjunction)3 MatchMode (org.hibernate.criterion.MatchMode)3 Criteria (org.hibernate.Criteria)2 Criterion (org.hibernate.criterion.Criterion)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1 SimpleExpression (org.hibernate.criterion.SimpleExpression)1 QueryParserException (org.hisp.dhis.query.QueryParserException)1 QueryPath (org.hisp.dhis.query.planner.QueryPath)1 Property (org.hisp.dhis.schema.Property)1 Schema (org.hisp.dhis.schema.Schema)1 Location (org.openmrs.Location)1 Provider (org.openmrs.Provider)1 AdministrationService (org.openmrs.api.AdministrationService)1 EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)1