コード例 #1
0
        public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromUri] Guid id, [FromUri] string phaseName, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.UPDATE, RightValue.APPROVED));

            preventPagingHeaders();

            string body = Request.Content.ReadAsStringAsync().Result;

            try
            {
                IFunctionalService service = getService(serviceName);
                if (SettingsManager.ProviderSettings.JobBinding &&
                    !service.IsBound(id, getOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException("Request failed as the job referred to in this request does not belong to this consumer.");
                }
                return(OKResult(service.DeleteToPhase(id, phaseName, body, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]), contentType: HttpUtils.GetContentType(Request), accept: HttpUtils.GetAccept(Request))));
            }
            catch (ArgumentException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid argument: id=" + id + ", phaseName=" + phaseName + ".\n" + e.Message));
            }
            catch (DeleteException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Problem deleting data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (RejectedException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Problem deleting data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Request failed for phase " + phaseName + " in job " + id + ".\n " + e.Message));
            }
        }
コード例 #2
0
        public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromUri] Guid id, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.DELETE, RightValue.APPROVED));

            try
            {
                IFunctionalService service = getService(serviceName);

                if (SettingsManager.ProviderSettings.JobBinding &&
                    !service.IsBound(id, getOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException("Request failed as one or more jobs referred to in this request do not belong to this consumer.");
                }

                service.Delete(id, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                if (SettingsManager.ProviderSettings.JobBinding)
                {
                    service.Unbind(id);
                }
            }
            catch (Exception e)
            {
                string errorMessage = "The DELETE request failed for a " + serviceName + " job with an ID of " + id + " due to the following error:\n " + e.Message;
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
            }

            HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.NoContent);

            return(result);
        }
コード例 #3
0
        public virtual HttpResponseMessage Get([FromUri] string serviceName, [FromUri] Guid id, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.QUERY, RightValue.APPROVED));

            // Check that we support that provider
            // if not then throw new HttpResponseException(HttpStatusCode.NotFound);

            jobType item;

            try
            {
                IFunctionalService service = getService(serviceName);
                item = service.Retrieve(id, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                if (SettingsManager.ProviderSettings.JobBinding &&
                    !service.IsBound(Guid.Parse(item.id), getOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException("Request failed as one or more jobs referred to in this request do not belong to this consumer.");
                }
            }
            catch (Exception e)
            {
                string errorMessage = "The GET request failed for a " + serviceName + " job with an ID of " + id + " due to the following error:\n " + e.Message;
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
            }

            if (item == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            HttpResponseMessage result = Request.CreateResponse <jobType>(HttpStatusCode.OK, item);

            return(result);
        }
コード例 #4
0
        public virtual ICollection <jobType> Get([FromUri] string serviceName, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.QUERY, RightValue.APPROVED));

            ICollection <jobType> items = new List <jobType>();

            try
            {
                IFunctionalService    service = getService(serviceName);
                ICollection <jobType> jobs    = service.Retrieve(zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));
                foreach (jobType job in jobs)
                {
                    if (!SettingsManager.ProviderSettings.JobBinding ||
                        service.IsBound(Guid.Parse(job.id), getOwnerId(sessionToken)))
                    {
                        items.Add(job);
                    }
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The GET request failed for functional services due to the following error:\n " + e.Message));
            }

            if (items == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(items);
        }
コード例 #5
0
        public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromBody] deleteRequestType deleteRequest, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.DELETE, RightValue.APPROVED));

            IFunctionalService         service  = getService(serviceName);
            ICollection <deleteStatus> statuses = new List <deleteStatus>();

            foreach (deleteIdType deleteId in deleteRequest.deletes)
            {
                try
                {
                    if (SettingsManager.ProviderSettings.JobBinding &&
                        !service.IsBound(Guid.Parse(deleteId.id), getOwnerId(sessionToken)))
                    {
                        throw new InvalidSessionException("Request failed as job does not belong to this consumer.");
                    }

                    service.Delete(Guid.Parse(deleteId.id), zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                    if (SettingsManager.ProviderSettings.JobBinding)
                    {
                        service.Unbind(Guid.Parse(deleteId.id));
                    }

                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.OK, deleteId.id));
                }
                catch (ArgumentException e)
                {
                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.BadRequest, deleteId.id, ProviderUtils.CreateError(HttpStatusCode.BadRequest, serviceName, "Invalid argument: id=" + deleteId.id + ".\n" + e.Message)));
                }
                catch (DeleteException e)
                {
                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.BadRequest, deleteId.id, ProviderUtils.CreateError(HttpStatusCode.BadRequest, serviceName, "Request failed for object " + serviceName + " with ID of " + deleteId.id + ".\n " + e.Message)));
                }
                catch (NotFoundException e)
                {
                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.NotFound, deleteId.id, ProviderUtils.CreateError(HttpStatusCode.BadRequest, serviceName, "Object " + serviceName + " with ID of " + deleteId.id + " not found.\n" + e.Message)));
                }
                catch (InvalidSessionException e)
                {
                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.BadRequest, deleteId.id, ProviderUtils.CreateError(HttpStatusCode.BadRequest, serviceName, "Request failed for object " + serviceName + " with ID of " + deleteId.id + ", job doesn't belong to this consumer.\n " + e.Message)));
                }
                catch (Exception e)
                {
                    statuses.Add(ProviderUtils.CreateDelete(HttpStatusCode.InternalServerError, deleteId.id, ProviderUtils.CreateError(HttpStatusCode.BadRequest, serviceName, "Request failed for object " + serviceName + " with ID of " + deleteId.id + ".\n " + e.Message)));
                }
            }

            return(Request.CreateResponse <deleteResponseType>(HttpStatusCode.OK, ProviderUtils.CreateDeleteResponse(statuses.ToArray())));
        }
