Search in sources :

Example 1 with PaginationParameters

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

the class ComponentPortlet method serveComponentList.

private void serveComponentList(ResourceRequest request, ResourceResponse response) throws PortletException {
    HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
    PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest);
    handlePaginationSortOrder(request, paginationParameters);
    PaginationData pageData = new PaginationData();
    pageData.setRowsPerPage(paginationParameters.getDisplayLength());
    pageData.setDisplayStart(paginationParameters.getDisplayStart());
    pageData.setAscending(paginationParameters.isAscending().get());
    int sortParam = -1;
    if (paginationParameters.getSortingColumn().isPresent()) {
        sortParam = paginationParameters.getSortingColumn().get();
        if (sortParam == 1 && Integer.valueOf(paginationParameters.getEcho()) == 1) {
            sortParam = -1;
        }
    }
    pageData.setSortColumnNumber(sortParam);
    Map<PaginationData, List<Component>> pageDataComponentList = getFilteredComponentList(request, pageData);
    Map<String, Set<String>> filterMap = getComponentFilterMap(request);
    JSONArray jsonComponents = getComponentData(pageDataComponentList.values().iterator().next(), paginationParameters, filterMap);
    JSONObject jsonResult = createJSONObject();
    jsonResult.put(DATATABLE_RECORDS_TOTAL, pageDataComponentList.keySet().iterator().next().getTotalRowCount());
    jsonResult.put(DATATABLE_RECORDS_FILTERED, pageDataComponentList.keySet().iterator().next().getTotalRowCount());
    jsonResult.put(DATATABLE_DISPLAY_DATA, jsonComponents);
    try {
        writeJSON(request, response, jsonResult);
    } catch (IOException e) {
        log.error("Problem rendering RequestStatus", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with PaginationParameters

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

the class UserPortlet method serveUsersListPresentInCouchDB.

private void serveUsersListPresentInCouchDB(ResourceRequest request, ResourceResponse response) {
    HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
    PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest);
    PortletUtils.handlePaginationSortOrder(request, paginationParameters, USER_FILTERED_FIELDS, USER_NO_SORT);
    UserService.Iface client = thriftClients.makeUserClient();
    PaginationData pageData = new PaginationData();
    pageData.setRowsPerPage(paginationParameters.getDisplayLength());
    pageData.setDisplayStart(paginationParameters.getDisplayStart());
    pageData.setAscending(paginationParameters.isAscending().get());
    if (paginationParameters.getSortingColumn().isPresent()) {
        int sortParam = paginationParameters.getSortingColumn().get();
        if (sortParam == 0 && Integer.valueOf(paginationParameters.getEcho()) == 1) {
            pageData.setSortColumnNumber(-1);
        } else {
            pageData.setSortColumnNumber(paginationParameters.getSortingColumn().get());
        }
    } else {
        pageData.setSortColumnNumber(-1);
    }
    Map<String, Set<String>> filterMap = getUserFilterMap(originalServletRequest);
    Map<PaginationData, List<org.eclipse.sw360.datahandler.thrift.users.User>> usersWithPageData = getFilteredUsersList(request, pageData, client, filterMap);
    List<org.eclipse.sw360.datahandler.thrift.users.User> users = new ArrayList<>();
    PaginationData pgDt = new PaginationData();
    if (!CommonUtils.isNullOrEmptyMap(usersWithPageData)) {
        users = usersWithPageData.values().iterator().next();
        pgDt = usersWithPageData.keySet().iterator().next();
    }
    JSONArray jsonUsers = getUserData(users, paginationParameters, filterMap);
    JSONObject jsonResult = createJSONObject();
    jsonResult.put(DATATABLE_RECORDS_TOTAL, pgDt.getTotalRowCount());
    jsonResult.put(DATATABLE_RECORDS_FILTERED, pgDt.getTotalRowCount());
    jsonResult.put(DATATABLE_DISPLAY_DATA, jsonUsers);
    try {
        writeJSON(request, response, jsonResult);
    } catch (IOException e) {
        log.error("Problem rendering list of users present in couch db", e);
    }
}
Also used : PaginationData(org.eclipse.sw360.datahandler.thrift.PaginationData) ImmutableSet(com.google.common.collect.ImmutableSet) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray) UserUtils.userGroupFromString(org.eclipse.sw360.portal.users.UserUtils.userGroupFromString) HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with PaginationParameters

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

the class MyProjectsPortlet method serveProjectList.

