/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="dataId"></param> public void SendMessageToSubsribers(string message, string dataId) { //call proxy class to SSC -> callservice for each subscriber var subscriptions = _subscriberService.Get(x => x.MessageID == dataId && x.IsAuthorized, includeProperties: "SubscriberIdentity"); if (subscriptions == null) { return; } foreach (var subscription in subscriptions) { // If no queueId setup new queue if (string.IsNullOrEmpty(subscription.QueueId)) { var queueId = SetupQueue(message, dataId, subscription.MbEndpoint, subscription.SubscriberIdentity); subscription.QueueId = queueId; _subscriberService.Update(subscription); } // Send PCM to AMSS service SendToAmssService(message, dataId, subscription.AmssEndpoint, subscription.SubscriberIdentity); } }
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); } }
public ResponseObj AddSubscription([FromBody] List <SubscriptionObject> subscriptions, [FromUri] string dataId) { log.Info("Incoming request to " + GetCurrentMethod()); if (string.IsNullOrEmpty(dataId)) { throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Missing required parameter dataID."); } var responseText = string.Empty; try { foreach (var subscription in subscriptions) { var mbUri = subscription.MbEndpointURL.ToString().ToLower(); var amssUri = subscription.AmssEndpointURL.ToString().ToLower(); var entity = _SpisSubscriptionService.Get(s => s.SubscriberIdentity.UID == subscription.IdentityId && s.MessageID == dataId && s.MbEndpoint.ToLower() == mbUri && s.AmssEndpoint.ToLower() == amssUri, includeProperties: "SubscriberIdentity, MessageType").FirstOrDefault(); if (entity == null) { responseText += string.Format("Subscription for dataId:{0} mb endpoint: {1} amss endpoint {2} was created\r\n", dataId, mbUri, amssUri); var acl = _aCLObjectService.Get(i => i.MessageID == dataId && i.Subscriber.UID == subscription.IdentityId).FirstOrDefault(); if (acl == null) { log.Debug(string.Format("No access for identity {0}", subscription.IdentityId)); throw CreateHttpResponseException(HttpStatusCode.Forbidden, string.Format("No access for identity {0}", subscription.IdentityId)); } entity = new SpisSubscription(); entity.MessageID = dataId; entity.IsAuthorized = true; entity.MbEndpoint = subscription.MbEndpointURL.ToString(); entity.AmssEndpoint = subscription.AmssEndpointURL.ToString(); entity.MessageType = _messageTypeService.Get(x => x.Name.ToLower() == "rtz").FirstOrDefault(); entity.SubscriberIdentity = _identityService.Get(x => x.UID == subscription.IdentityId).FirstOrDefault(); _SpisSubscriptionService.Insert(entity); _context.SaveChanges(); } else { responseText += string.Format("Subscription for dataId:{0} mb endpoint: {1} amss endpoint {2} already exists\r\n", dataId, mbUri, amssUri); if (entity.IsAuthorized == false) { entity.IsAuthorized = true; _SpisSubscriptionService.Update(entity); } } // Send message to PortCDM var message = _publishedMessageService.Get(x => x.MessageID == dataId).FirstOrDefault(); string messageString = null; if (message != null) { messageString = System.Text.Encoding.UTF8.GetString(message.Message); } entity.QueueId = _publishedMessageService.SendMessage(messageString, dataId, subscription.MbEndpointURL.ToString(), subscription.AmssEndpointURL.ToString(), new Identity { UID = subscription.IdentityId, Name = subscription.IdentityName }); responseText += string.Format("Port CDM queue was created with id: {0}\r\n", entity.QueueId); _SpisSubscriptionService.Update(entity); _context.SaveChanges(); } log.Debug(responseText); 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); } }