@Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, LayoutPrototype layoutPrototype) throws Exception {

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

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(
            layoutPrototype, LayoutPrototypePortletDataHandler.NAMESPACE);

    serviceContext.setAttribute("addDefaultLayout", false);

    LayoutPrototype importedLayoutPrototype = null;

    if (portletDataContext.isDataStrategyMirror()) {
      LayoutPrototype existingLayoutPrototype =
          LayoutPrototypeLocalServiceUtil.fetchLayoutPrototypeByUuidAndCompanyId(
              layoutPrototype.getUuid(), portletDataContext.getCompanyId());

      if (existingLayoutPrototype == null) {
        serviceContext.setUuid(layoutPrototype.getUuid());

        importedLayoutPrototype =
            LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
                userId,
                portletDataContext.getCompanyId(),
                layoutPrototype.getNameMap(),
                layoutPrototype.getDescription(),
                layoutPrototype.isActive(),
                serviceContext);
      } else {
        importedLayoutPrototype =
            LayoutPrototypeLocalServiceUtil.updateLayoutPrototype(
                existingLayoutPrototype.getLayoutPrototypeId(),
                layoutPrototype.getNameMap(),
                layoutPrototype.getDescription(),
                layoutPrototype.isActive(),
                serviceContext);
      }
    } else {
      importedLayoutPrototype =
          LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
              userId,
              portletDataContext.getCompanyId(),
              layoutPrototype.getNameMap(),
              layoutPrototype.getDescription(),
              layoutPrototype.isActive(),
              serviceContext);
    }

    importLayouts(portletDataContext, layoutPrototype, importedLayoutPrototype.getGroupId());

    portletDataContext.importClassedModel(
        layoutPrototype, importedLayoutPrototype, LayoutPrototypePortletDataHandler.NAMESPACE);
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype newLayoutPrototype = _persistence.create(pk);

    newLayoutPrototype.setMvccVersion(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUuid(ServiceTestUtil.randomString());

    newLayoutPrototype.setCompanyId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserName(ServiceTestUtil.randomString());

    newLayoutPrototype.setCreateDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setModifiedDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setName(ServiceTestUtil.randomString());

    newLayoutPrototype.setDescription(ServiceTestUtil.randomString());

    newLayoutPrototype.setSettings(ServiceTestUtil.randomString());

    newLayoutPrototype.setActive(ServiceTestUtil.randomBoolean());

    _persistence.update(newLayoutPrototype);

    LayoutPrototype existingLayoutPrototype =
        _persistence.findByPrimaryKey(newLayoutPrototype.getPrimaryKey());

    Assert.assertEquals(
        existingLayoutPrototype.getMvccVersion(), newLayoutPrototype.getMvccVersion());
    Assert.assertEquals(existingLayoutPrototype.getUuid(), newLayoutPrototype.getUuid());
    Assert.assertEquals(
        existingLayoutPrototype.getLayoutPrototypeId(), newLayoutPrototype.getLayoutPrototypeId());
    Assert.assertEquals(existingLayoutPrototype.getCompanyId(), newLayoutPrototype.getCompanyId());
    Assert.assertEquals(existingLayoutPrototype.getUserId(), newLayoutPrototype.getUserId());
    Assert.assertEquals(existingLayoutPrototype.getUserName(), newLayoutPrototype.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getCreateDate()),
        Time.getShortTimestamp(newLayoutPrototype.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getModifiedDate()),
        Time.getShortTimestamp(newLayoutPrototype.getModifiedDate()));
    Assert.assertEquals(existingLayoutPrototype.getName(), newLayoutPrototype.getName());
    Assert.assertEquals(
        existingLayoutPrototype.getDescription(), newLayoutPrototype.getDescription());
    Assert.assertEquals(existingLayoutPrototype.getSettings(), newLayoutPrototype.getSettings());
    Assert.assertEquals(existingLayoutPrototype.getActive(), newLayoutPrototype.getActive());
  }