public MDRRuleGroup copyRuleGroup( MDRRuleGroup ruleGroup, long groupId, ServiceContext serviceContext) throws PortalException, SystemException { Group group = groupPersistence.findByPrimaryKey(groupId); Map<Locale, String> nameMap = ruleGroup.getNameMap(); for (Map.Entry<Locale, String> entry : nameMap.entrySet()) { Locale locale = entry.getKey(); String name = entry.getValue(); if (Validator.isNull(name)) { continue; } String postfix = LanguageUtil.get(locale, PropsValues.MOBILE_DEVICE_RULES_RULE_GROUP_COPY_POSTFIX); nameMap.put(locale, name.concat(StringPool.SPACE).concat(postfix)); } MDRRuleGroup newRuleGroup = addRuleGroup(group.getGroupId(), nameMap, ruleGroup.getDescriptionMap(), serviceContext); List<MDRRule> rules = mdrRulePersistence.findByRuleGroupId(ruleGroup.getRuleGroupId()); for (MDRRule rule : rules) { serviceContext.setUuid(PortalUUIDUtil.generate()); mdrRuleLocalService.copyRule(rule, newRuleGroup.getRuleGroupId(), serviceContext); } return newRuleGroup; }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, MDRRuleGroup ruleGroup) throws Exception { long userId = portletDataContext.getUserId(ruleGroup.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(ruleGroup); serviceContext.setUserId(userId); MDRRuleGroup importedRuleGroup = null; if (portletDataContext.isDataStrategyMirror()) { MDRRuleGroup existingRuleGroup = fetchStagedModelByUuidAndGroupId( ruleGroup.getUuid(), portletDataContext.getScopeGroupId()); if (existingRuleGroup == null) { serviceContext.setUuid(ruleGroup.getUuid()); importedRuleGroup = MDRRuleGroupLocalServiceUtil.addRuleGroup( portletDataContext.getScopeGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } else { importedRuleGroup = MDRRuleGroupLocalServiceUtil.updateRuleGroup( existingRuleGroup.getRuleGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } } else { importedRuleGroup = MDRRuleGroupLocalServiceUtil.addRuleGroup( portletDataContext.getScopeGroupId(), ruleGroup.getNameMap(), ruleGroup.getDescriptionMap(), serviceContext); } portletDataContext.importClassedModel(ruleGroup, importedRuleGroup); }