public void ClaimValidators_ValidateAllEmptyFields_ExpectFailedValidationResults() { var claimInformation = new ClaimInputs(); ValidationResults results = _claimValidator.ValidateClaim(claimInformation); Assert.False(results.ValidationsPassed); Assert.Equal(10, results.ValidationsErrors.Count); }
/// <summary> /// Validates the claim. /// </summary> /// <returns>The claim.</returns> /// <param name="claim">Claim.</param> public ValidationResults ValidateClaim(ClaimInputs claim) { if (claim == null) { throw new ArgumentNullException(nameof(claim), "Cannot be null."); } var validationResults = new ValidationResults(); if (string.IsNullOrEmpty(claim.workAssignmentPK)) { validationResults.AddValidationError("The claim workAssignmentPK cannot be null or empty."); } if (string.IsNullOrEmpty(claim.orgId)) { validationResults.AddValidationError("The claim orgId cannot be null or empty."); } if (string.IsNullOrEmpty(claim.vehicleOwnerLastName)) { validationResults.AddValidationError("The claim vehicleOwnerLastName cannot be null or empty."); } if (string.IsNullOrEmpty(claim.taskId)) { validationResults.AddValidationError("The claim taskId cannot be null or empty."); } if (string.IsNullOrEmpty(claim.assignmentNote)) { validationResults.AddValidationError("The claim assignmentNote cannot be null or empty."); } if (string.IsNullOrEmpty(claim.roleCode)) { validationResults.AddValidationError("The claim roleCode cannot be null or empty."); } if (string.IsNullOrEmpty(claim.vehicleOwnerFirstName)) { validationResults.AddValidationError("The claim vehicleOwnerFirstName cannot be null or empty."); } if (string.IsNullOrEmpty(claim.businessCategory)) { validationResults.AddValidationError("The claim businessCategory cannot be null or empty."); } if (string.IsNullOrEmpty(claim.claimNumber)) { validationResults.AddValidationError("The claim claimNumber cannot be null or empty."); } return(validationResults); }
/// <summary> /// Converts the claim data. /// </summary> /// <returns>The claim data.</returns> /// <param name="claimData">Claim data.</param> public static ClaimOutputs ConvertClaimData(ClaimInputs claimData) { ClaimOutputs claimResponse = new ClaimOutputs() { id = claimData.id, taskId = claimData.taskId, claimNumber = claimData.claimNumber, status = claimData.customerStatus, workAssignmentId = (String.IsNullOrEmpty(claimData.workAssignmentPK)) ? null : claimData.workAssignmentPK, externalId = (String.IsNullOrEmpty(claimData.externalId)) ? null : claimData.externalId, createdAt = claimData.createdDate, updatedAt = claimData.updatedDate, username = claimData.userName, insurer = new Insurer() { companyName = claimData.orgId, phone = claimData.staffAppraiserCellPhone, email = claimData.staffAppraiserEmailAddress }, policyHolder = new PolicyHolder() { firstName = claimData.vehicleOwnerFirstName, lastName = claimData.vehicleOwnerLastName, phone = claimData.vehicleOwnerCellPhone, email = claimData.vehicleOwnerEmail }, identifiedVehicle = new IdentifiedVehicle() { vin = (String.IsNullOrEmpty(claimData.estimateVehicleVIN)) ? claimData.vehicleVIN : claimData.estimateVehicleVIN, vehicleNumber = (String.IsNullOrEmpty(claimData.vehicleNumber)) ? null : claimData.vehicleNumber, makeDescription = (String.IsNullOrEmpty(claimData.estimateVehicleMake)) ? claimData.assignmentVehicleMake : claimData.estimateVehicleMake, modelDescription = (String.IsNullOrEmpty(claimData.estimateVehicleModel)) ? claimData.assignmentVehicleModel : claimData.estimateVehicleModel, exteriorColor = (String.IsNullOrEmpty(claimData.exteriorColor)) ? null : claimData.exteriorColor, codes = new VehicleCodes() { fileID_US = ((String.IsNullOrEmpty(claimData.vehicleFileId)) ? null : claimData.vehicleFileId) + ((String.IsNullOrEmpty(claimData.vehicleStyleCode)) ? null : claimData.vehicleStyleCode) } } }; return(claimResponse); }
/// <summary> /// Posts the claim. /// </summary> /// <returns>The claim.</returns> /// <param name="claim">Claim.</param> public async Task <string> PostClaim(ClaimInputs claim) { if (claim == null) { throw new ArgumentNullException(nameof(claim), "Cannot be null"); } Console.WriteLine("[{0}] : Creating the claim # : [ {1} ] : with taskID : [ {2} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claim.claimNumber, claim.taskId); string serializedClaim = JsonConvert.SerializeObject(claim, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var requestBody = new StringContent(serializedClaim, Encoding.UTF8, "application/json"); string accessToken = InMemoryStorage.Instance().StoredDriverToken; var httpClient = new HttpClient(); var requestMessage = new HttpRequestMessage { RequestUri = new Uri($"{_mbeUrl}api/claims?access_token={accessToken}"), Method = HttpMethod.Post, Content = requestBody }; requestMessage.Headers.Add("correlation_id", ApiHelpers.GetRandomString()); HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage); if (_errorStatus.Contains(responseMessage.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); return(await PostClaim(claim)); } if (responseMessage.StatusCode != HttpStatusCode.OK && responseMessage.StatusCode != HttpStatusCode.Created) { return(string.Empty); } return(await responseMessage.Content.ReadAsStringAsync()); }
public void ClaimValidators_ValidateNullOrgId_ExpectFailedValidationResults() { var claimInformation = new ClaimInputs(); claimInformation.vehicleVIN = "4JGBB8GB4BA662410"; claimInformation.vehicleOwnerLastName = "James"; claimInformation.taskId = "4AEB108C224145A3B18443234D0EED10"; claimInformation.assignmentNote = "Hello World."; claimInformation.roleCode = "F3"; claimInformation.vehicleOwnerFirstName = "Jessy"; claimInformation.businessCategory = "094k"; claimInformation.claimNumber = "12-PG12-12345"; claimInformation.workAssignmentPK = "5A3B18443234D0E"; ValidationResults results = _claimValidator.ValidateClaim(claimInformation); Assert.False(results.ValidationsPassed); Assert.Equal(1, results.ValidationsErrors.Count); }
public async Task <object> SubmitAssignment([FromBody] ClaimInputs claimData) { try { Console.WriteLine("[{0}] submitAssignment : Creating the claim : [{1}] for task Id : [{2}]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimData.claimNumber, claimData.taskId); if (claimData == null) { throw new ArgumentNullException(nameof(claimData), "Cannot be null"); } ValidationResults validationResult = _claimValidators.ValidateClaim(claimData); if (!validationResult.ValidationsPassed) { return(StatusCode((int)HttpStatusCode.BadRequest, validationResult)); } string createdClaim = await _mbe.PostClaim(claimData); if (string.IsNullOrEmpty(createdClaim)) { return(StatusCode((int)HttpStatusCode.InternalServerError, new { message = "The MBE core was not able to process the request." })); } var claimPutDataObj = JsonConvert.DeserializeObject <ClaimInputs>(createdClaim); ClaimOutputs claimPutOutput = ApiHelpers.ConvertClaimData(claimPutDataObj); return(StatusCode((int)HttpStatusCode.Created, claimPutOutput)); } catch (Exception exc) { Console.WriteLine($"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : PostClaim : Error while posting a new claim. Error message: {exc.Message}"); return(StatusCode((int)HttpStatusCode.InternalServerError, exc)); } }
public async Task <object> PostSubmitDamages(string id, [FromBody] SubmitDamageInputs dataFromDg) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty"); } if (dataFromDg == null) { throw new ArgumentNullException(nameof(dataFromDg), "Cannot be null."); } Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : call made with claim ID : [ {1} ] and damages data : [ {2} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(dataFromDg)); Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : Get claim call made to validate Claim in MBE with Claim ID : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); string existingClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(existingClaim)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No claim found with ID {0}", id)), ReasonPhrase = "No content found with given claim Id" }); } ClaimInputs claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(existingClaim); if (!string.IsNullOrEmpty(dataFromDg.damageComment)) { HttpResponseMessage submitCommentsResponse = await _mbe.SubmitClaimComments(id, claimDataObj.claimNumber, claimDataObj.orgId, dataFromDg.damageComment); Console.WriteLine( $"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : SUBMIT ATTACHMENT COMMENTS RESULT: " + $"{submitCommentsResponse.Content.ReadAsStringAsync().Result}"); } var a2EHeader = new a2eHeaders { id = ApiHelpers.GetRandomString(), cid = ApiHelpers.GetRandomString(), messageType = "createestimaterequest" }; var a2EBody = new a2eBody { capturedDamage = dataFromDg.capturedDamage, vinDecodeFailed = claimDataObj.vinDecodeFailed, mileage = dataFromDg.mileage }; var dataToA2E = new dataToA2e { header = a2EHeader, claimContext = new ClaimContext { workAssignmentId = claimDataObj.workAssignmentPK, createdForProfileId = !string.IsNullOrEmpty(claimDataObj.externalId) ? claimDataObj.externalId : "477T2PPCOMPAPP2", orgId = claimDataObj.orgId }, body = a2EBody }; string publishingResults = await _eventManager.PublishEvent(dataToA2E); Console.WriteLine(publishingResults); return("Received damage data successfully"); }
public async Task <object> GetEstimateForClaim(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or emtpy."); } Console.WriteLine("[ {0} ] : GET ESTIMATE : Call made with claim id [{1}]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); Console.WriteLine("[ {0} ] : GET ESTIMATE : Calling GET CLAIM BY ID to validate claim ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { string existingClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(existingClaim)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No claim found with ID {0}", id)), ReasonPhrase = "No content found with given claim Id" }); } ClaimInputs claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(existingClaim); string downloadedEstimate = await _mbe.GetEstimageForClaim(id); Console.WriteLine("[ {0} ] : GET ESTIMATE : Received response from MBE as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(downloadedEstimate)); if (string.IsNullOrEmpty(downloadedEstimate)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Unable to get estimate for this claim"), ReasonPhrase = "Unable to get estimate for this claim" }); } estimateFilesOutput estimateFileOutPut = JsonConvert.DeserializeObject <estimateFilesOutput>(downloadedEstimate); var estimateOutput = new EstimateOutput { estimateTotals = new estimateTotals { estimateNetTotal = claimDataObj.estimateNetTotal, currency = "USD" }, estimateDocuments = new estimateDocuments { contentType = estimateFileOutPut.type, filename = estimateFileOutPut.name, fileBase64 = estimateFileOutPut.content } }; Console.WriteLine("[ {0} ] : GET ESTIMATE : Estimate data sent to APP as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(estimateOutput)); return(estimateOutput); } catch (Exception e) { Console.WriteLine( "[ {0} ] : GET ESTIMATE : Error occured while getting estimate for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }
public async Task <object> PostPhotoData(string id, [FromForm] photoDataInput photoMetadata, [FromForm] photoFileInputs fileData) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty."); } if (photoMetadata == null) { throw new ArgumentNullException(nameof(photoMetadata), "Cannot be null."); } if (fileData == null) { throw new ArgumentNullException(nameof(fileData), "Cannot be null."); } Console.WriteLine( "[ {0} ] : POST PHOTO : call made with claim ID : [ {1} ] , photo meta data [ {2} ] and with photo", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(photoMetadata)); PhotoFormData photoFormData = JsonConvert.DeserializeObject <PhotoFormData>(photoMetadata.metadata); string base64Stream = null; if (fileData.photo.Length > 0) { using (var ms = new MemoryStream()) { fileData.photo.CopyTo(ms); var fileBytes = ms.ToArray(); base64Stream = Convert.ToBase64String(fileBytes); Console.WriteLine("[ {0} ] : POST PHOTO : Photo data converted in to Base64 memory stream", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); } } string fileAttachmentType; string fileName = fileData.photo.FileName; string contentType = fileData.photo.ContentType; if (fileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) && contentType == "text/plain") { fileAttachmentType = "StatisticFile"; } else { fileAttachmentType = "UserUpload"; } Console.WriteLine("[ {0} ] : POST PHOTO : Calling GET CLAIM BY ID to validate claim", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { string getClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(getClaim)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No claim found with ID {0}", id)), ReasonPhrase = "No content found with given claim Id" }); } ClaimInputs claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(getClaim); var parametersToMbe = new PhotoInputsForMbe { data = base64Stream, fileName = fileName, attachmentType = fileAttachmentType, latitude = photoFormData.latitude, longitude = photoFormData.longitude, contentType = contentType, appName = "Digital Garage", userName = claimDataObj.userName, claimNumber = claimDataObj.claimNumber, orgId = claimDataObj.orgId }; var newDataForMbe = new Dictionary <string, PhotoInputsForMbe> { { "parameters", parametersToMbe } }; Console.WriteLine("[ {0} ] : POST PHOTO : Photodata prepared to send MBE : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(newDataForMbe)); string photoData = JsonConvert.SerializeObject(newDataForMbe); var photoContentJson = new StringContent(photoData, Encoding.UTF8, "application/json"); string photoResponseData = await _mbe.PostClaimPhoto(photoContentJson); Console.WriteLine("[ {0} ] : POST PHOTO : Received data from MBE : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(photoResponseData)); if (string.IsNullOrEmpty(photoResponseData)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Unable to upload photo, please try again"), ReasonPhrase = "Unable to upload photo" }); } var photoDataObj = JsonConvert.DeserializeObject(photoResponseData); return(photoDataObj); } catch (Exception e) { Console.WriteLine( "[ {0} ] : POST PHOTO : Error occured while posting photos for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }