@Override public ActionForward render( ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { long actionId = ParamUtil.getLong(renderRequest, "actionId"); MDRAction action = MDRActionServiceUtil.fetchAction(actionId); renderRequest.setAttribute(WebKeys.MOBILE_DEVICE_RULES_RULE_GROUP_ACTION, action); String type = BeanPropertiesUtil.getString(action, "type"); renderRequest.setAttribute(WebKeys.MOBILE_DEVICE_RULES_RULE_GROUP_ACTION_TYPE, type); String editorJSP = getEditorJSP(type); renderRequest.setAttribute(WebKeys.MOBILE_DEVICE_RULES_RULE_GROUP_ACTION_EDITOR_JSP, editorJSP); long ruleGroupInstanceId = BeanParamUtil.getLong(action, renderRequest, "ruleGroupInstanceId"); MDRRuleGroupInstance ruleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.getMDRRuleGroupInstance(ruleGroupInstanceId); renderRequest.setAttribute(WebKeys.MOBILE_DEVICE_RULES_RULE_GROUP_INSTANCE, ruleGroupInstance); return mapping.findForward("portlet.mobile_device_rules.edit_action"); }
@Override protected StagedModel getStagedModel(String uuid, Group group) { try { return MDRRuleGroupInstanceLocalServiceUtil.getMDRRuleGroupInstanceByUuidAndGroupId( uuid, group.getGroupId()); } catch (Exception e) { return null; } }
@Override protected void doImportStagedModel( PortletDataContext portletDataContext, Element ruleGroupInstanceElement, String path, MDRRuleGroupInstance ruleGroupInstance) throws Exception { long userId = portletDataContext.getUserId(ruleGroupInstance.getUserUuid()); String ruleGroupPath = StagedModelPathUtil.getPath( portletDataContext, MDRRuleGroup.class.getName(), ruleGroupInstance.getRuleGroupId()); MDRRuleGroup ruleGroup = (MDRRuleGroup) portletDataContext.getZipEntryAsObject(ruleGroupPath); StagedModelDataHandlerUtil.importStagedModel( portletDataContext, ruleGroupInstanceElement, ruleGroupPath, ruleGroup); Map<Long, Long> ruleGroupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroup.class); Long ruleGroupId = MapUtil.getLong( ruleGroupIds, ruleGroupInstance.getRuleGroupId(), ruleGroupInstance.getRuleGroupId()); long classPK = 0; String layoutUuid = ruleGroupInstanceElement.attributeValue("layout-uuid"); try { if (Validator.isNotNull(layoutUuid)) { Layout layout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId( layoutUuid, portletDataContext.getScopeGroupId(), portletDataContext.isPrivateLayout()); classPK = layout.getPrimaryKey(); } else { LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet( portletDataContext.getScopeGroupId(), portletDataContext.isPrivateLayout()); classPK = layoutSet.getLayoutSetId(); } } catch (Exception e) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(5); sb.append("Layout "); sb.append(layoutUuid); sb.append(" is missing for rule group instance "); sb.append(ruleGroupInstance.getRuleGroupInstanceId()); sb.append(", skipping this rule group instance."); _log.warn(sb.toString()); } return; } ServiceContext serviceContext = portletDataContext.createServiceContext( ruleGroupInstanceElement, ruleGroupInstance, MDRPortletDataHandler.NAMESPACE); serviceContext.setUserId(userId); MDRRuleGroupInstance importedRuleGroupInstance = null; if (portletDataContext.isDataStrategyMirror()) { MDRRuleGroupInstance existingMDRRuleGroupInstance = MDRRuleGroupInstanceUtil.fetchByUUID_G( ruleGroupInstance.getUuid(), portletDataContext.getScopeGroupId()); if (existingMDRRuleGroupInstance == null) { serviceContext.setUuid(ruleGroupInstance.getUuid()); importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.addRuleGroupInstance( portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK, ruleGroupId, ruleGroupInstance.getPriority(), serviceContext); } else { importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.updateRuleGroupInstance( existingMDRRuleGroupInstance.getRuleGroupInstanceId(), ruleGroupInstance.getPriority()); } } else { importedRuleGroupInstance = MDRRuleGroupInstanceLocalServiceUtil.addRuleGroupInstance( portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK, ruleGroupId, ruleGroupInstance.getPriority(), serviceContext); } portletDataContext.importClassedModel( ruleGroupInstance, importedRuleGroupInstance, MDRPortletDataHandler.NAMESPACE); }