2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2023 Nordix Foundation
4 * Modifications Copyright (C) 2020-2022 Bell Canada.
5 * Modifications Copyright (C) 2021 Pantheon.tech
6 * Modifications Copyright (C) 2022 TechMahindra Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.cps.api.impl;
26 import java.time.OffsetDateTime;
27 import java.util.Collection;
28 import java.util.stream.Collectors;
29 import lombok.RequiredArgsConstructor;
30 import org.onap.cps.api.CpsAdminService;
31 import org.onap.cps.api.CpsDataService;
32 import org.onap.cps.spi.CpsAdminPersistenceService;
33 import org.onap.cps.spi.model.Anchor;
34 import org.onap.cps.spi.model.Dataspace;
35 import org.onap.cps.spi.utils.CpsValidator;
36 import org.springframework.context.annotation.Lazy;
37 import org.springframework.stereotype.Component;
39 @Component("CpsAdminServiceImpl")
40 @RequiredArgsConstructor(onConstructor = @__(@Lazy))
41 public class CpsAdminServiceImpl implements CpsAdminService {
43 private final CpsAdminPersistenceService cpsAdminPersistenceService;
45 private final CpsDataService cpsDataService;
46 private final CpsValidator cpsValidator;
49 public void createDataspace(final String dataspaceName) {
50 cpsValidator.validateNameCharacters(dataspaceName);
51 cpsAdminPersistenceService.createDataspace(dataspaceName);
55 public void deleteDataspace(final String dataspaceName) {
56 cpsValidator.validateNameCharacters(dataspaceName);
57 cpsAdminPersistenceService.deleteDataspace(dataspaceName);
61 public Dataspace getDataspace(final String dataspaceName) {
62 cpsValidator.validateNameCharacters(dataspaceName);
63 return cpsAdminPersistenceService.getDataspace(dataspaceName);
67 public Collection<Dataspace> getAllDataspaces() {
68 return cpsAdminPersistenceService.getAllDataspaces();
72 public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
73 cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName);
74 cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName);
78 public Collection<Anchor> getAnchors(final String dataspaceName) {
79 cpsValidator.validateNameCharacters(dataspaceName);
80 return cpsAdminPersistenceService.getAnchors(dataspaceName);
84 public Collection<Anchor> getAnchors(final String dataspaceName, final String schemaSetName) {
85 cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
86 return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetName);
90 public Collection<Anchor> getAnchors(final String dataspaceName, final Collection<String> schemaSetNames) {
91 cpsValidator.validateNameCharacters(dataspaceName);
92 cpsValidator.validateNameCharacters(schemaSetNames);
93 return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetNames);
97 public Anchor getAnchor(final String dataspaceName, final String anchorName) {
98 cpsValidator.validateNameCharacters(dataspaceName, anchorName);
99 return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
103 public void deleteAnchor(final String dataspaceName, final String anchorName) {
104 cpsValidator.validateNameCharacters(dataspaceName, anchorName);
105 cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now());
106 cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName);
110 public void deleteAnchors(final String dataspaceName, final Collection<String> anchorNames) {
111 cpsValidator.validateNameCharacters(dataspaceName);
112 cpsValidator.validateNameCharacters(anchorNames);
113 cpsDataService.deleteDataNodes(dataspaceName, anchorNames, OffsetDateTime.now());
114 cpsAdminPersistenceService.deleteAnchors(dataspaceName, anchorNames);
118 public Collection<String> queryAnchorNames(final String dataspaceName, final Collection<String> moduleNames) {
119 cpsValidator.validateNameCharacters(dataspaceName);
120 final Collection<Anchor> anchors = cpsAdminPersistenceService.queryAnchors(dataspaceName, moduleNames);
121 return anchors.stream().map(Anchor::getName).collect(Collectors.toList());
125 public void updateAnchorSchemaSet(final String dataspaceName,
126 final String anchorName,
127 final String schemaSetName) {
128 cpsAdminPersistenceService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName);