private List <Models.VoyagePlan> ConvertToContract(List <PublishedRtzMessage> from) { List <Models.VoyagePlan> to = new List <Models.VoyagePlan>(); foreach (var msg in from) { var msgString = Serialization.ByteArrayToString(msg.Message); Models.VoyagePlan vp = new Models.VoyagePlan(msgString); to.Add(vp); } return(to); }
private GetVoyagePlanResponse GetPublishedVoyagePlans(Identity identity, List <KeyValuePair <string, string> > paramList, string uvid = null, int?routeStatusInt = null) { bool accessToAnyUVID = false; var result = new Models.GetVoyagePlanResponse(DateTime.UtcNow); result.VoyagePlans = new List <Models.VoyagePlan>(); List <PublishedRtzMessage> publishedVoyagePlans = null; //Get all published voyageplans based on parameter values if (uvid == null && routeStatusInt == null) { publishedVoyagePlans = _publishedMessageService.Get(x => (int)x.MessageStatus != 8). OrderByDescending(x => x.PublishTime).ToList(); } else if (uvid != null && routeStatusInt == null) { publishedVoyagePlans = _publishedMessageService.Get(x => x.MessageID == uvid && (int)x.MessageStatus != 8). OrderByDescending(x => x.PublishTime).ToList(); } else if (uvid == null && routeStatusInt != null) { publishedVoyagePlans = _publishedMessageService.Get(x => (int)x.MessageStatus != 8 && (int)x.MessageStatus == routeStatusInt). OrderByDescending(x => x.PublishTime).ToList(); } else { publishedVoyagePlans = _publishedMessageService.Get(x => x.MessageID == uvid && (int)x.MessageStatus == routeStatusInt). OrderByDescending(x => x.PublishTime).ToList(); } //Need to loop in order to distinguish the VP's with no access from the ones with access if (publishedVoyagePlans != null && publishedVoyagePlans.Count() > 0) { foreach (var publishedVoyagePlan in publishedVoyagePlans) { // Now look up if orgId is authorized to this voyageplan var aclObject = _aclObjectService.Get(x => x.Subscriber.ID == identity.ID && x.MessageID == publishedVoyagePlan.MessageID); if (aclObject == null || aclObject.Count() == 0) { //No access to this one, send notification to STM module var msg = "Authorization failed: ACL"; log.Debug(msg); //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.UNAUTHORIZED_REQUEST; notification.Subject = string.Format("Access denied for identity {0}.", identity.Name); notification.NotificationSource = EnumNotificationSource.VIS; _notificationService.Notify(notification); _context.SaveChanges(); // Log error _logEventService.LogError(EventNumber.VIS_getVoyagePlan_request, EventType.Error_authorization, paramList, InstanceContext.CallerServiceId); _context.SaveChanges(); } else { accessToAnyUVID = true; //Add it to response object var rtzString = Serialization.ByteArrayToString(publishedVoyagePlan.Message); var vp = new Models.VoyagePlan(rtzString); result.VoyagePlans.Add(vp); } } } else { //We didn't find any voyageplans i.e. return not found throw CreateHttpResponseException(HttpStatusCode.NotFound, "Voyageplans not found"); } //Final check to verify that we did return at least one VP if (!accessToAnyUVID) { throw CreateHttpResponseException(HttpStatusCode.Forbidden, "Authorization failed: ACL"); } return(result); }