Skip to content

Package: SoqlAttribute

SoqlAttribute

nameinstructionbranchcomplexitylinemethod
SoqlAttribute(SoqlNode)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getBasicGraphPattern(String)
M: 1 C: 152
99%
M: 1 C: 17
94%
M: 1 C: 9
90%
M: 1 C: 31
97%
M: 0 C: 1
100%
getFilterExpressions()
M: 4 C: 47
92%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 8
100%
M: 0 C: 1
100%
getOperator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValue()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isGroupBy()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isInstanceOf()
M: 0 C: 11
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isNot()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isObject()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isOrderBy()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
requiresFilter()
M: 0 C: 15
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setGroupBy(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setNot(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOperator(FilterableExpression)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOrderBy(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setValue(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toIri(SoqlNode)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.query.soql;
14:
15: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
16:
17: import java.util.Collections;
18: import java.util.List;
19:
20: public class SoqlAttribute extends SoqlParameter {
21:
22: private static final String TRIPLE_END = " . ";
23:
24: private String value;
25:
26: private boolean isNot = false;
27:
28: private FilterableExpression operator;
29:
30: private boolean isOrderBy = false;
31:
32: private boolean isGroupBy = false;
33:
34: public SoqlAttribute(SoqlNode firstNode) {
35: super(firstNode);
36: }
37:
38: public String getValue() {
39: return value;
40: }
41:
42: public void setValue(String value) {
43: this.value = value;
44: }
45:
46: public boolean isNot() {
47: return isNot;
48: }
49:
50: public void setNot(boolean not) {
51: isNot = not;
52: }
53:
54: public void setOperator(FilterableExpression operator) {
55: this.operator = operator;
56: }
57:
58: public FilterableExpression getOperator() {
59: return operator;
60: }
61:
62: public boolean isOrderBy() {
63: return isOrderBy;
64: }
65:
66: public void setOrderBy(boolean orderBy) {
67: isOrderBy = orderBy;
68: }
69:
70: public boolean isGroupBy() {
71: return isGroupBy;
72: }
73:
74: public void setGroupBy(boolean groupBy) {
75: isGroupBy = groupBy;
76: }
77:
78: public boolean requiresFilter() {
79:• return (operator != null && operator.requiresFilterExpression()) || getFirstNode().requiresFilterExpression();
80: }
81:
82: public boolean isObject() {
83:• return !getFirstNode().hasChild();
84: }
85:
86: public boolean isInstanceOf() {
87:• return !getFirstNode().hasChild() && operator == null;
88: }
89:
90: public List<String> getFilterExpressions() {
91:• assert requiresFilter();
92: String filterParam = getAsParam();
93: final String filterValue = SoqlUtils.soqlVariableToSparqlVariable(value);
94:• if (getFirstNode().requiresFilterExpression()) {
95: filterParam = getFirstNode().toFilterExpression(filterParam, filterValue);
96: }
97:• if (operator != null && operator.requiresFilterExpression()) {
98: return Collections.singletonList(operator.toFilterExpression(filterParam, filterValue));
99: } else {
100: return Collections.singletonList(filterParam + " = " + filterValue);
101: }
102: }
103:
104: public String getBasicGraphPattern(String rootVariable) {
105: StringBuilder buildTP = new StringBuilder(rootVariable).append(' ');
106:• if (isInstanceOf()) {
107: buildTP.append(SoqlConstants.RDF_TYPE).append(' ')
108: .append(toIri(getFirstNode())).append(TRIPLE_END);
109: } else {
110:• if (isObject()) {
111: return "";
112: }
113: SoqlNode pointer = getFirstNode().getChild();
114: StringBuilder buildParam = new StringBuilder("?");
115: buildParam.append(getFirstNode().getValue());
116: buildParam.append(pointer.getCapitalizedValue());
117: String param;
118:• if (pointer.hasChild() || value == null) {
119: param = "?" + pointer.getValue();
120: } else {
121:• if (requiresFilter()) {
122: param = buildParam.toString();
123: } else {
124: param = SoqlUtils.soqlVariableToSparqlVariable(value);
125: }
126: }
127: buildTP.append(toIri(pointer)).append(' ').append(param).append(TRIPLE_END);
128:• while (pointer.hasChild()) {
129: SoqlNode newPointer = pointer.getChild();
130:• if (newPointer.getIri().isEmpty()) {
131: break;
132: }
133: buildTP.append('?').append(pointer.getValue())
134: .append(' ').append(toIri(newPointer)).append(' ');
135: buildParam.append(newPointer.getCapitalizedValue());
136:• if (newPointer.hasChild()) {
137: buildTP.append('?').append(pointer.getChild().getValue());
138: } else {
139:• if (requiresFilter()) {
140: buildTP.append(buildParam);
141: } else {
142: buildTP.append(SoqlUtils.soqlVariableToSparqlVariable(value));
143: }
144: }
145: buildTP.append(TRIPLE_END);
146: pointer = newPointer;
147: }
148: }
149: return buildTP.toString();
150: }
151:
152: private static String toIri(SoqlNode node) {
153: return IdentifierTransformer.stringifyIri(node.getIri());
154: }
155: }