Basic code refactoring base client 95/57495/1
authorseshukm <seshu.kumar.m@huawei.com>
Wed, 25 Jul 2018 11:30:51 +0000 (19:30 +0800)
committerseshukm <seshu.kumar.m@huawei.com>
Wed, 25 Jul 2018 11:30:51 +0000 (19:30 +0800)
Issue-ID: SO-729

Change-Id: Ife12f0bc1670733fca76058f33d567f266ab2f7b
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java
openstack-client/src/main/java/com/woorea/openstack/base/client/HttpMethod.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClientConnector.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackCommand.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java
openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java

index 66130df..58ba733 100644 (file)
@@ -20,51 +20,51 @@ import java.io.InputStream;
 
 
 public class Entity<T> {
-       
-       private T entity;
-       
-       private String contentType;
-       
-       public static <T> Entity<T> json(T entity) {
-               return new Entity<T>(entity, "application/json");
-       }
-       
-       public static <T> Entity<T> stream(T entity) {
-               return new Entity<T>(entity, "application/octet-stream");
-       }
+    
+    private T entity;
+    
+    private String contentType;
+    
+    public static <T> Entity<T> json(T entity) {
+        return new Entity<T>(entity, "application/json");
+    }
+    
+    public static <T> Entity<T> stream(T entity) {
+        return new Entity<T>(entity, "application/octet-stream");
+    }
 
-       public Entity(T entity, String contentType) {
-               super();
-               this.entity = entity;
-               this.contentType = contentType;
-       }
+    public Entity(T entity, String contentType) {
+        super();
+        this.entity = entity;
+        this.contentType = contentType;
+    }
 
-       /**
-        * @return the entity
-        */
-       public T getEntity() {
-               return entity;
-       }
+    /**
+     * @return the entity
+     */
+    public T getEntity() {
+        return entity;
+    }
 
-       /**
-        * @param entity the entity to set
-        */
-       public void setEntity(T entity) {
-               this.entity = entity;
-       }
+    /**
+     * @param entity the entity to set
+     */
+    public void setEntity(T entity) {
+        this.entity = entity;
+    }
 
-       /**
-        * @return the contentType
-        */
-       public String getContentType() {
-               return contentType;
-       }
+    /**
+     * @return the contentType
+     */
+    public String getContentType() {
+        return contentType;
+    }
 
-       /**
-        * @param contentType the contentType to set
-        */
-       public void setContentType(String contentType) {
-               this.contentType = contentType;
-       }
-       
+    /**
+     * @param contentType the contentType to set
+     */
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+    
 }
index 200aaa9..dec8c3f 100644 (file)
@@ -17,5 +17,5 @@
 package com.woorea.openstack.base.client;
 
 public enum HttpMethod {
-       HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
+    HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
 }
index 656c50b..c852ecf 100644 (file)
@@ -45,18 +45,18 @@ package com.woorea.openstack.base.client;
  */\r
 public abstract class OpenStackBaseException extends RuntimeException\r
 {\r
-       private static final long serialVersionUID = 1L;\r
+    private static final long serialVersionUID = 1L;\r
 \r
-       /*\r
-        * Implement only the basic constructors\r
-        */\r
-       public OpenStackBaseException () {}\r
-       \r
-       public OpenStackBaseException(String message) {\r
-               super(message);\r
-       }\r
+    /*\r
+     * Implement only the basic constructors\r
+     */\r
+    public OpenStackBaseException () {}\r
+    \r
+    public OpenStackBaseException(String message) {\r
+        super(message);\r
+    }\r
 \r
-       public OpenStackBaseException(String message, Throwable cause) {\r
-               super(message, cause);\r
-       }\r
+    public OpenStackBaseException(String message, Throwable cause) {\r
+        super(message, cause);\r
+    }\r
 }\r
index 5b98440..0e4ae55 100644 (file)
@@ -19,6 +19,6 @@ package com.woorea.openstack.base.client;
 
 public interface OpenStackClientConnector {
 
-       public <T> OpenStackResponse request(OpenStackRequest<T> request);
+    public <T> OpenStackResponse request(OpenStackRequest<T> request);
 
 }
index 24f34ea..c66b548 100644 (file)
@@ -19,6 +19,6 @@ package com.woorea.openstack.base.client;
 //
 //public interface OpenStackCommand<R> {
 //
-//     OpenStackRequest createRequest(OpenStackClient connector);
+//    OpenStackRequest createRequest(OpenStackClient connector);
 //
 //}
