Search in sources :

Example 26 with Group

use of com.liferay.portal.kernel.model.Group in project liferay-imex by jpdacunha.

the class WcDDMImporter method doImport.

private void doImport(ServiceContext serviceContext, long companyId, User user, Properties config, File groupDir, Locale locale, boolean debug) {
    if (groupDir != null) {
        if (groupDir.exists()) {
            String groupFriendlyUrl = ImexNormalizer.getFriendlyURLByDirName(groupDir.getName());
            Group group = groupLocalService.fetchFriendlyURLGroup(companyId, groupFriendlyUrl);
            if (group != null) {
                reportService.getStartMessage(_log, group, locale);
                File[] structuresDirs = FileUtil.listFiles(groupDir);
                // For each structure dir
                for (File structureDir : structuresDirs) {
                    DDMStructure structure = doImportStructure(config, serviceContext, debug, group, user, locale, structureDir);
                    if (structure != null) {
                        doImportTemplate(config, serviceContext, debug, group, user, locale, structureDir, structure);
                        reportService.getSeparator(_log);
                    } else {
                        reportService.getError(_log, structureDir.getName(), "Structure import process returned unexpected null result: Skipping associated templates update.");
                    }
                }
                reportService.getEndMessage(_log, group, locale);
            } else {
                reportService.getDNE(_log, groupFriendlyUrl);
            }
        } else {
            reportService.getDNE(_log, groupDir.getAbsolutePath());
        }
    } else {
        _log.error("Skipping null dir ...");
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) DDMStructure(com.liferay.dynamic.data.mapping.model.DDMStructure) File(java.io.File)

Example 27 with Group

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

the class SetupSites method setupSite.

private static Group setupSite(Group parentGroup, long companyId, Site site) throws PortalException {
    Group liferayGroup = null;
    long groupId = -1;
    if (site.isDefault()) {
        liferayGroup = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);
        LOG.info(String.format("Setup: default site. Group ID: %1$s", groupId));
    } else if (site.getName() == null) {
        liferayGroup = GroupLocalServiceUtil.getCompanyGroup(companyId);
        LOG.info(String.format("Setup: global site. Group ID: %1$s", groupId));
    } else {
        try {
            liferayGroup = GroupLocalServiceUtil.getGroup(companyId, site.getName());
            LOG.info(String.format("Setup: Site %1$s already exists in system, not creating... (pk=%2$s,gid=%3$s)", site.getName(), liferayGroup.getPrimaryKey(), liferayGroup.getGroupId()));
        // b3farkas
        } catch (PortalException e) {
            LOG.debug("Site does not exist.", e);
        }
    }
    ServiceContext serviceContext = new ServiceContext();
    if (liferayGroup == null) {
        LOG.info(String.format("Setup: Group (Site) %1$s does not exist in system, creating...", site.getName()));
        // ?? SiteUtil.addSiteGroup(context, this.siteCode, this.defaultName,
        // websiteParentGroup);
        liferayGroup = GroupLocalServiceUtil.addGroup(SetupConfigurationThreadLocal.getRunAsUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID, Group.class.getName(), 0, 0, TranslationMapUtil.getTranslationMap(site.getNameTranslation(), groupId, site.getName(), site.getName()), null, site.getMembershipType(), true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, site.getSiteFriendlyUrl(), true, true, serviceContext);
        LOG.info(String.format("New site created."));
    } else {
        LOG.info(String.format("Updating site: %1$s", site.getName()));
        GroupLocalServiceUtil.updateFriendlyURL(liferayGroup.getGroupId(), site.getSiteFriendlyUrl());
    }
    groupId = liferayGroup.getGroupId();
    LOG.info(String.format(" - Group ID: %1$s", groupId));
    setSitePropertiesTo(site, liferayGroup);
    if (parentGroup != null && liferayGroup != null && site.isMaintainSiteHierarchy()) {
        liferayGroup.setParentGroupId(parentGroup.getGroupId());
        GroupLocalServiceUtil.updateGroup(liferayGroup);
    } else if (liferayGroup != null && site.isMaintainSiteHierarchy()) {
        liferayGroup.setParentGroupId(0);
        GroupLocalServiceUtil.updateGroup(liferayGroup);
    }
    if (liferayGroup == null) {
        LOG.error(String.format("Failed to create or update site (not found): %1$s", site.getName()));
        return null;
    }
    LOG.info("Setting site content...");
    SetupConfigurationThreadLocal.configureGroupExecutionContext(liferayGroup);
    long userId = SetupConfigurationThreadLocal.getRunAsUserId();
    setStaging(userId, liferayGroup, site.getStaging());
    // If staging group exists for present Group, add all content to staging group
    Group stagingGroup = liferayGroup.getStagingGroup();
    if (Objects.nonNull(stagingGroup)) {
        groupId = stagingGroup.getGroupId();
    }
    SetupDocumentFolders.setupDocumentFolders(site, groupId);
    LOG.info("Document Folders setting finished.");
    SetupDocuments.setupSiteDocuments(site, groupId);
    LOG.info("Documents setting finished.");
    SetupArticles.setupSiteStructuresAndTemplates(site, groupId);
    LOG.info("Site DDM structures and templates setting finished.");
    SetupPages.setupSitePages(site, groupId);
    LOG.info("Site Pages setting finished.");
    SetupWebFolders.setupWebFolders(site, groupId);
    LOG.info("Web folders setting finished.");
    SetupCategorization.setupVocabularies(site.getVocabulary(), groupId);
    LOG.info("Site Categories setting finished.");
    SetupArticles.setupSiteArticles(site.getArticle(), site.getAdt(), site.getDdlRecordset(), groupId);
    LOG.info("Site Articles setting finished.");
    setCustomFields(groupId, site.getCustomFieldSetting());
    LOG.info("Site custom fields set up.");
    SetupMenus.setMenus(groupId, site.getMenu());
    LOG.info("Site menus set up.");
    SetupPages.setupSitePortlets(site, groupId);
    LOG.info("Site Portlets setting finished.");
    // Users and Groups should be referenced to live Group
    setMembership(site.getMembership(), companyId, groupId);
    return liferayGroup;
}
Also used : Group(com.liferay.portal.kernel.model.Group) UserGroup(com.liferay.portal.kernel.model.UserGroup) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 28 with Group

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

