-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MetricPredicate and add MetricExistsPredicate
Signed-off-by: Claudio Mezzasalma <claudio.mezzasalma@eurotech.com>
- Loading branch information
Showing
7 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../src/main/java/org/eclipse/kapua/service/datastore/model/query/MetricExistsPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.service.datastore.model.query; | ||
|
||
/** | ||
* Query predicate for matching messages with existing metrics | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
public interface MetricExistsPredicate extends ExistsPredicate { | ||
|
||
/** | ||
* Gets the metric type to search. | ||
* This is required because metric with the same name can have different types. | ||
* | ||
* @return The metric type | ||
* @since 1.2.0 | ||
*/ | ||
Class<?> getType(); | ||
|
||
/** | ||
* Sets the metric type so search. | ||
* | ||
* @param type The metric type to search. | ||
* @since 1.2.0 | ||
*/ | ||
void setType(Class<?> type); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...a/org/eclipse/kapua/service/datastore/internal/model/query/MetricExistsPredicateImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.service.datastore.internal.model.query; | ||
|
||
import org.eclipse.kapua.service.datastore.client.DatamodelMappingException; | ||
import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils; | ||
import org.eclipse.kapua.service.datastore.internal.schema.KeyValueEntry; | ||
import org.eclipse.kapua.service.datastore.internal.schema.SchemaUtil; | ||
import org.eclipse.kapua.service.datastore.model.query.MetricExistsPredicate; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
/** | ||
* Implementation of query predicate for checking if a field exists | ||
* | ||
* @since 1.2.0 | ||
* | ||
*/ | ||
public class MetricExistsPredicateImpl extends ExistsPredicateImpl implements MetricExistsPredicate { | ||
|
||
private Class<?> type; | ||
|
||
public <V extends Comparable<V>> MetricExistsPredicateImpl(String fieldName, Class<V> type) { | ||
super(fieldName); | ||
|
||
this.type = type; | ||
} | ||
|
||
@Override | ||
public Class<?> getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public void setType(Class<?> type) { | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
/** | ||
* <pre> | ||
* { | ||
* "query": { | ||
* "exists" : { "field" : "metrics.metric.typ" } | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public ObjectNode toSerializedMap() throws DatamodelMappingException { | ||
ObjectNode rootNode = SchemaUtil.getObjectNode(); | ||
String fieldName = type == null ? String.format("metrics.%s", name) : String.format("metrics.%s.%s", name, DatastoreUtils.getClientMetricFromAcronym(type.getSimpleName().toLowerCase())); | ||
ObjectNode termNode = SchemaUtil.getField(new KeyValueEntry[] { new KeyValueEntry(PredicateConstants.FIELD_KEY, fieldName) }); | ||
rootNode.set(PredicateConstants.EXISTS_KEY, termNode); | ||
return rootNode; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters