summaryrefslogtreecommitdiffstats
path: root/aai-service/provider/src/main
diff options
context:
space:
mode:
authorRich Tabedzki <richard.tabedzki@att.com>2018-02-26 00:46:36 +0000
committerRich Tabedzki <richard.tabedzki@att.com>2018-02-26 01:14:44 +0000
commite920a1343b4aa55f95cd3db2595f52cbbea73399 (patch)
treed19650501630d7c070fb854849c9d48304336119 /aai-service/provider/src/main
parent8a3f1ea2bee98d30c74317fd31f83b6ea3ec4734 (diff)
Improved Java Code Conventions compliance
Changes made: * Fixed Code conventions bugs * Added test classes to improve code coverage Change-Id: Id524d002cb4fa1bf973be2cfb90729199af94d8e Issue-ID: CCSDK-151 Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
Diffstat (limited to 'aai-service/provider/src/main')
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java5
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java35
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java2
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java2
-rw-r--r--aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java97
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java41
6 files changed, 90 insertions, 92 deletions
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
index 3684cf21..6f466c3b 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.adaptors.aai;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
import java.util.Map;
import org.openecomp.aai.inventory.v11.*;
@@ -76,9 +75,9 @@ public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin {
public void logKeyError(String keys);
- public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ;
+ public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ;
public String getPathTemplateForResource(String resoourceName, String join, SvcLogicContext ctx) throws MalformedURLException;
- public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues);
+ public boolean isDeprecatedFormat(String resource, Map<String, String> nameValues);
String query(AAIRequest request) throws AAIServiceException;
String save(AAIRequest request) throws AAIServiceException;
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
index 252f3197..906cd838 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
@@ -103,7 +103,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
truststorePassword = props.getProperty(AAIService.TRUSTSTORE_PSSWD);
keystorePath = props.getProperty(AAIService.KEYSTORE_PATH);
keystorePassword = props.getProperty(AAIService.KEYSTORE_PSSWD);
-// this.read_timeout = read_timeout;
String tmpApplicationId =props.getProperty(AAIService.APPLICATION_ID);
if(tmpApplicationId == null || tmpApplicationId.isEmpty()) {
@@ -310,14 +309,12 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
errorresponse.setRequestError(requestError);
throw new AAIServiceException(responseCode, errorresponse);
} else {
-// StringBuilder errorStringBuilder = new StringBuilder();
String line = null;
while( ( line = reader.readLine() ) != null ) {
errorStringBuilder.append("\n").append( line );
}
ErrorResponse errorresponse = mapper.readValue(errorStringBuilder.toString(), ErrorResponse.class);
-// ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
throw new AAIServiceException(responseCode, errorresponse);
}
@@ -373,16 +370,16 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
LOG.error("", exc);
}
- URL requestUrl = null;
- HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion), HttpMethod.PUT);
+ URL requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion);
+ HttpURLConnection con = getConfiguredConnection(requestUrl, HttpMethod.PUT);
ObjectMapper mapper = AAIService.getObjectMapper();
- String json_text = request.toJSONString();
+ String jsonText = request.toJSONString();
- LOGwriteDateTrace("data", json_text);
- logMetricRequest("PUT "+requestUrl.getPath(), json_text, requestUrl.getPath());
+ LOGwriteDateTrace("data", jsonText);
+ logMetricRequest("PUT "+requestUrl.getPath(), jsonText, requestUrl.getPath());
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
- osw.write(json_text);
+ osw.write(jsonText);
osw.flush();
// Check for errors
@@ -454,8 +451,8 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
}
try {
- URL requestUrl = null;
- HttpURLConnection conn = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion), HttpMethod.DELETE);
+ URL requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion);
+ HttpURLConnection conn = getConfiguredConnection(requestUrl, HttpMethod.DELETE);
logMetricRequest("DELETE "+requestUrl.getPath(), "", requestUrl.getPath());
conn.setDoOutput(true);
@@ -527,11 +524,10 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
public Object query(AAIRequest request, Class clas) throws AAIServiceException {
Object response = null;
InputStream inputStream = null;
- HttpURLConnection con = null;
- URL requestUrl = null;
try {
- con = getConfiguredConnection(requestUrl = request.getRequestQueryUrl(HttpMethod.GET), HttpMethod.GET);
+ URL requestUrl = request.getRequestQueryUrl(HttpMethod.GET);
+ HttpURLConnection con = getConfiguredConnection(requestUrl, HttpMethod.GET);
logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
// Check for errors
@@ -574,7 +570,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
LOG.warn("GET", exc);
}
}
- con = null;
}
return response;
}
@@ -592,13 +587,13 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
URL requestUrl = null;
HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl("PATCH", resourceVersion), "PATCH");
ObjectMapper mapper = AAIService.getObjectMapper();
- String json_text = request.toJSONString();
+ String jsonText = request.toJSONString();
- LOGwriteDateTrace("data", json_text);
- logMetricRequest("PATCH "+requestUrl.getPath(), json_text, requestUrl.getPath());
+ LOGwriteDateTrace("data", jsonText);
+ logMetricRequest("PATCH "+requestUrl.getPath(), jsonText, requestUrl.getPath());
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
- osw.write(json_text);
+ osw.write(jsonText);
osw.flush();
// Check for errors
@@ -723,8 +718,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
String targetEntity = "A&AI";
String targetVirtualEntity = null;
- targetServiceName = "";
-
ml.logRequest(svcInstanceId, svcName, partnerName, targetEntity, targetServiceName, targetVirtualEntity, msg);
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
index 7966fa97..d1b148d5 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
@@ -818,7 +818,7 @@ public abstract class AAIDeclarations implements AAIClient {
return retval;
}
- public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
+ public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
{
Object response;
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
index 73454694..9e6e60f9 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
@@ -1520,7 +1520,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
}
@Override
- public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues) {
+ public boolean isDeprecatedFormat(String resource, Map<String, String> nameValues) {
return !AAIServiceUtils.isValidFormat(resource, nameValues);
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
index ff182f2d..9fac977d 100644
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
@@ -3,14 +3,14 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* 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.
@@ -25,53 +25,62 @@ import org.onap.ccsdk.sli.adaptors.aai.data.ErrorResponse;
public class AAIServiceException extends Exception {
- /**
- *
- */
- private static final long serialVersionUID = -9039257722542999522L;
-
- protected ErrorResponse errorResponse = null;
- protected int returnCode = -1;
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9039257722542999522L;
- public AAIServiceException() {
+ protected final ErrorResponse errorResponse;
+ protected final int returnCode;
- }
+ public AAIServiceException() {
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message) {
- super(message);
- }
+ public AAIServiceException(String message) {
+ super(message);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(Throwable cause) {
- super(cause);
- }
+ public AAIServiceException(Throwable cause) {
+ super(cause);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message, Throwable cause) {
- super(message, cause);
- }
+ public AAIServiceException(String message, Throwable cause) {
+ super(message, cause);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message, Throwable cause,
- boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
+ public AAIServiceException(String message, Throwable cause,
+ boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(int returnCode, ErrorResponse errorresponse) {
- this.errorResponse = errorresponse;
- this.returnCode = returnCode;
- }
-
- public ErrorResponse getErrorResponse() {
- return errorResponse;
- }
+ public AAIServiceException(int returnCode, ErrorResponse errorresponse) {
+ this.errorResponse = errorresponse;
+ this.returnCode = returnCode;
+ }
- public int getReturnCode() {
- return returnCode;
- }
-
- public String getMessage() {
- if(errorResponse != null) {
- return errorResponse.getRequestError().getServiceException().getText();
- } else {
- return super.getMessage();
- }
- }
+ public ErrorResponse getErrorResponse() {
+ return errorResponse;
+ }
+
+ public int getReturnCode() {
+ return returnCode;
+ }
+
+ public String getMessage() {
+ if(errorResponse != null) {
+ return errorResponse.getRequestError().getServiceException().getText();
+ } else {
+ return super.getMessage();
+ }
+ }
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
index 102835d9..ca2af1df 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
@@ -28,6 +28,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.Map;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -49,14 +50,14 @@ public class AAIServiceUtils {
private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
+ private AAIServiceUtils() {
+ }
+
public static String getPrimaryIdFromClass(Class<? extends AAIDatum> resourceClass){
// 1. find class
getLogger().debug(resourceClass.getName());
- AAIDatum instance = null;
try {
- instance = resourceClass.newInstance();
-
Annotation[] annotations = resourceClass.getAnnotations();
for(Annotation annotation : annotations) {
Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -73,19 +74,15 @@ public class AAIServiceUtils {
}
}
} catch(Exception exc) {
-
+ getLogger().warn("getPrimaryIdFromClass failed", exc);
}
return null;
}
public static String getSecondaryIdFromClass(Class<? extends AAIDatum> resourceClass){
- // 1. find class
getLogger().debug(resourceClass.getName());
- AAIDatum instance = null;
try {
- instance = resourceClass.newInstance();
-
Annotation[] annotations = resourceClass.getAnnotations();
for(Annotation annotation : annotations) {
Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -112,16 +109,16 @@ public class AAIServiceUtils {
return null;
}
- public static Method getRelationshipListGetterMethodFromClassDefinition(Class resourceClass) {
- Method getRelationshipListMethod = null;
-
- try {
- getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
- } catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
- }
- return getRelationshipListMethod;
- }
+ public static Method getRelationshipListGetterMethodFromClassDefinition(Class resourceClass) {
+ Method getRelationshipListMethod = null;
+
+ try {
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
+ return getRelationshipListMethod;
+ }
private static Logger getLogger() {
return LOG;
@@ -314,10 +311,10 @@ public class AAIServiceUtils {
return request.getRequestPath();
}
- public static boolean isValidFormat(String resource, HashMap<String, String> nameValues) {
+ public static boolean isValidFormat(String resource, Map<String, String> nameValues) {
switch(resource){
- case "custom-query":
+ case "custom-query":
case "formatted-query":
case "generic-query":
case "named-query":
@@ -336,10 +333,10 @@ public class AAIServiceUtils {
Set<String> keys = nameValues.keySet();
for(String key : keys) {
if(!key.contains(".")) {
- if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key) || "resource_path".equals(key))
+ if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key) || "resource_path".equals(key))
continue;
else {
- getLogger().warn(String.format("key '%s' is incompatible with resource type '%s'", key, resource));
+ getLogger().warn(String.format("key '%s' is incompatible with resource type '%s'", key, resource));
}
}
}