Search in sources :

Example 1 with ResultRow

use of com.liferay.portal.kernel.dao.search.ResultRow 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;
}
Also used : Locale(java.util.Locale) ResultRow(com.liferay.portal.kernel.dao.search.ResultRow) Group(com.liferay.portal.kernel.model.Group) SearchContainer(com.liferay.portal.kernel.dao.search.SearchContainer) Comparison(jorgediazest.util.data.Comparison) ResourceBundle(java.util.ResourceBundle) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 2 with ResultRow

use of com.liferay.portal.kernel.dao.search.ResultRow in project index-checker by jorgediaz-lr.

the class OutputUtils method generateSearchContainerRow.

public static ResultRow generateSearchContainerRow(ResourceBundle resourceBundle, Comparison comp, String groupIdOutput, String groupNameOutput, String type, Locale locale, int numberOfRows, String htmlOutput, int outputSize) {
    if (Validator.isNull(htmlOutput)) {
        return null;
    }
    ResultRow row = new com.liferay.taglib.search.ResultRow(comp, type, numberOfRows);
    if ((groupIdOutput != null) && (groupNameOutput != null)) {
        row.addText(groupIdOutput);
        row.addText(groupNameOutput);
    }
    String output = HtmlUtil.escape(LanguageUtil.get(resourceBundle, "output." + type));
    row.addText(HtmlUtil.escape(comp.getModelName()));
    row.addText(HtmlUtil.escape(comp.getModelDisplayName(locale)));
    row.addText(output.replace(" ", "&nbsp;"));
    if (outputSize < 0) {
        row.addText(StringPool.BLANK);
    } else {
        row.addText(StringPool.BLANK + outputSize);
    }
    row.addText(htmlOutput);
    return row;
}
Also used : ResultRow(com.liferay.portal.kernel.dao.search.ResultRow)

Aggregations

ResultRow (com.liferay.portal.kernel.dao.search.ResultRow)2 SearchContainer (com.liferay.portal.kernel.dao.search.SearchContainer)1 Group (com.liferay.portal.kernel.model.Group)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 Comparison (jorgediazest.util.data.Comparison)1