2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2022 Nordix Foundation
4 * Modifications Copyright (C) 2020-2022 Bell Canada.
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
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.api.impl;
25 import java.time.OffsetDateTime;
26 import java.util.Collection;
28 import java.util.stream.Collectors;
29 import lombok.AllArgsConstructor;
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.CmHandleQueryParameters;
35 import org.onap.cps.utils.CpsValidator;
36 import org.springframework.context.annotation.Lazy;
37 import org.springframework.stereotype.Component;
39 @Component("CpsAdminServiceImpl")
40 @AllArgsConstructor(onConstructor = @__(@Lazy))
41 public class CpsAdminServiceImpl implements CpsAdminService {
43 private final CpsAdminPersistenceService cpsAdminPersistenceService;
45 private final CpsDataService cpsDataService;
48 public void createDataspace(final String dataspaceName) {
49 CpsValidator.validateNameCharacters(dataspaceName);
50 cpsAdminPersistenceService.createDataspace(dataspaceName);
54 public void deleteDataspace(final String dataspaceName) {
55 CpsValidator.validateNameCharacters(dataspaceName);
56 cpsAdminPersistenceService.deleteDataspace(dataspaceName);
60 public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
61 CpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName);
62 cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName);
66 public Collection<Anchor> getAnchors(final String dataspaceName) {
67 CpsValidator.validateNameCharacters(dataspaceName);
68 return cpsAdminPersistenceService.getAnchors(dataspaceName);
72 public Collection<Anchor> getAnchors(final String dataspaceName, final String schemaSetName) {
73 CpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
74 return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetName);
78 public Anchor getAnchor(final String dataspaceName, final String anchorName) {
79 CpsValidator.validateNameCharacters(dataspaceName, anchorName);
80 return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
84 public void deleteAnchor(final String dataspaceName, final String anchorName) {
85 CpsValidator.validateNameCharacters(dataspaceName, anchorName);
86 cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now());
87 cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName);
91 public Collection<String> queryAnchorNames(final String dataspaceName, final Collection<String> moduleNames) {
92 CpsValidator.validateNameCharacters(dataspaceName);
93 final Collection<Anchor> anchors = cpsAdminPersistenceService.queryAnchors(dataspaceName, moduleNames);
94 return anchors.stream().map(Anchor::getName).collect(Collectors.toList());
98 public Set<String> queryCmHandles(final CmHandleQueryParameters cmHandleQueryParameters) {
99 return cpsAdminPersistenceService.queryCmHandles(cmHandleQueryParameters);