saveDeployment method
Save the deployment
persistently to a local cache.
Returns true
if successful.
Implementation
Future<bool> saveDeployment(SmartphoneDeployment deployment) async {
info("$runtimeType - Saving deployment to database.");
bool success = true;
try {
final Map<String, dynamic> map = {
STUDY_ID_COLUMN: deployment.studyId,
STUDY_DEPLOYMENT_ID_COLUMN: deployment.studyDeploymentId,
DEVICE_ROLE_NAME_COLUMN: deployment.deviceRoleName,
PARTICIPANT_ID_COLUMN: deployment.participantId,
PARTICIPANT_ROLE_NAME_COLUMN: deployment.participantRoleName,
DEPLOYMENT_STATUS_COLUMN: deployment.status.index,
UPDATED_AT_COLUMN: DateTime.now().toUtc().toIso8601String(),
DEPLOYED_AT_COLUMN: deployment.deployed?.toUtc().toIso8601String(),
DEPLOYMENT_COLUMN: jsonEncode(deployment),
};
await database?.insert(
DEPLOYMENT_TABLE_NAME,
map,
conflictAlgorithm: ConflictAlgorithm.replace,
);
} catch (exception) {
success = false;
warning('$runtimeType - Failed to save deployment - $exception');
}
return success;
}