Search in sources :

Example 1 with DataTablesParameters

use of org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters in project sw360portal by sw360.

the class DataTablesParserTest method testName.

@Test
public void testName() throws Exception {
    Map<String, String[]> parameterMap = getTestParameterMap();
    DataTablesParameters parameters = DataTablesParser.parametersFrom(parameterMap);
    assertThat(parameters, is(not(nullValue())));
    assertThat(parameters.getDraw(), is(1));
    assertThat(parameters.getLength(), is(10));
    assertThat(parameters.getStart(), is(5));
    DataTablesSearch search = parameters.getSearch();
    assertThat(search, is(equalTo(new DataTablesSearch("lookingFor", false))));
    List<DataTablesColumn> columns = parameters.getColumns();
    assertThat(columns, hasSize(1));
    DataTablesColumn column1 = columns.get(0);
    assertThat(column1.isSearchable(), is(true));
    assertThat(column1.getSearch(), is(equalTo(new DataTablesSearch("col0Sear", true))));
    List<DataTablesOrder> orders = parameters.getOrders();
    assertThat(columns, hasSize(1));
    DataTablesOrder order = orders.get(0);
    assertThat(order.getColumn(), is(0));
    assertThat(order.isAscending(), is(true));
}
Also used : DataTablesSearch(org.eclipse.sw360.portal.common.datatables.data.DataTablesSearch) DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) DataTablesColumn(org.eclipse.sw360.portal.common.datatables.data.DataTablesColumn) DataTablesOrder(org.eclipse.sw360.portal.common.datatables.data.DataTablesOrder) Test(org.junit.Test)

Example 2 with DataTablesParameters

use of org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters in project sw360portal by sw360.

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
    DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
    Release release = getReleaseForFossologyStatus(request);
    Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
    JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
    JSONArray data = JSONFactoryUtil.createJSONArray();
    for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
        JSONObject row = JSONFactoryUtil.createJSONObject();
        row.put("0", entry.getKey());
        row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
        data.put(row);
    }
    jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
    jsonResponse.put("data", data);
    jsonResponse.put("draw", parameters.getDraw());
    jsonResponse.put("recordsTotal", fossologyStatus.size());
    jsonResponse.put("recordsFiltered", fossologyStatus.size());
    writeJSON(request, response, jsonResponse);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 3 with DataTablesParameters

use of org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters in project sw360portal by sw360.

the class DataTablesParser method parametersFrom.

protected static DataTablesParameters parametersFrom(Map<String, String[]> parameterMap) {
    int draw = getSimpleInt(parameterMap, "draw");
    int length = getSimpleInt(parameterMap, "length");
    int start = getSimpleInt(parameterMap, "start");
    List<DataTablesOrder> orders = getOrders(parameterMap);
    List<DataTablesColumn> columns = getColumns(parameterMap);
    DataTablesSearch search = getSearch(parameterMap, "search");
    return new DataTablesParameters(draw, length, start, orders, columns, search);
}
Also used : DataTablesSearch(org.eclipse.sw360.portal.common.datatables.data.DataTablesSearch) DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) DataTablesColumn(org.eclipse.sw360.portal.common.datatables.data.DataTablesColumn) DataTablesOrder(org.eclipse.sw360.portal.common.datatables.data.DataTablesOrder)

Aggregations

DataTablesParameters (org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters)3 DataTablesColumn (org.eclipse.sw360.portal.common.datatables.data.DataTablesColumn)2 DataTablesOrder (org.eclipse.sw360.portal.common.datatables.data.DataTablesOrder)2 DataTablesSearch (org.eclipse.sw360.portal.common.datatables.data.DataTablesSearch)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 CommonUtils.nullToEmptyMap (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap)1 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1 Test (org.junit.Test)1