the class SetupSites method setupSites.

public static void setupSites(final List<com.ableneo.liferay.portal.setup.domain.Site> siteList, final Group parentGroup) throws PortalException {
    long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
    for (com.ableneo.liferay.portal.setup.domain.Site site : siteList) {
        Group liferayGroup = setupSite(parentGroup, companyId, site);
        List<com.ableneo.liferay.portal.setup.domain.Site> sites = site.getSite();
        setupSites(sites, liferayGroup);
    }
}
Also used : Site(com.ableneo.liferay.portal.setup.domain.Site) Group(com.liferay.portal.kernel.model.Group) UserGroup(com.liferay.portal.kernel.model.UserGroup) Site(com.ableneo.liferay.portal.setup.domain.Site)

Example 29 with Group

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

the class SetupUsers method addRolesToUser.

private static void addRolesToUser(final com.ableneo.liferay.portal.setup.domain.User setupUser, final User liferayUser) {
    try {
        for (com.ableneo.liferay.portal.setup.domain.Role userRole : setupUser.getRole()) {
            long runInCompanyId = SetupConfigurationThreadLocal.getRunInCompanyId();
            Role role = RoleLocalServiceUtil.getRole(runInCompanyId, userRole.getName());
            long[] roleIds = { role.getRoleId() };
            String roleType = userRole.getType();
            switch(roleType) {
                case "portal":
                    RoleLocalServiceUtil.addUserRoles(liferayUser.getUserId(), roleIds);
                    LOG.info(String.format("Adding regular role %1$s to user %2$s", userRole.getName(), liferayUser.getEmailAddress()));
                    break;
                case "site":
                case "organization":
                    Group group = GroupLocalServiceUtil.getGroup(runInCompanyId, userRole.getSite());
                    UserGroupRoleLocalServiceUtil.addUserGroupRoles(liferayUser.getUserId(), group.getGroupId(), roleIds);
                    LOG.info("Adding " + roleType + " role " + userRole.getName() + " to user " + liferayUser.getEmailAddress());
                    break;
                default:
                    LOG.error(String.format("unknown role type %1$s", roleType));
                    break;
            }
        }
    } catch (PortalException | SystemException e) {
        LOG.error(String.format("Error in adding roles to user %1$s", setupUser.getEmailAddress()), e);
    }
}
Also used : Role(com.liferay.portal.kernel.model.Role) Group(com.liferay.portal.kernel.model.Group) UserGroup(com.liferay.portal.kernel.model.UserGroup) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 30 with Group

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

