/// <summary> /// Enables the customer to create an support ticket. /// </summary> /// <param name="request"></param> /// <returns></returns> public CreateIncidentResponse CreateIncident(CreateIncidentRequest request) { var uri = new Uri($"{GetEndPoint(SupportManagementServices.Incidents, this.Region)}"); var headers = new HttpRequestHeaderParam() { OpcRetryToken = request.OpcRetryToken, OpcRequestId = request.OpcRequestId }; headers.FreeHeader.Add("ocid", request.Ocid); if (!string.IsNullOrEmpty(request.Homeregion)) { headers.FreeHeader.Add("homeregion", request.Homeregion); } using (var webResponse = this.RestClient.Post(uri, request.CreateIncident, headers)) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = reader.ReadToEnd(); return(new CreateIncidentResponse() { Incident = this.JsonSerializer.Deserialize <IncidentDetails>(response), OpcRequestId = webResponse.Headers.Get("opc-request-id"), ETag = webResponse.Headers.Get("ETag") }); } }
/// <summary> /// This API enables the customer to Create an Incident /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> public async Task <CreateIncidentResponse> CreateIncident(CreateIncidentRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createIncident"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/v2/incidents".Trim('/'))); HttpMethod method = new HttpMethod("Post"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken); } else { responseMessage = await this.restClient.HttpSend(requestMessage); } return(Converter.FromHttpResponseMessage <CreateIncidentResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateIncident failed with error: {e.Message}"); throw; } }
public IActionResult CreateIncident([FromRoute] int id, [FromBody] CreateIncidentRequest requestBody) { var service = _servicesManager.GetService(id); if (service == null) { return(NotFound(new { message = "A service with this ID does not exist." })); } var incident = requestBody.ToIncident(); incident.ServiceId = service.Id; incident = _incidentsManager.CreateIncident(incident); var incidentUpdate = requestBody.ToIncidentUpdate(); incidentUpdate.IncidentId = incident.Id; incidentUpdate = _incidentUpdatesManager.CreateIncidentUpdate(incidentUpdate); incident.MostRecentUpdateId = incidentUpdate.Id; _incidentsManager.UpdateIncident(incident); if (service.Status < incident.CausedStatus) { service.Status = incident.CausedStatus; _servicesManager.Update(service); } return(Ok(incident)); }
public async Task <HttpResponseMessage> PostAsync(CreateIncidentRequest request) { Log.Information("Create incident from file has been requested : {@createIncidentFromFileRequest}", request); try { if (!ModelState.IsValid) { Log.Error("Could not create incident from file: {errors}", ModelState.SerializeForLog()); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var incident = incidentRequestMapper.Map(request); await incidentExchangePublisher.PublishAsync(incident, incident.jobIdentifier); return(Request.CreateResponse(HttpStatusCode.OK, new ApiResponse { message = string.Format("The request has completed successfully. A incident has been queued for {0}.", request.JobIdentifier) })); } catch (Exception ex) { const string message = "An error occurred while creating the incident."; Log.Error(ex, message); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message)); } }
public async Task WhenPostFromFile_ThenMapRequest() { var request = new CreateIncidentRequest { JobIdentifier = It.IsAny <string>(), JobSubject = It.IsAny <string>(), JobPredicate = It.IsAny <string>() }; var sut = CreateController(new HttpRequestMessage()); await sut.PostAsync(request); incidentRequestMapper.Verify(x => x.Map(request)); }
public async Task WhenPostFromFile_AndUnexpectedException_ThenReturnInternalServerError() { incidentRequestMapper.Setup(x => x.Map(It.IsAny <CreateIncidentRequest>())) .Throws(new Exception()); var sut = CreateController(new HttpRequestMessage()); var request = new CreateIncidentRequest { JobIdentifier = It.IsAny <string>(), JobSubject = It.IsAny <string>(), JobPredicate = It.IsAny <string>() }; var result = await sut.PostAsync(request); Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode); }
public Guid CreateNewIncident(CreateIncidentRequest request, IIdentity currentUser) { var currentUserId = mZSupportId; if (!request.IsSupportIncident) { //если выбран текущий юзер как ответсвенный, то тащим его айдишник из ЦРМ. currentUserId = mSystemUsersService.FindUserIdByIdentity(currentUser); } if (currentUserId == null) { throw new AuthenticationException(String.Format("Пользователь с именем {0} не найден в црм", currentUser.Name)); } var incident = new Incident { Id = Guid.NewGuid(), Title = request.Header, Description = request.Body, New_prichina = request.CloseReason, iok_sort_group = request.Specialization, CaseOriginCode = 1, PriorityCode = 3, New_receive = DateTime.Now, CaseTypeCode = 1, CustomerId = new CrmEntityReference("account", request.OrganizationId), ResponsibleContactId = new CrmEntityReference("contact", request.ContactId), OwnerId = new CrmEntityReference("systemuser", currentUserId), svk_functional = request.FunctionalId == Guid.Empty? null: new CrmEntityReference("svk_functional", request.FunctionalId), SubjectId = request.SubjectId == Guid.Empty?null:new CrmEntityReference("subject", request.SubjectId) }; mIncidentsRepository.Create(incident); if (request.CloseAfterRegistration) { mIncidentsRepository.Deactivate(incident, 0, 0); } return(incident.Id); }
public async Task WhenPostFromFile_ThenPublishAsync() { var request = new CreateIncidentRequest { JobIdentifier = It.IsAny <string>(), JobSubject = It.IsAny <string>(), JobPredicate = It.IsAny <string>() }; var incident = new Incident { jobIdentifier = Guid.NewGuid().ToString() }; ExpectIncidentMapperToMap(incident); ExpectExchangeToPublish(); var sut = CreateController(new HttpRequestMessage()); await sut.PostAsync(request); exchange.Verify(x => x.PublishAsync(incident, It.IsAny <string>())); }
public async Task WhenPostFromFile_ThenReturnOk() { var request = new CreateIncidentRequest { JobIdentifier = It.IsAny <string>(), JobSubject = It.IsAny <string>(), JobPredicate = It.IsAny <string>() }; var incident = new Incident { jobIdentifier = Guid.NewGuid().ToString() }; ExpectIncidentMapperToMap(incident); ExpectExchangeToPublish(); var sut = CreateController(new HttpRequestMessage()); var result = await sut.PostAsync(request); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
protected override void ProcessRecord() { base.ProcessRecord(); CreateIncidentRequest request; try { request = new CreateIncidentRequest { CreateIncidentDetails = CreateIncidentDetails, Ocid = Ocid, OpcRequestId = OpcRequestId, Homeregion = Homeregion }; response = client.CreateIncident(request).GetAwaiter().GetResult(); WriteOutput(response, response.Incident); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public Guid?PostNewIncident(CreateIncidentRequest request) { NLogContaner.Instance.Error("********************************************"); NLogContaner.Instance.Error("Айди контакта {0}", request.ContactId); NLogContaner.Instance.Error("CloseAfter: {0}", request.CloseAfterRegistration); NLogContaner.Instance.Error("IsSupport: {0}", request.IsSupportIncident); NLogContaner.Instance.Error("Header: {0}", request.Header); NLogContaner.Instance.Error("Body: {0}", request.Body); NLogContaner.Instance.Error("Specialization: {0}", request.Specialization); NLogContaner.Instance.Error("OrgId: {0}", request.OrganizationId); NLogContaner.Instance.Error("FuncId: {0}", request.FunctionalId); NLogContaner.Instance.Error("SubjId: {0}", request.SubjectId); NLogContaner.Instance.Error("CloseReason: {0}", request.CloseReason); try { var currentUser = User; return(mIncidentsService.CreateNewIncident(request, currentUser.Identity)); } catch (Exception e) { NLogContaner.Instance.Error(e.ToString()); return(null); } }