Skip to content

Package: MetricPredicateImpl

MetricPredicateImpl

nameinstructionbranchcomplexitylinemethod
MetricPredicateImpl(String, Class, Comparable, Comparable)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getName()
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%
getType()
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%
setName(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setType(Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
toSerializedMap()
M: 50 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 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.service.datastore.internal.model.query.predicate;
14:
15: import com.fasterxml.jackson.databind.node.ObjectNode;
16: import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
17: import org.eclipse.kapua.service.datastore.internal.mediator.MessageField;
18: import org.eclipse.kapua.service.datastore.model.query.predicate.MetricPredicate;
19: import org.eclipse.kapua.service.storable.exception.MappingException;
20: import org.eclipse.kapua.service.storable.model.query.predicate.PredicateConstants;
21: import org.eclipse.kapua.service.storable.model.query.predicate.RangePredicateImpl;
22: import org.eclipse.kapua.service.storable.model.utils.MappingUtils;
23:
24: /**
25: * {@link MetricPredicate} implementation
26: *
27: * @since 1.0.0
28: */
29: public class MetricPredicateImpl extends RangePredicateImpl implements MetricPredicate {
30:
31: private String name;
32: private Class<?> type;
33:
34: public <V extends Comparable<V>> MetricPredicateImpl(String metricName, Class<V> type, V minValue, V maxValue) {
35: super(MessageField.METRICS, minValue, maxValue);
36:
37: setName(metricName);
38: setType(type);
39: }
40:
41: @Override
42: public String getName() {
43: return name;
44: }
45:
46: @Override
47: public void setName(String name) {
48: this.name = name;
49: }
50:
51: @Override
52: public Class<?> getType() {
53: return type;
54: }
55:
56: @Override
57: public void setType(Class<?> type) {
58: this.type = type;
59: }
60:
61: /**
62: * <pre>
63: * {
64: * "query": {
65: * "range" : {
66: * "metrics.temperature.int" : {
67: * "gte" : 10,
68: * "lte" : 20,
69: * }
70: * }
71: * }
72: * }
73: * </pre>
74: */
75: @Override
76: public ObjectNode toSerializedMap() throws MappingException {
77: ObjectNode valuesNode = MappingUtils.newObjectNode();
78:• if (getMaxValue() != null) {
79: MappingUtils.appendField(valuesNode, PredicateConstants.LTE_KEY, getMaxValue());
80: }
81:• if (getMinValue() != null) {
82: MappingUtils.appendField(valuesNode, PredicateConstants.GTE_KEY, getMinValue());
83: }
84:
85: ObjectNode termNode = MappingUtils.newObjectNode();
86: termNode.set(
87: getField().field()
88: .concat(".")
89: .concat(DatastoreUtils.normalizeMetricName(getName()))
90: .concat(".")
91: .concat(DatastoreUtils.getClientMetricFromAcronym(getType().getSimpleName().toLowerCase())),
92: valuesNode);
93:
94: ObjectNode rootNode = MappingUtils.newObjectNode();
95: rootNode.set(PredicateConstants.RANGE_KEY, termNode);
96: return rootNode;
97: }
98:
99: }