@Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, MDRAction action)
      throws Exception {

    Map<Long, Long> ruleGroupInstanceIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroupInstance.class);

    long ruleGroupInstanceId =
        MapUtil.getLong(
            ruleGroupInstanceIds, action.getRuleGroupInstanceId(), action.getRuleGroupInstanceId());

    ServiceContext serviceContext = portletDataContext.createServiceContext(action);

    serviceContext.setUserId(portletDataContext.getUserId(action.getUserUuid()));

    Element element = portletDataContext.getImportDataStagedModelElement(action);

    validateLayout(element, action);

    MDRAction importedAction = null;

    if (portletDataContext.isDataStrategyMirror()) {
      MDRAction existingAction =
          fetchStagedModelByUuidAndGroupId(action.getUuid(), portletDataContext.getScopeGroupId());

      if (existingAction == null) {
        serviceContext.setUuid(action.getUuid());

        importedAction =
            _mdrActionLocalService.addAction(
                ruleGroupInstanceId,
                action.getNameMap(),
                action.getDescriptionMap(),
                action.getType(),
                action.getTypeSettingsProperties(),
                serviceContext);
      } else {
        importedAction =
            _mdrActionLocalService.updateAction(
                existingAction.getActionId(), action.getNameMap(),
                action.getDescriptionMap(), action.getType(),
                action.getTypeSettingsProperties(), serviceContext);
      }
    } else {
      importedAction =
          _mdrActionLocalService.addAction(
              ruleGroupInstanceId,
              action.getNameMap(),
              action.getDescriptionMap(),
              action.getType(),
              action.getTypeSettingsProperties(),
              serviceContext);
    }

    portletDataContext.importClassedModel(action, importedAction);
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    long userId = portletDataContext.getUserId(ruleGroupInstance.getUserUuid());

    Map<Long, Long> ruleGroupIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MDRRuleGroup.class);

    Long ruleGroupId =
        MapUtil.getLong(
            ruleGroupIds, ruleGroupInstance.getRuleGroupId(), ruleGroupInstance.getRuleGroupId());

    long classPK = 0;

    Element ruleGroupInstanceElement =
        portletDataContext.getImportDataStagedModelElement(ruleGroupInstance);

    String layoutUuid = ruleGroupInstanceElement.attributeValue("layout-uuid");

    try {
      if (Validator.isNotNull(layoutUuid)) {
        Layout layout =
            _layoutLocalService.getLayoutByUuidAndGroupId(
                layoutUuid,
                portletDataContext.getScopeGroupId(),
                portletDataContext.isPrivateLayout());

        classPK = layout.getPrimaryKey();
      } else {
        LayoutSet layoutSet =
            _layoutSetLocalService.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(ruleGroupInstance);

    serviceContext.setUserId(userId);

    MDRRuleGroupInstance importedRuleGroupInstance = null;

    if (portletDataContext.isDataStrategyMirror()) {
      MDRRuleGroupInstance existingMDRRuleGroupInstance =
          fetchStagedModelByUuidAndGroupId(
              ruleGroupInstance.getUuid(), portletDataContext.getScopeGroupId());

      if (existingMDRRuleGroupInstance == null) {
        serviceContext.setUuid(ruleGroupInstance.getUuid());

        importedRuleGroupInstance =
            _mdrRuleGroupInstanceLocalService.addRuleGroupInstance(
                portletDataContext.getScopeGroupId(),
                ruleGroupInstance.getClassName(),
                classPK,
                ruleGroupId,
                ruleGroupInstance.getPriority(),
                serviceContext);
      } else {
        importedRuleGroupInstance =
            _mdrRuleGroupInstanceLocalService.updateRuleGroupInstance(
                existingMDRRuleGroupInstance.getRuleGroupInstanceId(),
                ruleGroupInstance.getPriority());
      }
    } else {
      importedRuleGroupInstance =
          _mdrRuleGroupInstanceLocalService.addRuleGroupInstance(
              portletDataContext.getScopeGroupId(),
              ruleGroupInstance.getClassName(),
              classPK,
              ruleGroupId,
              ruleGroupInstance.getPriority(),
              serviceContext);
    }

    portletDataContext.importClassedModel(ruleGroupInstance, importedRuleGroupInstance);
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, WikiPage page)
      throws Exception {

    long userId = portletDataContext.getUserId(page.getUserUuid());

    Element pageElement = portletDataContext.getImportDataStagedModelElement(page);

    String content =
        _wikiPageExportImportContentProcessor.replaceImportContentReferences(
            portletDataContext, page, page.getContent());

    page.setContent(content);

    ServiceContext serviceContext = portletDataContext.createServiceContext(page);

    serviceContext.setUuid(page.getUuid());

    Map<Long, Long> nodeIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class);

    long nodeId = MapUtil.getLong(nodeIds, page.getNodeId(), page.getNodeId());

    WikiPage importedPage = null;

    WikiPage existingPage = _wikiPageLocalService.fetchPage(nodeId, page.getTitle());

    if (existingPage == null) {
      importedPage =
          _wikiPageLocalService.addPage(
              userId,
              nodeId,
              page.getTitle(),
              page.getVersion(),
              page.getContent(),
              page.getSummary(),
              page.isMinorEdit(),
              page.getFormat(),
              page.getHead(),
              page.getParentTitle(),
              page.getRedirectTitle(),
              serviceContext);

      WikiPageResource pageResource =
          _wikiPageResourceLocalService.getPageResource(importedPage.getResourcePrimKey());

      String pageResourceUuid =
          GetterUtil.getString(pageElement.attributeValue("page-resource-uuid"));

      if (Validator.isNotNull(pageResourceUuid)) {
        pageResource.setUuid(pageElement.attributeValue("page-resource-uuid"));

        _wikiPageResourceLocalService.updateWikiPageResource(pageResource);
      }
    } else {
      existingPage =
          fetchStagedModelByUuidAndGroupId(page.getUuid(), portletDataContext.getScopeGroupId());

      if (existingPage == null) {
        existingPage = _wikiPageLocalService.fetchPage(nodeId, page.getTitle(), page.getVersion());
      }

      if (existingPage == null) {
        importedPage =
            _wikiPageLocalService.updatePage(
                userId,
                nodeId,
                page.getTitle(),
                0.0,
                page.getContent(),
                page.getSummary(),
                page.isMinorEdit(),
                page.getFormat(),
                page.getParentTitle(),
                page.getRedirectTitle(),
                serviceContext);
      } else {
        importedPage = existingPage;
      }
    }

    if (page.isHead()) {
      List<Element> attachmentElements =
          portletDataContext.getReferenceDataElements(
              pageElement, DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

      for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");

        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

        InputStream inputStream = null;

        try {
          String binPath = attachmentElement.attributeValue("bin-path");

          if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {

            try {
              inputStream = FileEntryUtil.getContentStream(fileEntry);
            } catch (NoSuchFileException nsfe) {
            }
          } else {
            inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
          }

          if (inputStream == null) {
            if (_log.isWarnEnabled()) {
              _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
            }

            continue;
          }

          _wikiPageLocalService.addPageAttachment(
              userId,
              importedPage.getNodeId(),
              importedPage.getTitle(),
              fileEntry.getTitle(),
              inputStream,
              null);
        } finally {
          StreamUtil.cleanUp(inputStream);
        }
      }
    }

    portletDataContext.importClassedModel(page, importedPage);

    Map<Long, Long> pageIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiPage.class + ".pageId");

    pageIds.put(page.getPageId(), importedPage.getPageId());
  }