2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
4 * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
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
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.api.impl;
24 import io.micrometer.core.annotation.Timed;
25 import java.util.Collection;
26 import lombok.RequiredArgsConstructor;
27 import org.onap.cps.api.CpsQueryService;
28 import org.onap.cps.spi.CpsDataPersistenceService;
29 import org.onap.cps.spi.FetchDescendantsOption;
30 import org.onap.cps.spi.PaginationOption;
31 import org.onap.cps.spi.model.DataNode;
32 import org.onap.cps.spi.utils.CpsValidator;
33 import org.springframework.stereotype.Service;
36 @RequiredArgsConstructor
37 public class CpsQueryServiceImpl implements CpsQueryService {
39 private final CpsDataPersistenceService cpsDataPersistenceService;
40 private final CpsValidator cpsValidator;
43 @Timed(value = "cps.data.service.datanode.query",
44 description = "Time taken to query data nodes")
45 public Collection<DataNode> queryDataNodes(final String dataspaceName, final String anchorName,
46 final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) {
47 cpsValidator.validateNameCharacters(dataspaceName, anchorName);
48 return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption);
52 public Collection<DataNode> queryDataNodesAcrossAnchors(final String dataspaceName,
53 final String cpsPath, final FetchDescendantsOption fetchDescendantsOption,
54 final PaginationOption paginationOption) {
55 cpsValidator.validateNameCharacters(dataspaceName);
56 cpsValidator.validatePaginationOption(paginationOption);
57 return cpsDataPersistenceService.queryDataNodesAcrossAnchors(dataspaceName, cpsPath,
58 fetchDescendantsOption, paginationOption);
62 public Integer countAnchorsForDataspaceAndCpsPath(final String dataspaceName, final String cpsPath) {
63 cpsValidator.validateNameCharacters(dataspaceName);
64 return cpsDataPersistenceService.countAnchorsForDataspaceAndCpsPath(dataspaceName, cpsPath);