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: 49 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, 2020 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.service.datastore.internal.model.query.predicate;
13:
14: import com.fasterxml.jackson.databind.node.ObjectNode;
15: import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
16: import org.eclipse.kapua.service.datastore.internal.mediator.MessageField;
17: import org.eclipse.kapua.service.datastore.model.query.predicate.MetricPredicate;
18: import org.eclipse.kapua.service.storable.exception.MappingException;
19: import org.eclipse.kapua.service.storable.model.query.predicate.PredicateConstants;
20: import org.eclipse.kapua.service.storable.model.query.predicate.RangePredicateImpl;
21: import org.eclipse.kapua.service.storable.model.utils.MappingUtils;
22:
23: /**
24: * {@link MetricPredicate} implementation
25: *
26: * @since 1.0.0
27: */
28: public class MetricPredicateImpl extends RangePredicateImpl implements MetricPredicate {
29:
30: private String name;
31: private Class<?> type;
32:
33: public <V extends Comparable<V>> MetricPredicateImpl(String metricName, Class<V> type, V minValue, V maxValue) {
34: super(MessageField.METRICS, minValue, maxValue);
35:
36: setName(metricName);
37: setType(type);
38: }
39:
40: @Override
41: public String getName() {
42: return name;
43: }
44:
45: @Override
46: public void setName(String name) {
47: this.name = name;
48: }
49:
50: @Override
51: public Class<?> getType() {
52: return type;
53: }
54:
55: @Override
56: public void setType(Class<?> type) {
57: this.type = type;
58: }
59:
60: /**
61: * <pre>
62: * {
63: * "query": {
64: * "range" : {
65: * "metrics.temperature.int" : {
66: * "gte" : 10,
67: * "lte" : 20,
68: * }
69: * }
70: * }
71: * }
72: * </pre>
73: */
74: @Override
75: public ObjectNode toSerializedMap() throws MappingException {
76: ObjectNode valuesNode = MappingUtils.newObjectNode();
77:• if (getMaxValue() != null) {
78: MappingUtils.appendField(valuesNode, PredicateConstants.LTE_KEY, getMaxValue());
79: }
80:• if (getMinValue() != null) {
81: MappingUtils.appendField(valuesNode, PredicateConstants.GTE_KEY, getMinValue());
82: }
83:
84: ObjectNode termNode = MappingUtils.newObjectNode();
85: termNode.set(
86: getField().field()
87: .concat(".")
88: .concat(getName())
89: .concat(".")
90: .concat(DatastoreUtils.getClientMetricFromAcronym(getType().getSimpleName().toLowerCase())),
91: valuesNode);
92:
93: ObjectNode rootNode = MappingUtils.newObjectNode();
94: rootNode.set(PredicateConstants.RANGE_KEY, termNode);
95: return rootNode;
96: }
97:
98: }