summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/main/java
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2020-11-09 03:28:44 +0000
committerRishi.Chail <rishi.chail@est.tech>2020-11-18 13:30:01 +0000
commit48830f146f6776afa180fefa101788b169bc841a (patch)
tree6154165d4a3d8f464511c39544cf62d0923964a3 /cps-rest/src/main/java
parente40f4d2dce4c4adf57b99c3daf524b14204279b9 (diff)
VSE: Create an anchor in the given dataspace
Issue-ID: CPS-42 https://jira.onap.org/browse/CPS-42 Signed-off-by: Rishi Chail <rishi.chail@est.tech> Change-Id: If67be6f13889808da4d9fe830595766af67e4fdf
Diffstat (limited to 'cps-rest/src/main/java')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/config/CpsConfig.java50
-rwxr-xr-x[-rw-r--r--]cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java27
-rw-r--r--cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java46
3 files changed, 71 insertions, 52 deletions
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();
- }
-}