index aaf47cc..21c58f8 100644 (file)
@@ -46,13 +46,13 @@ package com.woorea.openstack.base.client;
  */
 public class OpenStackConnectException extends OpenStackBaseException {
 
-       private static final long serialVersionUID = 7294957362769575271L;
+    private static final long serialVersionUID = 7294957362769575271L;
 
-       public OpenStackConnectException(String message) {
-               super(message);
-       }
+    public OpenStackConnectException(String message) {
+        super(message);
+    }
 
-       public OpenStackConnectException(String message, Throwable cause) {
-               super(message, cause);
-       }
+    public OpenStackConnectException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }
index fabd9db..3a082a2 100644 (file)
@@ -24,135 +24,135 @@ import java.util.ArrayList;
 import java.util.Map;
 
 public class OpenStackRequest<R> {
-       
-       private OpenStackClient client;
-       
-       public OpenStackRequest() {
-               
-       }
-       
-       public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, Class<R> returnType) {
-               this.client = client;
-               this.method = method;
-               this.path = new StringBuilder(path);
-               this.entity = entity;
-               this.returnType = returnType;
-               header("Accept", "application/json");
-       }
-       
-       private String endpoint;
-       
-       private HttpMethod method;
-       
-       private StringBuilder path = new StringBuilder();
-       
-       private Map<String, List<Object>> headers = new HashMap<>();
-       
-       private Entity<?> entity;
-       
-       private Class<R> returnType;
-       
-       public OpenStackRequest<R> endpoint(String endpoint) {
-               this.endpoint = endpoint;
-               return this;
-       }
-       
-       public String endpoint() {
-               return endpoint;
-       }
+    
+    private OpenStackClient client;
+    
+    public OpenStackRequest() {
+        
+    }
+    
+    public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity, Class<R> returnType) {
+        this.client = client;
+        this.method = method;
+        this.path = new StringBuilder(path);
+        this.entity = entity;
+        this.returnType = returnType;
+        header("Accept", "application/json");
+    }
+    
+    private String endpoint;
+    
+    private HttpMethod method;
+    
+    private StringBuilder path = new StringBuilder();
+    
+    private Map<String, List<Object>> headers = new HashMap<>();
+    
+    private Entity<?> entity;
+    
+    private Class<R> returnType;
+    
+    public OpenStackRequest<R> endpoint(String endpoint) {
+        this.endpoint = endpoint;
+        return this;
+    }
+    
+    public String endpoint() {
+        return endpoint;
+    }
 
-       public OpenStackRequest<R> method(HttpMethod method) {
-               this.method = method;
-               return this;
-       }
-       
-       public HttpMethod method() {
-               return method;
-       }
-       
-       public OpenStackRequest<R> path(String path) {
-               this.path.append(path);
-               return this;
-       }
-       
-       public String path() {
-               return path.toString();
-       }
+    public OpenStackRequest<R> method(HttpMethod method) {
+        this.method = method;
+        return this;
+    }
+    
+    public HttpMethod method() {
+        return method;
+    }
+    
+    public OpenStackRequest<R> path(String path) {
+        this.path.append(path);
+        return this;
+    }
+    
+    public String path() {
+        return path.toString();
+    }
 
-       public OpenStackRequest<R> header(String name, Object value) {
-               if(value != null) {
-                       headers.put(name, Arrays.asList(value));
-               }
-               return this;
-       }
-       
-       public Map<String, List<Object>> headers() {
-               return headers;
-       }
-       
-       public <T> Entity<T> entity(T entity, String contentType) {
-               return new Entity<>(entity, contentType);
-       }
-       
-       public Entity<?> entity() {
-               return entity;
-       }
-       
-       public <T> Entity<T> json(T entity) {
-               return entity(entity, "application/json");
-       }
-       
-       public void returnType(Class<R> returnType) {
-               this.returnType = returnType;
-       }
-       
-       public Class<R> returnType() {
-               return returnType;
-       }
-       
-       public R execute() {
-               return client.execute(this);
-       }
-       
-       public OpenStackResponse request() {
-               return client.request(this);
-       }
+    public OpenStackRequest<R> header(String name, Object value) {
+        if(value != null) {
+            headers.put(name, Arrays.asList(value));
+        }
+        return this;
+    }
+    
+    public Map<String, List<Object>> headers() {
+        return headers;
+    }
+    
+    public <T> Entity<T> entity(T entity, String contentType) {
+        return new Entity<>(entity, contentType);
+    }
+    
+    public Entity<?> entity() {
+        return entity;
+    }
+    
+    public <T> Entity<T> json(T entity) {
+        return entity(entity, "application/json");
+    }
+    
+    public void returnType(Class<R> returnType) {
+        this.returnType = returnType;
+    }
+    
+    public Class<R> returnType() {
+        return returnType;
+    }
+    
+    public R execute() {
+        return client.execute(this);
+    }
+    
+    public OpenStackResponse request() {
+        return client.request(this);
+    }
 
