use of com.haulmont.restapi.data.EntitiesSearchResult in project cuba by cuba-platform.
the class EntitiesController method loadEntitiesList.
@GetMapping("/{entityName}")
public ResponseEntity<String> loadEntitiesList(@PathVariable String entityName, @RequestParam(required = false) String view, @RequestParam(required = false) Integer limit, @RequestParam(required = false) Integer offset, @RequestParam(required = false) String sort, @RequestParam(required = false) Boolean returnNulls, @RequestParam(required = false) Boolean returnCount, @RequestParam(required = false) Boolean dynamicAttributes, @RequestParam(required = false) String modelVersion) {
EntitiesSearchResult entitiesSearchResult = entitiesControllerManager.loadEntitiesList(entityName, view, limit, offset, sort, returnNulls, returnCount, dynamicAttributes, modelVersion);
ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(HttpStatus.OK);
if (BooleanUtils.isTrue(returnCount)) {
responseBuilder.header("X-Total-Count", entitiesSearchResult.getCount().toString());
}
return responseBuilder.body(entitiesSearchResult.getJson());
}
use of com.haulmont.restapi.data.EntitiesSearchResult in project cuba by cuba-platform.
the class EntitiesController method searchEntitiesListGet.
@GetMapping("/{entityName}/search")
public ResponseEntity<String> searchEntitiesListGet(@PathVariable String entityName, @RequestParam String filter, @RequestParam(required = false) String view, @RequestParam(required = false) Integer limit, @RequestParam(required = false) Integer offset, @RequestParam(required = false) String sort, @RequestParam(required = false) Boolean returnNulls, @RequestParam(required = false) Boolean returnCount, @RequestParam(required = false) Boolean dynamicAttributes, @RequestParam(required = false) String modelVersion) {
EntitiesSearchResult entitiesSearchResult = entitiesControllerManager.searchEntities(entityName, filter, view, limit, offset, sort, returnNulls, returnCount, dynamicAttributes, modelVersion);
ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(HttpStatus.OK);
if (BooleanUtils.isTrue(returnCount)) {
responseBuilder.header("X-Total-Count", entitiesSearchResult.getCount().toString());
}
return responseBuilder.body(entitiesSearchResult.getJson());
}
use of com.haulmont.restapi.data.EntitiesSearchResult 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);
}
use of com.haulmont.restapi.data.EntitiesSearchResult in project cuba by cuba-platform.
the class EntitiesControllerManager method loadEntitiesList.
public EntitiesSearchResult loadEntitiesList(String entityName, @Nullable String viewName, @Nullable Integer limit, @Nullable Integer offset, @Nullable String sort, @Nullable Boolean returnNulls, @Nullable Boolean returnCount, @Nullable Boolean dynamicAttributes, @Nullable String modelVersion) {
entityName = restControllerUtils.transformEntityNameIfRequired(entityName, modelVersion, JsonTransformationDirection.FROM_VERSION);
MetaClass metaClass = restControllerUtils.getMetaClass(entityName);
checkCanReadEntity(metaClass);
String queryString = "select e from " + entityName + " e";
String json = _loadEntitiesList(queryString, viewName, limit, offset, sort, returnNulls, dynamicAttributes, modelVersion, metaClass, new HashMap<>());
json = restControllerUtils.transformJsonIfRequired(entityName, modelVersion, JsonTransformationDirection.TO_VERSION, json);
Long count = null;
if (BooleanUtils.isTrue(returnCount)) {
LoadContext ctx = LoadContext.create(metaClass.getJavaClass()).setQuery(LoadContext.createQuery(queryString));
count = dataManager.getCount(ctx);
}
return new EntitiesSearchResult(json, count);
}
use of com.haulmont.restapi.data.EntitiesSearchResult in project cuba by cuba-platform.
the class EntitiesController method searchEntitiesListPost.
@PostMapping("/{entityName}/search")
public ResponseEntity<String> searchEntitiesListPost(@PathVariable String entityName, @RequestBody String requestBodyJson) {
EntitiesSearchResult entitiesSearchResult = entitiesControllerManager.searchEntities(entityName, requestBodyJson);
ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(HttpStatus.OK);
JsonObject requestJsonObject = new JsonParser().parse(requestBodyJson).getAsJsonObject();
JsonPrimitive returnCount = requestJsonObject.getAsJsonPrimitive("returnCount");
if (returnCount != null && returnCount.getAsBoolean()) {
responseBuilder.header("X-Total-Count", entitiesSearchResult.getCount().toString());
}
return responseBuilder.body(entitiesSearchResult.getJson());
}
Aggregations