407a7673896f22ff3fd1ed4cd09ea768907bea0b
[cps.git] / cps-rest / src / main / java / org / onap / cps / rest / controller / AdminRestController.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation
4  *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.rest.controller;
22
23 import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
24
25 import java.util.Collection;
26 import org.modelmapper.ModelMapper;
27 import org.onap.cps.api.CpsAdminService;
28 import org.onap.cps.api.CpsModuleService;
29 import org.onap.cps.rest.api.CpsAdminApi;
30 import org.onap.cps.spi.model.Anchor;
31 import org.onap.cps.spi.model.SchemaSet;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.http.HttpStatus;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.RestController;
36 import org.springframework.web.multipart.MultipartFile;
37
38 @RestController
39 public class AdminRestController implements CpsAdminApi {
40
41     @Autowired
42     private CpsAdminService cpsAdminService;
43
44     @Autowired
45     private CpsModuleService cpsModuleService;
46
47     @Autowired
48     private ModelMapper modelMapper;
49
50     @Override
51     public ResponseEntity<String> createDataspace(final String dataspaceName) {
52         cpsAdminService.createDataspace(dataspaceName);
53         return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
54     }
55
56     @Override
57     public ResponseEntity<String> createSchemaSet(final String schemaSetName, final MultipartFile multipartFile,
58         final String dataspaceName) {
59         cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
60         return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
61     }
62
63     @Override
64     public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
65         final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
66         return new ResponseEntity<>(schemaSet, HttpStatus.OK);
67     }
68
69     /**
70      * Create a new anchor.
71      *
72      * @param dataspaceName dataspace name
73      * @param schemaSetName schema set name
74      * @param anchorName    anchorName
75      * @return a ResponseEntity with the anchor name.
76      */
77     @Override
78     public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
79         final String anchorName) {
80         cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
81         return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
82     }
83
84     @Override
85     public ResponseEntity<Object> deleteAnchor(final String dataspaceName, final String anchorName) {
86         return null;
87     }
88
89     @Override
90     public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
91         return null;
92     }
93
94     @Override
95     public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
96         return null;
97     }
98
99     @Override
100     public ResponseEntity<Object> getAnchors(final String dataspaceName) {
101         final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
102         return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
103     }
104 }