use of com.haulmont.restapi.service.filter.RestFilterParseResult in project cuba by cuba-platform.
the class EntitiesControllerManager method searchEntities.
public EntitiesSearchResult searchEntities(String entityName, String filterJson, @Nullable String viewName, @Nullable Integer limit, @Nullable Integer offset, @Nullable String sort, @Nullable Boolean returnNulls, @Nullable Boolean returnCount, @Nullable Boolean dynamicAttributes, @Nullable String modelVersion) {
if (filterJson == null) {
throw new RestAPIException("Cannot parse entities filter", "Entities filter cannot be null", HttpStatus.BAD_REQUEST);
}
entityName = restControllerUtils.transformEntityNameIfRequired(entityName, modelVersion, JsonTransformationDirection.FROM_VERSION);
MetaClass metaClass = restControllerUtils.getMetaClass(entityName);
checkCanReadEntity(metaClass);
RestFilterParseResult filterParseResult;
try {
filterParseResult = restFilterParser.parse(filterJson, metaClass);
} catch (RestFilterParseException e) {
throw new RestAPIException("Cannot parse entities filter", e.getMessage(), HttpStatus.BAD_REQUEST, e);
}
String jpqlWhere = filterParseResult.getJpqlWhere().replace("{E}", "e");
Map<String, Object> queryParameters = filterParseResult.getQueryParameters();
String queryString = "select e from " + entityName + " e where " + jpqlWhere;
String json = _loadEntitiesList(queryString, viewName, limit, offset, sort, returnNulls, dynamicAttributes, modelVersion, metaClass, queryParameters);
Long count = null;
if (BooleanUtils.isTrue(returnCount)) {
LoadContext ctx = LoadContext.create(metaClass.getJavaClass()).setQuery(LoadContext.createQuery(queryString).setParameters(queryParameters));
count = dataManager.getCount(ctx);
}
return new EntitiesSearchResult(json, count);
}
Aggregations