Fixing magic numbers 17/18217/10
authorDebalina Ghosh <debalina.ghosh@hp.com>
Mon, 13 Apr 2015 20:31:43 +0000 (13:31 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 11 May 2015 08:16:55 +0000 (08:16 +0000)
Change-Id: Id844166d94e9d8059bb48fadfbccec95fe45cf46
Signed-off-by: Debalina Ghosh <debalina.ghosh@hp.com>
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/AbstractDataStore.java
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/BindingToRestRpc.java
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/ConfigurationDataStoreImpl.java
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestListenableEventStreamContext.java
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java

index ce00e2c29585a2031d9624ed32e42f46499eb80f..9cb4a62c8aa393430d5bb575187b25dd9aa04fe6 100644 (file)
@@ -20,6 +20,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 public abstract class AbstractDataStore implements Datastore {
 
     private final RestconfClientImpl client;
+    private static final int STATUS_OK = 200;
+    private static final int STATUS_NOT_FOUND = 404;
 
     public AbstractDataStore(RestconfClientImpl client) {
         super();
@@ -50,14 +52,14 @@ public abstract class AbstractDataStore implements Datastore {
             @SuppressWarnings("unchecked")
             @Override
             public com.google.common.base.Optional<T> apply(ClientResponse response) {
-                switch (response.getStatus()) {
-                case 200: // Status OK
-                    DataObject dataObject = deserialize(domPath,response.getEntityInputStream());
-                    return (Optional<T>) Optional.of(dataObject);
-                case 404: // Status Not Found
-                    return Optional.<T> absent();
+              switch (response.getStatus()) {
+                case STATUS_OK:
+                  DataObject dataObject = deserialize(domPath,response.getEntityInputStream());
+                  return (Optional<T>) Optional.of(dataObject);
+                case STATUS_NOT_FOUND:
+                  return Optional.<T> absent();
                 default:
-                    throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
+                  throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
                 }
             }
 
index aa5342c66b962ea83fd9f8bbf41f42a20844f9f1..4a56b5a5e14dad3101c85e7136a687e4e93b68c5 100644 (file)
@@ -40,6 +40,7 @@ public class BindingToRestRpc implements InvocationHandler {
     private final BindingNormalizedNodeCodecRegistry mappingService;
     private final SchemaContext schcemaContext;
     private final Module module;
+    private static final int STATUS_OK = 200;
 
     public BindingToRestRpc(final Class<?> proxiedInterface,final BindingNormalizedNodeCodecRegistry mappingService2,final RestconfClientImpl client,final SchemaContext schemaContext) throws Exception {
         this.mappingService = mappingService2;
@@ -70,7 +71,7 @@ public class BindingToRestRpc implements InvocationHandler {
                 return client.post(ResourceUri.OPERATIONS.getPath() + "/" + moduleName + ":" + rpcMethodName,payloadString,new Function<ClientResponse, Object>() {
                     @Override
                     public Object apply(final ClientResponse clientResponse) {
-                        if (clientResponse.getStatus() != 200) {
+                        if (clientResponse.getStatus() != STATUS_OK) {
                             throw new IllegalStateException("Can't get data from restconf. "+clientResponse.getClientResponseStatus());
                         }
                         List<RpcError> errors =  new ArrayList<>();
index 309f3555651439c34345b6edb4902cff76ff7f46..0e6c7cd5a89223fa10707b61799da545bb550d11 100644 (file)
@@ -31,6 +31,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class ConfigurationDataStoreImpl extends AbstractDataStore implements ConfigurationDatastore  {
 
+    private static final int STATUS_OK = 200;
+
     @Override
     protected String getStorePrefix() {
         return ResourceUri.CONFIG.getPath();
@@ -52,7 +54,7 @@ public class ConfigurationDataStoreImpl extends AbstractDataStore implements Con
             @SuppressWarnings("unchecked")
             @Override
             public RpcResult<Boolean> apply(ClientResponse clientResponse) {
-                if (clientResponse.getStatus() != 200) {
+                if (clientResponse.getStatus() != STATUS_OK) {
                     RpcError rpcError = new RestRpcError(RpcError.ErrorSeverity.ERROR,RpcError.ErrorType.RPC,null,null,"HTTP status "+clientResponse.getStatus(),null,null);
                     Collection<RpcError> errors = new ArrayList<RpcError>();
                     errors.add(rpcError);
@@ -78,7 +80,7 @@ public class ConfigurationDataStoreImpl extends AbstractDataStore implements Con
             @SuppressWarnings("unchecked")
             @Override
             public RpcResult<Boolean> apply(ClientResponse clientResponse) {
-                if (clientResponse.getStatus() != 200) {
+                if (clientResponse.getStatus() != STATUS_OK) {
                     RpcError rpcError = new RestRpcError(RpcError.ErrorSeverity.ERROR,RpcError.ErrorType.RPC,null,null,"HTTP status "+clientResponse.getStatus(),null,null);
                     Collection<RpcError> errors = new ArrayList<RpcError>();
                     errors.add(rpcError);
index a14ea33b5f0adb484635d26b00d3517100b33d03..e741b246b84ace6c04ef29770a86eca98b1b398b 100644 (file)
@@ -55,6 +55,7 @@ public class RestListenableEventStreamContext<L extends NotificationListener> im
     private Method listenerCallbackMethod;
     private final RestconfClientImpl restconfClient;
     private final EventStreamInfo streamInfo;
+    private static final int STATUS_OK = 200;
 
     public RestListenableEventStreamContext(final EventStreamInfo streamInfo,final RestconfClientImpl restconfClient){
         this.restconfClient = restconfClient;
@@ -96,7 +97,7 @@ public class RestListenableEventStreamContext<L extends NotificationListener> im
             throw new IllegalStateException(e);
         }
         boolean success = true;
-        if (response.getStatus() != 200) {
+        if (response.getStatus() != STATUS_OK) {
             success = false;
         }
 
index 2672a5bc125af9f0b8d70d8b98f19f1eceb8d1f5..7291af0e8e33e552cc47aba891ca18f455bd10c6 100644 (file)
@@ -68,6 +68,8 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL
 
     private DataObjectSerializerGenerator generator;
 
+    private static final int STATUS_OK = 200;
+
     public RestconfClientImpl(final URL url, final SchemaContextHolder schemaContextHolder) {
         Preconditions.checkArgument(url != null, "Restconf endpoint URL must be supplied.");
         Preconditions.checkNotNull(schemaContextHolder, "Schema Context Holder must not be null.");
@@ -108,7 +110,7 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL
                 new Function<ClientResponse, Set<Class<? extends RpcService>>>() {
                     @Override
                     public Set<Class<? extends RpcService>> apply(final ClientResponse clientResponse) {
-                        if (clientResponse.getStatus() != 200) {
+                        if (clientResponse.getStatus() != STATUS_OK) {
                             throw new RuntimeException("Failed : HTTP error code : " + clientResponse.getStatus());
                         }
                         return RestconfUtils.rpcServicesFromInputStream(clientResponse.getEntityInputStream(),
@@ -129,7 +131,7 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL
                 new Function<ClientResponse, Set<EventStreamInfo>>() {
                     @Override
                     public Set<EventStreamInfo> apply(final ClientResponse clientResponse) {
-                        if (clientResponse.getStatus() != 200) {
+                        if (clientResponse.getStatus() != STATUS_OK) {
                             throw new RuntimeException("Failed : HTTP error code : " + clientResponse.getStatus());
                         }
                         try {