Package: JsonMessageQuery
JsonMessageQuery
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
JsonMessageQuery() |
|
|
|
|
|
||||||||||||||||||||
JsonMessageQuery(KapuaId) |
|
|
|
|
|
||||||||||||||||||||
addFetchAttributes(String) |
|
|
|
|
|
||||||||||||||||||||
getExcludes(StorableFetchStyle) |
|
|
|
|
|
||||||||||||||||||||
getFetchAttributes() |
|
|
|
|
|
||||||||||||||||||||
getFetchStyle() |
|
|
|
|
|
||||||||||||||||||||
getFields() |
|
|
|
|
|
||||||||||||||||||||
getIncludes(StorableFetchStyle) |
|
|
|
|
|
||||||||||||||||||||
getLimit() |
|
|
|
|
|
||||||||||||||||||||
getOffset() |
|
|
|
|
|
||||||||||||||||||||
getPredicate() |
|
|
|
|
|
||||||||||||||||||||
getScopeId() |
|
|
|
|
|
||||||||||||||||||||
getSortFields() |
|
|
|
|
|
||||||||||||||||||||
isAskTotalCount() |
|
|
|
|
|
||||||||||||||||||||
setAskTotalCount(boolean) |
|
|
|
|
|
||||||||||||||||||||
setFetchAttributes(List) |
|
|
|
|
|
||||||||||||||||||||
setFetchStyle(StorableFetchStyle) |
|
|
|
|
|
||||||||||||||||||||
setLimit(Integer) |
|
|
|
|
|
||||||||||||||||||||
setOffset(Integer) |
|
|
|
|
|
||||||||||||||||||||
setPredicate(StorablePredicate) |
|
|
|
|
|
||||||||||||||||||||
setScopeId(KapuaId) |
|
|
|
|
|
||||||||||||||||||||
setSortFields(List) |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.app.api.core.model.data;
14:
15: import org.eclipse.kapua.commons.model.id.KapuaEid;
16: import org.eclipse.kapua.model.id.KapuaId;
17: import org.eclipse.kapua.model.id.KapuaIdAdapter;
18: import org.eclipse.kapua.service.datastore.internal.mediator.MessageField;
19: import org.eclipse.kapua.service.datastore.internal.schema.MessageSchema;
20: import org.eclipse.kapua.service.storable.model.query.StorableFetchStyle;
21: import org.eclipse.kapua.service.storable.model.query.XmlAdaptedSortField;
22: import org.eclipse.kapua.service.storable.model.query.predicate.StorablePredicate;
23:
24: import javax.xml.bind.annotation.XmlAccessType;
25: import javax.xml.bind.annotation.XmlAccessorType;
26: import javax.xml.bind.annotation.XmlElement;
27: import javax.xml.bind.annotation.XmlElementWrapper;
28: import javax.xml.bind.annotation.XmlRootElement;
29: import javax.xml.bind.annotation.XmlTransient;
30: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31: import java.util.ArrayList;
32: import java.util.List;
33:
34: /**
35: * Message query implementation
36: *
37: * @since 1.0.0
38: */
39: @XmlRootElement(name = "query")
40: @XmlAccessorType(XmlAccessType.PROPERTY)
41: public class JsonMessageQuery {
42:
43: private StorablePredicate predicate;
44:
45: private KapuaId scopeId;
46: private Integer limit;
47: private Integer indexOffset;
48: private boolean askTotalCount;
49: private List<XmlAdaptedSortField> sortFields;
50: private StorableFetchStyle fetchStyle;
51: private List<String> fetchAttributes;
52:
53: /**
54: * Default constructor
55: *
56: * @since 1.0.0
57: */
58: public JsonMessageQuery() {
59: super();
60:
61: fetchStyle = StorableFetchStyle.SOURCE_FULL;
62: fetchAttributes = new ArrayList<>();
63: askTotalCount = false;
64: }
65:
66: /**
67: * Constructor.
68: *
69: * @param scopeId The scopeId of the query
70: * @since 1.0.0
71: */
72: public JsonMessageQuery(KapuaId scopeId) {
73: this();
74:
75: setScopeId(scopeId);
76: }
77:
78: @XmlElement(name = "scopeId")
79: @XmlJavaTypeAdapter(KapuaIdAdapter.class)
80: public KapuaId getScopeId() {
81: return scopeId;
82: }
83:
84: public void setScopeId(KapuaId scopeId) {
85: this.scopeId = KapuaEid.parseKapuaId(scopeId);
86: }
87:
88: @XmlTransient
89: public StorablePredicate getPredicate() {
90: return this.predicate;
91: }
92:
93: public void setPredicate(StorablePredicate predicate) {
94: this.predicate = predicate;
95: }
96:
97: @XmlElement(name = "offset")
98: public Integer getOffset() {
99: return indexOffset;
100: }
101:
102: public void setOffset(Integer offset) {
103: this.indexOffset = offset;
104: }
105:
106: @XmlElement(name = "limit")
107: public void setLimit(Integer limit) {
108: this.limit = limit;
109: }
110:
111: public Integer getLimit() {
112: return limit;
113: }
114:
115: @XmlElement(name = "askTotalCount")
116: public boolean isAskTotalCount() {
117: return askTotalCount;
118: }
119:
120: public void setAskTotalCount(boolean askTotalCount) {
121: this.askTotalCount = askTotalCount;
122: }
123:
124: @XmlTransient
125: public StorableFetchStyle getFetchStyle() {
126: return this.fetchStyle;
127: }
128:
129: public void setFetchStyle(StorableFetchStyle fetchStyle) {
130: this.fetchStyle = fetchStyle;
131: }
132:
133: @XmlElementWrapper(name = "fetchAttributeName")
134: @XmlElement(name = "fetchAttributeName")
135: public List<String> getFetchAttributes() {
136: return fetchAttributes;
137: }
138:
139: public void addFetchAttributes(String fetchAttribute) {
140: fetchAttributes.add(fetchAttribute);
141: }
142:
143: public void setFetchAttributes(List<String> fetchAttributeNames) {
144: fetchAttributes = fetchAttributeNames;
145: }
146:
147: @XmlElementWrapper(name = "sortFields")
148: @XmlElement(name = "sortField")
149: public List<XmlAdaptedSortField> getSortFields() {
150: return sortFields;
151: }
152:
153: public void setSortFields(List<XmlAdaptedSortField> sortFields) {
154: this.sortFields = sortFields;
155: }
156:
157: @XmlTransient
158: public String[] getIncludes(StorableFetchStyle fetchStyle) {
159: // Fetch mode
160: String[] includeSource = null;
161:• switch (fetchStyle) {
162: case FIELDS:
163: includeSource = getFields();
164: break;
165: case SOURCE_SELECT:
166: includeSource = new String[]{MessageSchema.MESSAGE_CAPTURED_ON, MessageSchema.MESSAGE_POSITION + ".*", MessageSchema.MESSAGE_METRICS + ".*"};
167: break;
168: case SOURCE_FULL:
169: includeSource = new String[]{"*"};
170: }
171: return includeSource;
172: }
173:
174: @XmlTransient
175: public String[] getExcludes(StorableFetchStyle fetchStyle) {
176: // Fetch mode
177: String[] excludeSource = null;
178:• switch (fetchStyle) {
179: case FIELDS:
180: excludeSource = new String[]{""};
181: break;
182: case SOURCE_SELECT:
183: excludeSource = new String[]{MessageSchema.MESSAGE_BODY};
184: break;
185: case SOURCE_FULL:
186: excludeSource = new String[]{""};
187: }
188: return excludeSource;
189: }
190:
191: @XmlTransient
192: public String[] getFields() {
193: return new String[]{
194: MessageField.MESSAGE_ID.field(),
195: MessageField.SCOPE_ID.field(),
196: MessageField.DEVICE_ID.field(),
197: MessageField.CLIENT_ID.field(),
198: MessageField.CHANNEL.field(),
199: MessageField.TIMESTAMP.field()};
200: }
201:
202: }