diff options
author | romaingimbert <romain.gimbert@orange.com> | 2018-06-25 10:41:39 +0200 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2018-06-25 10:41:39 +0200 |
commit | 0d1d0a45f166b4bc32618dc0c9cd2d79ceddaffc (patch) | |
tree | 9e5cb01e71bf1ac3a0c139a3a7d080aba64a757d | |
parent | ac8e5b3b6667eec54f357cda4489044ea04acec7 (diff) |
fix sonar alert
- fix some sonar alerts
Change-Id: I98f28b343f0e7fcac685e7aa92d198df500deb80
Issue-ID: EXTAPI-107
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
20 files changed, 91 insertions, 110 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java b/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java index 109edbe..a4b8feb 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/SdcClient.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.apache.commons.io.IOUtils; import org.onap.nbi.OnapComponentsUrlPaths; import org.onap.nbi.exceptions.BackendFunctionalException; @@ -44,7 +45,6 @@ import org.springframework.web.util.UriComponentsBuilder; @Service public class SdcClient { - public static final String HTTP_CALL_SDC_ON = "HTTP call SDC on "; @Autowired private RestTemplate restTemplate; @@ -79,9 +79,9 @@ public class SdcClient { UriComponentsBuilder callURI = UriComponentsBuilder.fromHttpUrl(sdcHost + OnapComponentsUrlPaths.SDC_ROOT_URL); if (parametersMap != null) { Map<String, String> stringStringMap = parametersMap.toSingleValueMap(); - for (String key : stringStringMap.keySet()) { - if (!key.equals("fields")) { - callURI.queryParam(key, stringStringMap.get(key)); + for (Entry<String, String> entry : stringStringMap.entrySet()) { + if (!entry.getKey().equals("fields")) { + callURI.queryParam(entry.getKey(), entry.getValue()); } } } @@ -118,17 +118,17 @@ public class SdcClient { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(HEADER_ECOMP_INSTANCE_ID, ecompInstanceId); httpHeaders.add(HEADER_AUTHORIZATION, sdcHeaderAuthorization); - HttpEntity<String> entity = new HttpEntity<>("parameters", httpHeaders); - - return entity; + return new HttpEntity<>("parameters", httpHeaders); } private ResponseEntity<Object> callSdc(URI callURI) { ResponseEntity<Object> response = restTemplate.exchange(callURI, HttpMethod.GET, buildRequestHeader(), Object.class); - LOGGER.debug("response body : " + response.getBody().toString()); - LOGGER.info("response status : " + response.getStatusCodeValue()); + if(LOGGER.isDebugEnabled()) { + LOGGER.debug("response body : {} ",response.getBody().toString()); + } + LOGGER.info("response status : {}", response.getStatusCodeValue()); loggDebugIfResponseKo(callURI.toString(), response); return response; } @@ -139,22 +139,21 @@ public class SdcClient { ResponseEntity<byte[]> response = restTemplate.exchange(callURI, HttpMethod.GET, buildRequestHeader(), byte[].class); LOGGER.info("response status : " + response.getStatusCodeValue()); - if (!response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn(HTTP_CALL_SDC_ON + callURI.toString() + " returns " + response.getStatusCodeValue() + ", "); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { + LOGGER.warn("HTTP call SDC on {} returns {} ", callURI.toString() , response.getStatusCodeValue()); } return response; } catch (BackendFunctionalException e) { - LOGGER.error(HTTP_CALL_SDC_ON + callURI.toString() + " error " + e); + LOGGER.error("HTTP call SDC on {} error : {}", callURI.toString() , e); return null; } } private void loggDebugIfResponseKo(String callURI, ResponseEntity<Object> response) { - if (!response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn(HTTP_CALL_SDC_ON + callURI + " returns " + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { + LOGGER.warn("HTTP call SDC on {} returns {} , {}", callURI , response.getStatusCodeValue() , response.getBody().toString()); } } } diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java index 262871a..e8ef9e3 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java @@ -19,7 +19,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.onap.nbi.commons.JsonRepresentation; -import org.onap.nbi.commons.Resource; import org.onap.nbi.commons.ResourceManagement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -33,7 +32,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/serviceSpecification") -public class ServiceSpecificationResource extends ResourceManagement<Resource> { +public class ServiceSpecificationResource extends ResourceManagement { @Autowired diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java index b76e697..6b70a18 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java @@ -106,8 +106,8 @@ public class ToscaInfosProcessor { } private void buildCharacteristicValuesFormShema(String parameterType, - List<LinkedHashMap> serviceSpecCharacteristicValues, Object aDefault, ArrayList entry_schema) { - LinkedHashMap constraints = (LinkedHashMap) entry_schema.get(0); + List<LinkedHashMap> serviceSpecCharacteristicValues, Object aDefault, ArrayList entrySchema) { + LinkedHashMap constraints = (LinkedHashMap) entrySchema.get(0); if (constraints != null) { ArrayList constraintsList = (ArrayList) constraints.get("constraints"); if (CollectionUtils.isNotEmpty(constraintsList)) { @@ -129,9 +129,9 @@ public class ToscaInfosProcessor { } - private LinkedHashMap getToscaInfosFromResourceUUID(LinkedHashMap node_templates, String name) { - if(node_templates!=null) { - for (Object nodeTemplateObject : node_templates.values()) { + private LinkedHashMap getToscaInfosFromResourceUUID(LinkedHashMap nodeTemplates, String name) { + if(nodeTemplates!=null) { + for (Object nodeTemplateObject : nodeTemplates.values()) { LinkedHashMap nodeTemplate = (LinkedHashMap) nodeTemplateObject; LinkedHashMap metadata = (LinkedHashMap) nodeTemplate.get("metadata"); if(metadata.get("UUID")!=null && metadata.get("type")!=null) { @@ -265,14 +265,10 @@ public class ToscaInfosProcessor { while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } - - fos.close(); } ze = zis.getNextEntry(); } - zis.closeEntry(); - zis.close(); } LOGGER.debug("Done"); diff --git a/src/main/java/org/onap/nbi/apis/serviceinventory/BaseClient.java b/src/main/java/org/onap/nbi/apis/serviceinventory/BaseClient.java index c973f32..4c9d8e5 100644 --- a/src/main/java/org/onap/nbi/apis/serviceinventory/BaseClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceinventory/BaseClient.java @@ -36,11 +36,12 @@ public abstract class BaseClient { ResponseEntity<Object> response = restTemplate.exchange(callURL, HttpMethod.GET, new HttpEntity<>("parameters", httpHeaders), Object.class); - LOGGER.debug("response body : " + response.getBody().toString()); - LOGGER.info("response status : " + response.getStatusCodeValue()); - if (!response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn("HTTP call on " + callURL + " returns " + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if(LOGGER.isDebugEnabled()){ + LOGGER.debug("response body : {}",response.getBody().toString()); + } + LOGGER.info("response status : {}", response.getStatusCodeValue()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { + LOGGER.warn("HTTP call on {} returns {}, {}", callURL , response.getStatusCodeValue() ,response.getBody().toString()); } return response; } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java index a7e3356..5e4668a 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.onap.nbi.OnapComponentsUrlPaths; import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo; import org.onap.nbi.exceptions.BackendFunctionalException; @@ -75,8 +76,7 @@ public class MultiClient { public ResponseEntity<Object> getServiceCatalog(String id) { StringBuilder callURL = new StringBuilder().append(serviceCatalogUrl.getServiceCatalogUrl()).append(id); - ResponseEntity<Object> response = callApiGet(callURL.toString(), new HttpHeaders(), null); - return response; + return callApiGet(callURL.toString(), new HttpHeaders(), null); } public boolean doesServiceExistInServiceInventory(String id, String serviceName, String globalSubscriberId) { @@ -86,10 +86,7 @@ public class MultiClient { param.put("relatedParty.id", globalSubscriberId); ResponseEntity<Object> response = callApiGet(callURL.toString(), new HttpHeaders(), param); - if (response == null || !response.getStatusCode().equals(HttpStatus.OK)) { - return false; - } - return true; + return response != null && response.getStatusCode().equals(HttpStatus.OK); } @@ -125,10 +122,7 @@ public class MultiClient { StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH) .append(customerId); ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI(), null); - if (response != null && response.getStatusCode().equals(HttpStatus.OK)) { - return true; - } - return false; + return(response != null && response.getStatusCode().equals(HttpStatus.OK)); } @@ -141,10 +135,7 @@ public class MultiClient { aaiHost + OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH + subscriberInfo.getGlobalSubscriberId(); ResponseEntity<Object> response = putRequest(param, callURL, buildRequestHeaderForAAI()); - if (response != null && response.getStatusCode().equals(HttpStatus.CREATED)) { - return true; - } - return false; + return response != null && response.getStatusCode().equals(HttpStatus.CREATED); } @@ -166,10 +157,7 @@ public class MultiClient { String callURL = aaiHost + OnapComponentsUrlPaths.AAI_PUT_SERVICE_FOR_CUSTOMER_PATH + serviceName; String callUrlFormated = callURL.replace("$customerId", globalSubscriberId); ResponseEntity<Object> response = putRequest(param, callUrlFormated, buildRequestHeaderForAAI()); - if (response != null && response.getStatusCode().equals(HttpStatus.CREATED)) { - return true; - } - return false; + return response != null && response.getStatusCode().equals(HttpStatus.CREATED); } @@ -178,9 +166,8 @@ public class MultiClient { ResponseEntity<Object> response = restTemplate.exchange(callUrl, HttpMethod.PUT, new HttpEntity<>(param, httpHeaders), Object.class); LOGGER.info("response status : " + response.getStatusCodeValue()); - if (!response.getStatusCode().equals(HttpStatus.CREATED)) { - LOGGER.warn("HTTP call on " + callUrl + " returns " + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) { + LOGGER.warn("HTTP call on {} returns {} , {}", callUrl , response.getStatusCodeValue(), response.getBody().toString()); } return response; } catch (BackendFunctionalException|ResourceAccessException e) { @@ -196,8 +183,9 @@ public class MultiClient { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(callURL); if (param != null) { - for (String paramName : param.keySet()) { - builder.queryParam(paramName, param.get(paramName)); + for (Entry<String, String> stringEntry : param.entrySet()) { + builder.queryParam(stringEntry.getKey(), stringEntry.getValue()); + } } URI uri = builder.build().encode().toUri(); @@ -205,11 +193,13 @@ public class MultiClient { ResponseEntity<Object> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(httpHeaders), Object.class); - LOGGER.debug("response body : " + response.getBody().toString()); - LOGGER.info("response status : " + response.getStatusCodeValue()); - if (!response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn("HTTP call on " + callURL + " returns " + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if(LOGGER.isDebugEnabled()){ + LOGGER.debug("response body : {}", response.getBody().toString()); + } + LOGGER.info("response status : {}", response.getStatusCodeValue()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { + LOGGER.warn("HTTP call on {} returns {} , {}", callURL , response.getStatusCodeValue(), response.getBody().toString()); + } return response; diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java index 12ee889..ca01af9 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java @@ -50,7 +50,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/serviceOrder") @EnableScheduling -public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { +public class ServiceOrderResource extends ResourceManagement { diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java index 3dba422..e2b10ab 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java @@ -37,7 +37,6 @@ import org.springframework.web.client.RestTemplate; public class SoClient { public static final String RESPONSE_STATUS = "response status : "; - public static final String RESPONSE_BODY = "response body : "; public static final String RETURNS = " returns "; public static final String ERROR_ON_CALLING = "error on calling "; @Autowired @@ -104,11 +103,12 @@ public class SoClient { private void logResponsePost(String url, ResponseEntity<CreateServiceInstanceResponse> response) { LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue()); - LOGGER.debug(RESPONSE_BODY + response.getBody().toString()); + if(LOGGER.isDebugEnabled()){ + LOGGER.debug("response body : {}", response.getBody().toString()); + } - if (!response.getStatusCode().equals(HttpStatus.CREATED)) { - LOGGER.warn("HTTP call SO on " + url + RETURNS + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) { + LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString()); } } @@ -131,11 +131,12 @@ public class SoClient { private void logResponseGet(String url, ResponseEntity<GetRequestStatusResponse> response) { if(response!=null){ - LOGGER.debug(RESPONSE_BODY + response.getBody().toString()); - LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue()); - if (!response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn("HTTP call on " + url + RETURNS + response.getStatusCodeValue() + ", " - + response.getBody().toString()); + if(LOGGER.isDebugEnabled()){ + LOGGER.debug("response body : {}", response.getBody().toString()); + } + LOGGER.info("response status : {}", response.getStatusCodeValue()); + if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { + LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString()); } } else { LOGGER.info("no response calling url {}",url); diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/utils/JsonEntityConverter.java b/src/main/java/org/onap/nbi/apis/serviceorder/utils/JsonEntityConverter.java index 9e8d87e..7be84c2 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/utils/JsonEntityConverter.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/utils/JsonEntityConverter.java @@ -21,6 +21,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; public final class JsonEntityConverter { + private JsonEntityConverter() { + } + private static final ObjectMapper MAPPER = new ObjectMapper(); public static String convertServiceOrderInfoToJson(ServiceOrderInfo serviceOrderInfo) { diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java index 42b9fac..3365525 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.onap.nbi.apis.serviceorder.model.OrderItemRelationship; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; @@ -69,13 +70,15 @@ public class SOTaskManager { } // then we replace all orderitem ids in reliedtasks field with internalid of the tasks for (ExecutionTask executionTask : executionTasksSaved) { - for (String key : internalIdOrderItemsMap.keySet()) { - String replace = executionTask.getReliedTasks().replace(key, - String.valueOf(internalIdOrderItemsMap.get(key))); + for (Entry<String, Long> entry : internalIdOrderItemsMap.entrySet()) { + String replace = executionTask.getReliedTasks().replace(entry.getKey(), + String.valueOf(entry.getValue())); executionTask.setReliedTasks(replace); } - LOGGER.debug("saving task with id {} , orderItemId {} , reliedtasks ", executionTask.getInternalId(), - executionTask.getOrderItemId(), executionTask.getReliedTasks()); + if(LOGGER.isDebugEnabled()) { + LOGGER.debug("saving task with id {} , orderItemId {} , reliedtasks {}", executionTask.getInternalId(), + executionTask.getOrderItemId(), executionTask.getReliedTasks()); + } executionTaskRepository.save(executionTask); } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java index 67c9b93..66bb408 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java @@ -296,7 +296,7 @@ public class SOTaskProcessor { * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from SDC */ private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) { - List<UserParams> userParams = new ArrayList<UserParams>(); + List<UserParams> userParams = new ArrayList<>(); if (!CollectionUtils.isEmpty(characteristics)) { for (ServiceCharacteristic characteristic : characteristics) { diff --git a/src/main/java/org/onap/nbi/apis/status/StatusResource.java b/src/main/java/org/onap/nbi/apis/status/StatusResource.java index 7235d2c..96332ec 100644 --- a/src/main/java/org/onap/nbi/apis/status/StatusResource.java +++ b/src/main/java/org/onap/nbi/apis/status/StatusResource.java @@ -31,7 +31,7 @@ import javax.servlet.http.HttpServletRequest; @RestController @RequestMapping("/status") -public class StatusResource extends ResourceManagement<ApplicationStatus> { +public class StatusResource extends ResourceManagement { @Autowired private StatusService statusService; diff --git a/src/main/java/org/onap/nbi/apis/status/StatusServiceImpl.java b/src/main/java/org/onap/nbi/apis/status/StatusServiceImpl.java index 5a19e48..a55e113 100644 --- a/src/main/java/org/onap/nbi/apis/status/StatusServiceImpl.java +++ b/src/main/java/org/onap/nbi/apis/status/StatusServiceImpl.java @@ -25,14 +25,8 @@ public class StatusServiceImpl implements StatusService { @Override public ApplicationStatus get(final String serviceName, final String serviceVersion) { - final boolean applicationIsUp = true; + return new ApplicationStatus(serviceName, (StatusType.OK), serviceVersion); - - final ApplicationStatus applicationStatus = - new ApplicationStatus(serviceName, (applicationIsUp ? StatusType.OK : StatusType.KO), serviceVersion); - - - return applicationStatus; } diff --git a/src/main/java/org/onap/nbi/commons/BeanUtils.java b/src/main/java/org/onap/nbi/commons/BeanUtils.java index 164ed83..06ec2f5 100644 --- a/src/main/java/org/onap/nbi/commons/BeanUtils.java +++ b/src/main/java/org/onap/nbi/commons/BeanUtils.java @@ -26,6 +26,9 @@ public class BeanUtils { private static final PropertyUtilsBean PUB = new PropertyUtilsBean(); + private BeanUtils() { + } + /** * * @param bean diff --git a/src/main/java/org/onap/nbi/commons/JacksonFilter.java b/src/main/java/org/onap/nbi/commons/JacksonFilter.java index 21628e0..07c113e 100644 --- a/src/main/java/org/onap/nbi/commons/JacksonFilter.java +++ b/src/main/java/org/onap/nbi/commons/JacksonFilter.java @@ -33,8 +33,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; public class JacksonFilter { - private final static List<String> SKIPPED_FIELDS = Arrays.asList("internalId"); + private static final List<String> SKIPPED_FIELDS = Arrays.asList("internalId"); + private JacksonFilter() { + } public static <R> List<ObjectNode> createNodes(List<R> list, JsonRepresentation jsonRepresentation) { @@ -65,7 +67,7 @@ public class JacksonFilter { // split fieldNames in 2 categories : // simpleFields for simple property names with no '.' // nestedFields for nested property names with a '.' - Set<String> simpleFields = new LinkedHashSet<String>(); + Set<String> simpleFields = new LinkedHashSet<>(); MultiValueMap nestedFields = new LinkedMultiValueMap(); buildFields(names, simpleFields, nestedFields); @@ -86,7 +88,7 @@ public class JacksonFilter { if (nestedBean == null) { continue; } - Set<String> nestedFieldNames = new LinkedHashSet<String>(entry.getValue()); + Set<String> nestedFieldNames = new LinkedHashSet<>(entry.getValue()); // current node is an array or a list if ((nestedBean.getClass().isArray()) || (Collection.class.isAssignableFrom(nestedBean.getClass()))) { handleListNode(mapper, rootNode, rootFieldName, nestedBean, nestedFieldNames); @@ -133,7 +135,7 @@ public class JacksonFilter { if (array.length > 0) { // create a node for each element in array // and add created node in an arrayNode - Collection<JsonNode> nodes = new LinkedList<JsonNode>(); + Collection<JsonNode> nodes = new LinkedList<>(); for (Object object : array) { ObjectNode nestedNode = JacksonFilter.createNode(mapper, object, nestedFieldNames); if ((nestedNode != null) && (nestedNode.size() > 0)) { diff --git a/src/main/java/org/onap/nbi/commons/QueryParserUtils.java b/src/main/java/org/onap/nbi/commons/QueryParserUtils.java index 53a0e61..a43b5bb 100644 --- a/src/main/java/org/onap/nbi/commons/QueryParserUtils.java +++ b/src/main/java/org/onap/nbi/commons/QueryParserUtils.java @@ -66,10 +66,10 @@ public class QueryParserUtils { Set<Entry<String, List<String>>> entrySet = queryParameters.entrySet(); - MultiValueMap<String, String> criterias = new LinkedMultiValueMap<String, String>(); + MultiValueMap<String, String> criterias = new LinkedMultiValueMap<>(); entrySet.stream().forEach(entry -> { - final List<String> tempValues = new ArrayList<String>(); + final List<String> tempValues = new ArrayList<>(); entry.getValue().stream().forEach(value -> tempValues.addAll(Arrays.asList(value.split(",")))); criterias.put(entry.getKey(), tempValues); }); diff --git a/src/main/java/org/onap/nbi/commons/ResourceManagement.java b/src/main/java/org/onap/nbi/commons/ResourceManagement.java index e90c2b0..82d9ebe 100644 --- a/src/main/java/org/onap/nbi/commons/ResourceManagement.java +++ b/src/main/java/org/onap/nbi/commons/ResourceManagement.java @@ -24,7 +24,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; -public class ResourceManagement<T extends Resource> { +public class ResourceManagement { /** * Build default 201 filtered response for resource diff --git a/src/main/java/org/onap/nbi/exceptions/ApiExceptionHandler.java b/src/main/java/org/onap/nbi/exceptions/ApiExceptionHandler.java index dbdae6a..fa2a65b 100644 --- a/src/main/java/org/onap/nbi/exceptions/ApiExceptionHandler.java +++ b/src/main/java/org/onap/nbi/exceptions/ApiExceptionHandler.java @@ -31,7 +31,7 @@ public class ApiExceptionHandler { public ResponseEntity<ApiError> backendExceptionHandler(final BackendFunctionalException exception) { ApiError apiError = new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", ""); - return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus()); + return new ResponseEntity<>(apiError, exception.getHttpStatus()); } @ExceptionHandler(TechnicalException.class) @@ -39,21 +39,21 @@ public class ApiExceptionHandler { public ResponseEntity<ApiError> technicalExceptionHandler(final TechnicalException exception) { ApiError apiError = new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", ""); - return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus()); + return new ResponseEntity<>(apiError, exception.getHttpStatus()); } @ExceptionHandler(RestClientException.class) @ResponseBody - public ResponseEntity<ApiError> RestClientExceptionHandler(final RestClientException exception) { + public ResponseEntity<ApiError> restClientExceptionHandler(final RestClientException exception) { ApiError apiError = new ApiError("500", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "Unable to " + "reach ONAP services", ""); - return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR); } @ExceptionHandler(ValidationException.class) @ResponseBody - public ResponseEntity<ApiError> ValidationExceptionHandler(final ValidationException exception) { + public ResponseEntity<ApiError> validationExceptionHandler(final ValidationException exception) { ApiError apiError = new ApiError("400", HttpStatus.BAD_REQUEST.getReasonPhrase(), exception.getMessages(), ""); - return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java b/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java index 47257cc..e037987 100644 --- a/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java +++ b/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java @@ -19,17 +19,13 @@ import org.springframework.http.HttpStatus; public class BackendFunctionalException extends ApiException { - private HttpStatus httpStatus; + private final HttpStatus httpStatus; public BackendFunctionalException(HttpStatus httpStatus, String message) { super(message); this.httpStatus = httpStatus; } - public BackendFunctionalException() { - super(); - } - public HttpStatus getHttpStatus() { return httpStatus; } diff --git a/src/main/java/org/onap/nbi/exceptions/TechnicalException.java b/src/main/java/org/onap/nbi/exceptions/TechnicalException.java index 956a15a..14d6321 100644 --- a/src/main/java/org/onap/nbi/exceptions/TechnicalException.java +++ b/src/main/java/org/onap/nbi/exceptions/TechnicalException.java @@ -19,23 +19,17 @@ import org.springframework.http.HttpStatus; public class TechnicalException extends ApiException { - private HttpStatus httpStatus; + private final HttpStatus httpStatus; public TechnicalException(String message) { super(message); this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; } - public TechnicalException() { - super(); - } public HttpStatus getHttpStatus() { return httpStatus; } - public void setHttpStatus(HttpStatus httpStatus) { - this.httpStatus = httpStatus; - } } diff --git a/src/main/java/org/onap/nbi/exceptions/ValidationException.java b/src/main/java/org/onap/nbi/exceptions/ValidationException.java index e077333..1cf7d36 100644 --- a/src/main/java/org/onap/nbi/exceptions/ValidationException.java +++ b/src/main/java/org/onap/nbi/exceptions/ValidationException.java @@ -21,7 +21,7 @@ import java.util.List; public class ValidationException extends ApiException { - private String messages; + private final String messages; public ValidationException(List<ObjectError> listErrors) { super(); |