-       /* (non-Javadoc)
-        * @see java.lang.Object#toString()
-        */
-       @Override
-       public String toString() {
-               return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method
-                               + ", path=" + path + ", headers=" + headers + ", entity="
-                               + entity + ", returnType=" + returnType + "]";
-       }
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method
+                + ", path=" + path + ", headers=" + headers + ", entity="
+                + entity + ", returnType=" + returnType + "]";
+    }
 
-       private Map<String, List<Object> > queryParams = new LinkedHashMap<>();
+    private Map<String, List<Object> > queryParams = new LinkedHashMap<>();
 
-       public Map<String, List<Object> > queryParams() {
-               return queryParams;
-       }
+    public Map<String, List<Object> > queryParams() {
+        return queryParams;
+    }
 
-       public OpenStackRequest<R> queryParam(String key, Object value) {
-               if (queryParams.containsKey(key)) {
-                       List<Object> values = queryParams.get(key);
-                       values.add(value);
-               } else {
-                       List<Object> values = new ArrayList<>();
-                       values.add(value);
-                       queryParams.put(key, values);
-               }
+    public OpenStackRequest<R> queryParam(String key, Object value) {
+        if (queryParams.containsKey(key)) {
+            List<Object> values = queryParams.get(key);
+            values.add(value);
+        } else {
+            List<Object> values = new ArrayList<>();
+            values.add(value);
+            queryParams.put(key, values);
+        }
 
-               return this;
+        return this;
     }
-       
-       protected static String buildPath(String ... elements) {
-           StringBuilder stringBuilder = new StringBuilder();
-           for (String element : elements) {
+    
+    protected static String buildPath(String ... elements) {
+        StringBuilder stringBuilder = new StringBuilder();
+        for (String element : elements) {
             stringBuilder.append(element);
         }
 
-           return stringBuilder.toString();
-       }
+        return stringBuilder.toString();
+    }
 }
index 1a2f4cb..0add524 100644 (file)
@@ -25,14 +25,14 @@ import java.util.Map;
 
 public interface OpenStackResponse {
 
-       public <T> T getEntity(Class<T> returnType);
+    public <T> T getEntity(Class<T> returnType);
 
-       public <T> T getErrorEntity(Class<T> returnType);
+    public <T> T getErrorEntity(Class<T> returnType);
 
-       public InputStream getInputStream();
+    public InputStream getInputStream();
 
-       public String header(String name);
-       
-       public Map<String, String> headers();
-       
+    public String header(String name);
+    
+    public Map<String, String> headers();
+    
 }
index edc7ec0..bbe0c6f 100644 (file)
@@ -22,38 +22,38 @@ package com.woorea.openstack.base.client;
 
 public class OpenStackResponseException extends OpenStackBaseException {
 
-       private static final long serialVersionUID = 7294957362769575271L;
-
-       protected String message;
-
-       protected int status;
-       
-       // Make the response available for exception handling (includes body)
-       protected OpenStackResponse response;
-
-       public OpenStackResponseException(String message, int status) {
-               this.message = message;
-               this.status = status;
-               this.response = null;
-       }
-
-       public OpenStackResponseException(String message, int status, OpenStackResponse response) {
-               this.message = message;
-               this.status = status;
-               this.response = response;
-       }
-
-       @Override
-       public String getMessage() {
-               return message;
-       }
-
-       public int getStatus() {
-               return status;
-       }
-
-       public OpenStackResponse getResponse() {
-               return response;
-       }
+    private static final long serialVersionUID = 7294957362769575271L;
+
+    protected String message;
+
+    protected int status;
+    
+    // Make the response available for exception handling (includes body)
+    protected OpenStackResponse response;
+
+    public OpenStackResponseException(String message, int status) {
+        this.message = message;
+        this.status = status;
+        this.response = null;
+    }
+
+    public OpenStackResponseException(String message, int status, OpenStackResponse response) {
+        this.message = message;
+        this.status = status;
+        this.response = response;
+    }
+
+    @Override
+    public String getMessage() {
+        return message;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public OpenStackResponse getResponse() {
+        return response;
+    }
 
 }