getExistMetrics function
Get exist metrics from Local Data Storage
key => global threat UUID unique (12)
value => metric Map List
metric Map List => {metric, normalization},....
Implementation
Future getExistMetrics(var type) async {
logger.d('getValuePath => ${Storage.getValuePath}');
try{
for (var path in Storage.getValuePath) {
Node metricNode = await Storage.controller.get(path);
var childrenNodes = await metricNode.getChildren();
var metricNodeIterator = childrenNodes.entries.iterator;
///loop exist metrics data based path
while (metricNodeIterator.moveNext()) {
///Normalization for metrics
var normalizationValue = await forUpdateNormalization(metricNodeIterator.current.value);
///get threats related this metrics
var threatsImpactNode = await metricNodeIterator.current.value.getValue('threatsImpact');
var threatsMetricList = threatsImpactNode!.getValue('en')!.split(';');
///{threat UUID,metric;....}
for (var metrics in threatsMetricList) {
///metric[0] => threat UUID
///metric[1] => high, medium, low
var metric = metrics.split(',');
///A Flag describes Positive or Negative
///To indicate if the higher is the sensor value is the better or not
///value the higher is positive, lower is negative
var flagNode = await metricNodeIterator.current.value.getValue('flag');
if (flagNode!.getValue('en') == '1') {
// Node impactNormal = NodeImpl(':pimn', 'gg');
// await impactNormal.addOrUpdateValue(NodeValueImpl('impact', metric[1]));
// await impactNormal.addOrUpdateValue(NodeValueImpl('normal', normalizationValue.toString()));
var metricMap ={};
metricMap['metric'] = metric[1];
metricMap['normalization'] = normalizationValue.toString();
if (type == Types.devices) {
try {
if(metric[0].isNotEmpty) CoreValues.devicePositive[metric[0]]!.add(metricMap);
} catch (e) {
var temp = <Map>[];
temp.add(metricMap);
CoreValues.devicePositive[metric[0]] = temp;
//print(CoreValues.devicePositive);
}
} else {
try {
if(metric[0].isNotEmpty) CoreValues.userPositive[metric[0]]!.add(metricMap);
//CoreValues.userPositive[threatsImpact[0]]!.add(impactNormal);
//print(CoreValues.userPositive);
} catch (e) {
var temp = <Map>[];
temp.add(metricMap);
CoreValues.userPositive[metric[0]] = temp;
//print(CoreValues.userPositive);
}
}
} else {
// Node impactNormal = NodeImpl(':nimpn', 'gg');
// await impactNormal.addOrUpdateValue(NodeValueImpl('impact', threatsImpact[1]));
// await impactNormal.addOrUpdateValue(NodeValueImpl('normal', normalizationValue.toString()));
var metricMap ={};
metricMap['metric'] = metric[1];
metricMap['normalization'] = normalizationValue.toString();
if (type == Types.devices) {
try {
if(metric[0].isNotEmpty) CoreValues.deviceNegative[metric[0]]!.add(metricMap);
//print(CoreValues.deviceNegative);
} catch (e) {
var temp = <Map>[];
temp.add(metricMap);
CoreValues.deviceNegative[metric[0]] = temp;
//print(CoreValues.deviceNegative);
}
} else {
try {
if(metric[0].isNotEmpty) CoreValues.userNegative[metric[0]]!.add(metricMap);
//CoreValues.userNegative[threatsImpact[0]]!.add(impactNormal);
//print(CoreValues.userNegative);
} catch (e) {
var temp = <Map>[];
temp.add(metricMap);
CoreValues.userNegative[metric[0]] = temp;
//print(CoreValues.userNegative);
}
}
}
}
}
}
} on StorageException {
logger.e('does not exist metric data');
}
catch (e) {
logger.e(e);
//continue;
}
}