Sonar Fixes, Formatting
[aaf/authz.git] / cadi / oauth-enduser / src / main / java / org / onap / aaf / cadi / enduser / SimpleRESTClient.java
index 7c63364..3b7ab03 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed 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.
@@ -56,18 +56,18 @@ public class SimpleRESTClient {
         public String[] headers() {
             return EMPTY;
         }};
-    
+
     public SimpleRESTClient(final TokenClientFactory tcf, final String tokenURL, final String endpoint, final String[] scope) throws CadiException, LocatorException, APIException {
         callTimeout = Integer.parseInt(tcf.access.getProperty(Config.AAF_CALL_TIMEOUT,Config.AAF_CALL_TIMEOUT_DEF));
         tokenClient = tcf.newClient(tokenURL);
         Result<TimedToken> rtt = tokenClient.getToken(scope);
-        if(rtt.isOK()) {
+        if (rtt.isOK()) {
             restClient = tcf.newTzClient(endpoint);
-            
-            if((client_id = tcf.access.getProperty(Config.AAF_APPID, null))==null) {
-                if((client_id = tcf.access.getProperty(Config.CADI_ALIAS, null))==null) {
+
+            if ((client_id = tcf.access.getProperty(Config.AAF_APPID, null))==null) {
+                if ((client_id = tcf.access.getProperty(Config.CADI_ALIAS, null))==null) {
                     throw new CadiException(Config.AAF_APPID + " or " + Config.CADI_ALIAS + " needs to be defined");
-                }                
+                }
             }
             try {
                 restClient.setToken(client_id,rtt.value);
@@ -78,7 +78,7 @@ public class SimpleRESTClient {
             throw new CadiException(rtt.error);
         }
     }
-    
+
     public SimpleRESTClient timeout(int newTimeout) {
         callTimeout = newTimeout;
         return this;
@@ -86,10 +86,10 @@ public class SimpleRESTClient {
 
     //Format:<ID>:<APP>:<protocol>[:AS][,<ID>:<APP>:<protocol>]*
     public SimpleRESTClient endUser(Principal principal) {
-        if(principal==null) {
+        if (principal==null) {
             chain = null;
         } else {
-            if(principal instanceof TaggedPrincipal) {
+            if (principal instanceof TaggedPrincipal) {
                 TaggedPrincipal tp = (TaggedPrincipal)principal;
                 chain = tp.getName() + ':' + (app==null?"":app) + ':' + tp.tag() + ":AS";
             } else {
@@ -98,10 +98,10 @@ public class SimpleRESTClient {
         }
         return this;
     }
-    
+
     /**
      * Single Threaded Class for building up content
-     * @author jg1555
+     * @author Instrumental
      *
      */
     public static class Input {
@@ -109,47 +109,47 @@ public class SimpleRESTClient {
 
         private String content;
         private StringBuilder sb;
-        
+
         public Input() {
             content = null;
             sb = null;
         }
-        
+
         public Input(final String content) {
             this.content = content;
         }
-        
+
         public void set(final String content) {
             this.content = content;
         }
-        
+
         public PrintWriter writer() {
             return new PrintWriter(new StringBuilderWriter(builder()));
         }
-        
+
         public StringBuilder builder() {
-            if(sb==null) {
+            if (sb==null) {
                 sb = new StringBuilder();
                 content = null;
             }
             return sb;
         }
-        
+
         /**
          * Reuse StringBuilder object
          */
         public void clear() {
             content = null;
-            if(sb!=null) {
+            if (sb!=null) {
                 sb.setLength(0);
             }
         }
-        
+
         @Override
         public String toString() {
-            if(content!=null) {
+            if (content!=null) {
                 return content;
-            } else if(sb!=null) {
+            } else if (sb!=null) {
                 return sb.toString();
             } else {
                 return "";
@@ -158,11 +158,11 @@ public class SimpleRESTClient {
 
         public byte[] getBytes() {
             byte[] rv;
-            if(content==null) {
-                if(sb==null) {
+            if (content==null) {
+                if (sb==null) {
                     rv = EMPTY_STREAM_BYTES;
                 } else {
-                    rv = sb.toString().getBytes();    
+                    rv = sb.toString().getBytes();
                 }
             } else {
                 rv = content.getBytes();
@@ -173,7 +173,7 @@ public class SimpleRESTClient {
     }
 
     /////////////////////////////////////////////////////////////
-    //  
+    //
     // CREATE
     //
     /////////////////////////////////////////////////////////////
@@ -192,13 +192,13 @@ public class SimpleRESTClient {
                 return client.create(path, contentType, new ETransfer(input));
             }
         });
-        if(!future.get(callTimeout)) {
+        if (!future.get(callTimeout)) {
             throw new RESTException(future);
-        }                    
+        }
     }
 
     /////////////////////////////////////////////////////////////
-    //  
+    //
     // READ
     //
     /////////////////////////////////////////////////////////////
@@ -217,15 +217,15 @@ public class SimpleRESTClient {
                 return client.read(path,accepts, headers());
             }
         });
-        if(future.get(callTimeout)) {
+        if (future.get(callTimeout)) {
             return future.value;
         } else {
             throw new RESTException(future);
-        }                    
+        }
     }
-    
+
     /////////////////////////////////////////////////////////////
-    //  
+    //
     // UPDATE
     //
     /////////////////////////////////////////////////////////////
@@ -245,22 +245,22 @@ public class SimpleRESTClient {
                 return client.update(path, contentType, new ETransfer(input));
             }
         });
-        if(future.get(callTimeout)) {
+        if (future.get(callTimeout)) {
             return future.value;
         } else {
             throw new RESTException(future);
-        }                    
+        }
     }
 
     /////////////////////////////////////////////////////////////
-    //  
+    //
     // DELETE
     //
     /////////////////////////////////////////////////////////////
     public void delete(final String path) throws RESTException, CadiException, LocatorException, APIException  {
         delete(path,APPLICATION_JSON);
     }
-        
+
     public void delete(final String path, final String contentType) throws RESTException, CadiException, LocatorException, APIException  {
         Future<Void> future = restClient.best(new Retryable<Future<Void>>() {
             @Override
@@ -268,19 +268,19 @@ public class SimpleRESTClient {
                 return client.delete(path, contentType);
             }
         });
-        if(!future.get(callTimeout)) {
+        if (!future.get(callTimeout)) {
             throw new RESTException(future);
-        }                    
+        }
     }
 
     /////////////////////////////////////////////////////////////
-    
+
     private static class ETransfer implements EClient.Transfer {
         private Input input;
         public ETransfer(final Input input) {
             this.input = input;
         }
-        
+
         @Override
         public void transfer(OutputStream os) throws IOException, APIException {
             os.write(input.getBytes());
@@ -290,16 +290,16 @@ public class SimpleRESTClient {
     public interface Headers {
         String[] headers();
     }
-    
+
     public String[] headers() {
-        if(chain==null) {
+        if (chain==null) {
             return headers.headers();
         } else {
             String[] strs = headers.headers();
             String[] rv = new String[strs.length+2];
             rv[0]=Config.CADI_USER_CHAIN;
             rv[1]=chain;
-            for(int i = 0;i<strs.length;++i) {
+            for (int i = 0;i<strs.length;++i) {
                 rv[i+2]=strs[i];
             }
             return rv;