@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);
  }
  protected void validateLayouts(
      LayoutSetPrototype importedLayoutSetPrototype,
      LayoutPrototype importedLayoutPrototype,
      Layout layoutSetPrototypeLayout)
      throws Exception {

    validatePrototypedLayouts(LayoutSetPrototype.class, importedLayoutSetPrototype.getGroupId());
    validatePrototypedLayouts(LayoutPrototype.class, importedLayoutPrototype.getGroupId());

    Assert.assertNotNull(layoutSetPrototypeLayout.getLayoutPrototypeUuid());

    Layout importedLayout =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layoutSetPrototypeLayout.getUuid(), importedLayoutSetPrototype.getGroupId(), true);

    Assert.assertNotNull(importedLayout);
    Assert.assertEquals(importedLayoutSetPrototype.getGroupId(), importedLayout.getGroupId());
    Assert.assertEquals(importedLayoutPrototype.getUuid(), importedLayout.getLayoutPrototypeUuid());
  }
  protected void exportLayouts(
      PortletDataContext portletDataContext,
      LayoutPrototype layoutPrototype,
      Element layoutPrototypeElement)
      throws Exception {

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            layoutPrototype.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    for (Layout layout : layouts) {
      StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

      portletDataContext.addReferenceElement(
          layoutPrototype,
          layoutPrototypeElement,
          layout,
          PortletDataContext.REFERENCE_TYPE_EMBEDDED,
          false);
    }
  }