public IHttpActionResult PutDefault([FromUri] Guid id = default(Guid)) { if (!ModelState.IsValid) { return(this.Error().InvalidParameters("Invalid scenario parameters")); } if (id != Guid.Empty) { // Check that scenario exists var scenario = _scenarioRepository.Get(id); if (scenario == null) { return(NotFound()); } // Check that scenario isn't referenced by a run var run = _runRepository.FindByScenarioId(id); if (run != null) { return(this.Error().InvalidParameters("Scenario cannot be the default because it is used by a run")); } } TenantSettings tenantSettings = _tenantSettingsRepository.Get(); tenantSettings.DefaultScenarioId = id; _tenantSettingsRepository.AddOrUpdate(tenantSettings); return(Ok()); }
public LandmarkRunTriggerModelValidation(IRunRepository runRepository) { RuleFor(c => c.ScenarioId).NotEmpty().WithMessage("Scenario id missing"); RuleFor(c => c).Custom((command, context) => { var run = runRepository.FindByScenarioId(command.ScenarioId); var scenario = run?.Scenarios.Find(s => s.Id == command.ScenarioId); if (run is null || scenario is null) { context.AddFailure($"Run for scenario {command.ScenarioId} was not found"); return; } if (!run.IsCompleted) { context.AddFailure("Run is not completed yet"); } if (!run.IsOptimiserNeeded) { context.AddFailure("Run has no optimizations enabled"); } }); }
protected override string DownloadScenarioInputFiles(Guid scenarioId, string localFolder, string localInputFolder) { var run = _runRepository.FindByScenarioId(scenarioId); if (run is null) { throw new Exception($"Run for scenario: {scenarioId.ToString()} was not found"); } return(_inputFilesGenerator.PopulateScenarioData(run, scenarioId)); }
public IHttpActionResult Get(Guid scenarioId) { var scenarioResult = _scenarioResultRepository.Find(scenarioId); if (scenarioResult == null) { return(NotFound()); } var scenarioResultModel = _mapper.Map <ScenarioResultModel>(scenarioResult); // Add failures. This is a temporary solution until the frontend is // changed. Originally then failures were stored in the ScenarioResult document. // TODO: Remove Failures property from ScenarioResultModel when frontend has been changed. var failures = _failuresRepository.Get(scenarioId); if (failures != null) { var failuresList = GetFailureModels(failures.Items); failuresList.ForEach(item => scenarioResultModel.Failures.Add(item)); } Run run = _runRepository.FindByScenarioId(scenarioId); scenarioResultModel.Run = new RunReference() { Id = run.Id, Description = run.Description }; return(Ok(scenarioResultModel)); }
/// <inheritdoc /> public async Task <LandmarkTriggerRunResult> TriggerRunAsync(LandmarkRunTriggerModel command, ScheduledRunSettingsModel scheduledRunSettings = null) { if (command is null) { throw new ArgumentNullException(nameof(command)); } RaiseInfo($"Starting Landmark run trigger process for ScenarioId: {command.ScenarioId}"); var run = command.ScenarioId != Guid.Empty ? _runRepository.FindByScenarioId(command.ScenarioId) : default; if (run is null) { throw new InvalidOperationException($"Run for scenario {command.ScenarioId} was not found"); } var scenario = run.Scenarios.SingleOrDefault(s => s.Id == command.ScenarioId); if (scenario is null) { throw new InvalidOperationException($"Scenario {command.ScenarioId} was not found"); } try { var request = new LandmarkBookingRequest { InputFiles = _landmarkAutoBookPayloadProvider.GetFiles(run.Id, command.ScenarioId).ToList() }; var autoBookTriggerResult = await _landmarkApi.TriggerRunAsync(request, scheduledRunSettings).ConfigureAwait(false); scenario.ExternalRunInfo = new ExternalRunInfo { ExternalRunId = autoBookTriggerResult.ProcessingId, ExternalStatus = scheduledRunSettings is null ? ExternalScenarioStatus.Accepted : ExternalScenarioStatus.Scheduled, ExternalStatusModifiedDate = _clock.GetCurrentInstant().ToDateTimeUtc(), QueueName = scheduledRunSettings?.QueueName, Priority = scheduledRunSettings?.Priority, ScheduledDateTime = scheduledRunSettings?.DateTime, Comment = scheduledRunSettings?.Comment, CreatorId = scheduledRunSettings?.CreatorId, CreatedDateTime = _clock.GetCurrentInstant().ToDateTimeUtc() }; _runRepository.Update(run); _runRepository.SaveChanges(); RaiseInfo($"Landmark run triggered for Run: {run.Id} and Scenario: {command.ScenarioId}. Processing id: {autoBookTriggerResult.ProcessingId}"); return(new LandmarkTriggerRunResult { RunId = run.Id, ExternalRunId = autoBookTriggerResult.ProcessingId, Status = scheduledRunSettings is null ? ExternalScenarioStatus.Accepted : ExternalScenarioStatus.Scheduled }); }