geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch feature/GEODE-4131 updated: GEODE-4131: remove ConverterUtil
Date Thu, 28 Dec 2017 21:23:06 GMT
This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch feature/GEODE-4131
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-4131 by this push:
     new fefcc7a  GEODE-4131: remove ConverterUtil
fefcc7a is described below

commit fefcc7a5d9586ec637ada420af6a8bbebc80cb5e
Author: Jinmei Liao <jiliao@pivotal.io>
AuthorDate: Thu Dec 28 13:22:33 2017 -0800

    GEODE-4131: remove ConverterUtil
---
 .../web/controllers/ShellCommandsController.java   |   4 -
 .../internal/web/shell/HttpOperationInvoker.java   |   9 +-
 .../management/internal/web/util/ConvertUtils.java | 128 -----------------
 .../ShellCommandsControllerProcessCommandTest.java |   3 -
 .../internal/web/util/ConvertUtilsJUnitTest.java   | 151 ---------------------
 5 files changed, 4 insertions(+), 291 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
index a3c18e0..39b0753 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java
@@ -20,10 +20,7 @@ import static org.apache.geode.management.internal.web.util.UriUtils.decode;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
@@ -55,7 +52,6 @@ import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
 import org.apache.geode.management.internal.web.domain.QueryParameterSource;
-import org.apache.geode.management.internal.web.util.ConvertUtils;
 
 /**
  * The ShellCommandsController class implements GemFire REST API calls for Gfsh Shell Commands.
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
index 0d9d8c5..b17d348 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
@@ -14,6 +14,7 @@
  */
 package org.apache.geode.management.internal.web.shell;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Properties;
@@ -26,7 +27,7 @@ import javax.management.ObjectName;
 import javax.management.QueryExp;
 
 import org.apache.logging.log4j.Logger;
-import org.springframework.core.io.Resource;
+import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.MediaType;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -42,7 +43,6 @@ import org.apache.geode.management.internal.cli.shell.OperationInvoker;
 import org.apache.geode.management.internal.web.domain.QueryParameterSource;
 import org.apache.geode.management.internal.web.http.support.HttpRequester;
 import org.apache.geode.management.internal.web.shell.support.HttpMBeanProxyFactory;
