diff options
Diffstat (limited to 'cps-rest')
-rwxr-xr-x[-rw-r--r--] | cps-rest/docs/api/swagger/openapi.yml | 38 | ||||
-rwxr-xr-x[-rw-r--r--] | cps-rest/pom.xml | 4 | ||||
-rwxr-xr-x | cps-rest/src/main/java/org/onap/cps/config/CpsConfig.java | 50 | ||||
-rwxr-xr-x[-rw-r--r--] | cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java | 27 | ||||
-rw-r--r-- | cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java | 46 |
5 files changed, 98 insertions, 67 deletions
diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml index 82f47c088f..0c7c83c561 100644..100755 --- a/cps-rest/docs/api/swagger/openapi.yml +++ b/cps-rest/docs/api/swagger/openapi.yml @@ -81,26 +81,19 @@ paths: type: string requestBody: content: - multipart/form-data: + application/json: schema: - required: - - file - properties: - multipartFile: - type: string - description: multipartFile - format: binary + title: Anchor + description: anchor + $ref: '#/components/schemas/Anchor' required: true responses: - 200: - description: OK + 201: + description: Created content: application/json: schema: - type: object - 201: - description: Created - content: {} + type: string 401: description: Unauthorized content: {} @@ -370,4 +363,19 @@ paths: 404: description: Not Found content: {} -components: {}
\ No newline at end of file +components: + schemas: + Anchor: + type: object + title: Anchor + required: + - anchorName + - namespace + - revision + properties: + anchorName: + type: string + namespace: + type: string + revision: + type: string
\ No newline at end of file diff --git a/cps-rest/pom.xml b/cps-rest/pom.xml index fc3e6325e2..3a82ca3770 100644..100755 --- a/cps-rest/pom.xml +++ b/cps-rest/pom.xml @@ -51,6 +51,10 @@ <artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
+ <groupId>org.modelmapper</groupId>
+ <artifactId>modelmapper</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
diff --git a/cps-rest/src/main/java/org/onap/cps/config/CpsConfig.java b/cps-rest/src/main/java/org/onap/cps/config/CpsConfig.java new file mode 100755 index 0000000000..cca5fe7d8d --- /dev/null +++ b/cps-rest/src/main/java/org/onap/cps/config/CpsConfig.java @@ -0,0 +1,50 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.config;
+
+import org.modelmapper.ModelMapper;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+
+@Configuration
+public class CpsConfig {
+
+ /**
+ * Swagger configuration.
+ */
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.OAS_30).select().apis(RequestHandlerSelectors.any())
+ .paths(PathSelectors.any()).build();
+ }
+
+ /**
+ * ModelMapper configuration.
+ */
+ @Bean
+ public ModelMapper modelMapper() {
+ return new ModelMapper();
+ }
+}
\ No newline at end of file diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java index f0c5fcbc43..9e57408fb7 100644..100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java @@ -27,10 +27,13 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.validation.Valid; +import org.modelmapper.ModelMapper; import org.onap.cps.api.CpService; +import org.onap.cps.api.model.AnchorDetails; import org.onap.cps.exceptions.CpsException; import org.onap.cps.exceptions.CpsValidationException; import org.onap.cps.rest.api.CpsRestApi; +import org.onap.cps.rest.model.Anchor; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -49,9 +52,22 @@ public class CpsRestController implements CpsRestApi { @Autowired private CpService cpService; + @Autowired + private ModelMapper modelMapper; + + /** + * Create a new anchor. + * + * @param anchor the anchor details object. + * @param dataspaceName the dataspace name. + * @return a ResponseEntity with the anchor name. + */ @Override - public ResponseEntity<Object> createAnchor(@Valid MultipartFile multipartFile, String dataspaceName) { - return null; + public final ResponseEntity<String> createAnchor(@Valid Anchor anchor, String dataspaceName) { + final AnchorDetails anchorDetails = modelMapper.map(anchor, AnchorDetails.class); + anchorDetails.setDataspace(dataspaceName); + final String anchorName = cpService.createAnchor(anchorDetails); + return new ResponseEntity<String>(anchorName, HttpStatus.CREATED); } @Override @@ -151,7 +167,7 @@ public class CpsRestController implements CpsRestApi { try { final Gson gson = new Gson(); gson.fromJson(getJsonString(multipartFile), Object.class); - } catch (JsonSyntaxException e) { + } catch (final JsonSyntaxException e) { throw new CpsValidationException("Not a valid JSON file.", e); } } @@ -160,13 +176,12 @@ public class CpsRestController implements CpsRestApi { try { final File file = File.createTempFile("tempFile", ".yang"); file.deleteOnExit(); - try (OutputStream outputStream = new FileOutputStream(file)) { outputStream.write(multipartFile.getBytes()); } return file; - } catch (IOException e) { + } catch (final IOException e) { throw new CpsException(e); } } @@ -174,7 +189,7 @@ public class CpsRestController implements CpsRestApi { private static String getJsonString(final MultipartFile multipartFile) { try { return new String(multipartFile.getBytes()); - } catch (IOException e) { + } catch (final IOException e) { throw new CpsException(e); } } diff --git a/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java b/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java deleted file mode 100644 index 73e179511b..0000000000 --- a/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Bell Canada. All rights reserved. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.swagger.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; - -/** - * Swagger configuration. - */ -@Configuration -public class SpringFoxConfig { - - /** - * Define api configuration. - */ - @Bean - public Docket api() { - return new Docket(DocumentationType.OAS_30) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) - .build(); - } -} |