/// <summary> /// Tests if there is overlapping data in Raptor /// </summary> protected async Task <(bool isValidFilterForProjectExtents, FilterResult filterResult)> ValidateFilterAgainstProjectExtents(Guid projectUid, Guid?filterUid) { if (!filterUid.HasValue) { return(true, null); } try { var filterTask = GetCompactionFilter(projectUid, filterUid, filterMustExist: true); var projectId = GetLegacyProjectId(projectUid); await Task.WhenAll(filterTask, projectId); var projectExtents = await ProjectStatisticsHelper.GetProjectStatisticsWithProjectSsExclusions(projectUid, projectId.Result, GetUserId(), CustomHeaders); //No data in Raptor - stop if (projectExtents == null) { return(false, null); } var filter = await filterTask; //No filter dates defined - project extents requested. Proceed further if (filter.StartUtc == null && filter.EndUtc == null) { return(true, filter); } //Do we have intersecting dates? True if yes if (filter.StartUtc != null && filter.EndUtc != null) { return(true, filter); } //Handle 'as-at' dates where StartUTC is null but EndUTC is not null if (filter.StartUtc == null && filter.EndUtc != null) { return(true, filter); } //All other cases - proceed further return(true, filter); } catch { //Some exception - do not proceed further return(false, null); } }
/// <summary> /// Validates new edit is within production data date range for the project /// </summary> private async Task ValidateDates(Guid projectUid, ProductionDataEdit dataEdit) { var projectExtents = await ProjectStatisticsHelper.GetProjectStatisticsWithProjectSsExclusions(projectUid, VelociraptorConstants.NO_PROJECT_ID, GetUserId(), CustomHeaders); if (projectExtents == null) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Cannot obtain ProjectStatistics.")); } if (dataEdit.startUTC < projectExtents.startTime || dataEdit.endUTC > projectExtents.endTime) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, $"Data edit outside production data date range: {projectExtents.startTime}-{projectExtents.endTime}")); } }
public async Task <ProjectStatisticsResult> GetProjectStatistics( [FromQuery] Guid projectUid) { Log.LogInformation($"{nameof(GetProjectStatistics)}: {Request.QueryString}"); try { var projectId = await GetLegacyProjectId(projectUid); var result = await ProjectStatisticsHelper.GetProjectStatisticsWithProjectSsExclusions(projectUid, projectId, GetUserId(), CustomHeaders); Log.LogInformation($"{nameof(GetProjectStatistics)}: result: {JsonConvert.SerializeObject(result)}"); return(result); } catch (ServiceException se) { Log.LogError(se, $"{nameof(GetProjectStatistics)}: exception"); throw; } finally { Log.LogInformation($"{nameof(GetProjectStatistics)}: returned: {Response.StatusCode}"); } }