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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations