Ejemplo n.º 1
0
 @Override
 public void setProperty(Object bean, String param, Object value) {
   try {
     BeanUtil.setProperty(bean, param, value);
   } catch (Exception e) {
     _log.error(e, e);
   }
 }
  protected SyncDLObject updateFileEntries(
      ZipReader zipReader,
      String zipFileId,
      JSONWebServiceActionParametersMap jsonWebServiceActionParametersMap)
      throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    List<NameValue<String, Object>> innerParameters =
        jsonWebServiceActionParametersMap.getInnerParameters("serviceContext");

    if (innerParameters != null) {
      for (NameValue<String, Object> innerParameter : innerParameters) {
        try {
          BeanUtil.setProperty(serviceContext, innerParameter.getName(), innerParameter.getValue());
        } catch (Exception e) {
          if (_log.isDebugEnabled()) {
            _log.debug(e.getMessage(), e);
          }
        }
      }
    }

    String urlPath = MapUtil.getString(jsonWebServiceActionParametersMap, "urlPath");

    if (urlPath.endsWith("/add-file-entry")) {
      long repositoryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "repositoryId");
      long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId");
      String sourceFileName =
          MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName");
      String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType");
      String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title");
      String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description");
      String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog");

      InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId);

      File tempFile = null;

      try {
        tempFile = FileUtil.createTempFile(inputStream);

        String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum");

        return addFileEntry(
            repositoryId,
            folderId,
            sourceFileName,
            mimeType,
            title,
            description,
            changeLog,
            tempFile,
            checksum,
            serviceContext);
      } finally {
        FileUtil.delete(tempFile);
      }
    } else if (urlPath.endsWith("/add-folder")) {
      long repositoryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "repositoryId");
      long parentFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "parentFolderId");
      String name = MapUtil.getString(jsonWebServiceActionParametersMap, "name");
      String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description");

      return addFolder(repositoryId, parentFolderId, name, description, serviceContext);
    } else if (urlPath.endsWith("/move-file-entry")) {
      long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId");
      long newFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "newFolderId");

      return moveFileEntry(fileEntryId, newFolderId, serviceContext);
    } else if (urlPath.endsWith("/move-file-entry-to-trash")) {
      long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId");

      return moveFileEntryToTrash(fileEntryId);
    } else if (urlPath.endsWith("/move-folder")) {
      long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId");
      long parentFolderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "parentFolderId");

      return moveFolder(folderId, parentFolderId, serviceContext);
    } else if (urlPath.endsWith("/move-folder-to-trash")) {
      long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId");

      return moveFolderToTrash(folderId);
    } else if (urlPath.endsWith("/patch-file-entry")) {
      long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId");
      long sourceVersionId = MapUtil.getLong(jsonWebServiceActionParametersMap, "sourceVersionId");
      String sourceFileName =
          MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName");
      String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType");
      String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title");
      String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description");
      String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog");
      boolean majorVersion = MapUtil.getBoolean(jsonWebServiceActionParametersMap, "majorVersion");

      InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId);

      File tempFile = null;

      try {
        tempFile = FileUtil.createTempFile(inputStream);

        String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum");

        return patchFileEntry(
            fileEntryId,
            sourceVersionId,
            sourceFileName,
            mimeType,
            title,
            description,
            changeLog,
            majorVersion,
            tempFile,
            checksum,
            serviceContext);
      } finally {
        FileUtil.delete(tempFile);
      }
    } else if (urlPath.endsWith("/update-file-entry")) {
      long fileEntryId = MapUtil.getLong(jsonWebServiceActionParametersMap, "fileEntryId");
      String sourceFileName =
          MapUtil.getString(jsonWebServiceActionParametersMap, "sourceFileName");
      String mimeType = MapUtil.getString(jsonWebServiceActionParametersMap, "mimeType");
      String title = MapUtil.getString(jsonWebServiceActionParametersMap, "title");
      String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description");
      String changeLog = MapUtil.getString(jsonWebServiceActionParametersMap, "changeLog");
      boolean majorVersion = MapUtil.getBoolean(jsonWebServiceActionParametersMap, "majorVersion");

      File tempFile = null;

      try {
        InputStream inputStream = zipReader.getEntryAsInputStream(zipFileId);

        if (inputStream != null) {
          tempFile = FileUtil.createTempFile(inputStream);
        }

        String checksum = MapUtil.getString(jsonWebServiceActionParametersMap, "checksum");

        return updateFileEntry(
            fileEntryId,
            sourceFileName,
            mimeType,
            title,
            description,
            changeLog,
            majorVersion,
            tempFile,
            checksum,
            serviceContext);
      } finally {
        FileUtil.delete(tempFile);
      }
    } else if (urlPath.endsWith("/update-folder")) {
      long folderId = MapUtil.getLong(jsonWebServiceActionParametersMap, "folderId");
      String name = MapUtil.getString(jsonWebServiceActionParametersMap, "name");
      String description = MapUtil.getString(jsonWebServiceActionParametersMap, "description");

      return updateFolder(folderId, name, description, serviceContext);
    }

    return null;
  }