DnsResult ApproveReject(IEnumerable <Response> responses, RoutingStatus newStatus, string message = null) { using (var db = new DataContext()) { return(ApproveReject(db, responses, newStatus, message)); } }
static void Main(string[] args) { while (true) { Console.WriteLine(">>>"); var command = Console.ReadLine(); try { RoutingStatus routingStatus = CommandRouter.RouteCommand(command); switch (routingStatus) { case RoutingStatus.Quit: Console.WriteLine("Exiting..."); return; case RoutingStatus.Invalid: Console.WriteLine(ErrorMessage.InvalidCommand); Console.WriteLine(ConstantsKey.CommandHelp); break; case RoutingStatus.Success: break; } } catch (BaseException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine("Fatal Error: {0}", e.Message); } } }
public void PutUserIdRoutingstatusTest() { // TODO: add unit test for the method 'PutUserIdRoutingstatus' string userId = null; // TODO: replace null with proper value RoutingStatus body = null; // TODO: replace null with proper value var response = instance.PutUserIdRoutingstatus(userId, body); Assert.IsInstanceOf <RoutingStatus> (response, "response is RoutingStatus"); }
public Delivery(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime?estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { NextExpectedActivity = nextExpectedActivity; LastKnownActivity = lastKnownActivity; RoutingStatus = routingStatus; TransportStatus = transportStatus; EstimatedTimeOfArrival = estimatedTimeOfArrival; IsUnloadedAtDestination = isUnloadedAtDestination; IsMisdirected = isMisdirected; CalculatedAt = calculatedAt; }
public Delivery(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { NextExpectedActivity = nextExpectedActivity; LastKnownActivity = lastKnownActivity; RoutingStatus = routingStatus; TransportStatus = transportStatus; EstimatedTimeOfArrival = estimatedTimeOfArrival; IsUnloadedAtDestination = isUnloadedAtDestination; IsMisdirected = isMisdirected; CalculatedAt = calculatedAt; }
private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification) { _calculatedAt = DateTime.Now; _lastEvent = lastHandlingEvent; _isMisdirected = CalculateMisdirectionStatus(itinerary); _routingStatus = CalculateRoutingStatus(itinerary, specification); _transportStatus = CalculateTransportStatus(); _lastKnownLocation = CalculateLastKnownLocation(); _estimatedTimeOfArrival = CalculateEta(itinerary); _nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary); _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification); }
protected CargoState(CargoState previousState, IItinerary newItinerary) : this(previousState) { if (null == newItinerary) { throw new ArgumentNullException("newItinerary"); } if (!previousState.RouteSpecification.IsSatisfiedBy(newItinerary)) { string message = string.Format("The itinerary provided do not satisfy the route of {0}.", Identifier); throw new ArgumentException(message, "itinerary"); } Itinerary = newItinerary; _routingStatus = RoutingStatus.Routed; _estimatedTimeOfArrival = this.Itinerary.FinalArrivalDate; }
public Delivery(Cargo parent, HandlingEventType? nextExpectedEvent, string nextExpectedLocation, HandlingEventType? lastKnownEvent, string lastKnownLocation, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) : this() { Id = Guid.NewGuid(); Cargo = parent; NextExpectedEventType = nextExpectedEvent; NextExpectedLocation = nextExpectedLocation; LastKnownEventType = lastKnownEvent; LastKnownLocation = lastKnownLocation; RoutingStatus = routingStatus; TransportStatus = transportStatus; Eta = estimatedTimeOfArrival; UnloadedAtDest = isUnloadedAtDestination; IsMisdirected = isMisdirected; CalculatedAt = calculatedAt; }
public Delivery(Cargo parent, HandlingEventType?nextExpectedEvent, string nextExpectedLocation, HandlingEventType?lastKnownEvent, string lastKnownLocation, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime?estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) : this() { Id = Guid.NewGuid(); Cargo = parent; NextExpectedEventType = nextExpectedEvent; NextExpectedLocation = nextExpectedLocation; LastKnownEventType = lastKnownEvent; LastKnownLocation = lastKnownLocation; RoutingStatus = routingStatus; TransportStatus = transportStatus; Eta = estimatedTimeOfArrival; UnloadedAtDest = isUnloadedAtDestination; IsMisdirected = isMisdirected; CalculatedAt = calculatedAt; }
private void LogStatusChange <T>(Lpp.Security.SecurityTarget st, RoutingStatus newStatus, RequestDataMart datamart) where T : Events.RequestStatusChangeBase, new() { throw new Lpp.Utilities.CodeToBeUpdatedException(); //Audit.CreateEvent(st, new T //{ // ActingUser = Auth.CurrentUser.Id, // Request = dm.RequestId, // Project = (dm.Request.Project ?? VirtualSecObjects.AllProjects).SID, // RequestType = dm.Request.RequestTypeId, // Name = dm.Request.Name, // DataMart = dm.DataMartId, // OldStatus = RoutingStatuses.AwaitingRequestApproval.ToString(), // NewStatus = newStatus.ToString(), //}) //.Log(); }
protected CargoState(TrackingId identifier, IRouteSpecification routeSpecification) { if (null == identifier) { throw new ArgumentNullException("identifier"); } if (null == routeSpecification) { throw new ArgumentNullException("routeSpecification"); } _calculationDate = DateTime.UtcNow; this.Identifier = identifier; this.RouteSpecification = routeSpecification; _routingStatus = RoutingStatus.NotRouted; _estimatedTimeOfArrival = null; }
protected CargoState(CargoState previousState) { if (null == previousState) { throw new ArgumentNullException("previousState"); } _calculationDate = DateTime.UtcNow; _routingStatus = previousState.RoutingStatus; this.Identifier = previousState.Identifier; this.RouteSpecification = previousState.RouteSpecification; this.Itinerary = previousState.Itinerary; if (_routingStatus == RoutingStatus.Routed) { _estimatedTimeOfArrival = this.Itinerary.FinalArrivalDate; } else { _estimatedTimeOfArrival = null; } }
protected CargoState(CargoState previousState, IRouteSpecification routeSpecification) : this(previousState) { if (null == routeSpecification) { throw new ArgumentNullException("routeSpecification"); } this.RouteSpecification = routeSpecification; if (null != this.Itinerary) { if (this.RouteSpecification.IsSatisfiedBy(this.Itinerary)) { _routingStatus = RoutingStatus.Routed; _estimatedTimeOfArrival = this.Itinerary.FinalArrivalDate; } else { _routingStatus = RoutingStatus.Misrouted; } } }
public virtual void UpdateHistory(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { Delivery delivery = new Delivery(this, nextExpectedActivity, lastKnownActivity, routingStatus, transportStatus, estimatedTimeOfArrival, isUnloadedAtDestination, isMisdirected, calculatedAt); _history.Add(delivery); CurrentInformation = delivery; }
public virtual void UpdateHistory(HandlingEventType? nextExpectedEvent, string nextExpectedLocation, HandlingEventType? lastKnownEvent, string lastKnownLocation, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime? estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { Delivery delivery = new Delivery(this, nextExpectedEvent, nextExpectedLocation, lastKnownEvent, lastKnownLocation, routingStatus, transportStatus, estimatedTimeOfArrival, isUnloadedAtDestination, isMisdirected, calculatedAt); DeliveryHistory.Add(delivery); CurrentInformation = delivery; }
public void Init() { instance = new RoutingStatus(); }
partial void OnRoutingStatusChanging(RoutingStatus value);
DnsResult ApproveReject(DataContext db, IEnumerable <Response> responses, RoutingStatus newStatus, string message = null) { var cantTouch = responses.Where(r => r.RequestDataMart.Status != RoutingStatus.AwaitingResponseApproval).ToArray(); if (cantTouch.Any()) { //var datamarts = db.RequestDataMarts.Where(dm => cantTouch.Select(t => t.RequestDataMartID).Contains(dm.ID)).GroupBy(dm => dm.DataMart).Select(dm => dm.Key.Organization.Name + "\\" + dm.Key.Name).ToArray(); var datamarts = responses.GroupBy(r => new { ID = r.RequestDataMart.DataMartID, DataMartName = r.RequestDataMart.DataMart.Name, OrgName = r.RequestDataMart.DataMart.Organization.Name }).Select(dm => dm.Key.OrgName + "\\" + dm.Key.DataMartName).ToArray(); return(DnsResult.Failed("The following DataMarts are not in a valid state to 'Approve/Reject': " + string.Join(", ", datamarts))); } Guid[] instanceIDs = responses.Select(r => r.ID).ToArray(); var globalAclFilter = db.GlobalAcls.FilterAcl(Auth.ApiIdentity, PermissionIdentifiers.DataMartInProject.ApproveResponses); var datamartsAclFilter = db.DataMartAcls.FilterAcl(Auth.ApiIdentity, PermissionIdentifiers.DataMartInProject.ApproveResponses); var projectAclFilter = db.ProjectAcls.FilterAcl(Auth.ApiIdentity, PermissionIdentifiers.DataMartInProject.ApproveResponses); var projectDataMartsAclFilter = db.ProjectDataMartAcls.FilterAcl(Auth.ApiIdentity, PermissionIdentifiers.DataMartInProject.ApproveResponses); var organizationAclFilter = db.OrganizationAcls.FilterAcl(Auth.ApiIdentity, PermissionIdentifiers.DataMartInProject.ApproveResponses); var hasPermission = (from r in db.Responses let globalAcls = globalAclFilter let datamartAcls = datamartsAclFilter.Where(a => a.DataMart.Requests.Any(rd => rd.ID == r.RequestDataMartID)) let projectAcls = projectAclFilter.Where(a => a.Project.Requests.Any(rd => rd.ID == r.RequestDataMart.RequestID)) let orgAcls = organizationAclFilter.Where(a => a.Organization.Requests.Any(rq => rq.ID == r.RequestDataMart.RequestID)) let projectDataMartsAcls = projectDataMartsAclFilter.Where(a => a.Project.Requests.Any(rd => rd.ID == r.RequestDataMart.RequestID) && a.DataMart.Requests.Any(rd => rd.ID == r.RequestDataMartID)) where instanceIDs.Contains(r.ID) && (globalAcls.Any() || datamartAcls.Any() || projectAcls.Any() || projectDataMartsAcls.Any() || orgAcls.Any()) && (globalAcls.All(a => a.Allowed) && datamartAcls.All(a => a.Allowed) && projectAcls.All(a => a.Allowed) && projectDataMartsAcls.All(a => a.Allowed) && orgAcls.All(a => a.Allowed)) select r.ID).ToArray(); if (instanceIDs.Length != hasPermission.Length) { var deniedInstances = instanceIDs.Except(hasPermission); var deniedDataMarts = db.RequestDataMarts.Where(dm => dm.Responses.Any(r => deniedInstances.Contains(r.ID))) .GroupBy(dm => dm.DataMart) .Select(dm => dm.Key.Organization.Name + "\\" + dm.Key.Name) .ToArray(); return(DnsResult.Failed("Access Denied to 'Approve/Reject Response' for the following DataMarts: " + string.Join(", ", deniedDataMarts))); } var requests = GetRequests(db, instanceIDs); var routes = db.RequestDataMarts.Include(dm => dm.Responses).Where(dm => dm.Responses.Any(r => instanceIDs.Contains(r.ID))); var routeIDs = routes.Select(rt => rt.ID).ToArray(); var responseIDs = responses.Select(res => res.ID).ToArray(); var statusChangeLogs = db.LogsRoutingStatusChange.Where(l => routeIDs.Contains(l.RequestDataMartID) && (l.ResponseID == null || (l.ResponseID.HasValue && responseIDs.Contains(l.ResponseID.Value)))).ToArray(); foreach (var route in routes) { if (newStatus == RoutingStatus.ResponseRejectedAfterUpload) { route.Status = newStatus; } //if the response has ever had a status of Completed or ResponseModified it should be changed to ResponseModified else if (statusChangeLogs.Where(l => l.RequestDataMartID == route.ID && (l.NewStatus == RoutingStatus.Completed || l.NewStatus == RoutingStatus.ResultsModified)).Any()) { route.Status = RoutingStatus.ResultsModified; } else { route.Status = DTO.Enums.RoutingStatus.Completed; } route.Responses.Where(r => r.Count == r.RequestDataMart.Responses.Max(x => x.Count)).ForEach(r => r.ResponseMessage = message ?? r.ResponseMessage); } foreach (var req in requests) { req.Item1.UpdatedOn = DateTime.UtcNow; req.Item1.UpdatedByID = Auth.ApiIdentity.ID; } db.SaveChanges(); SendRequestCompleteNotifications(db, requests); return(DnsResult.Success); }
public virtual void UpdateHistory(HandlingActivity nextExpectedActivity, HandlingActivity lastKnownActivity, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime?estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { Delivery delivery = new Delivery(this, nextExpectedActivity, lastKnownActivity, routingStatus, transportStatus, estimatedTimeOfArrival, isUnloadedAtDestination, isMisdirected, calculatedAt); _history.Add(delivery); CurrentInformation = delivery; }
private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification) { _calculatedAt = DateTime.Now; _lastEvent = lastHandlingEvent; _misdirected = CalculateMisdirectionStatus(itinerary); _routingStatus = CalculateRoutingStatus(itinerary, specification); _transportStatus = CalculateTransportStatus(); _lastKnownLocation = CalculateLastKnownLocation(); _currentVoyage = CalculateCurrentVoyage(); _eta = CalculateEta(itinerary); _nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary); _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification); }
public virtual void UpdateHistory(HandlingEventType?nextExpectedEvent, string nextExpectedLocation, HandlingEventType?lastKnownEvent, string lastKnownLocation, RoutingStatus routingStatus, TransportStatus transportStatus, DateTime?estimatedTimeOfArrival, bool isUnloadedAtDestination, bool isMisdirected, DateTime calculatedAt) { Delivery delivery = new Delivery(this, nextExpectedEvent, nextExpectedLocation, lastKnownEvent, lastKnownLocation, routingStatus, transportStatus, estimatedTimeOfArrival, isUnloadedAtDestination, isMisdirected, calculatedAt); DeliveryHistory.Add(delivery); CurrentInformation = delivery; }
private bool SubmitRequest(Guid requestID, ApiIdentity identity) { /** * Due to concurrency issues that are being created somehow by doing the update first * this operation is being done using a standalone datacontext and fresh data from db. * */ RoutingStatus targetStatus = RoutingStatus.AwaitingRequestApproval; using (var datacontext = new DataContext()) { var request = datacontext.Requests.Include(r => r.DataMarts.Select(rr => rr.Responses)).Include(r => r.RequestType).Single(r => r.ID == requestID); var project = datacontext.Projects.SingleOrDefault(p => p.ID == request.ProjectID); if (project == null) { /** * BMS: We used to allow a metadata request to be submitted w/o a project, however this causes the request to be lost from any view, * so now I force the request to a project until we figure out how to display requests w/o project assignments. **/ throw new Exception("Cannot submit a request outside of a Project context. Please select a Project."); } if (!project.Active || project.Deleted) { throw new Exception("Cannot submit requests for project " + project.Name + ", because the project is marked inactive."); } if (project.StartDate != null && project.StartDate > DateTime.UtcNow) { throw new Exception("Cannot submit requests for project " + project.Name + ", because the project has not started yet."); } if (project.EndDate != null && project.EndDate < DateTime.UtcNow) { throw new Exception("Cannot submit requests for project " + project.Name + ", because the project has already finished."); } var dueDate = request.DueDate; if (dueDate != null && dueDate < DateTime.UtcNow.Date) { throw new Exception("Due date must be set in the future."); } var pastDueDate = false; foreach (var dm in request.DataMarts) { if (dm.DueDate != null && dm.DueDate < DateTime.UtcNow.Date) { pastDueDate = true; } } if (pastDueDate) { throw new Exception("Request's DataMart Due dates must be set in the future."); } var grantedDataMarts = GetGrantedDataMarts(project, request.RequestTypeID, identity).ToArray(); var nonGrantedDataMartIDs = datacontext.RequestDataMarts.Where(dm => dm.RequestID == request.ID).Select(dm => dm.DataMartID).Except(grantedDataMarts.Select(d => d.ID)).ToArray(); if (nonGrantedDataMartIDs.Length > 0) { var nonGrantedDmNames = datacontext.DataMarts.Where(dm => nonGrantedDataMartIDs.Contains(dm.ID)).Select(dm => dm.Name); throw new Exception("You do not have permission to submit requests of type '" + request.RequestType.Name + "' to the following data marts: " + string.Join(", ", nonGrantedDmNames)); } // Remove datamarts that do not belong to the Project var invalidDataMarts = (from dm in datacontext.RequestDataMarts.Where(d => d.RequestID == request.ID) join pdm in datacontext.ProjectDataMarts.Where(p => p.ProjectID == request.ProjectID) on dm.DataMartID equals pdm.DataMartID into pdms where !pdms.Any() select dm).ToList(); if (invalidDataMarts.Count > 0) { datacontext.RequestDataMarts.RemoveRange(invalidDataMarts); } if (request.SubmittedOn.HasValue) { throw new Exception("Cannot submit a request that has already been submitted"); } if (request.Template) { throw new Exception("Cannot submit a request template"); } if (request.Scheduled) { throw new Exception("Cannot submit a scheduled request"); } var filters = new ExtendedQuery { Projects = (a) => a.ProjectID == request.ProjectID, ProjectOrganizations = a => a.ProjectID == request.ProjectID && a.OrganizationID == request.OrganizationID, Organizations = a => a.OrganizationID == request.OrganizationID, Users = a => a.UserID == request.CreatedByID }; if (request.DataMarts.Count < 2) { var skip2DataMartRulePerms = AsyncHelpers.RunSync(() => datacontext.HasGrantedPermissions <Request>(identity, request, filters, PermissionIdentifiers.Portal.SkipTwoDataMartRule)); if (!skip2DataMartRulePerms.Contains(PermissionIdentifiers.Portal.SkipTwoDataMartRule)) { throw new Exception("Cannot submit a request with less than 2 datamarts."); } } var permissions = AsyncHelpers.RunSync(() => datacontext.HasGrantedPermissions <Request>(identity, request, filters, PermissionIdentifiers.Request.SkipSubmissionApproval)); if (permissions.Contains(PermissionIdentifiers.Request.SkipSubmissionApproval)) { targetStatus = RoutingStatus.Submitted; } request.Status = targetStatus == RoutingStatus.Submitted ? RequestStatuses.Submitted : RequestStatuses.AwaitingRequestApproval; request.SubmittedOn = DateTime.UtcNow; request.SubmittedByID = identity.ID; //set the version on the request request.AdapterPackageVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location).FileVersion; foreach (var d in request.DataMarts) { if (grantedDataMarts.Any(dm => dm.ID == d.DataMartID)) { d.Status = targetStatus; foreach (var response in d.Responses) { response.SubmittedByID = identity.ID; response.SubmittedOn = request.SubmittedOn ?? DateTime.UtcNow; } } else { datacontext.RequestDataMarts.Remove(d); } } datacontext.SaveChanges(); //SALMAN - TODO //if (result.IsSuccess && targetStatus == RoutingStatus.Submitted) //{ // ExecuteIfLocalRequest(ctx, datacontext); //} //return result; return(true); } }
/// <summary> /// returns routing information /// </summary> /// <returns></returns> internal IList <CustomerOrderSummary> GetOrderSummary(RoutingStatus status) { return(_repos.GetOrderSummary(null, status)); }