Search in sources :

Example 1 with TablePageQuery

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;
}
Also used : TablePage(org.activiti.engine.management.TablePage) DataResponse(org.activiti.rest.common.api.DataResponse) TablePageQuery(org.activiti.engine.management.TablePageQuery) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TablePageQuery

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapItem(org.activiti.explorer.data.MapItem) Item(com.vaadin.data.Item) TablePageQuery(org.activiti.engine.management.TablePageQuery) MapItem(org.activiti.explorer.data.MapItem) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TablePageQuery (org.activiti.engine.management.TablePageQuery)2 Item (com.vaadin.data.Item)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 TablePage (org.activiti.engine.management.TablePage)1 MapItem (org.activiti.explorer.data.MapItem)1 DataResponse (org.activiti.rest.common.api.DataResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1