Support pagination in query across all anchors(ep4)
[cps.git] / cps-service / src / main / java / org / onap / cps / api / impl / CpsQueryServiceImpl.java
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.api.impl;
23
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;
34
35 @Service
36 @RequiredArgsConstructor
37 public class CpsQueryServiceImpl implements CpsQueryService {
38
39     private final CpsDataPersistenceService cpsDataPersistenceService;
40     private final CpsValidator cpsValidator;
41
42     @Override
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);
49     }
50
51     @Override
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);
59     }
60
61     @Override
62     public Integer countAnchorsForDataspaceAndCpsPath(final String dataspaceName, final String cpsPath) {
63         cpsValidator.validateNameCharacters(dataspaceName);
64         return cpsDataPersistenceService.countAnchorsForDataspaceAndCpsPath(dataspaceName, cpsPath);
65     }
66 }