public virtual Models.ResponseObj UploadVoyagePlan([FromBody] string voyagePlan, [FromUri] string deliveryAckEndPoint = null, [FromUri] string callbackEndpoint = null) { log.Info("Incoming request to " + GetCurrentMethod()); var messageType = _messageTypeService.Get(x => x.Name.ToLower() == "rtz").First(); var request = Request; var headers = request.Headers; var paramList = new List <KeyValuePair <string, string> >(); var param = new KeyValuePair <string, string>("deliveryAckEndPoint", deliveryAckEndPoint); paramList.Add(param); param = new KeyValuePair <string, string>("callbackEndpoint", callbackEndpoint); paramList.Add(param); //First, validate that we have mandatory in-parameters var parser = RtzParserFactory.Create(voyagePlan); var uvid = parser.VesselVoyage; if (string.IsNullOrEmpty(uvid)) { log.Debug("UVID is empty"); throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required parameter UVID is missing."); } if (!FormatValidation.IsValidUvid(uvid)) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Invalid UVID format"); } if (voyagePlan == null) { log.Debug("VoyagePlan is empty"); throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required parameter VoyagePlan is missing."); } try { if (string.IsNullOrEmpty(InstanceContext.CallerOrgId)) { log.Debug("Calling organization identity missing in header."); throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required header incomingOrganizationId is missing."); } //Write to log table _logEventService.LogInfo(EventNumber.VIS_uploadVoyagePlan_request, EventDataType.RTZ, paramList, voyagePlan); // Get identity ether from internal id talbe or from id registry var identity = _identityService.GetCallerIdentity(); var result = new UploadedMessage(); result.AckDelivered = false; result.DeliveryAckEndpoint = deliveryAckEndPoint; result.DeliveryAckReqested = string.IsNullOrEmpty(deliveryAckEndPoint) ? false : true; result.FetchedByShip = false; result.FetchTime = null; result.FromOrg = identity; result.FromServiceId = InstanceContext.CallerServiceId; result.Message = Serialization.StrToByteArray(voyagePlan); result.MessageType = _messageTypeService.Get(x => x.Name.ToLower() == "rtz").First(); result.Notified = false; result.ReceiveTime = DateTime.UtcNow; result.MessageID = uvid; result.CallbackEndpoint = string.IsNullOrEmpty(callbackEndpoint) ? string.Empty : callbackEndpoint; _uploadedMessageService.InsertRTZ(result); //Save to DB _context.SaveChanges(); //Notify STM module var notification = new Common.Services.Internal.Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.MESSAGE_WAITING; notification.Subject = "New voyageplan uploaded."; notification.NotificationSource = EnumNotificationSource.VIS; var notified = _notificationService.Notify(notification); if (notified) { _context.Entry(result).Reload(); result.Notified = true; _uploadedMessageService.Update(result); } var responsObj = new ResponseObj("Success store message"); //Save to DB _context.SaveChanges(); _logEventService.LogSuccess(EventNumber.VIS_uploadVoyagePlan_response, EventDataType.Other, null, JsonConvert.SerializeObject(responsObj, Formatting.Indented)); return(responsObj); } catch (HttpResponseException ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.VIS_uploadVoyagePlan_request, EventType.Error_internal, paramList, JsonConvert.SerializeObject(ex.Response, Formatting.Indented)); throw; } catch (Exception ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.VIS_uploadVoyagePlan_request, EventType.Error_internal, paramList, ex.Message); string msg = "VIS internal server error. " + ex.Message; throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }
public virtual ResponseObj UploadPCMMessage([FromBody] string pcmMessageObject, [FromUri] string deliveryAckEndPoint = null) { log.Info("Incoming request to " + GetCurrentMethod()); var messageType = _messageTypeService.Get(x => x.Name.ToLower() == "pcm").First(); var parser = new PcmParser(pcmMessageObject); string dataId = parser.PcmMessageId; var errorMsgResponse = string.Empty; var request = Request; var headers = request.Headers; if (string.IsNullOrEmpty(pcmMessageObject)) { log.Debug("PCM Message is empty"); errorMsgResponse += "Required parameter pcmMessageObject is missing." + Environment.NewLine; throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required parameter pcmMessageObject is missing."); } var param = new KeyValuePair <string, string>("deliveryAckEndPoint", deliveryAckEndPoint); var paramList = new List <KeyValuePair <string, string> >(); paramList.Add(param); try { if (string.IsNullOrEmpty(InstanceContext.CallerOrgId)) { log.Debug("Calling organization identity missing in header."); errorMsgResponse += "Calling organization identity missing in header." + Environment.NewLine; throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required header incomingOrganizationId is missing."); } //Write to log table _logEventService.LogInfo(EventNumber.SPIS_uploadPCM_request, EventDataType.PCM, paramList, pcmMessageObject); // Get identity ether from internal id talbe or from id registry var identity = _identityService.GetCallerIdentity(); var result = new UploadedMessage(); result.AckDelivered = false; result.DeliveryAckEndpoint = deliveryAckEndPoint; result.DeliveryAckReqested = string.IsNullOrEmpty(deliveryAckEndPoint) ? false : true; result.FetchedByShip = false; result.FetchTime = null; result.FromOrg = identity; result.FromServiceId = InstanceContext.CallerServiceId; result.Message = Serialization.StrToByteArray(pcmMessageObject); result.MessageType = messageType; result.Notified = false; result.ReceiveTime = DateTime.UtcNow; result.MessageID = dataId; //Notify STM module var notification = new Common.Services.Internal.Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.MESSAGE_WAITING; notification.Subject = "PCM message uploaded."; notification.NotificationSource = EnumNotificationSource.SPIS; result.Notified = _notificationService.Notify(notification); _uploadedMessageService.InsertPCM(result); var responsObj = new ResponseObj("Success store message"); //Save to DB _context.SaveChanges(); _logEventService.LogSuccess(EventNumber.SPIS_uploadPCM_response, EventDataType.None, paramList, JsonConvert.SerializeObject(responsObj, Formatting.Indented)); return(responsObj); } catch (HttpResponseException ex) { var responseString = JsonConvert.SerializeObject(ex.Response, Formatting.Indented); log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.SPIS_uploadPCM_request, EventType.Error_internal, paramList, responseString); throw; } catch (DbEntityValidationException dbEx) { var response = request.CreateResponse(HttpStatusCode.InternalServerError); StringBuilder sb = new StringBuilder(); foreach (var item in dbEx.EntityValidationErrors) { sb.Append(item + " errors: "); foreach (var i in item.ValidationErrors) { sb.Append(i.PropertyName + " : " + i.ErrorMessage); } sb.Append(Environment.NewLine); } string msg = "SPIS internal server error. " + dbEx.Message; _logEventService.LogError(EventNumber.SPIS_uploadPCM_request, EventType.Error_internal, paramList, dbEx.Message); log.ErrorFormat("Validation errors: {0}", sb.ToString()); throw CreateHttpResponseException(HttpStatusCode.InternalServerError, sb.ToString()); } catch (Exception ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.SPIS_uploadPCM_request, EventType.Error_internal, paramList, ex.Message); string msg = "SPIS internal server error. " + ex.Message; throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }