tryDeployment method

  1. @override
Future<StudyStatus> tryDeployment({
  1. bool useCached = true,
})
override

Verifies whether the primary device is ready for deployment and in case it is, deploy the study previously added.

If useCached is true (default), a previously cached deployment will be retrieved from the phone locally. If useCached is false, the deployment will be retrieved from the deploymentService, based on the study.

In case already deployed, nothing happens and the current status is returned.

Implementation

@override
Future<StudyStatus> tryDeployment({bool useCached = true}) async {
  assert(
      study != null,
      'Cannot deploy without a valid study deployment id and device role name. '
      "Call 'addStudy()' or 'addStudyProtocol()' first.");

  info('$runtimeType - Trying to deploy study: $study');
  if (useCached) {
    // restore the deployment and app task queue
    bool success = await restoreDeployment();
    if (success) {
      await AppTaskController().restoreQueue();
      return status = deployment?.status ?? StudyStatus.Deployed;
    }
  }

  // if no cache, get the deployment from the deployment service
  // and save a local cache
  status = await super.tryDeployment();
  if (status == StudyStatus.Deployed && deployment != null) {
    deployment!.studyId = study?.studyId;
    deployment!.participantId = study?.participantId;
    deployment!.participantRoleName = study?.participantRoleName;
    deployment?.status = status;
    deployment!.deployed = DateTime.now().toUtc();

    // create local folder structure and store local deployment
    Settings().getCacheBasePath(deployment!.studyDeploymentId);
    saveDeployment();
  }

  return status;
}