Search in sources :

Example 31 with Group

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

the class SetupOrganizations method setupOrganizations.

public static void setupOrganizations(final Iterable<com.ableneo.liferay.portal.setup.domain.Organization> organizations, final Organization parentOrg, final Group parentGroup) {
    for (com.ableneo.liferay.portal.setup.domain.Organization organization : organizations) {
        try {
            Organization liferayOrg = null;
            Group liferayGroup = null;
            long groupId = -1;
            long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
            try {
                Organization org = OrganizationLocalServiceUtil.getOrganization(companyId, organization.getName());
                liferayGroup = org.getGroup();
                groupId = org.getGroupId();
                liferayOrg = org;
                LOG.info(String.format("Setup: Organization %1$s already exist in system, not creating...", organization.getName()));
            } catch (PortalException | SystemException e) {
                LOG.debug("Organization does not exist.", e);
            }
            if (groupId == -1) {
                LOG.info(String.format("Setup: Organization %1$s does not exist in system, creating...", organization.getName()));
                Organization newOrganization = OrganizationLocalServiceUtil.addOrganization(SetupConfigurationThreadLocal.getRunAsUserId(), OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, organization.getName(), "organization", 0, 0, ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, "Created by setup module.", false, new ServiceContext());
                addOrganizationUser(newOrganization, UserLocalServiceUtil.getUser(SetupConfigurationThreadLocal.getRunAsUserId()));
                liferayOrg = newOrganization;
                liferayGroup = liferayOrg.getGroup();
                groupId = newOrganization.getGroupId();
                LOG.info(String.format("New Organization created. Group ID: %1$s", groupId));
            }
            if (parentOrg != null && liferayOrg != null && organization.isMaintainOrganizationHierarchy()) {
                liferayOrg.setParentOrganizationId(parentOrg.getOrganizationId());
                OrganizationLocalServiceUtil.updateOrganization(liferayOrg);
            } else if (liferayOrg != null && organization.isMaintainOrganizationHierarchy()) {
                liferayOrg.setParentOrganizationId(0);
                OrganizationLocalServiceUtil.updateOrganization(liferayOrg);
            }
            setCustomFields(groupId, organization, liferayOrg);
            LOG.info("Organization custom fields set up.");
            Site orgSite = organization.getSite();
            if (orgSite == null) {
                LOG.info("Organization has no site defined. All is set.");
            } else if (orgSite.isDefault() || orgSite.getName() == null || orgSite.getName().isEmpty()) {
                LOG.error("It is not possible to set global or default within organization. Skipping site setup.");
            } else {
                LOG.info("Setting up site for organization.");
                liferayGroup.setSite(true);
                liferayGroup.setName(orgSite.getName());
                GroupLocalServiceUtil.updateGroup(liferayGroup);
                liferayGroup = liferayOrg.getGroup();
                if (liferayGroup != null && orgSite.getSiteFriendlyUrl() != null && !orgSite.getSiteFriendlyUrl().isEmpty()) {
                    liferayGroup.setFriendlyURL(orgSite.getSiteFriendlyUrl());
                    GroupLocalServiceUtil.updateGroup(liferayGroup);
                    liferayGroup = liferayOrg.getGroup();
                }
                if (parentGroup != null && liferayGroup != null && orgSite.isMaintainSiteHierarchy()) {
                    liferayGroup.setParentGroupId(parentGroup.getGroupId());
                    GroupLocalServiceUtil.updateGroup(liferayGroup);
                } else if (liferayGroup != null && orgSite.isMaintainSiteHierarchy()) {
                    liferayGroup.setParentGroupId(0);
                    GroupLocalServiceUtil.updateGroup(liferayGroup);
                }
                SetupConfigurationThreadLocal.configureGroupExecutionContext(liferayGroup);
                LOG.info("Setting organization site content...");
                SetupDocumentFolders.setupDocumentFolders(orgSite, groupId);
                LOG.info("Document Folders setting finished.");
                SetupDocuments.setupSiteDocuments(orgSite, groupId);
                LOG.info("Documents setting finished.");
                SetupPages.setupSitePages(orgSite, groupId);
                LOG.info("Organization Pages setting finished.");
                SetupWebFolders.setupWebFolders(orgSite, groupId);
                LOG.info("Web folders setting finished.");
                SetupCategorization.setupVocabularies(orgSite.getVocabulary(), groupId);
                LOG.info("Organization Categories setting finished.");
                SetupArticles.setupSiteArticles(orgSite.getArticle(), orgSite.getAdt(), orgSite.getDdlRecordset(), groupId);
                LOG.info("Organization Articles setting finished.");
                SetupSites.setCustomFields(groupId, orgSite.getCustomFieldSetting());
                LOG.info("Organization site custom fields set up.");
            }
            List<com.ableneo.liferay.portal.setup.domain.Organization> orgs = organization.getOrganization();
            setupOrganizations(orgs, liferayOrg, liferayGroup);
        } catch (Exception e) {
            LOG.error(String.format("Error by setting up organization %1$s", organization.getName()), e);
        }
    }
}
Also used : Site(com.ableneo.liferay.portal.setup.domain.Site) Group(com.liferay.portal.kernel.model.Group) Organization(com.liferay.portal.kernel.model.Organization) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 32 with Group

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

the class IndexCheckerPermissionsHelper method addPermissionsClassNameGroupIdFields.

public void addPermissionsClassNameGroupIdFields(Data data) {
    String className = getPermissionsClassName(data);
    long classPK = getPermissionsClassPK(data);
    if (Validator.isNull(className) || (classPK <= 0)) {
        return;
    }
    Indexer indexer = IndexerRegistryUtil.getIndexer(className);
    if (!indexer.isPermissionAware()) {
        return;
    }
    long groupId = 0L;
    Object groupIdObj = data.get("groupId", 0L);
    if (groupIdObj instanceof Number) {
        Number groupIdNumber = (Number) groupIdObj;
        groupId = groupIdNumber.longValue();
        Group group = GroupLocalServiceUtil.fetchGroup(groupId);
        if ((group != null) && group.isLayout()) {
            groupId = group.getParentGroupId();
        }
    }
    data.set("permissionsClassName", className);
    data.set("permissionsClassPK", classPK);
    data.set("permissionsGroupId", groupId);
}
Also used : Group(com.liferay.portal.kernel.model.Group) Indexer(com.liferay.portal.kernel.search.Indexer)

Example 33 with Group

use of com.liferay.portal.kernel.model.Group 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 34 with Group

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

the class OutputUtils method getPortletRepository.

public static Repository getPortletRepository(String portletId) throws PortalException {
    List<Company> companies = CompanyLocalServiceUtil.getCompanies(false);
    Company company = companies.get(0);
    Group group = GroupServiceUtil.getCompanyGroup(company.getCompanyId());
    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(group.getGroupId(), portletId);
    if (repository == null) {
        repository = PortletFileRepositoryUtil.addPortletRepository(group.getGroupId(), portletId, new ServiceContext());
    }
    return repository;
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) Repository(com.liferay.portal.kernel.model.Repository) ServiceContext(com.liferay.portal.kernel.service.ServiceContext)

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