Search in sources :

Example 1 with Group

use of com.liferay.portal.kernel.model.Group in project index-checker by jorgediaz-lr.

the class IndexCheckerOutput method generateCSVOutput.

public static List<String> generateCSVOutput(PortletConfig portletConfig, String title, Locale locale, boolean groupBySite, Map<Company, Long> companyProcessTime, Map<Company, Map<Long, List<Comparison>>> companyResultDataMap, Map<Company, String> companyError) {
    List<String> out = new ArrayList<>();
    ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
    if (companyResultDataMap != null) {
        String[] headerKeys;
        if (groupBySite) {
            headerKeys = new String[] { "output.company", "output.groupid", "output.groupname", "output.entityclass", "output.entityname", "output.errortype", "output.count", "output.primarykeys" };
        } else {
            headerKeys = new String[] { "output.company", "output.entityclass", "output.entityname", "output.errortype", "output.count", "output.primarykeys" };
        }
        List<String> headers = OutputUtils.getHeaders(portletConfig, locale, headerKeys);
        out.add(OutputUtils.getCSVRow(headers));
    }
    for (Map.Entry<Company, Long> companyEntry : companyProcessTime.entrySet()) {
        Long processTime = companyEntry.getValue();
        Company company = companyEntry.getKey();
        String companyOutput = company.getCompanyId() + " - " + company.getWebId();
        if (companyResultDataMap != null) {
            Map<Long, List<Comparison>> resultDataMap = companyResultDataMap.get(company);
            int numberOfRows = 0;
            for (Map.Entry<Long, List<Comparison>> entry : resultDataMap.entrySet()) {
                String groupIdOutput = null;
                String groupNameOutput = null;
                if (groupBySite) {
                    try {
                        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);
                        }
                    } catch (Exception e) {
                        groupIdOutput = "" + entry.getKey();
                    }
                }
                for (Comparison comp : entry.getValue()) {
                    String lineError = OutputUtils.generateCSVRow(resourceBundle, comp, companyOutput, groupIdOutput, groupNameOutput, "error", locale, comp.getError(), -1);
                    if (lineError != null) {
                        numberOfRows++;
                        out.add(lineError);
                    }
                    for (String type : comp.getOutputTypes()) {
                        String attribute = "pk";
                        if (type.contains("right")) {
                            attribute = Field.UID;
                        }
                        String line = OutputUtils.generateCSVRow(resourceBundle, comp, companyOutput, groupIdOutput, groupNameOutput, type, attribute, locale);
                        if (line != null) {
                            numberOfRows++;
                            out.add(line);
                        }
                    }
                }
            }
            if (numberOfRows == 0) {
                out.add(StringPool.BLANK);
                out.add("No results found: your system is ok or perhaps you " + "have to change some filters");
            }
        }
        String errorMessage = companyError.get(company);
        if (Validator.isNotNull(errorMessage)) {
            out.add("Company: " + company.getCompanyId() + " - " + company.getWebId());
            out.add(errorMessage);
        }
        out.add(StringPool.BLANK);
        out.add("Executed " + title + " for company " + company.getCompanyId() + " in " + processTime + " ms");
        out.add(StringPool.BLANK);
    }
    Bundle bundle = FrameworkUtil.getBundle(IndexCheckerOutput.class);
    out.add("Version: " + bundle.getVersion());
    out.add(StringPool.BLANK);
    return out;
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) Comparison(jorgediazest.util.data.Comparison) ResourceBundle(java.util.ResourceBundle) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 2 with Group

use of com.liferay.portal.kernel.model.Group in project index-checker by jorgediaz-lr.

the class IndexCheckerPortlet method getSiteGroupDescriptions.

public List<String> getSiteGroupDescriptions(List<Long> siteGroupIds, Locale locale) {
    List<String> groupDescriptionList = new ArrayList<>();
    for (Long siteGroupId : siteGroupIds) {
        Group group = GroupLocalServiceUtil.fetchGroup(siteGroupId);
        String groupDescription = group.getName(locale);
        groupDescription = groupDescription.replace("LFR_ORGANIZATION", "(Org)");
        if (group.isCompany() && !group.isStagingGroup()) {
            groupDescription = GroupConstants.GLOBAL;
        }
        if (GroupConstants.GUEST.equals(groupDescription) || group.isCompany()) {
            groupDescription += " - " + group.getCompanyId();
        }
        groupDescriptionList.add(groupDescription);
    }
    return groupDescriptionList;
}
Also used : Group(com.liferay.portal.kernel.model.Group) ArrayList(java.util.ArrayList)

Example 3 with Group

use of com.liferay.portal.kernel.model.Group in project index-checker by jorgediaz-lr.

the class IndexCheckerPortlet method dumpToLog.

