use of com.liferay.portal.kernel.dao.search.SearchContainer in project index-checker by jorgediaz-lr.
the class IndexCheckerOutput method generateSearchContainer.
public static SearchContainer<Comparison> generateSearchContainer(PortletConfig portletConfig, RenderRequest renderRequest, boolean groupBySite, Map<Long, List<Comparison>> resultDataMap, PortletURL serverURL) {
Locale locale = renderRequest.getLocale();
ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
String[] headerKeys;
if (groupBySite) {
headerKeys = new String[] { "output.groupid", "output.groupname", "output.entityclass", "output.entityname", "output.errortype", "output.count", "output.primarykeys" };
} else {
headerKeys = new String[] { "output.entityclass", "output.entityname", "output.errortype", "output.count", "output.primarykeys" };
}
List<String> headerNames = OutputUtils.getHeaders(portletConfig, locale, headerKeys);
SearchContainer<Comparison> searchContainer = new SearchContainer<>(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.MAX_DELTA, serverURL, headerNames, null);
int numberOfRows = 0;
for (Map.Entry<Long, List<Comparison>> entry : resultDataMap.entrySet()) {
String groupIdOutput = null;
String groupNameOutput = null;
if (groupBySite) {
Group group = GroupLocalServiceUtil.fetchGroup(entry.getKey());
if (group == null) {
groupIdOutput = LanguageUtil.get(resourceBundle, "output.not-applicable-groupid");
groupNameOutput = LanguageUtil.get(resourceBundle, "output.not-applicable-groupname");
} else {
groupIdOutput = "" + group.getGroupId();
groupNameOutput = group.getName(locale);
}
}
List<Comparison> results = searchContainer.getResults();
if ((results == null) || results.isEmpty()) {
results = new ArrayList<>();
}
results.addAll(entry.getValue());
results = ListUtil.subList(results, searchContainer.getStart(), searchContainer.getEnd());
searchContainer.setResults(results);
List<ResultRow> resultRows = searchContainer.getResultRows();
for (Comparison comp : entry.getValue()) {
ResultRow rowError = OutputUtils.generateSearchContainerRow(resourceBundle, comp, groupIdOutput, groupNameOutput, "error", locale, numberOfRows, comp.getError());
if (rowError != null) {
numberOfRows++;
resultRows.add(rowError);
}
for (String type : comp.getOutputTypes()) {
String attribute = "pk";
if (type.contains("right")) {
attribute = Field.UID;
}
int maxSize = 0;
ResultRow row = OutputUtils.generateSearchContainerRow(resourceBundle, comp, groupIdOutput, groupNameOutput, type, attribute, locale, numberOfRows, maxSize);
if (row != null) {
numberOfRows++;
resultRows.add(row);
}
}
}
}
searchContainer.setTotal(numberOfRows);
return searchContainer;
}
Aggregations