import org.apache.commons.lang3.tuple.Pair;\r
import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClient;\r
import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;\r
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;\r
import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;\r
import org.openecomp.dcae.apod.analytics.common.service.processor.AbstractMessageProcessor;\r
import org.openecomp.dcae.apod.analytics.common.service.processor.GenericMessageChainProcessor;\r
import org.slf4j.LoggerFactory;\r
\r
import java.io.IOException;\r
+import java.math.BigDecimal;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.Comparator;\r
* @param jsonFieldPaths Json Field Paths\r
* @return Map containing key as json path and values as values associated with that json path\r
*/\r
- public static Map<String, List<Long>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>\r
+ public static Map<String, List<BigDecimal>> getJsonPathValue(@Nonnull String message, @Nonnull Set<String>\r
jsonFieldPaths) {\r
\r
- final Map<String, List<Long>> jsonFieldPathMap = new HashMap<>();\r
+ final Map<String, List<BigDecimal>> jsonFieldPathMap = new HashMap<>();\r
final DocumentContext documentContext = JsonPath.parse(message);\r
\r
for (String jsonFieldPath : jsonFieldPaths) {\r
- final List<Long> jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<Long>>() {\r
- });\r
+ List<BigDecimal> jsonFieldValues = null;\r
+\r
+ try {\r
+ jsonFieldValues = documentContext.read(jsonFieldPath, new TypeRef<List<BigDecimal>>() {\r
+ });\r
+ } catch (Exception e) {\r
+ final String errorMessage = String.format(\r
+ "Unable to convert jsonFieldPath: %s value to valid number. " +\r
+ "Json Path value is not in a valid number format. Incoming message: %s",\r
+ jsonFieldPath, message);\r
+ throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e);\r
+ }\r
// If Json Field Values are not or empty\r
if (jsonFieldValues != null && !jsonFieldValues.isEmpty()) {\r
// Filter out all null values in the filed values list\r
- final List<Long> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,\r
- Predicates.<Long>notNull()));\r
+ final List<BigDecimal> nonNullValues = Lists.newLinkedList(Iterables.filter(jsonFieldValues,\r
+ Predicates.<BigDecimal>notNull()));\r
// If there are non null values put them in the map\r
if (!nonNullValues.isEmpty()) {\r
jsonFieldPathMap.put(jsonFieldPath, nonNullValues);\r
* @param fieldThresholds Policy Thresholds for Field Path\r
* @return Optional of violated threshold for a field path\r
*/\r
- public static Optional<Threshold> thresholdCalculator(final List<Long> messageFieldValues, final List<Threshold>\r
+ public static Optional<Threshold> thresholdCalculator(final List<BigDecimal> messageFieldValues, final\r
+ List<Threshold>\r
fieldThresholds) {\r
// order thresholds by severity\r
Collections.sort(fieldThresholds, THRESHOLD_COMPARATOR);\r
// Now apply each threshold to field values\r
for (Threshold fieldThreshold : fieldThresholds) {\r
- for (Long messageFieldValue : messageFieldValues) {\r
+ for (BigDecimal messageFieldValue : messageFieldValues) {\r
final Boolean isThresholdViolated =\r
- fieldThreshold.getDirection().operate(messageFieldValue, fieldThreshold.getThresholdValue());\r
+ fieldThreshold.getDirection().operate(messageFieldValue, new BigDecimal(fieldThreshold\r
+ .getThresholdValue()));\r
if (isThresholdViolated) {\r
final Threshold violatedThreshold = Threshold.copy(fieldThreshold);\r
violatedThreshold.setActualFieldValue(messageFieldValue);\r