コード例 #6
0
        public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri] Guid id, [FromUri] string phaseName, [FromBody] stateType item, [MatrixParameter] string[] zone = null, [MatrixParameter] string[] context = null)
        {
            string sessionToken = CheckAuthorisation(serviceName, zone, context, new Right(RightType.UPDATE, RightValue.APPROVED));

            preventPagingHeaders();

            HttpResponseMessage result;

            try
            {
                IFunctionalService service = getService(serviceName);
                if (SettingsManager.ProviderSettings.JobBinding &&
                    !service.IsBound(id, getOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException("Request failed as the job referred to in this request does not belong to this consumer.");
                }
                stateType state = service.CreateToState(id, phaseName, item, zone: (zone == null ? null : zone[0]), context: (context == null ? null : context[0]));

                string uri = Url.Link("ServiceStatesRoute", new { controller = serviceName, id = id, phaseName = phaseName, stateId = state.id });
                result = Request.CreateResponse <stateType>(HttpStatusCode.Created, state);
                result.Headers.Location = new Uri(uri);
            }
            catch (ArgumentException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid argument: id=" + id + ", phaseName=" + phaseName + ".\n" + e.Message));
            }
            catch (CreateException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Problem creating state data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (RejectedException e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Problem creating state data for " + phaseName + "@" + id + ".\n", e));
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Request failed for creating state for phase " + phaseName + " in job " + id + ".\n " + e.Message));
            }

            return(result);
        }
コード例 #7
0
        public virtual HttpResponseMessage Put(
            [FromUri] string serviceName,
            [FromUri] Guid id,
            [FromUri] string phaseName,
            [MatrixParameter] string[] zoneId    = null,
            [MatrixParameter] string[] contextId = null)
        {
            string sessionToken =
                CheckAuthorisation(serviceName, zoneId, contextId, new Right(RightType.UPDATE, RightValue.APPROVED));
            string body = Request.Content.ReadAsStringAsync().Result;

            try
            {
                IFunctionalService service = GetService(serviceName);

                if (ProviderSettings.JobBinding && !service.IsBound(id, GetOwnerId(sessionToken)))
                {
                    throw new InvalidSessionException(
                              "Request failed as the job referred to in this request does not belong to this consumer.");
                }

                return(OkResult(
                           service.UpdateToPhase(
                               id,
                               phaseName,
                               body,
                               zoneId?[0],
                               contextId?[0],
                               HttpUtils.GetContentType(Request), HttpUtils.GetAccept(Request))));
            }
            catch (ArgumentException e)
            {
                throw new HttpResponseException(
                          Request.CreateErrorResponse(
                              HttpStatusCode.BadRequest,
                              "Invalid argument for Phase " + phaseName + " in job " + id + ".\n" + e.Message));
            }
            catch (UpdateException e)
            {
                throw new HttpResponseException(
                          Request.CreateErrorResponse(
                              HttpStatusCode.BadRequest,
                              "Problem updating data for " + phaseName + "@" + id + ".\n",
                              e));
            }
            catch (RejectedException e)
            {
                throw new HttpResponseException(
                          Request.CreateErrorResponse(
                              HttpStatusCode.Unauthorized,
                              "Problem updating data for " + phaseName + "@" + id + ".\n",
                              e));
            }
            catch (Exception e)
            {
                throw new HttpResponseException(
                          Request.CreateErrorResponse(
                              HttpStatusCode.InternalServerError,
                              "Request failed for phase " + phaseName + " in job " + id + ".\n " + e.Message,
                              e));
            }
        }