@Override
    public Void call() throws PortalException {
      Group group = _groupLocalService.getGroup(_groupId);

      Layout layout = _layoutLocalService.fetchLayout(_plid);

      if (group.hasStagingGroup()) {
        group = group.getStagingGroup();

        if (layout != null) {
          layout =
              _layoutLocalService.fetchLayoutByUuidAndGroupId(
                  layout.getUuid(), group.getGroupId(), layout.isPrivateLayout());
        }
      }

      javax.portlet.PortletPreferences jxPortletPreferences = null;

      if (layout == null) {
        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(
                group.getCompanyId(), group.getGroupId(), _portletId);
      } else {
        jxPortletPreferences =
            PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, _portletId);
      }

      ExportImportDateUtil.updateLastPublishDate(
          _portletId, jxPortletPreferences, _dateRange, _endDate);

      return null;
    }
  protected PortletDataContext getPortletDataContext(
      ExportImportConfiguration exportImportConfiguration) throws PortalException {

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long sourcePlid = MapUtil.getLong(settingsMap, "sourcePlid");
    long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
    String portletId = MapUtil.getString(settingsMap, "portletId");
    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    DateRange dateRange = ExportImportDateUtil.getDateRange(exportImportConfiguration);

    Layout layout = _layoutLocalService.getLayout(sourcePlid);
    ZipWriter zipWriter = ExportImportHelperUtil.getPortletZipWriter(portletId);

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            layout.getCompanyId(),
            sourceGroupId,
            parameterMap,
            dateRange.getStartDate(),
            dateRange.getEndDate(),
            zipWriter);

    portletDataContext.setOldPlid(sourcePlid);
    portletDataContext.setPlid(sourcePlid);
    portletDataContext.setPortletId(portletId);

    return portletDataContext;
  }
  protected PortletDataContext getPortletDataContext(
      ExportImportConfiguration exportImportConfiguration) throws Exception {

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
    boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout");
    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    DateRange dateRange = ExportImportDateUtil.getDateRange(exportImportConfiguration);

    Group group = _groupLocalService.getGroup(sourceGroupId);
    ZipWriter zipWriter = ExportImportHelperUtil.getLayoutSetZipWriter(sourceGroupId);

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            group.getCompanyId(),
            sourceGroupId,
            parameterMap,
            dateRange.getStartDate(),
            dateRange.getEndDate(),
            zipWriter);

    portletDataContext.setPrivateLayout(privateLayout);

    return portletDataContext;
  }
    @Override
    public Void call() throws PortalException {
      StagedModelRepository<T> stagedModelRepository = getStagedModelRepository();

      if (stagedModelRepository == null) {
        return null;
      }

      T stagedModel = stagedModelRepository.fetchStagedModelByUuidAndGroupId(_uuid, _groupId);

      if (stagedModel == null) {
        return null;
      }

      Date endDate = null;

      if (_dateRange != null) {
        endDate = _dateRange.getEndDate();
      }

      ExportImportDateUtil.updateLastPublishDate(
          (StagedGroupedModel) stagedModel, _dateRange, endDate);

      stagedModelRepository.saveStagedModel(stagedModel);

      return null;
    }
    @Override
    public Void call() throws PortalException {
      Group group = _groupLocalService.getGroup(_groupId);

      Date endDate = null;

      if (_dateRange != null) {
        endDate = _dateRange.getEndDate();
      }

      if (group.hasStagingGroup()) {
        Group stagingGroup = group.getStagingGroup();

        ExportImportDateUtil.updateLastPublishDate(
            stagingGroup.getGroupId(), _privateLayout, _dateRange, endDate);
      } else {
        ExportImportDateUtil.updateLastPublishDate(_groupId, _privateLayout, _dateRange, endDate);
      }

      return null;
    }
    @Override
    public Void call() throws PortalException {
      StagedModelRepository<T> stagedModelRepository = getStagedModelRepository();

      if (stagedModelRepository == null) {
        return null;
      }

      T stagedModel = stagedModelRepository.fetchStagedModelByUuidAndGroupId(_uuid, _groupId);

      if (stagedModel == null) {
        return null;
      }

      Date endDate = null;

      if (_dateRange != null) {
        endDate = _dateRange.getEndDate();
      }

      ExportImportDateUtil.updateLastPublishDate(
          (StagedGroupedModel) stagedModel, _dateRange, endDate);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setModifiedDate(stagedModel.getModifiedDate());

      ServiceContextThreadLocal.pushServiceContext(serviceContext);

      try {
        stagedModelRepository.saveStagedModel(stagedModel);
      } finally {
        ServiceContextThreadLocal.popServiceContext();
      }

      return null;
    }
  public void exportPortletData(
      PortletDataContext portletDataContext,
      Portlet portlet,
      Layout layout,
      javax.portlet.PortletPreferences jxPortletPreferences,
      Element parentElement)
      throws Exception {

    if (portlet == null) {
      return;
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) {

      return;
    }

    Group group = layout.getGroup();

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    String portletId = portlet.getPortletId();

    if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

      if (_log.isDebugEnabled()) {
        _log.debug(
            "Not exporting data for " + portletId + " because it is configured not to be staged");
      }

      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Exporting data for " + portletId);
    }

    StringBundler sb = new StringBundler(4);

    sb.append(ExportImportPathUtil.getPortletPath(portletDataContext, portletId));
    sb.append(StringPool.SLASH);

    if (portlet.isPreferencesUniquePerLayout()) {
      sb.append(layout.getPlid());
    } else {
      sb.append(portletDataContext.getScopeGroupId());
    }

    sb.append("/portlet-data.xml");

    String path = sb.toString();

    if (portletDataContext.hasPrimaryKey(String.class, path)) {
      return;
    }

    Date originalStartDate = portletDataContext.getStartDate();

    Date portletLastPublishDate =
        ExportImportDateUtil.getLastPublishDate(portletDataContext, jxPortletPreferences);

    portletDataContext.setStartDate(portletLastPublishDate);

    long groupId = portletDataContext.getGroupId();

    portletDataContext.setGroupId(portletDataContext.getScopeGroupId());

    portletDataContext.clearScopedPrimaryKeys();

    String data = null;

    try {
      data = portletDataHandler.exportData(portletDataContext, portletId, jxPortletPreferences);
    } catch (PortletDataException pde) {
      throw pde;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      portletDataContext.setGroupId(groupId);
      portletDataContext.setStartDate(originalStartDate);
    }

    if (Validator.isNull(data)) {
      if (_log.isDebugEnabled()) {
        _log.debug("Not exporting data for " + portletId + " because null data was returned");
      }

      return;
    }

    Element portletDataElement = parentElement.addElement("portlet-data");

    portletDataElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, data);

    boolean updateLastPublishDate =
        MapUtil.getBoolean(
            portletDataContext.getParameterMap(), PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

      DateRange adjustedDateRange =
          new DateRange(portletLastPublishDate, portletDataContext.getEndDate());

      ExportImportProcessCallbackRegistryUtil.registerCallback(
          new UpdatePortletLastPublishDateCallable(
              adjustedDateRange,
              portletDataContext.getEndDate(),
              portletDataContext.getGroupId(),
              layout.getPlid(),
              portletId));
    }
  }