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 /ms/controllerblueprints/application/src | |
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>
Diffstat (limited to 'ms/controllerblueprints/application/src')
-rw-r--r-- | ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java | 309 |
1 files changed, 155 insertions, 154 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; + } +} |