getThreatRecommendation method

Future<List<Recommendation>> getThreatRecommendation({
  1. String language = "en",
  2. required String recommendationType,
})

get list of threat recommendation

@param option language as string @param recommendationType as string @return list of Recommendation object

Implementation

Future<List<Recommendation>> getThreatRecommendation(
    {String language: "en", required String recommendationType}) async {
  List<Recommendation> r = [];
  try {
    _node = await _storageController.get(":Global:recommendations");
    for (String recId in await _node!
        .getChildNodesCsv()
        .then((value) => value.split(","))) {
      Node recNode =
          await _storageController.get(":Global:recommendations:$recId");
      DescriptionShortLong descriptionShortLong = DescriptionShortLong(
          shortDescription: await recNode
              .getValue("short")
              .then((value) => value!.getValue(language)!),
          longDescription: await recNode
              .getValue("long")
              .then((value) => value!.getValue(language)!));

      if (await recNode.getValue("recommendationType") != null &&
          await recNode.getValue("relatedThreatsWeights") != null) {
        List<ThreatWeight> relatedThreatsWeight =
            ThreatWeight.convertFromJson(await recNode
                .getValue("relatedThreatsWeights")
                .then((value) => value!.getValue(language)!));
        String type = await recNode
            .getValue("recommendationType")
            .then((value) => value!.getValue(language)!);
        if (type == recommendationType) {
          r.add(Recommendation(
              recommendationId: recId,
              description: descriptionShortLong,
              relatedThreatsWeight: relatedThreatsWeight,
              recommendationType: type));
        }
      }
    }
    return r;
  } on StorageException {
    throw Exception("Node not Found");
  }
}