@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);
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MDRRuleGroup newMDRRuleGroup = _persistence.create(pk);

    newMDRRuleGroup.setUuid(RandomTestUtil.randomString());

    newMDRRuleGroup.setGroupId(RandomTestUtil.nextLong());

    newMDRRuleGroup.setCompanyId(RandomTestUtil.nextLong());

    newMDRRuleGroup.setUserId(RandomTestUtil.nextLong());

    newMDRRuleGroup.setUserName(RandomTestUtil.randomString());

    newMDRRuleGroup.setCreateDate(RandomTestUtil.nextDate());

    newMDRRuleGroup.setModifiedDate(RandomTestUtil.nextDate());

    newMDRRuleGroup.setName(RandomTestUtil.randomString());

    newMDRRuleGroup.setDescription(RandomTestUtil.randomString());

    _persistence.update(newMDRRuleGroup);

    MDRRuleGroup existingMDRRuleGroup =
        _persistence.findByPrimaryKey(newMDRRuleGroup.getPrimaryKey());

    Assert.assertEquals(existingMDRRuleGroup.getUuid(), newMDRRuleGroup.getUuid());
    Assert.assertEquals(existingMDRRuleGroup.getRuleGroupId(), newMDRRuleGroup.getRuleGroupId());
    Assert.assertEquals(existingMDRRuleGroup.getGroupId(), newMDRRuleGroup.getGroupId());
    Assert.assertEquals(existingMDRRuleGroup.getCompanyId(), newMDRRuleGroup.getCompanyId());
    Assert.assertEquals(existingMDRRuleGroup.getUserId(), newMDRRuleGroup.getUserId());
    Assert.assertEquals(existingMDRRuleGroup.getUserName(), newMDRRuleGroup.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMDRRuleGroup.getCreateDate()),
        Time.getShortTimestamp(newMDRRuleGroup.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMDRRuleGroup.getModifiedDate()),
        Time.getShortTimestamp(newMDRRuleGroup.getModifiedDate()));
    Assert.assertEquals(existingMDRRuleGroup.getName(), newMDRRuleGroup.getName());
    Assert.assertEquals(existingMDRRuleGroup.getDescription(), newMDRRuleGroup.getDescription());
  }
  @Override
  protected void validateImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> dependentStagedModels =
        dependentStagedModelsMap.get(MDRRuleGroup.class.getName());

    Assert.assertEquals(1, dependentStagedModels.size());

    MDRRuleGroup ruleGroup = (MDRRuleGroup) dependentStagedModels.get(0);

    MDRRuleGroupLocalServiceUtil.getMDRRuleGroupByUuidAndGroupId(
        ruleGroup.getUuid(), group.getGroupId());
  }