Search in sources :

Example 21 with Group

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

the class SiteCommonServiceImpl method attachToParentSite.

@Override
public Group attachToParentSite(Group group, String parentGroupFriendlyURL) throws PortalException {
    long companyId = group.getCompanyId();
    long parentGroupId = getSiteParentGroupId(companyId, parentGroupFriendlyURL);
    Group returnedGroup = attachToParentSite(group, parentGroupId);
    if (parentGroupId != GroupConstants.DEFAULT_PARENT_GROUP_ID) {
        reportService.getMessage(_log, "Attached [" + group.getFriendlyURL() + "] to [" + parentGroupFriendlyURL + "] ...");
    } else {
        _log.debug("[" + group.getFriendlyURL() + "] was attached to default group");
    }
    return returnedGroup;
}
Also used : Group(com.liferay.portal.kernel.model.Group)

Example 22 with Group

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

the class ImportRolePermissionsServiceImpl method updateActions.

private void updateActions(long companyId, Role role, PortletPermissions portletPermissions) throws Exception {
    List<Resource> resourceList = new LinkedList<Resource>();
    resourceList.add(portletPermissions.getPortletResource());
    resourceList.addAll(portletPermissions.getModelResourceList());
    for (Resource resource : resourceList) {
        List<String> actions = ResourceActionsUtil.getResourceActions(resource.getResourceName());
        actions = ListUtil.sort(actions);
        String selResource = resource.getResourceName();
        for (Action action : resource.getActionList()) {
            String actionId = action.getActionId();
            int scope = action.getScope().getIntValue();
            Set<String> groupNames = action.getSitesNames();
            String[] groupIds = new String[groupNames.size()];
            int i = 0;
            for (String groupName : groupNames) {
                Group group = groupLocalService.getGroup(companyId, groupName);
                groupIds[i] = Long.toString(group.getGroupId());
                i++;
            }
            updateAction(role, selResource, actionId, scope, groupIds);
            if (_log.isDebugEnabled()) {
                _log.debug("Updating role=[" + role.getName() + "], resource=[" + selResource + "], actionId=[" + actionId + "], scope=[" + scope + "], groupIds=[" + groupIds + "][" + groupIds.length + "]");
            }
        }
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) Action(com.liferay.imex.role.model.Action) Resource(com.liferay.imex.role.model.Resource) LinkedList(java.util.LinkedList)

Example 23 with Group

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

the class SiteImporter method doUpdateSiteDatas.

private void doUpdateSiteDatas(long companyId, User user, Properties config, File groupDir, Locale locale, Map<String, String> toUpdateParentGroups, boolean debug) throws Exception {
    if (groupDir != null) {
        if (groupDir.exists()) {
            String dirName = groupDir.getName();
            String groupFriendlyUrl = ImexNormalizer.getFriendlyURLByDirName(dirName);
            reportService.getStartMessage(_log, groupFriendlyUrl);
            String siteDescriptorFileName = FileNames.getSiteFileName(groupFriendlyUrl, processor.getFileExtension());
            ImexSite imexSite = (ImexSite) processor.read(ImexSite.class, groupDir, siteDescriptorFileName);
            UnicodeProperties typeSettingsProperties = imexSite.getUnicodeProperties();
            ServiceContext serviceContext = new ServiceContext();
            boolean site = imexSite.isSite();
            long userId = user.getUserId();
            String className = imexSite.getClassName();
            long classPK = imexSite.getClassPK();
            Map<Locale, String> nameMap = imexSite.getNameMap();
            Map<Locale, String> descriptionMap = imexSite.getDescriptionMap();
            int type = imexSite.getType();
            String friendlyURL = imexSite.getFriendlyURL();
            boolean active = imexSite.isActive();
            int membershipRestriction = imexSite.getMemberShipRestriction();
            boolean manualMembership = imexSite.isManualMemberShip();
            boolean inheritContent = imexSite.isInheritContent();
            long liveGroupId = GroupConstants.DEFAULT_LIVE_GROUP_ID;
            long defaultParentGroupId = GroupConstants.DEFAULT_PARENT_GROUP_ID;
            String logPrefix = "SITE : " + groupFriendlyUrl;
            Group group = groupLocalService.fetchFriendlyURLGroup(companyId, friendlyURL);
            if (group == null) {
                OnMissingSiteMethodEnum createMethod = behaviorManagerService.getOnMissingBehavior(config, groupFriendlyUrl);
                if (createMethod.getValue().equals(OnMissingSiteMethodEnum.CREATE.getValue())) {
                    String stringList = GetterUtil.getString(config.get(ImExSiteImporterPropsKeys.IMPORT_SITE_LIFERAY_SYSTEM_GROUPS_FRIENDLYURL_LIST));
                    List<String> neverCreateFriendlyURLS = CollectionUtil.getList(stringList);
                    if (neverCreateFriendlyURLS.contains(groupFriendlyUrl)) {
                        reportService.getError(_log, groupFriendlyUrl, "is evaluated as  [" + OnMissingSiteMethodEnum.CREATE.getValue() + "] but it appears to be a system group. Skipping creation");
                        getReportService().getSkipped(_log, groupFriendlyUrl);
                    } else {
                        group = groupLocalService.addGroup(userId, defaultParentGroupId, className, classPK, liveGroupId, nameMap, descriptionMap, type, manualMembership, membershipRestriction, friendlyURL, site, active, serviceContext);
                        groupLocalService.updateGroup(group.getGroupId(), typeSettingsProperties.toString());
                        doImportLars(groupDir, config, user, group, locale, debug);
                        reportService.getOK(_log, dirName, logPrefix, createMethod.getValue());
                    }
                } else {
                    _log.debug("Site creation were skipped.");
                    getReportService().getSkipped(_log, groupFriendlyUrl);
                }
            } else {
                OnExistsSiteMethodEnum duplicateMethod = behaviorManagerService.getOnExistsBehavior(config, group);
                if (!duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.SKIP.getValue())) {
                    if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.UPDATE_GROUP_ONLY.getValue())) {
                        updateLiferayGroup(typeSettingsProperties, serviceContext, nameMap, descriptionMap, type, friendlyURL, active, membershipRestriction, manualMembership, inheritContent, defaultParentGroupId, group);
                    } else {
                        // Si le group existe
                        if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.UPDATE.getValue())) {
                            updateLiferayGroup(typeSettingsProperties, serviceContext, nameMap, descriptionMap, type, friendlyURL, active, membershipRestriction, manualMembership, inheritContent, defaultParentGroupId, group);
                        } else if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.RECREATE.getValue())) {
                            // Reseting parent group
                            siteCommonService.eraseSiteHierarchy(group);
                            // Deleting site
                            group = groupLocalService.deleteGroup(group);
                            // Creating site again
                            group = groupLocalService.addGroup(userId, defaultParentGroupId, className, classPK, liveGroupId, nameMap, descriptionMap, type, manualMembership, membershipRestriction, friendlyURL, site, active, serviceContext);
                        } else if (duplicateMethod.getValue().equals(OnExistsSiteMethodEnum.DELETE.getValue())) {
                            // Reseting parent group
                            siteCommonService.eraseSiteHierarchy(group);
                            // Deleting site
                            group = groupLocalService.deleteGroup(group);
                        }
                        // Importing LARS
                        doImportLars(groupDir, config, user, group, locale, debug);
                        groupLocalService.updateGroup(group.getGroupId(), typeSettingsProperties.toString());
                    }
                    reportService.getOK(_log, dirName, logPrefix, duplicateMethod.getValue());
                } else {
                    getReportService().getSkipped(_log, groupFriendlyUrl);
                }
            }
            // Registering sites hierarchy to update
            String parentGroupIdFriendlyUrl = imexSite.getParentGroupIdFriendlyUrl();
            if (group != null && Validator.isNotNull(parentGroupIdFriendlyUrl)) {
                toUpdateParentGroups.put(groupFriendlyUrl, parentGroupIdFriendlyUrl);
            } else {
                _log.debug("Site identified by [" + groupFriendlyUrl + "] has no parent group");
            }
            reportService.getEndMessage(_log, groupFriendlyUrl);
        } else {
            reportService.getDNE(_log, groupDir.getAbsolutePath());
        }
    } else {
        _log.error("Skipping null dir ...");
    }
}
Also used : Locale(java.util.Locale) Group(com.liferay.portal.kernel.model.Group) ImexSite(com.liferay.imex.site.model.ImexSite) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) OnMissingSiteMethodEnum(com.liferay.imex.site.model.OnMissingSiteMethodEnum) OnExistsSiteMethodEnum(com.liferay.imex.site.model.OnExistsSiteMethodEnum)

