use of org.hisp.dhis.gist.GistQuery.Filter in project dhis2-core by dhis2.
the class DefaultGistAccessControl method canReadObject.
@Override
public boolean canReadObject(Class<? extends PrimaryKeyObject> type, String uid) {
if (!IdentifiableObject.class.isAssignableFrom(type)) {
return true;
}
@SuppressWarnings("unchecked") Class<? extends IdentifiableObject> ioType = (Class<? extends IdentifiableObject>) type;
if (!aclService.isClassShareable(ioType)) {
return aclService.canRead(currentUser, ioType);
}
List<?> res = gistService.gist(GistQuery.builder().elementType(ioType).autoType(GistAutoType.M).fields(singletonList(new Field("sharing", Transform.NONE))).filters(singletonList(new Filter("id", Comparison.EQ, uid))).build());
Sharing sharing = res.isEmpty() ? new Sharing() : (Sharing) res.get(0);
BaseIdentifiableObject object = new BaseIdentifiableObject();
object.setSharing(sharing);
return aclService.canRead(currentUser, object, ioType);
}
use of org.hisp.dhis.gist.GistQuery.Filter in project dhis2-core by dhis2.
the class GistBuilder method createFiltersHQL.
private String createFiltersHQL() {
String rootJunction = query.isAnyFilter() ? " or " : " and ";
List<Filter> filters = query.getFilters();
if (!query.hasFilterGroups()) {
return join(filters, rootJunction, "1=1", this::createFilterHQL);
}
String groupJunction = query.isAnyFilter() ? " and " : " or ";
Map<Integer, List<Filter>> grouped = filters.stream().collect(groupingBy(Filter::getGroup, toList()));
StringBuilder hql = new StringBuilder();
for (List<Filter> group : grouped.values()) {
if (!group.isEmpty()) {
hql.append('(');
for (Filter f : group) {
int index = filters.indexOf(f);
hql.append(createFilterHQL(index, f));
hql.append(groupJunction);
}
hql.append("1=1");
hql.append(')');
}
hql.append(rootJunction);
}
hql.append("1=1");
return hql.toString().replaceAll("(?: and | or )1=1", "");
}
use of org.hisp.dhis.gist.GistQuery.Filter in project dhis2-core by dhis2.
the class GistBuilder method addCountParameters.
public void addCountParameters(BiConsumer<String, Object> dest, BiFunction<String, Class<?>, Object> argumentParser) {
Owner owner = query.getOwner();
if (owner != null) {
dest.accept("OwnerId", owner.getId());
}
int i = 0;
for (Filter filter : query.getFilters()) {
Comparison operator = filter.getOperator();
if (!operator.isUnary() && !operator.isAccessCompare()) {
Object value = filter.isAttribute() ? filter.getValue()[0] : getParameterValue(context.resolveMandatory(filter.getPropertyPath()), filter, argumentParser);
dest.accept("f_" + i, operator.isStringCompare() ? completeLikeExpression(operator, stringParameterValue(operator, value)) : value);
}
i++;
}
}
use of org.hisp.dhis.gist.GistQuery.Filter in project dhis2-core by dhis2.
the class GistPlanner method withPresetFields.
/**
* Expands any field presets into individual fields while taking explicitly
* removed fields into account.
*/
private List<Field> withPresetFields(List<Field> fields) {
Set<String> explicit = fields.stream().map(Field::getPropertyPath).collect(toSet());
List<Field> expanded = new ArrayList<>();
for (Field f : fields) {
String path = f.getPropertyPath();
if (isPresetField(path)) {
Schema schema = context.getHome();
Predicate<Property> canRead = getAccessFilter(schema);
schema.getProperties().stream().filter(getPresetFilter(path)).sorted(GistPlanner::propertyTypeOrder).forEach(p -> {
if (!explicit.contains(p.key()) && !explicit.contains("-" + p.key()) && !explicit.contains("!" + p.key())) {
if (canRead.test(p)) {
expanded.add(new Field(p.key(), Transform.AUTO));
}
addReferenceFields(expanded, path, schema, p);
}
});
} else if (isExcludeField(path)) {
expanded.removeIf(field -> field.getPropertyPath().equals(path.substring(1)));
} else {
expanded.add(f);
}
}
return expanded;
}
Aggregations