Merge "Allow duplicate leaf names in Cps Path leaf condition"
[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  *  Modifications Copyright (C) 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.cpspath.parser;
23
24 import static org.onap.cps.cpspath.parser.CpsPathPrefixType.ABSOLUTE;
25
26 import java.util.List;
27 import lombok.AccessLevel;
28 import lombok.AllArgsConstructor;
29 import lombok.EqualsAndHashCode;
30 import lombok.Getter;
31 import lombok.Setter;
32
33 @Getter
34 @Setter(AccessLevel.PACKAGE)
35 public class CpsPathQuery {
36
37     private String xpathPrefix;
38     private String normalizedParentPath;
39     private String normalizedXpath;
40     private List<String> containerNames;
41     private CpsPathPrefixType cpsPathPrefixType = ABSOLUTE;
42     private String descendantName;
43     private List<DataLeaf> leavesData;
44     private String ancestorSchemaNodeIdentifier = "";
45     private String textFunctionConditionLeafName;
46     private String textFunctionConditionValue;
47     private List<String> booleanOperators;
48     private List<String> comparativeOperators;
49     private String containsFunctionConditionLeafName;
50     private String containsFunctionConditionValue;
51
52     /**
53      * Returns a cps path query.
54      *
55      * @param cpsPathSource cps path
56      * @return a CpsPathQuery object.
57      */
58     public static CpsPathQuery createFrom(final String cpsPathSource) {
59         return CpsPathUtil.getCpsPathQuery(cpsPathSource);
60     }
61
62     /**
63      * Has ancestor axis been included in cpsPath.
64      *
65      * @return boolean value.
66      */
67     public boolean hasAncestorAxis() {
68         return !(ancestorSchemaNodeIdentifier.isEmpty());
69     }
70
71     /**
72      * Have leaf value conditions been included in cpsPath.
73      *
74      * @return boolean value.
75      */
76     public boolean hasLeafConditions() {
77         return leavesData != null;
78     }
79
80     /**
81      * Has text function condition been included in cpsPath.
82      *
83      * @return boolean value.
84      */
85     public boolean hasTextFunctionCondition() {
86         return textFunctionConditionLeafName != null;
87     }
88
89     /**
90      * Has contains function condition been included in cpsPath.
91      *
92      * @return boolean value.
93      */
94     public boolean hasContainsFunctionCondition() {
95         return containsFunctionConditionLeafName != null;
96     }
97
98     /**
99      * Returns boolean indicating xpath is an absolute path to a list element.
100      *
101      * @return true if xpath is an absolute path to a list element
102      */
103     public boolean isPathToListElement() {
104         return cpsPathPrefixType == ABSOLUTE && hasLeafConditions();
105     }
106
107     @Getter
108     @EqualsAndHashCode
109     @AllArgsConstructor
110     public static class DataLeaf {
111         private final String name;
112         private final Object value;
113     }
114 }