Search in sources :

Example 1 with OnExistsSiteMethodEnum

use of com.liferay.imex.site.model.OnExistsSiteMethodEnum 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 2 with OnExistsSiteMethodEnum

use of com.liferay.imex.site.model.OnExistsSiteMethodEnum in project liferay-imex by jpdacunha.

the class ImportSiteBehaviorManagerServiceImpl method getOnExistsBehavior.

@Override
public OnExistsSiteMethodEnum getOnExistsBehavior(Properties config, Group group) {
    if (group != null) {
        String suffix = "." + group.getFriendlyURL().replaceAll("/", "");
        String value = getOnExistsBehaviorForSite(suffix, config);
        if (value != null && !value.equals("")) {
            reportService.getMessage(_log, "Loading specific behavior : [" + value + "] for group [" + group.getFriendlyURL() + "] ...");
            OnExistsSiteMethodEnum converted = OnExistsSiteMethodEnum.fromValue(value);
            if (converted != null) {
                return converted;
            }
        }
    }
    String defaultValue = GetterUtil.getString(config.get(ImExSiteImporterPropsKeys.IMPORT_SITE_ON_EXISTS));
    OnExistsSiteMethodEnum defaultEnumValue = OnExistsSiteMethodEnum.fromValue(defaultValue);
    if (Validator.isNull(defaultEnumValue)) {
        _log.error("Parameter identified by [" + ImExSiteImporterPropsKeys.IMPORT_SITE_ON_EXISTS + "] is not properly configured. Please check your configuration file.");
        defaultEnumValue = OnExistsSiteMethodEnum.SKIP;
    }
    return defaultEnumValue;
}
Also used : OnExistsSiteMethodEnum(com.liferay.imex.site.model.OnExistsSiteMethodEnum)

Aggregations

OnExistsSiteMethodEnum (com.liferay.imex.site.model.OnExistsSiteMethodEnum)2 ImexSite (com.liferay.imex.site.model.ImexSite)1 OnMissingSiteMethodEnum (com.liferay.imex.site.model.OnMissingSiteMethodEnum)1 Group (com.liferay.portal.kernel.model.Group)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1 UnicodeProperties (com.liferay.portal.kernel.util.UnicodeProperties)1 Locale (java.util.Locale)1