diff options
author | Arundathi Patil <arundpil@in.ibm.com> | 2018-10-30 14:12:12 +0530 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2018-11-02 18:07:49 +0000 |
commit | 115a90365564d9cb5a6415f4fa525b999a36b5ea (patch) | |
tree | 15ab3799a2112df522bde461ab908f4795ba4189 | |
parent | ad2bd5603230897091b93167b683b05955b91330 (diff) |
SwaggerConfig,ResourceAssignmentInitializer-Sonar
Fixed sonar issues/code-smells accross these files
Issue-ID: CCSDK-631
Change-Id: I0312937af688341e37b68f7da6229fdf935d620d
Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
2 files changed, 155 insertions, 163 deletions
diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java index cfcccf33..8b96f04a 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java @@ -1,154 +1,155 @@ -/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints;
-
-import com.google.common.collect.Lists;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.RequestMethod;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.builders.ResponseMessageBuilder;
-import springfox.documentation.schema.ModelRef;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.service.Contact;
-import springfox.documentation.service.Header;
-import springfox.documentation.service.ResponseMessage;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * SwaggerConfig
- *
- * @author Brinda Santh 8/13/2018
- */
-@Configuration
-@EnableSwagger2
-@SuppressWarnings("unused")
-public class SwaggerConfig {
- @Value("${appVersion}")
- private String appVersion;
- @Value("${swagger.contact.name}")
- private String contactName;
- @Value("${swagger.contact.url}")
- private String contactUrl;
- @Value("${swagger.contact.email}")
- private String contactEmail;
-
- @Bean
- @SuppressWarnings("unused")
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .globalResponseMessage(RequestMethod.GET, getDefaultGetResponseMessages())
- .globalResponseMessage(RequestMethod.POST, getDefaultPostResponseMessages())
- .globalResponseMessage(RequestMethod.PUT, getDefaultPutResponseMessages())
- .globalResponseMessage(RequestMethod.DELETE, getDefaultDeleteResponseMessages())
- .select()
- .apis(RequestHandlerSelectors.any())
- .paths(PathSelectors.any())
- .build()
- .apiInfo(apiInfo());
- }
-
- private ApiInfo apiInfo() {
- return new ApiInfo(
- "Controller Blueprints API",
- "Controller blueprints API for VNF Self Service.",
- appVersion,
- "Terms of service",
- new Contact(contactName, contactUrl, contactEmail),
- "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList());
- }
-
- private List<ResponseMessage> getDefaultGetResponseMessages() {
- List<ResponseMessage> defaultResponseMessages = Lists.newArrayList();
- Map<String, Header> defaultHeaders = getDefaultResponseHeaders();
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.NOT_FOUND, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders));
- return defaultResponseMessages;
- }
-
- private List<ResponseMessage> getDefaultPostResponseMessages() {
- List<ResponseMessage> defaultResponseMessages = Lists.newArrayList();
- Map<String, Header> defaultHeaders = getDefaultResponseHeaders();
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.CREATED, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders));
- return defaultResponseMessages;
- }
-
- private List<ResponseMessage> getDefaultPutResponseMessages() {
- List<ResponseMessage> defaultResponseMessages = Lists.newArrayList();
- Map<String, Header> defaultHeaders = getDefaultResponseHeaders();
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders));
- return defaultResponseMessages;
- }
-
- private List<ResponseMessage> getDefaultDeleteResponseMessages() {
- List<ResponseMessage> defaultResponseMessages = Lists.newArrayList();
- Map<String, Header> defaultHeaders = getDefaultResponseHeaders();
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders));
- defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders));
- return defaultResponseMessages;
- }
-
- private ResponseMessage getResponseBuilder(@NotNull HttpStatus httpStatus, Map<String, Header> defaultHeaders) {
- ResponseMessageBuilder responseMessageBuilder = new ResponseMessageBuilder();
- responseMessageBuilder.code(httpStatus.value())
- .message(httpStatus.getReasonPhrase())
- .headersWithDescription(defaultHeaders)
- .build();
- return responseMessageBuilder.build();
- }
-
- private Map<String, Header> getDefaultResponseHeaders() {
- Map<String, Header> defaultHeaders = new HashMap<>();
- defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID,
- new Header(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, "Transaction Id", new ModelRef("string")));
- defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION,
- new Header(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION, "API Latest Version", new ModelRef("string")));
- defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION,
- new Header(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION, "API Minor Version", new ModelRef("string")));
- defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION,
- new Header(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION, "API Patch Version", new ModelRef("string")));
- return defaultHeaders;
- }
-}
+/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints; + +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.RequestMethod; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.builders.ResponseMessageBuilder; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.service.Header; +import springfox.documentation.service.ResponseMessage; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * SwaggerConfig + * + * @author Brinda Santh 8/13/2018 + */ +@Configuration +@EnableSwagger2 +@SuppressWarnings("unused") +public class SwaggerConfig { + @Value("${appVersion}") + private String appVersion; + @Value("${swagger.contact.name}") + private String contactName; + @Value("${swagger.contact.url}") + private String contactUrl; + @Value("${swagger.contact.email}") + private String contactEmail; + private String stringModelRef = "string"; + + @Bean + @SuppressWarnings("unused") + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .globalResponseMessage(RequestMethod.GET, getDefaultGetResponseMessages()) + .globalResponseMessage(RequestMethod.POST, getDefaultPostResponseMessages()) + .globalResponseMessage(RequestMethod.PUT, getDefaultPutResponseMessages()) + .globalResponseMessage(RequestMethod.DELETE, getDefaultDeleteResponseMessages()) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfo( + "Controller Blueprints API", + "Controller blueprints API for VNF Self Service.", + appVersion, + "Terms of service", + new Contact(contactName, contactUrl, contactEmail), + "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList()); + } + + private List<ResponseMessage> getDefaultGetResponseMessages() { + List<ResponseMessage> defaultResponseMessages = Lists.newArrayList(); + Map<String, Header> defaultHeaders = getDefaultResponseHeaders(); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.NOT_FOUND, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders)); + return defaultResponseMessages; + } + + private List<ResponseMessage> getDefaultPostResponseMessages() { + List<ResponseMessage> defaultResponseMessages = Lists.newArrayList(); + Map<String, Header> defaultHeaders = getDefaultResponseHeaders(); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.CREATED, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders)); + return defaultResponseMessages; + } + + private List<ResponseMessage> getDefaultPutResponseMessages() { + List<ResponseMessage> defaultResponseMessages = Lists.newArrayList(); + Map<String, Header> defaultHeaders = getDefaultResponseHeaders(); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders)); + return defaultResponseMessages; + } + + private List<ResponseMessage> getDefaultDeleteResponseMessages() { + List<ResponseMessage> defaultResponseMessages = Lists.newArrayList(); + Map<String, Header> defaultHeaders = getDefaultResponseHeaders(); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.OK, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.BAD_REQUEST, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.UNAUTHORIZED, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.FORBIDDEN, defaultHeaders)); + defaultResponseMessages.add(getResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR, defaultHeaders)); + return defaultResponseMessages; + } + + private ResponseMessage getResponseBuilder(@NotNull HttpStatus httpStatus, Map<String, Header> defaultHeaders) { + ResponseMessageBuilder responseMessageBuilder = new ResponseMessageBuilder(); + responseMessageBuilder.code(httpStatus.value()) + .message(httpStatus.getReasonPhrase()) + .headersWithDescription(defaultHeaders) + .build(); + return responseMessageBuilder.build(); + } + + private Map<String, Header> getDefaultResponseHeaders() { + Map<String, Header> defaultHeaders = new HashMap<>(); + defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, + new Header(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, "Transaction Id", new ModelRef(stringModelRef))); + defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION, + new Header(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION, "API Latest Version", new ModelRef(stringModelRef))); + defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION, + new Header(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION, "API Minor Version", new ModelRef(stringModelRef))); + defaultHeaders.put(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION, + new Header(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION, "API Patch Version", new ModelRef(stringModelRef))); + return defaultHeaders; + } +} diff --git a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java index 3c845329..cd118e0f 100644 --- a/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java +++ b/ms/vlantag-api/src/main/java/org/onap/ccsdk/apps/ms/vlantagapi/core/ResourceAssignmentInitializer.java @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.ms.vlantagapi.core;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,15 +45,10 @@ import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDao; import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDaoImpl;
import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDao;
import org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDaoImpl;
-import org.onap.ccsdk.sli.adaptors.util.db.CachedDataSourceWrap;
-import org.onap.ccsdk.sli.adaptors.util.db.DataSourceWrap;
import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
/**
@@ -68,9 +62,6 @@ import org.springframework.stereotype.Component; @Component
@Configuration
public class ResourceAssignmentInitializer {
-
- private static final Logger log = LoggerFactory.getLogger(ResourceAssignmentInitializer.class);
-
@Bean
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
|