summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main
diff options
context:
space:
mode:
authorshivasubedi <shiva.subedi@est.tech>2021-04-26 17:51:04 +0100
committerRishi Chail <rishi.chail@est.tech>2021-04-28 10:14:20 +0000
commita439dfa869d7ba55daeb97ae16735c3fd0a12985 (patch)
tree6ed309a7efd31b42667a94da1ca9462f13991f83 /cps-rest/src/main
parentd006d121ed9044caa1b769cca931fc183c448a3b (diff)
Fix Code smells
Issue-ID: CPS-89 Change-Id: Ib1b6fbc6b6d712f169100825683e6db3e7c85cb9 Signed-off-by: shivasubedi <shiva.subedi@est.tech>
Diffstat (limited to 'cps-rest/src/main')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java5
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java3
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java2
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java15
4 files changed, 11 insertions, 14 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index ead365af06..74b1a418d1 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -30,7 +30,6 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
import org.onap.cps.spi.model.Anchor;
-import org.onap.cps.spi.model.SchemaSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -71,7 +70,7 @@ public class AdminRestController implements CpsAdminApi {
@Override
public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
- final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
+ final var schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
return new ResponseEntity<>(schemaSet, HttpStatus.OK);
}
@@ -104,7 +103,7 @@ public class AdminRestController implements CpsAdminApi {
@Override
public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
return new ResponseEntity<>(anchor, HttpStatus.OK);
}
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
index ddd3ac48ec..c8b7412593 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java
@@ -24,7 +24,6 @@ package org.onap.cps.rest.controller;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.rest.api.CpsDataApi;
import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.model.DataNode;
import org.onap.cps.utils.DataMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -62,7 +61,7 @@ public class DataRestController implements CpsDataApi {
final String xpath, final Boolean includeDescendants) {
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
- final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath,
+ final var dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath,
fetchDescendantsOption);
return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
}
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
index 0437e70fe5..2a89ef2230 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
@@ -83,7 +83,7 @@ public class CpsRestExceptionHandler {
if (exception.getCause() != null || !(exception instanceof CpsException)) {
log.error("Exception occurred", exception);
}
- final ErrorMessage errorMessage = new ErrorMessage();
+ final var errorMessage = new ErrorMessage();
errorMessage.setStatus(status.toString());
errorMessage.setMessage(exception.getMessage());
errorMessage.setDetails(exception instanceof CpsException ? ((CpsException) exception).getDetails() :
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java b/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
index e3b0b2835c..d5c2b092b0 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/utils/MultipartFileUtil.java
@@ -25,7 +25,6 @@ import static org.opendaylight.yangtools.yang.common.YangConstants.RFC6020_YANG_
import com.google.common.collect.ImmutableMap;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Locale;
@@ -58,7 +57,7 @@ public class MultipartFileUtil {
public static Map<String, String> extractYangResourcesMap(final MultipartFile multipartFile) {
final String originalFileName = multipartFile.getOriginalFilename();
if (resourceNameEndsWithExtension(originalFileName, YANG_FILE_EXTENSION)) {
- return ImmutableMap.of(originalFileName, extractYangResourceContent(multipartFile));
+ return Map.of(originalFileName, extractYangResourceContent(multipartFile));
}
if (resourceNameEndsWithExtension(originalFileName, ZIP_FILE_EXTENSION)) {
return extractYangResourcesMapFromZipArchive(multipartFile);
@@ -70,10 +69,10 @@ public class MultipartFileUtil {
private static Map<String, String> extractYangResourcesMapFromZipArchive(final MultipartFile multipartFile) {
final ImmutableMap.Builder<String, String> yangResourceMapBuilder = ImmutableMap.builder();
- final ZipFileSizeValidator zipFileSizeValidator = new ZipFileSizeValidator();
+ final var zipFileSizeValidator = new ZipFileSizeValidator();
try (
- final InputStream inputStream = multipartFile.getInputStream();
- final ZipInputStream zipInputStream = new ZipInputStream(inputStream);
+ final var inputStream = multipartFile.getInputStream();
+ final var zipInputStream = new ZipInputStream(inputStream);
) {
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
@@ -129,10 +128,10 @@ public class MultipartFileUtil {
private static String extractYangResourceContent(final ZipInputStream zipInputStream,
final ZipFileSizeValidator zipFileSizeValidator) throws IOException {
- try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
- int totalSizeEntry = 0;
+ try (final var byteArrayOutputStream = new ByteArrayOutputStream()) {
+ var totalSizeEntry = 0;
int numberOfBytesRead;
- final byte[] buffer = new byte[READ_BUFFER_SIZE];
+ final var buffer = new byte[READ_BUFFER_SIZE];
zipFileSizeValidator.incrementTotalEntryInArchive();
while ((numberOfBytesRead = zipInputStream.read(buffer, 0, READ_BUFFER_SIZE)) > 0) {
byteArrayOutputStream.write(buffer, 0, numberOfBytesRead);