resolveRecommendation method
Resolve a recommendation
- Get the sensor node with
- Update the currentRecommendationId of the sensor node to be empty
- Create a recommendation status node
Implementation
Future<bool> resolveRecommendation(
String rootType, String sensorId, String geigerValue) async {
String recommendationStatusPath = '$recommendationStatusRootPath:$sensorId';
String? currentRecommendationId = await _readValueNode(
recommendationStatusPath, 'currentRecommendationId');
if (currentRecommendationId == null || currentRecommendationId.isEmpty) {
log('Cannot find the recommendation for the sensor data: $sensorId');
return false;
}
log('Before adding a recommendation status node $currentRecommendationId');
try {
Node node =
NodeImpl(currentRecommendationId, pluginId, deviceSensorDataRootPath);
await node.addOrUpdateValue(
NodeValueImpl(
'name', 'Recommendation status of $currentRecommendationId'),
);
await addMultilingualValues(node, 'description', [
MultilingualValues(
language: "en",
value:
"Reflects the status of the recommendation with the indicated ID. geigerValue 0=resolved, 1=active")
]);
await node.addOrUpdateValue(
NodeValueImpl('minValue', '0'),
);
await node.addOrUpdateValue(
NodeValueImpl('maxValue', '1'),
);
await node.addOrUpdateValue(
NodeValueImpl('valueType', 'int'),
);
await node.addOrUpdateValue(
NodeValueImpl('flag', '0'),
);
await node.addOrUpdateValue(
NodeValueImpl('urgency', 'low'),
);
await node.addOrUpdateValue(
NodeValueImpl('threatsImpact', ''),
);
await node.addOrUpdateValue(
NodeValueImpl('geigerValue', geigerValue),
);
await node.addOrUpdateValue(
NodeValueImpl('recommendationId', currentRecommendationId),
);
log('A recommendation status node has been created');
log(node.toString());
try {
log('Going to add a recommendation status node $currentRecommendationId');
await storageController!.addOrUpdate(node);
log('After adding a recommendation status node $currentRecommendationId');
log('Going to update the sensor node');
try {
await sendDataNode(
sensorId,
recommendationStatusRootPath!,
['currentRecommendationId'],
[''],
);
return true;
} catch (e3) {
log('Failed to update the sensor node');
log(
e3.toString(),
);
return false;
}
} catch (e2, trace2) {
log('Failed to update Storage');
log(e2.toString());
if (exceptionHandler != null) {
exceptionHandler!(e2, trace2);
}
return false;
}
} catch (e, trace) {
log('Failed to add a recommendation status node $currentRecommendationId');
log(e.toString());
if (exceptionHandler != null) {
exceptionHandler!(e, trace);
}
return false;
}
}