Example #1
0
        public ResponseObj RemoveSubscriptions([FromUri] string dataId, [FromBody] List <SubscriptionObject> subscriptionObjects)
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            try
            {
                foreach (var subscriptionObject in subscriptionObjects)
                {
                    var identityToDelete = _identityService.Get(i => i.UID == subscriptionObject.IdentityId).FirstOrDefault();
                    if (identityToDelete == null)
                    {
                        log.Info(string.Format("Identity {0} did not exist for messageId {1}.", subscriptionObject.IdentityId, dataId));
                        return(new ResponseObj(dataId));
                    }

                    var mbUrl   = subscriptionObject.MbEndpointURL.ToString().ToLower();
                    var amssUrl = subscriptionObject.AmssEndpointURL.ToString().ToLower();

                    var currentSub = _SpisSubscriptionService.Get(s => s.MessageID == dataId &&
                                                                  s.SubscriberIdentity.UID == subscriptionObject.IdentityId &&
                                                                  s.AmssEndpoint == amssUrl &&
                                                                  s.MbEndpoint == mbUrl).FirstOrDefault();

                    if (currentSub != null)
                    {
                        //Delete it
                        _SpisSubscriptionService.Delete(currentSub);
                        var msg = string.Format("Subscription removed for identity {0} on messageId {1}.", subscriptionObject.IdentityId, dataId);
                        log.Info(msg);
                    }
                }

                _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 = "SPIS internal server error. " + ex.Message;
                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg);
            }
        }
        public ResponseObj RemoveAuthorizedIdentitites([FromUri] string dataId,
                                                       [FromBody] List <IdentityDescriptionObject> identityDescriptionObjects)
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            if (dataId == null)
            {
                throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Missing dataID");
            }

            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 = _SpisSubscriptionService.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);
                                _SpisSubscriptionService.Delete(subscriber);
                                log.Info(msg);
                            }
                        }
                    }
                }

                _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 = "SPIS internal server error. " + ex.Message;

                throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg);
            }
        }
        public ResponseObj RemovePublishedMessage([FromUri] string dataId)
        {
            log.Info("Incoming request to " + GetCurrentMethod());

            if (string.IsNullOrEmpty(dataId))
            {
                throw CreateHttpResponseException(HttpStatusCode.BadRequest, "DataID is requeird");
            }

            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 = _spisSubscriptionService.Get(x => x.MessageID == dataId);
                    if (subscriptions != null)
                    {
                        foreach (var subscription in subscriptions)
                        {
                            _spisSubscriptionService.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);

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