use of org.activiti.engine.management.TablePageQuery in project Activiti by Activiti.
the class TableDataResource method getTableData.
@RequestMapping(value = "/management/tables/{tableName}/data", method = RequestMethod.GET, produces = "application/json")
public DataResponse getTableData(@PathVariable String tableName, @RequestParam Map<String, String> allRequestParams) {
// Check if table exists before continuing
if (managementService.getTableMetaData(tableName) == null) {
throw new ActivitiObjectNotFoundException("Could not find a table with name '" + tableName + "'.", String.class);
}
String orderAsc = allRequestParams.get("orderAscendingColumn");
String orderDesc = allRequestParams.get("orderDescendingColumn");
if (orderAsc != null && orderDesc != null) {
throw new ActivitiIllegalArgumentException("Only one of 'orderAscendingColumn' or 'orderDescendingColumn' can be supplied.");
}
Integer start = null;
if (allRequestParams.containsKey("start")) {
start = Integer.valueOf(allRequestParams.get("start"));
}
if (start == null) {
start = 0;
}
Integer size = null;
if (allRequestParams.containsKey("size")) {
size = Integer.valueOf(allRequestParams.get("size"));
}
if (size == null) {
size = DEFAULT_RESULT_SIZE;
}
DataResponse response = new DataResponse();
TablePageQuery tablePageQuery = managementService.createTablePageQuery().tableName(tableName);
if (orderAsc != null) {
tablePageQuery.orderAsc(orderAsc);
response.setOrder("asc");
response.setSort(orderAsc);
}
if (orderDesc != null) {
tablePageQuery.orderDesc(orderDesc);
response.setOrder("desc");
response.setSort(orderDesc);
}
TablePage listPage = tablePageQuery.listPage(start, size);
response.setSize(((Long) listPage.getSize()).intValue());
response.setStart(((Long) listPage.getFirstResult()).intValue());
response.setTotal(listPage.getTotal());
response.setData(listPage.getRows());
return response;
}
use of org.activiti.engine.management.TablePageQuery in project Activiti by Activiti.
the class TableDataQuery method loadItems.
public List<Item> loadItems(int start, int count) {
TablePageQuery query = managementService.createTablePageQuery().tableName(tableName);
if (sortPropertyIds != null && sortPropertyIds.length > 0) {
for (int i = 0; i < sortPropertyIds.length; i++) {
// all container properties for table data are Strings
String column = (String) sortPropertyIds[i];
if (sortPropertyIdsAscending[i] == true) {
query.orderAsc(column);
} else {
query.orderDesc(column);
}
}
}
List<Map<String, Object>> rows = query.listPage(start, count).getRows();
List<Item> items = new ArrayList<Item>();
for (Map<String, Object> row : rows) {
HashMap<String, Object> newRow = new HashMap<String, Object>();
for (Entry<String, Object> rowEntry : row.entrySet()) {
String key = rowEntry.getKey();
if (key != null) {
key = key.toUpperCase();
}
newRow.put(key, rowEntry.getValue());
}
items.add(new MapItem(newRow));
}
return items;
}
Aggregations