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
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.rest.controller;
23 import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
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.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.web.bind.annotation.RestController;
35 import org.springframework.web.multipart.MultipartFile;
38 public class AdminRestController implements CpsAdminApi {
41 private CpsAdminService cpsAdminService;
44 private CpsModuleService cpsModuleService;
47 private ModelMapper modelMapper;
50 public ResponseEntity<String> createDataspace(final String dataspaceName) {
51 cpsAdminService.createDataspace(dataspaceName);
52 return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
56 public ResponseEntity<String> createSchemaSet(final String schemaSetName, final MultipartFile multipartFile,
57 final String dataspaceName) {
58 cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
59 return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
63 * Create a new anchor.
65 * @param dataspaceName dataspace name
66 * @param schemaSetName schema set name
67 * @param anchorName anchorName
68 * @return a ResponseEntity with the anchor name.
71 public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
72 final String anchorName) {
73 cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
74 return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
78 public ResponseEntity<Object> deleteAnchor(final String dataspaceName, final String anchorName) {
83 public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
88 public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
93 public ResponseEntity<Object> getAnchors(final String dataspaceName) {
94 final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
95 return new ResponseEntity<>(anchorDetails, HttpStatus.OK);