Delete schema set - REST and service layers
[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 import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED;
25
26 import java.util.Collection;
27 import org.modelmapper.ModelMapper;
28 import org.onap.cps.api.CpsAdminService;
29 import org.onap.cps.api.CpsModuleService;
30 import org.onap.cps.rest.api.CpsAdminApi;
31 import org.onap.cps.spi.model.Anchor;
32 import org.onap.cps.spi.model.SchemaSet;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.RestController;
37 import org.springframework.web.multipart.MultipartFile;
38
39 @RestController
40 public class AdminRestController implements CpsAdminApi {
41
42     @Autowired
43     private CpsAdminService cpsAdminService;
44
45     @Autowired
46     private CpsModuleService cpsModuleService;
47
48     @Autowired
49     private ModelMapper modelMapper;
50
51     @Override
52     public ResponseEntity<String> createDataspace(final String dataspaceName) {
53         cpsAdminService.createDataspace(dataspaceName);
54         return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
55     }
56
57     @Override
58     public ResponseEntity<String> createSchemaSet(final MultipartFile multipartFile,
59         final String schemaSetName, final String dataspaceName) {
60         cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
61         return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
62     }
63
64     @Override
65     public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
66         final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
67         return new ResponseEntity<>(schemaSet, HttpStatus.OK);
68     }
69
70     @Override
71     public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
72         cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
73         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
74     }
75
76     /**
77      * Create a new anchor.
78      *
79      * @param dataspaceName dataspace name
80      * @param schemaSetName schema set name
81      * @param anchorName    anchorName
82      * @return a ResponseEntity with the anchor name.
83      */
84     @Override
85     public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
86         final String anchorName) {
87         cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
88         return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
89     }
90
91     @Override
92     public ResponseEntity<Object> deleteAnchor(final String dataspaceName, final String anchorName) {
93         return null;
94     }
95
96     @Override
97     public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
98         return null;
99     }
100
101     @Override
102     public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
103         return null;
104     }
105
106     @Override
107     public ResponseEntity<Object> getAnchors(final String dataspaceName) {
108         final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
109         return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
110     }
111 }