コード例 #1
0
  @Override
  public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException {

    ExportImportConfiguration exportImportConfiguration =
        getExportImportConfiguration(backgroundTask);

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

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

    StringBundler sb = new StringBundler(4);

    sb.append(
        StringUtil.replace(
            exportImportConfiguration.getName(), StringPool.SPACE, StringPool.UNDERLINE));
    sb.append(StringPool.DASH);
    sb.append(Time.getShortTimestamp());
    sb.append(".lar");

    File larFile =
        LayoutLocalServiceUtil.exportLayoutsAsFile(
            groupId,
            privateLayout,
            layoutIds,
            parameterMap,
            dateRange.getStartDate(),
            dateRange.getEndDate());

    BackgroundTaskLocalServiceUtil.addBackgroundTaskAttachment(
        userId, backgroundTask.getBackgroundTaskId(), sb.toString(), larFile);

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

    if (updateLastPublishDate) {
      ExportImportDateUtil.updateLastPublishDate(
          groupId, privateLayout, dateRange, dateRange.getEndDate());
    }

    return BackgroundTaskResult.SUCCESS;
  }
    @Override
    public MissingReferences call() throws PortalException {
      Map<String, Serializable> settingsMap = _exportImportConfiguration.getSettingsMap();

      long userId = MapUtil.getLong(settingsMap, "userId");
      long targetPlid = MapUtil.getLong(settingsMap, "targetPlid");
      long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");
      String portletId = MapUtil.getString(settingsMap, "portletId");
      Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");

      long sourcePlid = MapUtil.getLong(settingsMap, "sourcePlid");
      long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
      DateRange dateRange =
          ExportImportDateUtil.getDateRange(
              _exportImportConfiguration, ExportImportDateUtil.RANGE_FROM_LAST_PUBLISH_DATE);

      File larFile = null;
      MissingReferences missingReferences = null;

      try {
        larFile =
            LayoutLocalServiceUtil.exportPortletInfoAsFile(
                sourcePlid,
                sourceGroupId,
                portletId,
                parameterMap,
                dateRange.getStartDate(),
                dateRange.getEndDate());

        markBackgroundTask(_backgroundTaskId, "exported");

        missingReferences =
            LayoutLocalServiceUtil.validateImportPortletInfo(
                userId, targetPlid, targetGroupId, portletId, parameterMap, larFile);

        markBackgroundTask(_backgroundTaskId, "validated");

        LayoutLocalServiceUtil.importPortletInfo(
            userId, targetPlid, targetGroupId, portletId, parameterMap, larFile);
      } finally {
        larFile.delete();
      }

      return missingReferences;
    }
    @Override
    public MissingReferences call() throws PortalException {
      long stagingRequestId = 0;

      File file = null;
      FileInputStream fileInputStream = null;
      HttpPrincipal httpPrincipal = null;
      MissingReferences missingReferences = null;

      try {
        Map<String, Serializable> settingsMap = _exportImportConfiguration.getSettingsMap();

        long sourceGroupId = MapUtil.getLong(settingsMap, "sourceGroupId");
        boolean privateLayout = MapUtil.getBoolean(settingsMap, "privateLayout");

        initThreadLocals(sourceGroupId, privateLayout);

        Map<Long, Boolean> layoutIdMap = (Map<Long, Boolean>) settingsMap.get("layoutIdMap");
        Map<String, String[]> parameterMap =
            (Map<String, String[]>) settingsMap.get("parameterMap");
        long remoteGroupId = MapUtil.getLong(settingsMap, "remoteGroupId");
        DateRange dateRange = ExportImportDateUtil.getDateRange(_exportImportConfiguration);

        BackgroundTask backgroundTask =
            BackgroundTaskLocalServiceUtil.getBackgroundTask(_backgroundTaskId);

        Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap();

        httpPrincipal = (HttpPrincipal) taskContextMap.get("httpPrincipal");

        file =
            exportLayoutsAsFile(
                sourceGroupId,
                privateLayout,
                layoutIdMap,
                parameterMap,
                remoteGroupId,
                dateRange.getStartDate(),
                dateRange.getEndDate(),
                httpPrincipal);

        String checksum = FileUtil.getMD5Checksum(file);

        fileInputStream = new FileInputStream(file);

        stagingRequestId =
            StagingServiceHttp.createStagingRequest(httpPrincipal, remoteGroupId, checksum);

        byte[] bytes = new byte[PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE];

        int i = 0;
        int j = 0;

        String numberFormat =
            String.format(
                "%%0%dd", String.valueOf((int) (file.length() / bytes.length)).length() + 1);

        while ((i = fileInputStream.read(bytes)) >= 0) {
          String fileName = file.getName() + String.format(numberFormat, j++);

          if (i < PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE) {
            byte[] tempBytes = new byte[i];

            System.arraycopy(bytes, 0, tempBytes, 0, i);

            StagingServiceHttp.updateStagingRequest(
                httpPrincipal, stagingRequestId, fileName, tempBytes);
          } else {
            StagingServiceHttp.updateStagingRequest(
                httpPrincipal, stagingRequestId, fileName, bytes);
          }

          bytes = new byte[PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE];
        }

        markBackgroundTask(_backgroundTaskId, "exported");

        StagingServiceHttp.publishStagingRequest(
            httpPrincipal, stagingRequestId, privateLayout, parameterMap);
      } catch (IOException ioe) {
        deleteTempLarOnFailure(file);

        throw new SystemException(ioe);
      } catch (Throwable t) {
        deleteTempLarOnFailure(file);

        throw t;
      } finally {
        StreamUtil.cleanUp(fileInputStream);

        if (stagingRequestId > 0) {
          StagingServiceHttp.cleanUpStagingRequest(httpPrincipal, stagingRequestId);
        }
      }

      deleteTempLarOnSuccess(file);

      return missingReferences;
    }