From e2ce0d5bf9476134ba5427496c9d20089ca856cb Mon Sep 17 00:00:00 2001 From: SravanKumarGunda Date: Thu, 30 Jul 2020 19:34:57 +0530 Subject: Code Improvements-Vnfsdk-refrepo sonar issue fixes Signed-off-by: SravanKumarGunda Issue-ID: VNFSDK-608 Change-Id: Ifba4c2f804786b40305c562460071ef430164de2 --- .../src/main/java/org/onap/vtp/VTPResource.java | 2 +- .../onap/vtp/execution/VTPExecutionResource.java | 80 ++++++++++++---------- .../org/onap/vtp/scenario/VTPScenarioResource.java | 17 ++--- 3 files changed, 52 insertions(+), 47 deletions(-) (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java index 254cc6ad..0d813c74 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java @@ -107,7 +107,7 @@ public class VTPResource { return this.makeRpcAndGetJson(args, VTP_EXECUTION_GRPC_TIMEOUT); } - protected JsonElement makeRpcAndGetJson(List args, int timeout) throws VTPException, IOException { + protected JsonElement makeRpcAndGetJson(List args, int timeout) throws VTPException { Result result = this.makeRpc(args, timeout); JsonParser jsonParser = new JsonParser(); return jsonParser.parse(result.getOutput()); diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java index eb43b937..3bd522ff 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java @@ -16,7 +16,6 @@ package org.onap.vtp.execution; -import java.io.EOFException; import java.io.File; import java.io.IOException; import java.nio.file.StandardCopyOption; @@ -28,7 +27,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.logging.Logger; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; @@ -146,26 +144,28 @@ public class VTPExecutionResource extends VTPResource{ private Map storeTestCaseInputFiles(List bodyParts) throws IOException { Map map = new HashMap<>(); - if (bodyParts != null) - for (FormDataBodyPart part: bodyParts) { - String name = part.getContentDisposition().getFileName(); - String path = VTP_EXECUTION_TEMP_STORE + "/" + name; - - File f = new File(path); - if (f.exists()) { - FileUtils.forceDelete(f); - } - FileUtils.forceMkdir(f.getParentFile()); + if (bodyParts != null) { + for (FormDataBodyPart part: bodyParts) { + String name = part.getContentDisposition().getFileName(); + String path = VTP_EXECUTION_TEMP_STORE + "/" + name; //NOSONAR + + File f = new File(path); + if (f.exists()) { + FileUtils.forceDelete(f); + } + FileUtils.forceMkdir(f.getParentFile()); - BodyPartEntity fileEntity = (BodyPartEntity) part.getEntity(); - java.nio.file.Files.copy( - fileEntity.getInputStream(), - f.toPath(), - StandardCopyOption.REPLACE_EXISTING); + BodyPartEntity fileEntity = (BodyPartEntity) part.getEntity(); + java.nio.file.Files.copy( + fileEntity.getInputStream(), + f.toPath(), + StandardCopyOption.REPLACE_EXISTING); - IOUtils.closeQuietly(fileEntity.getInputStream()); + IOUtils.closeQuietly(fileEntity.getInputStream()); + + map.put(name, path); + } - map.put(name, path); } return map; @@ -197,9 +197,11 @@ public class VTPExecutionResource extends VTPResource{ LOG.error("IOException occurs",e); } - for (Map.Entry entry: map.entrySet()) { - if (executionsJson.contains(FILE + entry.getKey())) { - executionsJson = executionsJson.replaceAll(FILE + entry.getKey(), entry.getValue()); + if (map != null) { + for (Map.Entry entry: map.entrySet()) { + if (executionsJson.contains(FILE + entry.getKey())) { + executionsJson = executionsJson.replaceAll(FILE + entry.getKey(), entry.getValue()); + } } } @@ -220,11 +222,13 @@ public class VTPExecutionResource extends VTPResource{ executions = this.executeHandler(executions, requestId); - for (Map.Entry entry: map.entrySet()) { - try { - FileUtils.forceDelete(new File(entry.getValue())); - } catch (IOException e) { - LOG.error("IOException occurs",e); + if (map != null) { + for (Map.Entry entry: map.entrySet()) { + try { + FileUtils.forceDelete(new File(entry.getValue())); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } } } @@ -236,13 +240,13 @@ public class VTPExecutionResource extends VTPResource{ String scenario, String testSuiteName, String testCaseName, - String profile, + String profile, //NOSONAR String startTime, - String endTime) throws Exception{ + String endTime) throws VTPException, IOException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "execution-list", FORMAT, "json" - })); + )); if (startTime != null && !startTime.isEmpty()) { args.add("--start-time"); @@ -337,18 +341,18 @@ public class VTPExecutionResource extends VTPResource{ @ApiParam("Test profile name") @QueryParam("profileName") String profileName, @ApiParam("Test execution start time") @QueryParam("startTime") String startTime, @ApiParam("Test execution end time") @QueryParam("endTime") String endTime - ) throws Exception { + ) throws VTPException, IOException { return Response.ok(this.listTestExecutionsHandler( requestId, scenario, testsuiteName, testcaseName, profileName, startTime, endTime).getExecutions().toString(), MediaType.APPLICATION_JSON).build(); } public VTPTestExecution getTestExecutionHandler( - String executionId) throws Exception{ + String executionId) throws VTPException, IOException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "execution-show", "--execution-id", executionId, FORMAT, "json" - })); + )); JsonElement result = this.makeRpcAndGetJson(args); @@ -418,7 +422,7 @@ public class VTPExecutionResource extends VTPResource{ response = VTPError.class) }) public Response getTestExecution( @ApiParam("Test execution Id") @PathParam("executionId") String executionId - ) throws Exception { + ) throws VTPException, IOException { return Response.ok(this.getTestExecutionHandler(executionId).toString(), MediaType.APPLICATION_JSON).build(); } @@ -426,9 +430,9 @@ public class VTPExecutionResource extends VTPResource{ public String getTestExecutionLogsHandler( String executionId, String action) throws VTPException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "execution-show-" + action, "--execution-id", executionId, FORMAT, "text" - })); + )); Result result = this.makeRpc(args); diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java index 29cb8f6a..4b319328 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java @@ -65,9 +65,10 @@ public class VTPScenarioResource extends VTPResource{ public VTPTestScenarioList listTestScenariosHandler() throws VTPException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "product-list", FORMAT, "json" - })); + )); + JsonElement results = null; try { @@ -113,9 +114,9 @@ public class VTPScenarioResource extends VTPResource{ public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "service-list", PRODUCT_ARG, scenario, FORMAT, "json" - })); + )); JsonElement results = null; try { @@ -158,9 +159,9 @@ public class VTPScenarioResource extends VTPResource{ public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "schema-list", PRODUCT_ARG, scenario, FORMAT, "json" - })); + )); if (testSuiteName != null) { args.add("--service"); args.add(testSuiteName); @@ -209,9 +210,9 @@ public class VTPScenarioResource extends VTPResource{ public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException { List args = new ArrayList<>(); - args.addAll(Arrays.asList(new String[] { + args.addAll(Arrays.asList( PRODUCT_ARG, OPEN_CLI, "schema-show", PRODUCT_ARG, scenario, "--service", testSuiteName, "--command", testCaseName , FORMAT, "json" - })); + )); JsonElement results = null; try { results = this.makeRpcAndGetJson(args); -- cgit 1.2.3-korg