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