2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * Modifications Copyright (C) 2021 Pantheon.tech
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.rest.controller;
24 import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
25 import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED;
27 import java.util.Collection;
28 import org.modelmapper.ModelMapper;
29 import org.onap.cps.api.CpsAdminService;
30 import org.onap.cps.api.CpsModuleService;
31 import org.onap.cps.rest.api.CpsAdminApi;
32 import org.onap.cps.spi.model.Anchor;
33 import org.onap.cps.spi.model.SchemaSet;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.http.HttpStatus;
36 import org.springframework.http.ResponseEntity;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RestController;
39 import org.springframework.web.multipart.MultipartFile;
42 @RequestMapping("${rest.api.cps-base-path}")
43 public class AdminRestController implements CpsAdminApi {
46 private CpsAdminService cpsAdminService;
49 private CpsModuleService cpsModuleService;
52 private ModelMapper modelMapper;
55 public ResponseEntity<String> createDataspace(final String dataspaceName) {
56 cpsAdminService.createDataspace(dataspaceName);
57 return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
61 public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
62 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
66 public ResponseEntity<String> createSchemaSet(final MultipartFile multipartFile,
67 final String schemaSetName, final String dataspaceName) {
68 cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
69 return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
73 public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
74 final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
75 return new ResponseEntity<>(schemaSet, HttpStatus.OK);
79 public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
80 cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
81 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
85 * Create a new anchor.
87 * @param dataspaceName dataspace name
88 * @param schemaSetName schema set name
89 * @param anchorName anchorName
90 * @return a ResponseEntity with the anchor name.
93 public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
94 final String anchorName) {
95 cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
96 return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
100 public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) {
101 cpsAdminService.deleteAnchor(dataspaceName, anchorName);
102 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
106 public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
107 final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
108 return new ResponseEntity<>(anchor, HttpStatus.OK);
112 public ResponseEntity<Object> getAnchors(final String dataspaceName) {
113 final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
114 return new ResponseEntity<>(anchorDetails, HttpStatus.OK);