private void serveProjectList(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    List<Project> myProjects = new ArrayList<>();
    User user = UserCacheHolder.getUserFromRequest(request);
    HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
    PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest);
    PortletUtils.handlePaginationSortOrder(request, paginationParameters, projectFilteredFields, PROJECT_NO_SORT);
    String rolesAndClearingStateSelected = request.getParameter("rolesandclearingstate");
    List<Boolean> listOfRolesAndClearingStateSelected = Arrays.stream(rolesAndClearingStateSelected.split(",")).map(role -> Boolean.parseBoolean(role)).collect(Collectors.toList());
    Boolean userChoice = Boolean.parseBoolean(request.getParameter("userChoice"));
    Map<String, Boolean> userRoles = new HashMap<>();
    for (int i = 0; i < listOfRoles.size(); i++) {
        userRoles.put(listOfRoles.get(i), listOfRolesAndClearingStateSelected.get(i));
    }
    Map<String, Boolean> clearingState = new HashMap<>();
    int rolesSize = listOfRoles.size();
    for (int j = 0; j < listOfClearingState.size(); j++) {
        clearingState.put(listOfClearingState.get(j), listOfRolesAndClearingStateSelected.get(j + rolesSize));
    }
    try {
        if (userChoice) {
            UserService.Iface userClient = thriftClients.makeUserClient();
            User userByEmail = userClient.getByEmail(user.getEmail());
            if (userByEmail != null) {
                userByEmail.setMyProjectsPreferenceSelection(userRoles);
                userClient.updateUser(userByEmail);
            }
        }
        myProjects = thriftClients.makeProjectClient().getMyProjects(user, userRoles);
    } catch (TException e) {
        log.error("Could not fetch myProjects from backend for user, " + user.getEmail(), e);
    }
    myProjects = getWithFilledClearingStateSummary(myProjects, user);
    myProjects = getWithFilledClearingStatus(myProjects, clearingState);
    JSONArray jsonProjects = getProjectData(myProjects, paginationParameters, request);
    JSONObject jsonResult = JSONFactoryUtil.createJSONObject();
    jsonResult.put("aaData", jsonProjects);
    jsonResult.put(DATATABLE_RECORDS_TOTAL, myProjects.size());
    jsonResult.put(DATATABLE_RECORDS_FILTERED, myProjects.size());
    try {
        writeJSON(request, response, jsonResult);
    } catch (IOException e) {
        log.error("Problem generating project list", e);
    }
}
Also used : ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary) Arrays(java.util.Arrays) User(org.eclipse.sw360.datahandler.thrift.users.User) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) ConfigurationPolicy(org.osgi.service.component.annotations.ConfigurationPolicy) ProjectClearingState(org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ImmutableList(com.google.common.collect.ImmutableList) DATATABLE_RECORDS_TOTAL(org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL) Map(java.util.Map) DATATABLE_RECORDS_FILTERED(org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_FILTERED) javax.portlet(javax.portlet) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) PortalUtil(com.liferay.portal.kernel.util.PortalUtil) TException(org.apache.thrift.TException) JSONFactoryUtil(com.liferay.portal.kernel.json.JSONFactoryUtil) IOException(java.io.IOException) Math.min(java.lang.Math.min) JSONObject(com.liferay.portal.kernel.json.JSONObject) Collectors(java.util.stream.Collectors) PaginationParser(org.eclipse.sw360.portal.common.datatables.PaginationParser) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) List(java.util.List) LanguageUtil(com.liferay.portal.kernel.language.LanguageUtil) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) Optional(java.util.Optional) MY_PROJECTS_PORTLET_NAME(org.eclipse.sw360.portal.common.PortalConstants.MY_PROJECTS_PORTLET_NAME) JSONArray(com.liferay.portal.kernel.json.JSONArray) Comparator(java.util.Comparator) Collections(java.util.Collections) PortletUtils(org.eclipse.sw360.portal.common.PortletUtils) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) HashMap(java.util.HashMap) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) ArrayList(java.util.ArrayList) JSONArray(com.liferay.portal.kernel.json.JSONArray) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 4 with PaginationParameters

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

the class ChangeLogsPortletUtils method serveChangeLogsList.

private JSONObject serveChangeLogsList(ResourceRequest request, ResourceResponse response, ChangeLogsService.Iface changeLogsClient) {
    HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
    PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest);
    if (!paginationParameters.getSortingColumn().isPresent()) {
        for (ChangeLogs._Fields filteredField : changeLogsFields) {
            if (!isNullOrEmpty(request.getParameter(filteredField.toString()))) {
                paginationParameters.setSortingColumn(Optional.of(CHANGELOGS_NO_SORT));
                break;
            }
        }
    }
    List<ChangeLogs> changeLogsList = getFilteredChangeLogList(request, changeLogsClient);
    JSONArray jsonProjects = getChangeLogData(changeLogsList, paginationParameters, request);
    JSONObject jsonResult = createJSONObject();
    jsonResult.put(DATATABLE_RECORDS_TOTAL, changeLogsList.size());
    jsonResult.put(DATATABLE_RECORDS_FILTERED, changeLogsList.size());
    jsonResult.put(DATATABLE_DISPLAY_DATA, jsonProjects);
    return jsonResult;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 5 with PaginationParameters

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

the class PaginationParser method parametersFrom.

protected static PaginationParameters parametersFrom(Map<String, String[]> parameterMap) {
    PaginationParameters paginationParameters = new PaginationParameters();
    paginationParameters.setEcho(getSimple(parameterMap, DATATABLE_ECHO));
    paginationParameters.setColumnNames(getSimple(parameterMap, DATATABLE_COLUMNS));
    paginationParameters.setColumnCount(getSimpleInt(parameterMap, DATATABLE_COLUMN_COUNT));
    paginationParameters.setDisplayLength(getSimpleInt(parameterMap, DATATABLE_DISPLAY_LENGTH));
    paginationParameters.setDisplayStart(getSimpleInt(parameterMap, DATATABLE_DISPLAY_START));
    paginationParameters.setAscending(isAscendingSortOrder(parameterMap, DATATABLE_SORT_DIRECTION));
    paginationParameters.setSortingColumn(getColumnSortIndexByParameterMap(parameterMap, DATATABLE_SORT_COLUMN));
    return paginationParameters;
}
Also used : PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters)

Aggregations

JSONArray (com.liferay.portal.kernel.json.JSONArray)9 JSONObject (com.liferay.portal.kernel.json.JSONObject)9 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)8 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)8 PaginationParameters (org.eclipse.sw360.portal.common.datatables.data.PaginationParameters)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 TException (org.apache.thrift.TException)2 CommonUtils.nullToEmptySet (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet)2 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)2 PaginationData (org.eclipse.sw360.datahandler.thrift.PaginationData)2 ChangeLogs (org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs)2 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)2 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 UserService (org.eclipse.sw360.datahandler.thrift.users.UserService)2 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1