Example 24 with Group

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

the class VirtualhostImporter method updateVirtualHosts.

private void updateVirtualHosts(long companyId, Locale locale, Map<Long, TreeMap<String, String>> layoutSetHostnames) throws PortalException {
    // Updating bunch of virtualhosts for each layoutSet - The Liferay method destriy all existing virtualhosts first
    for (Entry<Long, TreeMap<String, String>> entry : layoutSetHostnames.entrySet()) {
        long layoutSetId = entry.getKey();
        TreeMap<String, String> currentLayoutSetHostnames = entry.getValue();
        virtualHostLocalService.updateVirtualHosts(companyId, layoutSetId, currentLayoutSetHostnames);
        Company company = companyLocalService.getCompanyById(companyId);
        String name = "Company : " + company.getName();
        if (layoutSetId != VirtualhostCommonService.DEFAULT_LAYOUTSET_ID) {
            LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(layoutSetId);
            Group group = layoutSet.getGroup();
            name = "Site : " + GroupUtil.getGroupName(group, locale);
        }
        // To avoid diplaying null in logs
        Map<String, String> toDisplay = new HashMap<String, String>();
        toDisplay.putAll(currentLayoutSetHostnames);
        toDisplay = CollectionUtil.replaceNullValues(toDisplay, DEFAULT_LANGUAGE_MESSAGE);
        reportService.getOK(_log, name, "Virtual Hosts : " + toDisplay);
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Example 25 with Group

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

the class VirtualhostImporter method converToUpdatableMap.

private Map<Long, TreeMap<String, String>> converToUpdatableMap(long companyId, List<ExtendedImexVirtualhost> virtualHosts) throws PortalException {
    // Constructing structured map to update
    Map<Long, TreeMap<String, String>> layoutSetHostnames = new HashMap<Long, TreeMap<String, String>>();
    for (ExtendedImexVirtualhost extendedVirtualHostObj : virtualHosts) {
        ImexVirtualhost virtualHostObj = extendedVirtualHostObj.getVirtualhost();
        String companyWebId = virtualHostObj.getCompanyWebId();
        String groupFriendlyURL = virtualHostObj.getGroupFriendlyURL();
        boolean isPublicVirtualHost = virtualHostObj.isPublicVirtualHost();
        long layoutSetId = VirtualhostCommonService.DEFAULT_LAYOUTSET_ID;
        boolean isCompanyVirtualHost = virtualHostObj.isCompanyVirtualHost();
        File virtualHostFile = extendedVirtualHostObj.getSourceFile();
        String originFileName = virtualHostFile.getName();
        String languageId = virtualHostObj.getLanguageId();
        try {
            // Verify if company exists
            companyLocalService.getCompanyByWebId(companyWebId);
            if (!isCompanyVirtualHost) {
                // Verify if group exists
                Group group = groupLocalService.getFriendlyURLGroup(companyId, groupFriendlyURL);
                LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(group.getGroupId(), !isPublicVirtualHost);
                layoutSetId = layoutSet.getLayoutSetId();
            }
            String hostname = virtualHostObj.getHostname();
            TreeMap<String, String> currentLayoutSetHostnames = null;
            if (Validator.isNotNull(hostname)) {
                TreeMap<String, String> treeMap = layoutSetHostnames.get(layoutSetId);
                if (treeMap == null) {
                    layoutSetHostnames.put(layoutSetId, new TreeMap<String, String>());
                } else {
                    _log.debug("Updating existing TreeMap");
                }
                currentLayoutSetHostnames = layoutSetHostnames.get(layoutSetId);
                if (!currentLayoutSetHostnames.containsKey(hostname)) {
                    currentLayoutSetHostnames.put(hostname, languageId);
                } else {
                    _log.debug("Current TreeMap already contains [" + hostname + "]");
                }
            } else {
                reportService.getError(_log, originFileName, "missing required information hostname");
            }
        } catch (NoSuchCompanyException e) {
            reportService.getDNE(_log, "company identified by [" + companyWebId + "]");
            reportService.getSkipped(_log, originFileName);
        } catch (NoSuchGroupException e) {
            reportService.getDNE(_log, "group identified by [" + groupFriendlyURL + "]");
            reportService.getSkipped(_log, originFileName);
        }
    }
    return layoutSetHostnames;
}
Also used : Group(com.liferay.portal.kernel.model.Group) HashMap(java.util.HashMap) NoSuchCompanyException(com.liferay.portal.kernel.exception.NoSuchCompanyException) TreeMap(java.util.TreeMap) NoSuchGroupException(com.liferay.portal.kernel.exception.NoSuchGroupException) ImexVirtualhost(com.liferay.imex.virtualhost.model.ImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) File(java.io.File) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

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