-import org.apache.geode.management.internal.web.util.ConvertUtils;
 
 /**
  * The HttpOperationInvoker class is an abstract base class encapsulating common functionality
for
@@ -420,9 +420,8 @@ public class HttpOperationInvoker implements OperationInvoker {
     if (command.hasFileData()) {
       MultiValueMap<String, Object> content = new LinkedMultiValueMap<String, Object>();
 
-      Resource[] resources = ConvertUtils.convert(command.getFileList());
-      for (Resource resource : resources) {
-        content.add(RESOURCES_REQUEST_PARAMETER, resource);
+      for (File file : command.getFileList()) {
+        content.add(RESOURCES_REQUEST_PARAMETER, new FileSystemResource(file));
       }
       return httpRequester.post(link, MediaType.MULTIPART_FORM_DATA, content, String.class);
     }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
b/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
deleted file mode 100644
index 2d2b991..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/util/ConvertUtils.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.geode.management.internal.web.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.web.multipart.MultipartFile;
-
-import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.web.io.MultipartFileResourceAdapter;
-
-/**
- * The ConvertUtils class is a support class for performing conversions used by the GemFire
web
- * application and REST interface.
- * <p/>
- *
- * @see org.apache.geode.management.internal.cli.CliUtil
- * @since GemFire 8.0
- */
-@SuppressWarnings("unused")
-public abstract class ConvertUtils {
-
-  /**
-   * Converts the 2-dimensional byte array of file data, which includes the name of the file
as
-   * bytes followed by the byte content of the file, for all files being transmitted by Gfsh
to the
-   * GemFire Manager.
-   * <p/>
-   *
-   * @param fileList a 2 dimensional byte array of files names and file content.
-   * @return an array of Spring Resource objects encapsulating the details (name and content)
of
-   *         each file being transmitted by Gfsh to the GemFire Manager.
-   * @see org.springframework.core.io.ByteArrayResource
-   * @see org.springframework.core.io.Resource
-   * @see org.apache.geode.management.internal.cli.CliUtil#bytesToData(byte[][])
-   * @see org.apache.geode.management.internal.cli.CliUtil#bytesToNames(byte[][])
-   */
-  public static Resource[] convert(final List<File> fileList) {
-    if (fileList == null) {
-      return new Resource[0];
-    }
-
-    final List<Resource> resources = new ArrayList<Resource>();
-
-    for (File file : fileList) {
-      resources.add(new FileSystemResource(file));
-    }
-
-    return resources.toArray(new Resource[resources.size()]);
-  }
-
-  /**
-   * Converts the array of MultipartFiles into a 2-dimensional byte array containing content
from
-   * each MultipartFile. The 2-dimensional byte array format is used by Gfsh and the GemFire
Manager
-   * to transmit file data.
-   * <p/>
-   *
-   * @param files an array of Spring MultipartFile objects to convert into the 2-dimensional
byte
-   *        array format.
-   * @return a 2-dimensional byte array containing the content of each MultipartFile.
-   * @throws IOException if an I/O error occurs reading the contents of a MultipartFile.
-   * @see #convert(org.springframework.core.io.Resource...)
-   * @see org.springframework.web.multipart.MultipartFile
-   */
-  public static byte[][] convert(final MultipartFile... files) throws IOException {
-    if (files == null) {
-      return new byte[0][];
-    }
-
-    final List<Resource> resources = new ArrayList<Resource>(files.length);
-    for (final MultipartFile file : files) {
-      resources.add(new MultipartFileResourceAdapter(file));
-    }
-    return convert(resources.toArray(new Resource[resources.size()]));
-  }
-
-  /**
-   * Converts the array of Resources into a 2-dimensional byte array containing content from
each
-   * Resource. The 2-dimensional byte array format is used by Gfsh and the GemFire Manager
to
-   * transmit file data.
-   * <p/>
-   *
-   * @param resources an array of Spring Resource objects to convert into the 2-dimensional
byte
-   *        array format.
-   * @return a 2-dimensional byte array containing the content of each Resource.
-   * @throws IllegalArgumentException if the filename of a Resource was not specified.
-   * @throws IOException if an I/O error occurs reading the contents of a Resource!
-   * @see org.springframework.core.io.Resource
-   */
-  public static byte[][] convert(final Resource... resources) throws IOException {
-    if (resources == null) {
-      return new byte[0][];
-    }
-
-    final List<byte[]> fileData = new ArrayList<byte[]>(resources.length * 2);
-
-    for (final Resource resource : resources) {
-      if (StringUtils.isBlank(resource.getFilename())) {
-        throw new IllegalArgumentException(String.format(
-            "The filename of Resource (%1$s) must be specified!", resource.getDescription()));
-      }
-
-      fileData.add(resource.getFilename().getBytes());
-      fileData.add(IOUtils.toByteArray(resource.getInputStream()));
-    }
-
-    return fileData.toArray(new byte[fileData.size()][]);
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
index f65e899..a0139dd 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/web/controllers/ShellCommandsControllerProcessCommandTest.java
@@ -18,8 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.FileUtils;
@@ -35,7 +33,6 @@ import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.multipart.MultipartFile;
 
-import org.apache.geode.management.RemoteInputStreamAttribute;
 import org.apache.geode.management.internal.cli.CommandResponseBuilder;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.result.ErrorResultData;
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
b/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
deleted file mode 100644
index 11aa070..0000000
--- a/geode-web/src/test/java/org/apache/geode/management/internal/web/util/ConvertUtilsJUnitTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.geode.management.internal.web.util;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.Resource;
-import org.springframework.web.multipart.MultipartFile;
-
-import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.management.internal.web.io.MultipartFileAdapter;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-/**
- * The ConvertUtilsJUnitTest class is a test suite testing the contract and functionality
of the
- * ConvertUtilsJUnitTest class.
- * <p/>
- *
- * @see org.apache.geode.management.internal.web.util.ConvertUtils
- * @see org.junit.Assert
- * @see org.junit.Test
- * @since GemFire 8.0
- */
-@Category(UnitTest.class)
-public class ConvertUtilsJUnitTest {
-
-  private MultipartFile createMultipartFile(final String filename, final byte[] content)
{
-    return new MultipartFileAdapter() {
-      @Override
-      public byte[] getBytes() throws IOException {
-        return content;
-      }
-
-      @Override
-      public InputStream getInputStream() throws IOException {
-        return new ByteArrayInputStream(getBytes());
-      }
-
-      @Override
-      public String getName() {
-        return filename;
-      }
-
-      @Override
-      public String getOriginalFilename() {
-        return filename;
-      }
-
-      @Override
-      public long getSize() {
-        return content.length;
-      }
-    };
-  }
-
-  private Resource createResource(final String filename, final byte[] content) {
-    return new ByteArrayResource(content, String.format("Content of file (%1$s).", filename))
{
-      @Override
-      public String getFilename() {
-        return filename;
-      }
-    };
-  }
-
-  @Test
-  public void testConvertMultipartFile() throws IOException {
-    final MultipartFile[] files = {
-        createMultipartFile("/path/to/multi-part/file1.txt",
-            "The contents of multi-part file1.".getBytes()),
-        createMultipartFile("/path/to/multi-part/file2.txt",
-            "The contents of multi-part file2.".getBytes())};
-
-    final byte[][] fileData = ConvertUtils.convert(files);
-
-    assertNotNull(fileData);
-    assertEquals(files.length * 2, fileData.length);
-
-    for (int index = 0; index < fileData.length; index += 2) {
-      assertEquals(files[index / 2].getOriginalFilename(), new String(fileData[index]));
-      assertEquals(new String(files[index / 2].getBytes()), new String(fileData[index + 1]));
-    }
-  }
-
-  @Test
-  public void testConvertResource() throws IOException {
-    final Resource[] resources =
-        {createResource("/path/to/file1.txt", "Contents of file1.".getBytes()),
-            createResource("/path/to/file2.txt", "Contents of file2.".getBytes())};
-
-    final byte[][] fileData = ConvertUtils.convert(resources);
-
-    assertNotNull(fileData);
-    assertEquals(resources.length * 2, fileData.length);
-
-    for (int index = 0; index < fileData.length; index += 2) {
-      assertEquals(resources[index / 2].getFilename(), new String(fileData[index]));
-      assertEquals(new String(IOUtils.toByteArray(resources[index / 2].getInputStream())),
-          new String(fileData[index + 1]));
-    }
-  }
-
-  @Test(expected = IllegalArgumentException.class)
-  public void testConvertResourceWithResourceHavingNoFilename() throws IOException {
-    try {
-      ConvertUtils.convert(createResource(null, "test".getBytes()));
-    } catch (IllegalArgumentException expected) {
-      assertEquals(
-          "The filename of Resource (Byte array resource [Content of file (null).]) must
be specified!",
-          expected.getMessage());
-      throw expected;
-    }
-  }
-
-  @Test
-  public void testConvertResourceWithEmpty() throws IOException {
-    final byte[][] fileData = ConvertUtils.convert(new Resource[0]);
-
-    assertNotNull(fileData);
-    assertEquals(0, fileData.length);
-  }
-
-  @Test
-  public void testConvertResourceWithNull() throws IOException {
-    final byte[][] fileData = ConvertUtils.convert((Resource[]) null);
-
-    assertNotNull(fileData);
-    assertEquals(0, fileData.length);
-  }
-
-}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message