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