public static void dumpToLog(boolean groupBySite, Map<Long, List<Comparison>> comparisonDataMap, Locale locale) {
    if (!_log.isInfoEnabled()) {
        return;
    }
    for (Map.Entry<Long, List<Comparison>> entry : comparisonDataMap.entrySet()) {
        String groupTitle = null;
        Group group = GroupLocalServiceUtil.fetchGroup(entry.getKey());
        if ((group == null) && groupBySite) {
            groupTitle = "N/A";
        } else if (group != null) {
            groupTitle = group.getGroupId() + " - " + group.getName(locale);
        }
        if (groupTitle != null) {
            _log.info("");
            _log.info("---------------");
            _log.info("GROUP: " + groupTitle);
            _log.info("---------------");
        }
        for (Comparison comparison : entry.getValue()) {
            comparison.dumpToLog();
        }
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) Comparison(jorgediazest.util.data.Comparison) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 4 with Group

use of com.liferay.portal.kernel.model.Group in project index-checker by jorgediaz-lr.

the class IndexCheckerPortlet method getGroupIds.

public List<Long> getGroupIds(Company company, Set<ExecutionMode> executionMode, String[] filterGroupIdArr) {
    if ((filterGroupIdArr != null) && (filterGroupIdArr.length == 1) && filterGroupIdArr[0].equals("-1000")) {
        filterGroupIdArr = null;
    }
    boolean queryBySite = executionMode.contains(ExecutionMode.QUERY_BY_SITE);
    if (!queryBySite && (filterGroupIdArr == null)) {
        return null;
    }
    List<Group> groups = GroupLocalServiceUtil.getCompanyGroups(company.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    List<Long> groupIds = new ArrayList<>();
    boolean allSites = false;
    boolean userSites = false;
    if (filterGroupIdArr != null) {
        for (String filterGroupId : filterGroupIdArr) {
            if (filterGroupId.equals("0")) {
                groupIds.add(0L);
            }
            if (filterGroupId.equals("-1")) {
                allSites = true;
            }
            if (filterGroupId.equals("-2")) {
                userSites = true;
            }
        }
    }
    if (filterGroupIdArr == null) {
        groupIds.add(0L);
    }
    for (Group group : groups) {
        if (filterGroupIdArr == null) {
            groupIds.add(group.getGroupId());
            continue;
        }
        if (allSites && (group.isSite() || group.isStagingGroup() || group.isCompany())) {
            groupIds.add(group.getGroupId());
            continue;
        }
        if (userSites && (group.isUser() || group.isUserGroup())) {
            groupIds.add(group.getGroupId());
            continue;
        }
        String groupIdStr = "" + group.getGroupId();
        for (String filterGroupId : filterGroupIdArr) {
            if (groupIdStr.equals(filterGroupId)) {
                groupIds.add(group.getGroupId());
                break;
            }
        }
    }
    return groupIds;
}
Also used : Group(com.liferay.portal.kernel.model.Group) ArrayList(java.util.ArrayList)

Example 5 with Group

use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.

the class SetupPages method addMenuViewPortletIntoPage.

private static void addMenuViewPortletIntoPage(PageType page, Layout layout, MenuViewPortletType portlet, long companyId, long groupId) throws PortalException {
    if (isLinkPage(page)) {
        LOG.info(" ! SKIP-page is a link");
        return;
    }
    LOG.info("Adding MenuViewPortlet: " + portlet.getColumn() + "@" + portlet.getColumnPosition() + "-" + portlet.getPortletId() + "; " + portlet.getAdtTemplate() + ":" + portlet.getMenuName());
    PagePortletType toInsert = null;
    Long menuId = getMenuIdByName(groupId, portlet.getMenuName());
    if (menuId == null || menuId == 0L) {
        LOG.info(" ! SKIP-no such menu to add");
        return;
    }
    portlet.getPortletPreference().add(newPortletPreference("siteNavigationMenuId", String.valueOf(menuId)));
    DDMTemplate adtTemplate = getAdtTemplate(groupId, portlet.getAdtTemplate(), portlet.getAdtTemplateSiteUrl());
    if (adtTemplate == null) {
        LOG.info(" ! SKIP-no such template to display with");
        return;
    }
    portlet.getPortletPreference().add(newPortletPreference("displayStyle", "ddmTemplate_" + portlet.getAdtTemplate()));
    Group group = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, portlet.getAdtTemplateSiteUrl());
    portlet.getPortletPreference().add(// 
    newPortletPreference("displayStyleGroupId", String.valueOf(group.getPrimaryKey())));
    toInsert = new PagePortletType();
    toInsert.setColumn(portlet.getColumn());
    toInsert.setColumnPosition(portlet.getColumnPosition());
    toInsert.setPortletId(portlet.getPortletId());
    toInsert.setRolePermissions(portlet.getRolePermissions());
    for (Entry<String, String> e : CONFIG_MENU_VIEW_PREFERENCES.entrySet()) {
        toInsert.getPortletPreference().add(newPortletPreference(e.getKey(), e.getValue()));
    }
    toInsert.getPortletPreference().addAll(portlet.getPortletPreference());
    insertPortletIntoPage(page, layout, toInsert, companyId, groupId);
}
Also used : Group(com.liferay.portal.kernel.model.Group) PagePortletType(com.ableneo.liferay.portal.setup.domain.PagePortletType) DDMTemplate(com.liferay.dynamic.data.mapping.model.DDMTemplate)

Aggregations

Group (com.liferay.portal.kernel.model.Group)34 PortalException (com.liferay.portal.kernel.exception.PortalException)9 UserGroup (com.liferay.portal.kernel.model.UserGroup)6 ArrayList (java.util.ArrayList)6 Company (com.liferay.portal.kernel.model.Company)5 LayoutSet (com.liferay.portal.kernel.model.LayoutSet)4 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)4 ImexException (com.liferay.imex.core.util.exception.ImexException)3 SystemException (com.liferay.portal.kernel.exception.SystemException)3 List (java.util.List)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 PagePortletType (com.ableneo.liferay.portal.setup.domain.PagePortletType)2 Site (com.ableneo.liferay.portal.setup.domain.Site)2 Action (com.liferay.imex.role.model.Action)2 Resource (com.liferay.imex.role.model.Resource)2 ImexVirtualhost (com.liferay.imex.virtualhost.model.ImexVirtualhost)2 Role (com.liferay.portal.kernel.model.Role)2 UnicodeProperties (com.liferay.portal.kernel.util.UnicodeProperties)2 File (java.io.File)2