updateMetrics function

Future updateMetrics(
  1. dynamic type,
  2. dynamic node
)

Implementation

Future updateMetrics(var type,var node) async {

  print('>>>>>>updateMetrics');

  try {
    //var metricNode = await Storage.controller!.get(path.toString());
    var metricNode = node;
    var normalizationValue = await forUpdate(metricNode);
    var threatsImpactNode = await metricNode.getValue('threatsImpact');
    var threatsImpacts = threatsImpactNode!.getValue('en')!.split(';');


  for (var list in threatsImpacts) {
    var threatsImpact = list.split(',');

    var flagNode = await metricNode.getValue('flag');

  if (flagNode!.getValue('en') == '1') {
    Node impactNormal = NodeImpl(':upipn', '');
    await impactNormal
        .addOrUpdateValue(NodeValueImpl('impact', threatsImpact[1]));
    await impactNormal.addOrUpdateValue(
    NodeValueImpl('normal', normalizationValue.toString()));

  //type == types.Devices ? coreValues.devicePositive[threatsImpact[0]]!.add(impactNormal) : coreValues.userPositive[threatsImpact[0]]!.add(impactNormal);

        if (type == Types.devices) {
              try {
                CoreValues.devicePositive[threatsImpact[0]]!.add(impactNormal);
                //print(CoreValues.devicePositive);
              } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.devicePositive[threatsImpact[0]] = temp;
                //print(CoreValues.devicePositive);
              }
            } else {
              try {
                   CoreValues.userPositive[threatsImpact[0]]!.add(impactNormal);
                  //print(CoreValues.userPositive);
              } catch (e) {
                  var temp = <Node>[];
                  temp.add(impactNormal);
                  CoreValues.userPositive[threatsImpact[0]] = temp;

                //print(CoreValues.userPositive);
                }
            }
        } else {
            Node impactNormal = NodeImpl(':unipn', 'gg');
            await impactNormal
                .addOrUpdateValue(NodeValueImpl('impact', threatsImpact[1]));
            await impactNormal.addOrUpdateValue(
            NodeValueImpl('normal', normalizationValue.toString()));
            //   type == types.Devices ? coreValues.deviceNegative[threatsImpact[0]]!.add(impactNormal) : coreValues.userNegative[threatsImpact[0]]!.add(impactNormal);

            if (type == Types.devices) {
                  try {
                    CoreValues.deviceNegative[threatsImpact[0]]!.add(impactNormal);
                  //print(CoreValues.deviceNegative);
                  } catch (e) {
                  var temp = <Node>[];
                  temp.add(impactNormal);
                  CoreValues.deviceNegative[threatsImpact[0]] = temp;
                  //print(CoreValues.deviceNegative);
                  }
            } else {
                try {
                CoreValues.userNegative[threatsImpact[0]]!.add(impactNormal);
                //print(CoreValues.userNegative);
                } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.userNegative[threatsImpact[0]] = temp;
                //print(CoreValues.userNegative);
                }
            }
        }
  }

  }catch(e) {

    print(e);

  }

  print('>>>>>>updateMetrics>>>>>>>');

}