diff options
author | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2018-07-31 15:48:07 -0400 |
---|---|---|
committer | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2018-08-01 14:04:24 -0400 |
commit | 74f9d832beba72c1121bef875b8e36ddb3cd5740 (patch) | |
tree | 16961ab8598f3e3b916d7a8fd97ccfdea0057dca /pomba | |
parent | 46c24a62f6931364075e9bd1cd33446dfdc9575b (diff) |
Fixing issues from SONAR report
Change-Id: I69e042690f464303fed0c9188b1555adf1f06481
Issue-ID: SDNC-317
Signed-off-by: Tait,Trevor(rt0435) <rtait@amdocs.com>
Diffstat (limited to 'pomba')
14 files changed, 82 insertions, 77 deletions
diff --git a/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/DataQuality.java b/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/DataQuality.java index 3e7836a..f8c677a 100644 --- a/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/DataQuality.java +++ b/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/DataQuality.java @@ -18,14 +18,14 @@ package org.onap.sdnc.apps.pomba.networkdiscovery.datamodel; public class DataQuality { - public static enum Status { + public enum Status { ok, error } private Status status; private String errorText; - + public Status getStatus() { return this.status; } diff --git a/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/NetworkDiscoveryResponse.java b/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/NetworkDiscoveryResponse.java index 136688a..0360930 100644 --- a/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/NetworkDiscoveryResponse.java +++ b/pomba/network-discovery-api/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/datamodel/NetworkDiscoveryResponse.java @@ -17,7 +17,6 @@ */ package org.onap.sdnc.apps.pomba.networkdiscovery.datamodel; -import java.util.List; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement diff --git a/pomba/network-discovery/pom.xml b/pomba/network-discovery/pom.xml index e4f03fd..44e919b 100644 --- a/pomba/network-discovery/pom.xml +++ b/pomba/network-discovery/pom.xml @@ -47,12 +47,6 @@ limitations under the License. </dependencies> </dependencyManagement> - <developers> - <developer> - <id>${userId}</id> - </developer> - </developers> - <dependencies> <!-- Springframework dependencies --> <dependency> diff --git a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/ApplicationException.java b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/ApplicationException.java index 6cc3592..fa29645 100644 --- a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/ApplicationException.java +++ b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/ApplicationException.java @@ -20,7 +20,7 @@ package org.onap.sdnc.apps.pomba.networkdiscovery; import javax.ws.rs.core.Response.Status; public class ApplicationException extends Exception { - public static enum Error { + public enum Error { GENERAL_FAILURE("NET.0001", "An error occurred: %s"), MISSING_PARAM("NET.0002", "Missing required parameter %s"), UNAUTHORIZED("NET.0003", "Unauthorized"); diff --git a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/CallbackConfiguration.java b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/CallbackConfiguration.java index 30d872f..1d2bdab 100644 --- a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/CallbackConfiguration.java +++ b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/CallbackConfiguration.java @@ -53,7 +53,7 @@ public class CallbackConfiguration { private String basicAuthPassword; @Bean(name="callbackClient") - public Client getClient() throws Exception { + public Client getClient() { ClientConfig configuration = new ClientConfig() .property(ClientProperties.CONNECT_TIMEOUT, this.connectionTimeout) .property(ClientProperties.READ_TIMEOUT, this.readTimeout) diff --git a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/EnricherConfiguration.java b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/EnricherConfiguration.java index 0a08577..9b2db05 100644 --- a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/EnricherConfiguration.java +++ b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/EnricherConfiguration.java @@ -29,58 +29,58 @@ import org.springframework.core.env.Environment; @Configuration public class EnricherConfiguration { - @Autowired + @Autowired private Environment env; - - @Value("${enricher.url}") - private String url; - @Value("${enricher.keyStorePath}") - private String keyStorePath; + @Value("${enricher.url}") + private String url; - @Value("${enricher.keyStorePassword}") - private String keyStorePassword; + @Value("${enricher.keyStorePath}") + private String keyStorePath; - @Value("${enricher.connectionTimeout:5000}") - private int connectionTimeout; + @Value("${enricher.keyStorePassword}") + private String keyStorePassword; - @Value("${enricher.readTimeout:60000}") - private int readTimeout; + @Value("${enricher.connectionTimeout:5000}") + private int connectionTimeout; - @Bean(name="enricherClient") - public RestClient restClient() { - return new RestClient() - .validateServerHostname(false) - .validateServerCertChain(false) - .connectTimeoutMs(this.connectionTimeout) - .readTimeoutMs(this.readTimeout) + @Value("${enricher.readTimeout:60000}") + private int readTimeout; + + @Bean(name="enricherClient") + public RestClient restClient() { + return new RestClient() + .validateServerHostname(false) + .validateServerCertChain(false) + .connectTimeoutMs(this.connectionTimeout) + .readTimeoutMs(this.readTimeout) .clientCertFile(this.keyStorePath) .clientCertPassword(this.keyStorePassword); - } + } + + @Bean(name="enricherBaseUrl") + public String getURL() { + return this.url; + } + + @Bean(name="enricherTypeURLs") + public Map<String, String> enricherTypeURLs() { + + Map<String, String> result = new HashMap<>(); + String types = this.env.getProperty("enricher.types"); + if (types == null) { + return result; + } - @Bean(name="enricherBaseUrl") - public String getURL() { - return this.url; - } - - @Bean(name="enricherTypeURLs") - public Map<String, String> enricherTypeURLs() { + StringTokenizer tokenizer = new StringTokenizer(types, ", "); + while (tokenizer.hasMoreTokens()) { + String type = tokenizer.nextToken(); + String enricherUrl = this.env.getProperty("enricher.type." + type + ".url"); + result.put(type, enricherUrl); + } - Map<String, String> result = new HashMap<>(); - String types = this.env.getProperty("enricher.types"); - if (types == null) { - return result; - } - - StringTokenizer tokenizer = new StringTokenizer(types, ", "); - while (tokenizer.hasMoreTokens()) { - String type = tokenizer.nextToken(); - String url = this.env.getProperty("enricher.type." + type + ".url"); - result.put(type, url); - } - return result; - } + } } diff --git a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/JerseyConfiguration.java b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/JerseyConfiguration.java index 5d93f64..b4488db 100644 --- a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/JerseyConfiguration.java +++ b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/JerseyConfiguration.java @@ -17,17 +17,14 @@ */ package org.onap.sdnc.apps.pomba.networkdiscovery; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import java.util.logging.Logger; + import javax.ws.rs.ApplicationPath; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; + import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.filter.LoggingFilter; +import org.glassfish.jersey.logging.LoggingFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletProperties; import org.onap.sdnc.apps.pomba.networkdiscovery.service.rs.RestServiceImpl; @@ -36,6 +33,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + @Component @ApplicationPath("/") public class JerseyConfiguration extends ResourceConfig { @@ -56,7 +59,7 @@ public class JerseyConfiguration extends ResourceConfig { public JerseyConfiguration() { register(RestServiceImpl.class); property(ServletProperties.FILTER_FORWARD_ON_404, true); - register(new LoggingFilter(log, true)); + register(new LoggingFeature(log)); } @Bean diff --git a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/service/rs/RestServiceImpl.java b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/service/rs/RestServiceImpl.java index 94c7492..4e6fdcb 100644 --- a/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/service/rs/RestServiceImpl.java +++ b/pomba/network-discovery/src/main/java/org/onap/sdnc/apps/pomba/networkdiscovery/service/rs/RestServiceImpl.java @@ -51,9 +51,6 @@ public class RestServiceImpl implements RestService { @Resource(name="basicAuthHeader") private String basicAuthHeader; - public RestServiceImpl() { - } - @Override public Response findbyResourceIdAndType(HttpServletRequest request, String version, @@ -76,7 +73,7 @@ public class RestServiceImpl implements RestService { version = "v1"; } - if (!this.basicAuthHeader.equals(authorization)) { + if (authorization == null || !this.basicAuthHeader.equals(authorization)) { throw new ApplicationException(UNAUTHORIZED, Status.UNAUTHORIZED); } if ((fromAppId == null) || fromAppId.trim().isEmpty()) { diff --git a/pomba/service-decomposition/pom.xml b/pomba/service-decomposition/pom.xml index b66ed25..6252246 100644 --- a/pomba/service-decomposition/pom.xml +++ b/pomba/service-decomposition/pom.xml @@ -98,6 +98,12 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>com.vaadin.external.google</groupId> + <artifactId>android-json</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.mockito</groupId> diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/exception/DiscoveryException.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/exception/DiscoveryException.java index 107f98b..eee34fe 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/exception/DiscoveryException.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/exception/DiscoveryException.java @@ -20,7 +20,7 @@ package org.onap.sdnc.apps.pomba.servicedecomposition.exception; import javax.ws.rs.core.Response.Status; public class DiscoveryException extends Exception { - public static enum Error { + public enum Error { FETCH_RESOURCE_FAILED("SD.0001", "A&AI query failed: %s"), RELATIONSHIP_LINK_PARSE_ERROR("SD.0002", "Error in parsing relationship link"), SERVICE_INSTANCE_NOT_FOUND("SD.0003", "Service Instance not Found"), diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java index 4a0f0ed..191eb32 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java @@ -30,7 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; @org.springframework.stereotype.Service public class SpringServiceImpl implements SpringService { private static EELFLogger log = EELFManager.getInstance().getLogger(SpringServiceImpl.class); - public static String APP_NAME = "ServiceDiscovery"; + public static final String APP_NAME = "ServiceDiscovery"; @Autowired private RestClient aaiClient; diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/rs/RestServiceImpl.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/rs/RestServiceImpl.java index 19734f0..12c3935 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/rs/RestServiceImpl.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/rs/RestServiceImpl.java @@ -61,7 +61,7 @@ public class RestServiceImpl implements RestService { adapter.getServiceDescriptor().setServiceName(SERVICE_NAME); adapter.entering(request); try { - if (!this.basicAuthHeader.equals(authorization)) { + if (authorization == null || !this.basicAuthHeader.equals(authorization)) { throw new DiscoveryException(UNAUTHORIZED, Status.UNAUTHORIZED); } diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java index 8d74670..3043269 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java @@ -24,15 +24,18 @@ import static org.onap.sdnc.apps.pomba.servicedecomposition.exception.DiscoveryE import static org.onap.sdnc.apps.pomba.servicedecomposition.exception.DiscoveryException.Error.SERVICE_RELATIONSHIP_PARSE_ERROR; import com.sun.jersey.core.util.MultivaluedMapImpl; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response.Status; + import org.json.JSONArray; import org.json.JSONObject; import org.onap.aai.restclient.client.OperationResult; @@ -43,6 +46,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + + public class RestUtil { // Parameters for Query AAI Model Data API // HTTP headers @@ -116,7 +121,7 @@ public class RestUtil { String url = baseURL + generateServiceInstanceURL(aaiServiceInstancePath, serviceInstanceId); // Response from service instance API call JSONObject serviceInstancePayload = new JSONObject( - getResource(aaiClient, url, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML))); + getResource(aaiClient, url, transactionId)); // Handle the case if the service instance is not found in AAI if (serviceInstancePayload == null || serviceInstancePayload.length() == 0) { logger.info("Service Instance " + serviceInstanceId + " is not found from AAI"); @@ -153,7 +158,7 @@ public class RestUtil { // Logic to Create the Generic VNF JSON and extract further relationships for (JSONObject vnfPayload : vnfList) { List<String> vnfcLinkLst = extractRelatedLink(vnfPayload, Catalog.VNFC.resourceName); - if (vnfcLinkLst != null && vnfcLinkLst.size() != 0) { + if (vnfcLinkLst != null && !vnfcLinkLst.isEmpty()) { logger.info("The number of the API call for vnfc is:" + vnfcLinkLst.size()); List<JSONObject> vnfcList = processResourceList(aaiClient, baseURL, transactionId, Catalog.VNFC.resourceName, vnfcLinkLst); @@ -165,7 +170,7 @@ public class RestUtil { } List<String> networkLinkLst = extractRelatedLink(vnfPayload, Catalog.L3NETWORK.resourceName); - if (networkLinkLst != null && networkLinkLst.size() != 0) { + if (networkLinkLst != null && !networkLinkLst.isEmpty()) { logger.info("The number of the API call for l3-network is:" + networkLinkLst.size()); List<JSONObject> networkList = processResourceList(aaiClient, baseURL, transactionId, Catalog.L3NETWORK.resourceName, networkLinkLst); @@ -176,7 +181,7 @@ public class RestUtil { logger.info("No l3-network found for vnf-id:" + vnfPayload.getString("vnf-id")); } List<String> vserverLinkLst = extractRelatedLink(vnfPayload, Catalog.VSERVER.resourceName); - if (vserverLinkLst != null && vserverLinkLst.size() != 0) { + if (vserverLinkLst != null && !vserverLinkLst.isEmpty()) { logger.info("The number of the API call for vserver is:" + vserverLinkLst.size()); List<JSONObject> vserverList = processResourceList(aaiClient, baseURL, transactionId, Catalog.VSERVER.resourceName, vserverLinkLst); @@ -195,7 +200,7 @@ public class RestUtil { } // Add generic vnf with related resource payload to response - if (vnfLst != null && vnfLst.size() != 0) { + if (vnfLst != null && !vnfLst.isEmpty()) { response.put(Catalog.VNF.collectionName, vnfLst); } @@ -226,7 +231,7 @@ public class RestUtil { // Response from generic VNF API call JSONObject resourcePayload = new JSONObject( - getResource(aaiClient, resourceURL, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML))); + getResource(aaiClient, resourceURL, transactionId)); if (resourcePayload == null || resourcePayload.length() == 0) { logger.info("Resource with url " + resourceLink + " is not found from AAI"); } else { @@ -270,12 +275,12 @@ public class RestUtil { logger.info("Related-To Object found null"); continue; } - List<String> relatedLinkList = relationMap.get(relatedToObj.toString()); + List<String> relatedLinkList = relationMap.get(relatedToObj); if (relatedLinkList == null) { relatedLinkList = new ArrayList<>(); - relationMap.put(relatedToObj.toString(), relatedLinkList); + relationMap.put(relatedToObj, relatedLinkList); } - relatedLinkList.add(relatedLinkObj.toString()); + relatedLinkList.add(relatedLinkObj); } } return relationMap; @@ -289,7 +294,7 @@ public class RestUtil { * @return * @throws DiscoveryException */ - private static String getResource(RestClient client, String url, String transId, MediaType mediaType) + private static String getResource(RestClient client, String url, String transId) throws DiscoveryException { OperationResult result = client.get(url, buildHeaders(transId), MediaType.valueOf(MediaType.APPLICATION_JSON)); diff --git a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/componenttest/mockito/WebConfigurationTest.java b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/componenttest/mockito/WebConfigurationTest.java index 9728a48..11d58cb 100644 --- a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/componenttest/mockito/WebConfigurationTest.java +++ b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/componenttest/mockito/WebConfigurationTest.java @@ -19,6 +19,7 @@ package org.onap.sdnc.apps.pomba.servicedecomposition.componenttest.mockito; import static junit.framework.TestCase.assertEquals; +import static org.mockito.Mockito.mock; import org.junit.Test; import org.onap.sdnc.apps.pomba.servicedecomposition.WebConfiguration; @@ -30,7 +31,7 @@ public class WebConfigurationTest { public void runTest() { WebConfiguration webConfiguration = new WebConfiguration(); WebMvcConfigurerAdapter webMvcConfigurerAdapter = webConfiguration.forwardToIndex(); - ViewResolverRegistry registry = new ViewResolverRegistry(); + ViewResolverRegistry registry = mock(ViewResolverRegistry.class); webMvcConfigurerAdapter.configureViewResolvers(registry); assertEquals(registry.hasRegistrations(), false); } |