Search in sources :

Example 1 with ModerationState

use of org.eclipse.sw360.datahandler.thrift.ModerationState in project sw360 by eclipse.

the class ModerationRequestRepository method queryViewWithPagination.

private Map<PaginationData, List<ModerationRequest>> queryViewWithPagination(String moderator, PaginationData pageData, boolean open) {
    final int rowsPerPage = pageData.getRowsPerPage();
    Map<PaginationData, List<ModerationRequest>> result = Maps.newHashMap();
    List<ModerationRequest> modReqs = Lists.newArrayList();
    final boolean ascending = pageData.isAscending();
    final int sortColumnNo = pageData.getSortColumnNumber();
    String query = null;
    final Selector typeSelector = eq("type", "moderation");
    final Selector openModerationState = or(eq("moderationState", "PENDING"), eq("moderationState", "INPROGRESS"));
    final Selector closedModerationState = or(eq("moderationState", "APPROVED"), eq("moderationState", "REJECTED"));
    final Selector filterByModeratorSelector = PredicatedOperation.elemMatch("moderators", PredicateExpression.eq(moderator));
    final Selector emptyComponentTypeSelector = or(Expression.exists("componentType", false), eq("componentType", ""));
    final Selector commonSelector = and(typeSelector, open ? openModerationState : closedModerationState, filterByModeratorSelector);
    QueryBuilder qb = new QueryBuilder(commonSelector);
    if (rowsPerPage != -1) {
        qb.limit(rowsPerPage);
    }
    qb.skip(pageData.getDisplayStart());
    switch(sortColumnNo) {
        case -1:
            qb = qb.useIndex("byModerators");
            qb = ascending ? qb.sort(Sort.asc("moderators")) : qb.sort(Sort.desc("moderators"));
            query = qb.build();
            break;
        case 0:
            qb = qb.useIndex("byDate");
            qb = ascending ? qb.sort(Sort.asc("timestamp")) : qb.sort(Sort.desc("timestamp"));
            query = qb.build();
            break;
        case 1:
            qb = qb.useIndex("byComponentType");
            qb = ascending ? qb.sort(Sort.asc("componentType")) : qb.sort(Sort.desc("componentType"));
            query = qb.build();
            break;
        case 2:
            qb = qb.useIndex("byDocumentName");
            qb = ascending ? qb.sort(Sort.asc("documentName")) : qb.sort(Sort.desc("documentName"));
            query = qb.build();
            break;
        case 3:
            qb = qb.useIndex("byUsers");
            qb = ascending ? qb.sort(Sort.asc("requestingUser")) : qb.sort(Sort.desc("requestingUser"));
            query = qb.build();
            break;
        case 4:
            qb = qb.useIndex("byDepartment");
            qb = ascending ? qb.sort(Sort.asc("requestingUserDepartment")) : qb.sort(Sort.desc("requestingUserDepartment"));
            query = qb.build();
            break;
        case 5:
            qb = qb.useIndex("byModerators");
            qb = ascending ? qb.sort(Sort.asc("moderators")) : qb.sort(Sort.desc("moderators"));
            query = qb.build();
            break;
        case 6:
            qb = qb.useIndex("byModerationState");
            qb = ascending ? qb.sort(Sort.asc("moderationState")) : qb.sort(Sort.desc("moderationState"));
            query = qb.build();
            break;
        default:
            break;
    }
    try {
        QueryResult<ModerationRequest> queryResult = getConnector().getQueryResult(query, ModerationRequest.class);
        modReqs = queryResult.getDocs();
        if (1 == sortColumnNo) {
            final Selector selectorCompType = and(typeSelector, open ? openModerationState : closedModerationState, filterByModeratorSelector, emptyComponentTypeSelector);
            QueryBuilder emptyCTypeQb = new QueryBuilder(selectorCompType);
            emptyCTypeQb.limit(rowsPerPage);
            emptyCTypeQb.skip(pageData.getDisplayStart());
            QueryResult<ModerationRequest> queryResultWithoutSorting = getConnector().getQueryResult(emptyCTypeQb.build(), ModerationRequest.class);
            List<ModerationRequest> mods = queryResultWithoutSorting.getDocs();
            if (ascending) {
                mods.addAll(modReqs);
                modReqs = mods;
            } else {
                modReqs.addAll(mods);
            }
        }
    } catch (Exception e) {
        log.error("Error getting moderation requests", e);
    }
    result.put(pageData, modReqs);
    return result;
}
Also used : PaginationData(org.eclipse.sw360.datahandler.thrift.PaginationData) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) ArrayList(java.util.ArrayList) List(java.util.List) QueryBuilder(com.cloudant.client.api.query.QueryBuilder) IOException(java.io.IOException) Selector(com.cloudant.client.api.query.Selector)

Example 2 with ModerationState

use of org.eclipse.sw360.datahandler.thrift.ModerationState in project sw360 by eclipse.

the class AbstractTasksPortlet method getModerationData.

public JSONArray getModerationData(List<ModerationRequest> moderationList) {
    JSONArray projectData = JSONFactoryUtil.createJSONArray();
    for (ModerationRequest moderationRequest : moderationList) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put("DT_RowId", moderationRequest.getId());
        jsonObject.put("id", moderationRequest.getId());
        jsonObject.put("name", moderationRequest.getDocumentName());
        jsonObject.put("state", moderationState(moderationRequest.getModerationState()));
        projectData.put(jsonObject);
    }
    return projectData;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 3 with ModerationState

use of org.eclipse.sw360.datahandler.thrift.ModerationState in project sw360 by eclipse.

the class ModerationPortlet method getModerationData.

private JSONArray getModerationData(List<ModerationRequest> moderationList, PaginationParameters paginationParameters, ResourceRequest request, boolean open) {
    Map<String, Set<String>> filterMap = getModerationFilterMap(request);
    int count = PortletUtils.getProjectDataCount(paginationParameters, moderationList.size());
    User user = UserCacheHolder.getUserFromRequest(request);
    boolean isClearingAdmin = PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user);
    JSONArray moderationRequestData = createJSONArray();
    final int start = filterMap.isEmpty() ? 0 : paginationParameters.getDisplayStart();
    for (int i = start; i < count; i++) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        ModerationRequest modreq = moderationList.get(i);
        jsonObject.put("id", modreq.getId());
        jsonObject.put("renderTimestamp", modreq.getTimestamp() + "");
        jsonObject.put("componentType", printEnumValueWithTooltip(request, modreq.getComponentType()));
        jsonObject.put("documentName", modreq.getDocumentName());
        jsonObject.put("requestingUser", UserUtils.displayUser(modreq.getRequestingUser(), null));
        jsonObject.put("requestingUserDepartment", modreq.getRequestingUserDepartment());
        jsonObject.put("moderators", displayUserCollection(modreq.getModerators()));
        jsonObject.put("moderationState", printEnumValueWithTooltip(request, modreq.getModerationState()));
        if (!open) {
            jsonObject.put("isClearingAdmin", isClearingAdmin);
        }
        moderationRequestData.put(jsonObject);
    }
    return moderationRequestData;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) CommonUtils.nullToEmptySet(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet) User(org.eclipse.sw360.datahandler.thrift.users.User) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Aggregations

ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 JSONArray (com.liferay.portal.kernel.json.JSONArray)2 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 QueryBuilder (com.cloudant.client.api.query.QueryBuilder)1 Selector (com.cloudant.client.api.query.Selector)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CommonUtils.nullToEmptySet (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet)1 PaginationData (org.eclipse.sw360.datahandler.thrift.PaginationData)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1