the class SetupDocuments method setupSiteDocuments.

public static void setupSiteDocuments(final Site site, long groupId) {
    for (Document doc : site.getDocument()) {
        String folderPath = doc.getDocumentFolderName();
        String documentName = doc.getDocumentFilename();
        String documentTitle = doc.getDocumentTitle();
        String filenameInFilesystem = doc.getFileSystemName();
        long userId = SetupConfigurationThreadLocal.getRunAsUserId();
        long company = SetupConfigurationThreadLocal.getRunInCompanyId();
        switch(doc.getFileUploadType()) {
            case GENERAL:
                // groupid == site group (as-is)
                break;
            case LOGO_IMAGE:
                // groupid = 'Control Panel' groups id..
                try {
                    Group controlPanelGroup = GroupLocalServiceUtil.loadGetGroup(company, GroupConstants.CONTROL_PANEL);
                    groupId = controlPanelGroup.getGroupId();
                } catch (PortalException e) {
                    LOG.error("Can not get group for " + GroupConstants.CONTROL_PANEL + " and company " + company + ":", e);
                    return;
                }
                break;
            default:
                LOG.error("Can not understand enum value '" + doc.getFileUploadType() + "' as upload-type.. check dependencies, implement on need!");
                return;
        }
        long repoId = groupId;
        FileEntry fe = DocumentUtil.findDocument(documentName, folderPath, groupId, groupId);
        byte[] fileBytes = null;
        try {
            fileBytes = ResourcesUtil.getFileBytes(filenameInFilesystem);
        } catch (IOException e) {
            LOG.error(String.format("Can not read file: %1$s. Skipping file", filenameInFilesystem));
            continue;
        }
        if (fileBytes != null) {
            if (fe == null) {
                Folder folder = null;
                if (Validator.isBlank(folderPath)) {
                    folder = FolderUtil.findFolder(groupId, repoId, folderPath, true);
                } else {
                    try {
                        folder = DLAppLocalServiceUtil.getMountFolder(repoId);
                    } catch (PortalException e) {
                        LOG.warn("Mount folder not found for file [{}], stopped creating the document.", documentName, e);
                    }
                }
                if (folder != null) {
                    LOG.info("{} is not found! It will be created! (c: {},grp: {}", documentName, company, groupId);
                    fe = DocumentUtil.createDocument(groupId, folder.getFolderId(), documentName, documentTitle, userId, repoId, fileBytes);
                }
            } else {
                LOG.info(documentName + " is found! Content will be updated! (c:" + company + ",grp:" + groupId + " ");
                DocumentUtil.updateFile(fe, fileBytes, userId, documentName);
            }
            SetupPermissions.updatePermission(String.format("Document %1$s/%2$s", folderPath, documentName), company, fe.getFileEntryId(), DLFileEntry.class, doc.getRolePermissions(), DEFAULT_PERMISSIONS);
        }
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) DLFileEntry(com.liferay.document.library.kernel.model.DLFileEntry) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) Document(com.ableneo.liferay.portal.setup.domain.Document) Folder(com.liferay.portal.kernel.repository.model.Folder)

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