39854552639212946be6fccbeea0beb7fddda41e
[cps.git] / cps-path-parser / src / main / java / org / onap / cps / cpspath / parser / CpsPathQuery.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2023 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.cpspath.parser;
22
23 import static org.onap.cps.cpspath.parser.CpsPathPrefixType.ABSOLUTE;
24
25 import java.util.List;
26 import java.util.Map;
27 import lombok.AccessLevel;
28 import lombok.Getter;
29 import lombok.Setter;
30
31 @Getter
32 @Setter(AccessLevel.PACKAGE)
33 public class CpsPathQuery {
34
35     private String xpathPrefix;
36     private String normalizedParentPath;
37     private String normalizedXpath;
38     private List<String> containerNames;
39     private CpsPathPrefixType cpsPathPrefixType = ABSOLUTE;
40     private String descendantName;
41     private Map<String, Object> leavesData;
42     private String ancestorSchemaNodeIdentifier = "";
43     private String textFunctionConditionLeafName;
44     private String textFunctionConditionValue;
45
46     /**
47      * Returns a cps path query.
48      *
49      * @param cpsPathSource cps path
50      * @return a CpsPathQuery object.
51      */
52     public static CpsPathQuery createFrom(final String cpsPathSource) {
53         return CpsPathUtil.getCpsPathQuery(cpsPathSource);
54     }
55
56     /**
57      * Has ancestor axis been included in cpsPath.
58      *
59      * @return boolean value.
60      */
61     public boolean hasAncestorAxis() {
62         return !(ancestorSchemaNodeIdentifier.isEmpty());
63     }
64
65     /**
66      * Have leaf value conditions been included in cpsPath.
67      *
68      * @return boolean value.
69      */
70     public boolean hasLeafConditions() {
71         return leavesData != null;
72     }
73
74     /**
75      * Has text function condition been included in cpsPath.
76      *
77      * @return boolean value.
78      */
79     public boolean hasTextFunctionCondition() {
80         return textFunctionConditionLeafName != null;
81     }
82
83     /**
84      * Returns boolean indicating xpath is an absolute path to a list element.
85      *
86      * @return true if xpath is an absolute path to a list element
87      */
88     public boolean isPathToListElement() {
89         return cpsPathPrefixType == ABSOLUTE && hasLeafConditions();
90     }
91
92 }