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;
}
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;
}
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;
}
Aggregations