public ResponseObj RemoveAuthorizedIdentitites([FromUri] string dataId, [FromBody] List <IdentityDescriptionObject> identityDescriptionObjects) { log.Info("Incoming request to " + GetCurrentMethod()); if (dataId == null) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Missing UVID"); } if (!FormatValidation.IsValidUvid(dataId)) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Invalid UVID format"); } if (identityDescriptionObjects == null || identityDescriptionObjects.Count == 0) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "No identities to remove"); } try { foreach (var identityDescriptionObject in identityDescriptionObjects) { // Get matching ACL-object from DB var identityToDelete = _identityService.Get(i => i.UID == identityDescriptionObject.IdentityId).FirstOrDefault(); if (identityToDelete == null) { log.Info(string.Format("Identity {0} did not exist for messageId {1}.", identityDescriptionObject.IdentityId, dataId)); return(new ResponseObj(dataId)); } var current = _aclObjectService.Get(x => x.MessageID == dataId && x.Subscriber.ID == identityToDelete.ID, includeProperties: "Subscriber").FirstOrDefault(); // If it exists, delete it if (current != null) { var subscribers = _subscriptionService.Get(s => s.MessageID == dataId && s.SubscriberIdentity.ID == current.Subscriber.ID); _aclObjectService.Delete(current); var msg = string.Format("ACL removed for identity {0} on messageId {1}.", identityDescriptionObject.IdentityId, dataId); log.Info(msg); // Remove subscriber if (subscribers != null) { foreach (var subscriber in subscribers) { msg = string.Format("Subscriber {0} removed on messageId {1}", subscriber.SubscriberIdentity.UID, dataId); _subscriptionService.Delete(subscriber); log.Info(msg); } } } } SetLastInteractionTime(); _context.SaveChanges(); return(new ResponseObj(dataId));; } catch (HttpResponseException ex) { log.Error(ex.Message, ex); throw; } catch (Exception ex) { log.Error(ex.Message, ex); string msg = "VIS internal server error. " + ex.Message; throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }
public ResponseObj RemovePublishedMessage([FromUri] string dataId) { log.Info("Incoming request to " + GetCurrentMethod()); if (!FormatValidation.IsValidUvid(dataId)) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Invalid UVID format"); } try { var message = _publishedMessageService.Get(x => x.MessageID == dataId).FirstOrDefault(); if (message == null) { var msg = string.Format("No message found with id {0}.", dataId); log.Info(msg); throw CreateHttpResponseException(HttpStatusCode.NotFound, msg); } else { // Delete subscriptions var subscriptions = _visSubscriptionService.Get(x => x.MessageID == dataId); if (subscriptions != null) { foreach (var subscription in subscriptions) { _visSubscriptionService.Delete(subscription); } } // Delete ACL var acls = _aclObjectService.Get(x => x.MessageID == dataId); if (acls != null) { foreach (var acl in acls) { _aclObjectService.Delete(acl); } } // Delete message _publishedMessageService.Delete(message); var msg = string.Format("Published message with id {0} was removed.", dataId); log.Info(msg); SetLastInteractionTime(); _context.SaveChanges(); return(new ResponseObj(dataId)); } } catch (HttpResponseException ex) { log.Error(ex.Message, ex); throw; } catch (Exception ex) { log.Error(ex.Message, ex); string msg = "VIS internal server error. " + ex.Message; throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }