use of org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL 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");
}
}
use of org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL in project sw360 by eclipse.
the class UserPortlet method serveUsersListAbsentInCouchDB.
private void serveUsersListAbsentInCouchDB(ResourceRequest request, ResourceResponse response) {
Set<String> setOfEmailOfUsersPresentInCouchDB = new TreeSet<String>();
try {
UserService.Iface client = thriftClients.makeUserClient();
setOfEmailOfUsersPresentInCouchDB = CommonUtils.nullToEmptySet(client.getUserEmails());
} catch (TException e) {
log.error("Problem getting departments/emails of all user.", e);
}
final Set<String> setOfEmailOfUsersPresentInCouchDBFinal = setOfEmailOfUsersPresentInCouchDB;
List<org.eclipse.sw360.datahandler.thrift.users.User> usersAbsentInCouchDB;
List<User> liferayUsers;
try {
liferayUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
} catch (SystemException e) {
log.error("Could not get user List from liferay", e);
liferayUsers = Collections.emptyList();
}
usersAbsentInCouchDB = liferayUsers.stream().filter(liferayUser -> !setOfEmailOfUsersPresentInCouchDBFinal.contains(liferayUser.getEmailAddress())).filter(liferayUser -> {
String firstName = liferayUser.getFirstName();
String lastName = liferayUser.getLastName();
String emailAddress = liferayUser.getEmailAddress();
List<Organization> organizations;
try {
organizations = liferayUser.getOrganizations();
} catch (PortalException | SystemException e) {
return false;
}
String department = "";
if (organizations != null && organizations.size() > 0) {
department = organizations.get(0).getName();
}
String userGroup = "";
List<Role> roles;
try {
roles = liferayUser.getRoles();
} catch (SystemException e) {
return false;
}
List<String> roleNames = new ArrayList<>();
for (Role role : roles) {
roleNames.add(role.getName());
}
for (UserGroup group : UserGroup.values()) {
String roleConstantFromUserGroup = getRoleConstantFromUserGroup(group);
if (roleNames.contains(roleConstantFromUserGroup)) {
userGroup = group.toString();
break;
}
}
String gid = liferayUser.getScreenName();
String passwordHash = liferayUser.getPassword();
return !(isNullOrEmpty(firstName) || isNullOrEmpty(lastName) || isNullOrEmpty(emailAddress) || isNullOrEmpty(department) || isNullOrEmpty(userGroup) || isNullOrEmpty(gid) || isNullOrEmpty(passwordHash));
}).map(liferayUser -> {
String emailAddress = liferayUser.getEmailAddress();
String department = null;
List<String> primaryRoles = liferayUser.getRoles().stream().map(role -> role.getName()).collect(Collectors.toList());
try {
department = liferayUser.getOrganizations().get(0).getName();
} catch (PortalException pe) {
log.error("Error occured while retrieving Organisation name of the user. ", pe);
}
return new org.eclipse.sw360.datahandler.thrift.users.User().setGivenname(liferayUser.getFirstName()).setLastname(liferayUser.getLastName()).setDepartment(department).setPrimaryRoles(primaryRoles).setEmail(emailAddress);
}).collect(Collectors.toList());
JSONArray userRequestData = createJSONArray();
for (org.eclipse.sw360.datahandler.thrift.users.User user : usersAbsentInCouchDB) {
createUserJsonObject(user, userRequestData, true);
}
JSONObject jsonResult = createJSONObject();
jsonResult.put(DATATABLE_RECORDS_TOTAL, usersAbsentInCouchDB.size());
jsonResult.put(DATATABLE_RECORDS_FILTERED, usersAbsentInCouchDB.size());
jsonResult.put(DATATABLE_DISPLAY_DATA, userRequestData);
try {
writeJSON(request, response, jsonResult);
} catch (IOException e) {
log.error("Problem rendering list of users absent in couch db", e);
}
}
use of org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL 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);
}
}
use of org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL 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);
}
}
use of org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL 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;
}
Aggregations