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); }
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()))); }