From 1ad102dc465b2d2e344500cb9666b307eae0d3ef Mon Sep 17 00:00:00 2001 From: "r.bogacki" Date: Tue, 9 Jul 2019 14:10:53 +0200 Subject: Major Sonar fixes Major Sonar fixes in different classes: -Removed unnecessary code. -Removed unused variables. -Removed unnecessary imports. -Simplified diamond operators. Issue-ID: SO-2102 Signed-off-by: Robert Bogacki Change-Id: I098e3dcd93b804e58220bb41ea15325e820e3a59 --- .../WorkflowSpecificationsHandler.java | 26 ++++++++++++---------- .../tenantisolation/ModelDistributionRequest.java | 5 ++--- .../process/CreateVnfOperationalEnvironment.java | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java index bba8064f7c..b57bb5d1d8 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -91,13 +93,13 @@ public class WorkflowSpecificationsHandler { List workflows = catalogDbClient.findWorkflowByModelUUID(vnfModelVersionId); List nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW); - if (nativeWorkflows != null && nativeWorkflows.size() != 0) { + if (nativeWorkflows != null && !nativeWorkflows.isEmpty()) { workflows.addAll(nativeWorkflows); } WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows); - String jsonResponse = null; + String jsonResponse; try { ObjectMapper mapper = new ObjectMapper(); jsonResponse = mapper.writeValueAsString(workflowSpecifications); @@ -116,11 +118,11 @@ public class WorkflowSpecificationsHandler { } protected WorkflowSpecifications mapWorkflowsToWorkflowSpecifications(List workflows) { - if (workflows == null || workflows.size() == 0) { + if (workflows == null || workflows.isEmpty()) { return null; } WorkflowSpecifications workflowSpecifications = new WorkflowSpecifications(); - List workflowSpecificationList = new ArrayList(); + List workflowSpecificationList = new ArrayList<>(); for (Workflow workflow : workflows) { WorkflowSpecificationList workflowSpecificationListItem = new WorkflowSpecificationList(); @@ -153,10 +155,10 @@ public class WorkflowSpecificationsHandler { private List buildActivitySequence(Workflow workflow) { List workflowActivitySpecSequences = workflow.getWorkflowActivitySpecSequence(); - if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.size() == 0) { + if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.isEmpty()) { return null; } - List activitySequences = new ArrayList(); + List activitySequences = new ArrayList<>(); for (WorkflowActivitySpecSequence workflowActivitySpecSequence : workflowActivitySpecSequences) { if (workflowActivitySpecSequence != null) { ActivitySpec activitySpec = workflowActivitySpecSequence.getActivitySpec(); @@ -174,17 +176,17 @@ public class WorkflowSpecificationsHandler { private List buildWorkflowInputParameters(Workflow workflow) { List workflowActivitySpecSequences = workflow.getWorkflowActivitySpecSequence(); - if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.size() == 0) { - return new ArrayList(); + if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.isEmpty()) { + return new ArrayList<>(); } - Map workflowInputParameterMap = new HashMap(); + Map workflowInputParameterMap = new HashMap<>(); for (WorkflowActivitySpecSequence workflowActivitySpecSequence : workflowActivitySpecSequences) { if (workflowActivitySpecSequence != null) { ActivitySpec activitySpec = workflowActivitySpecSequence.getActivitySpec(); if (activitySpec != null) { List activitySpecUserParameters = activitySpec.getActivitySpecUserParameters(); - if (activitySpecUserParameters != null && activitySpecUserParameters.size() != 0) { + if (activitySpecUserParameters != null && !activitySpecUserParameters.isEmpty()) { for (ActivitySpecUserParameters activitySpecUserParameter : activitySpecUserParameters) { UserParameters userParameter = activitySpecUserParameter.getUserParameters(); if (userParameter != null) { @@ -199,7 +201,7 @@ public class WorkflowSpecificationsHandler { } if (workflowInputParameterMap.size() == 0) { - return new ArrayList(); + return new ArrayList<>(); } List workflowInputParameterList = workflowInputParameterMap.values().stream().collect(Collectors.toList()); @@ -220,7 +222,7 @@ public class WorkflowSpecificationsHandler { private List buildValidationList(UserParameters userParameter) { List validationList = null; if (userParameter.getMaxLength() != null || userParameter.getAllowableChars() != null) { - validationList = new ArrayList(); + validationList = new ArrayList<>(); Validation validation = new Validation(); if (userParameter.getMaxLength() != null) { validation.setMaxLength(userParameter.getMaxLength().toString()); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java index b2933df030..216588432b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java @@ -75,8 +75,7 @@ public class ModelDistributionRequest { @Transactional public Response updateModelDistributionStatus(String requestJSON, @PathParam("version") String version, @PathParam("distributionId") String distributionId) throws ApiException { - long startTime = System.currentTimeMillis(); - Distribution distributionRequest = null; + Distribution distributionRequest; try { ObjectMapper mapper = new ObjectMapper(); @@ -146,7 +145,7 @@ public class ModelDistributionRequest { } re.setServiceException(se); - String requestErrorStr = null; + String requestErrorStr; try { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_DEFAULT); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironment.java index fe81a07212..5eb4a67fa6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironment.java @@ -145,7 +145,7 @@ public class CreateVnfOperationalEnvironment { throws TenantIsolationException { List endpointList = serviceEndPointList.getServiceEndPointList(); logger.debug("Number of service endpoints from GRM: {}", endpointList.size()); - List serviceEndPointRequestList = new ArrayList(); + List serviceEndPointRequestList = new ArrayList<>(); for (ServiceEndPoint serviceEndpoint : endpointList) { serviceEndPointRequestList.add(buildServiceEndpoint(serviceEndpoint)); } -- cgit 1.2.3-korg