public void ProjectIDsRequest_Invalid(int projectId, string projectUid, string errorMessage) { var request = new ProjectIDs(projectId, Guid.Parse(projectUid)); var ex = Assert.ThrowsException <ServiceException>(() => request.Validate()); Assert.IsNotNull(ex, "should be exception"); Assert.AreEqual(HttpStatusCode.BadRequest, ex.Code, "Invalid HttpStatusCode."); Assert.AreEqual(ContractExecutionStatesEnum.ValidationError, ex.GetResult.Code, "Invalid executionState."); Assert.AreEqual(errorMessage, ex.GetResult.Message, "Invalid error message."); }
public async Task <MachineLayerIdsExecutionResult> GetMachineLiftsByDateRange([FromRoute] Guid projectUid, [FromQuery] string startUtc = null, [FromQuery] string endUtc = null) { _log.LogInformation($"{nameof(GetMachineLiftsByDateRange)} Request. projectUid: {projectUid} startUtc: {startUtc} endUtc: {endUtc}"); var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid); projectIds.Validate(); var response = await GetMachineLiftsWith(projectIds, startUtc, endUtc); _log.LogDebug($"{nameof(GetMachineLiftsByDateRange)} Response: {JsonConvert.SerializeObject(response)}"); return(response); }
protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { try { var request = CastRequestObjectTo <GetEditDataRequest>(item); #if RAPTOR if (UseTRexGateway("ENABLE_TREX_GATEWAY_EDIT_DATA")) { #endif var projectIds = new ProjectIDs(request.ProjectId.Value, request.ProjectUid.Value); projectIds.Validate(); var assetUid = await GetAssetUid(projectIds, request.assetId); var parameters = new Dictionary <string, string> { { "projectUid", request.ProjectUid.Value.ToString() } } ; if (assetUid.HasValue) { parameters.Add("assetUid", assetUid.ToString()); } var queryParams = $"?{new System.Net.Http.FormUrlEncodedContent(parameters).ReadAsStringAsync().Result}"; var results = await trexCompactionDataProxy.SendDataGetRequest <TRexEditDataResult>(request.ProjectUid.Value.ToString(), $"/productiondataedit{queryParams}", customHeaders); var assetMatches = await GetAssetIds(projectIds, results.DataEdits.Select(d => d.AssetUid).ToList()); var convertedResults = from d in results.DataEdits select ProductionDataEdit.CreateProductionDataEdit(assetMatches[d.AssetUid], d.StartUtc, d.EndUtc, d.MachineDesignName, d.LiftNumber); return(EditDataResult.CreateEditDataResult(convertedResults.ToList())); #if RAPTOR } return(ProcessWithRaptor(request)); #endif } finally { ContractExecutionStates.ClearDynamic(); } }
public async Task <MachineExecutionResult> GetMachinesOnProjectTbc([FromRoute] long projectId) { _log.LogInformation($"{nameof(GetMachinesOnProjectTbc)} Request. projectId: {projectId}"); var projectIds = new ProjectIDs(projectId, await((RaptorPrincipal)User).GetProjectUid(projectId)); projectIds.Validate(); var response = await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(_logger, #if RAPTOR _raptorClient, #endif configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy, customHeaders : CustomHeaders, customerUid : CustomerUid, userId : UserId, fileImportProxy : FileImportProxy) .ProcessAsync(projectIds) as MachineExecutionResult; _log.LogInformation($"{nameof(GetMachinesOnProjectTbc)} Response: {JsonConvert.SerializeObject(response)}"); return(response); }
protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { try { var request = CastRequestObjectTo <EditDataRequest>(item); //Note: request.dataEdit should only be null for a global undo. This is checked in request model validation //so the following should never happen. But just in case... if (request.dataEdit == null && !request.undo) { return(new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, "No data edit to perform")); } #if RAPTOR if (UseTRexGateway("ENABLE_TREX_GATEWAY_EDIT_DATA")) { #endif var projectIds = new ProjectIDs(request.ProjectId.Value, request.ProjectUid.Value); projectIds.Validate(); var assetUid = await GetAssetUid(projectIds, request.dataEdit.assetId); var trexRequest = new TRexEditData(assetUid ?? Guid.Empty, request.dataEdit.startUTC, request.dataEdit.endUTC, request.dataEdit.onMachineDesignName, request.dataEdit.liftNumber); var trexResult = await trexCompactionDataProxy.SendDataDeleteRequest <ContractExecutionResult, TRexEditData>(trexRequest, "/productiondataedit", customHeaders, true); if (trexResult.Code != ContractExecutionStatesEnum.ExecutedSuccessfully) { throw new ServiceException(HttpStatusCode.BadRequest, trexResult); } return(trexResult); #if RAPTOR } return(ProcessWithRaptor(request)); #endif } finally { ContractExecutionStates.ClearDynamic(); } }
public async Task <ContractExecutionResult> GetMachineOnProject([FromRoute] Guid projectUid, [FromRoute] Guid machineUid) { _log.LogInformation($"{nameof(GetMachineOnProject)} Request. projectUid: {projectUid} machineUid: {machineUid}"); var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid); projectIds.Validate(); var response = await RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(_logger, #if RAPTOR _raptorClient, #endif configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy, customHeaders : CustomHeaders, customerUid : CustomerUid, userId : UserId, fileImportProxy : FileImportProxy) .ProcessAsync(projectIds) as MachineExecutionResult; _log.LogInformation($"{nameof(GetMachineOnProject)} Response: machineUidFilter {machineUid} responsePreFilter {JsonConvert.SerializeObject(response)}"); response?.FilterByMachineUid(machineUid); return(response); }
public async Task <MachineDesignsResult> GetMachineDesigns([FromRoute] Guid projectUid) { _log.LogInformation($"{nameof(GetMachineDesigns)} Request. projectUid: {projectUid}"); var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid); projectIds.Validate(); var result = await RequestExecutorContainerFactory.Build <GetAssetOnDesignPeriodsExecutor>(_logger, #if RAPTOR _raptorClient, #endif configStore : _configStore, trexCompactionDataProxy : _trexCompactionDataProxy, customHeaders : CustomHeaders, customerUid : CustomerUid, userId : UserId, fileImportProxy : FileImportProxy) .ProcessAsync(projectIds) as MachineDesignsExecutionResult; _log.LogDebug($"{nameof(GetMachineDesigns)} MachineDesignsExecutionResult: {result}"); var response = CreateUniqueMachineDesignList(result); _log.LogDebug($"{nameof(GetMachineDesigns)} Response: {response}"); return(response); }
public void ProjectIDsRequest_Success(int projectId, string projectUid) { var request = new ProjectIDs(projectId, Guid.Parse(projectUid)); request.Validate(); }
public async Task <MachineDesignDetailsExecutionResult> GetMachineDesignByDateRangeDetails([FromRoute] Guid projectUid, [FromQuery] string startUtc, [FromQuery] string endUtc) { _log.LogInformation($"{nameof(GetMachineDesignByDateRangeDetails)} Request. projectUid: {projectUid} startUtc: {startUtc} endUtc: {endUtc}"); var projectIds = new ProjectIDs(await((RaptorPrincipal)User).GetLegacyProjectId(projectUid), projectUid); projectIds.Validate(); ValidateDates(startUtc, endUtc, out var beginUtc, out var finishUtc); var designsResultTask = RequestExecutorContainerFactory.Build <GetAssetOnDesignPeriodsExecutor>(_logger, #if RAPTOR _raptorClient, #endif configStore: _configStore, trexCompactionDataProxy: _trexCompactionDataProxy, customHeaders: CustomHeaders, customerUid: CustomerUid, userId: UserId, fileImportProxy: FileImportProxy) .ProcessAsync(projectIds); var machineResultTask = RequestExecutorContainerFactory.Build <GetMachineIdsExecutor>(_logger, #if RAPTOR _raptorClient, #endif configStore: _configStore, trexCompactionDataProxy: _trexCompactionDataProxy, customHeaders: CustomHeaders, customerUid: CustomerUid) .ProcessAsync(projectIds); await Task.WhenAll(designsResultTask, machineResultTask); var designsResult = await designsResultTask as MachineDesignsExecutionResult; var machineResult = await machineResultTask as MachineExecutionResult; _log.LogDebug($"{nameof(GetMachineDesignByDateRangeDetails)} MachineDesignsExecutionResult: {JsonConvert.SerializeObject(designsResult)}"); _log.LogDebug($"{nameof(GetMachineDesignByDateRangeDetails)} MachineExecutionResult: {JsonConvert.SerializeObject(machineResult)}"); // for this pairing to work, we need both executors to be using the same source: Raptor/TRex, // otherwise there will be a mismatch of OnMachineDesignId v.s. Uid. var designDetailsList = new List <MachineDesignDetails>(); if (machineResult != null && designsResult != null) { foreach (var machine in machineResult.MachineStatuses) { var filteredDesigns = designsResult.AssetOnDesignPeriods.Where( design => ( design.AssetUid.HasValue ? design.AssetUid == machine.AssetUid : design.MachineId == machine.AssetId ) && IsDateRangeOverlapping(design.StartDate, design.EndDate, beginUtc, finishUtc)).ToList(); if (filteredDesigns.Count > 0) { designDetailsList.Add(new MachineDesignDetails( machine.AssetId, machine.MachineName, machine.IsJohnDoe, RemoveDuplicateMachineDesigns(filteredDesigns).ToArray(), machine.AssetUid)); } } } var response = new MachineDesignDetailsExecutionResult(designDetailsList); _log.LogInformation($"{nameof(GetMachineDesignByDateRangeDetails)} Response. {JsonConvert.SerializeObject(response)}"); return(response); }