Example #1
0
        public void testBuildCreateAddresseeSqlStatementExpectedException()
        {
            AddresseeDao dao   = new AddresseeDao(_cxn);
            OracleQuery  query = dao.buildCreateAddresseeQuery(new domain.sm.Addressee(), 1);

            Assert.Fail("Previous line should have thrown exception");
        }
 public void testBuildReadMessageSqlStatementWithDate()
 {
     AddresseeDao dao = new AddresseeDao(_cxn);
     OracleQuery query = dao.buildReadMessageRequest(new domain.sm.Addressee() { ReadDate = DateTime.Now });
     Assert.IsTrue(String.Equals(query.Command.CommandText, "UPDATE SMS.ADDRESSEE SET READ_DATE=:readDate, OPLOCK=:oplockPlusOne, MODIFIED_DATE=:modifiedDate WHERE ADDRESSEE_ID=:addresseeId AND OPLOCK=:oplock RETURNING SECURE_MESSAGE_ID INTO :outId"));
     Assert.IsTrue(((Oracle.DataAccess.Types.OracleDate)query.Command.Parameters["readDate"].Value).Year > 1900, "The read date should be set");
 }
Example #3
0
        public void testBuildCreateAddresseeSqlStatement()
        {
            AddresseeDao dao   = new AddresseeDao(_cxn);
            OracleQuery  query = dao.buildCreateAddresseeQuery(new domain.sm.Addressee()
            {
                Folder = new domain.sm.Folder(), Owner = new domain.sm.User()
            }, 1);

            Assert.IsTrue(String.Equals(query.Command.CommandText, "INSERT INTO SMS.ADDRESSEE (ADDRESSEE_ROLE, SECURE_MESSAGE_ID, USER_ID, FOLDER_ID) VALUES (:addresseeRole, :smId, :userId, :folderId) RETURNING ADDRESSEE_ID INTO :outId"));
        }
Example #4
0
        public void testBuildReadMessageSqlStatementWithDate()
        {
            AddresseeDao dao   = new AddresseeDao(_cxn);
            OracleQuery  query = dao.buildReadMessageRequest(new domain.sm.Addressee()
            {
                ReadDate = DateTime.Now
            });

            Assert.IsTrue(String.Equals(query.Command.CommandText, "UPDATE SMS.ADDRESSEE SET READ_DATE=:readDate, OPLOCK=:oplockPlusOne, MODIFIED_DATE=:modifiedDate WHERE ADDRESSEE_ID=:addresseeId AND OPLOCK=:oplock RETURNING SECURE_MESSAGE_ID INTO :outId"));
            Assert.IsTrue(((Oracle.DataAccess.Types.OracleDate)query.Command.Parameters["readDate"].Value).Year > 1900, "The read date should be set");
        }
Example #5
0
        public domain.sm.Addressee moveMessageToFolder(domain.sm.Addressee addressee, domain.sm.Folder newFolder)
        {
            domain.sm.Addressee dbAddressee = new AddresseeDao(_cxn).getAddressee(addressee.Id);
            if (dbAddressee == null || dbAddressee.Id <= 0)
            {
                throw new MdoException("Couldn't find that addressee record");
            }

            checkValidMove(Convert.ToInt32(dbAddressee.FolderId), Convert.ToInt32(newFolder.Id), addressee.Owner.Id);

            dbAddressee.FolderId = newFolder.Id;
            dbAddressee.Oplock   = addressee.Oplock;
            return(new AddresseeDao(_cxn).updateAddressee(dbAddressee));
        }
Example #6
0
        public void testGetAddresseesForMessageSqlStatement()
        {
            OracleQuery request = new AddresseeDao(_cxn).buildGetAddresseesForMessageQuery(1);

            Assert.IsTrue(String.Equals(request.Command.CommandText, "SELECT ADDRESSEE_ID, ADDRESSEE_ROLE, SECURE_MESSAGE_ID, USER_ID, OPLOCK AS ADDROPLOCK, FOLDER_ID, READ_DATE, REMINDER_DATE FROM SMS.ADDRESSEE WHERE SECURE_MESSAGE_ID=:messageId AND ACTIVE=1"));
        }
Example #7
0
        public dto.sm.MessageTO readMessage(string pwd, Int32 addresseeId, Int32 addresseeOplock)
        {
            MessageTO result = new MessageTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing appPwd");
            }
            else if (addresseeId <= 0)
            {
                result.fault = new FaultTO("Must supply addressee ID");
            }
            if (result.fault != null)
            {
                return result;
            }

            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AddresseeDao dao = new AddresseeDao(cxn);
                    gov.va.medora.mdo.domain.sm.Addressee addressee = dao.readMessage(new Addressee() { Id = addresseeId, Oplock = addresseeOplock });
                    MessageTO message = new MessageTO(addressee.Message);
                    message.addressees = new AddresseeTO[1] { new AddresseeTO(addressee) };
                    result = message;
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
Example #8
0
        public MessageTO moveMessage(string pwd, Int32 userId, Int32 messageId, Int32 newFolderId)
        {
            MessageTO result = new MessageTO();

            try
            {
                Message message = new Message();
                message.Id = messageId;
                message.Addressees = new List<Addressee>() { new Addressee() { FolderId = newFolderId, Owner = new User() { Id = userId } } };
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AddresseeDao dao = new AddresseeDao(cxn);
                    message.Addressees[0] = dao.moveMessage(new Message() { Id = messageId }, new User() { Id = userId }, new Folder() { Id = newFolderId });
                    result = new MessageTO(message);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }
            return result;
        }
Example #9
0
        public domain.sm.Addressee moveMessageToFolder(domain.sm.Addressee addressee, domain.sm.Folder newFolder)
        {
            domain.sm.Addressee dbAddressee = new AddresseeDao(_cxn).getAddressee(addressee.Id);
            if (dbAddressee == null || dbAddressee.Id <= 0)
            {
                throw new MdoException("Couldn't find that addressee record");
            }

            checkValidMove(Convert.ToInt32(dbAddressee.FolderId), Convert.ToInt32(newFolder.Id), addressee.Owner.Id);

            dbAddressee.FolderId = newFolder.Id;
            dbAddressee.Oplock = addressee.Oplock;
            return new AddresseeDao(_cxn).updateAddressee(dbAddressee);
        }
Example #10
0
        public void deleteDraft(Message message)
        {
            if (message == null || message.Id <= 0)
            {
                throw new MdoException("Invalid Message");
            }
            Message dbMessage = getMessageComplete(message.Id);
            if (dbMessage == null || dbMessage.Id <= 0)
            {
                throw new MdoException("No message found with that ID");
            }
            if (dbMessage.SentDate.Year > 1900)
            {
                throw new MdoException("This message is not a valid draft - already sent");
            }
            if (dbMessage.MessageThread == null || dbMessage.MessageThread.Id <= 0 || dbMessage.Addressees == null ||
                dbMessage.Addressees.Count != 1 || dbMessage.Addressees[0] == null || dbMessage.Addressees[0].Id <= 0)
            {
                throw new MdoException("Data integrity - message thread/addressee appears malformed in database");
            }
            if (dbMessage.Addressees[0].FolderId != (int)domain.sm.enums.SystemFolderEnum.Drafts)
            {
                throw new MdoException("You can only delete messages marked as DRAFT");
            }
            try
            {
                _cxn.beginTransaction();

                AddresseeDao addrDao = new AddresseeDao(_cxn);

                // turns out there might be multiple draft messages for a thread - they should all be deleted
                domain.sm.Thread msgThread = getMessagesFromThread(dbMessage.MessageThread.Id);
                foreach (Message msg in msgThread.Messages)
                {
                    IList<domain.sm.Addressee> allAddressees = addrDao.getAddresseesForMessage(msg.Id);
                    if (allAddressees != null && allAddressees.Count != 1)
                    {
                        throw new MdoException("Data integrity: Invalid draft. This draft message has more than one addressee.");
                    }

                    if (msg.SentDate.Year > 1900 || msg.CompletedDate.Year > 1900 ||
                        allAddressees[0].Owner.Id != dbMessage.Addressees[0].Owner.Id || allAddressees[0].FolderId != (Int32)domain.sm.enums.SystemFolderEnum.Drafts)
                    {
                        throw new MdoException("Data integrity: There appears to be multiple messages associated with the thread. The data is inconsistent between them.");
                    }
                    addrDao.deleteAddressee(allAddressees[0].Id);
                    deleteMessage(msg.Id);
                }

                // see if there were any attachments for this draft message
                if (dbMessage.Attachment)
                {
                    AttachmentDao attachDao = new AttachmentDao(_cxn);
                    attachDao.deleteAttachment(Convert.ToInt32(dbMessage.AttachmentId));
                }

                deleteThread(dbMessage.MessageThread.Id);

                _cxn.commitTransaction();
            }
            catch (Exception)
            {
                _cxn.rollbackTransaction();
                throw;
            }
        }
Example #11
0
        public Message sendDraft(Message message)
        {
            if (message == null || message.Id <= 0)
            {
                throw new MdoException("Invalid message");
            }

            Message dbMessage = getMessageComplete(message.Id);
            if (dbMessage == null || dbMessage.Id <= 0)
            {
                throw new MdoException("No message found for that ID");
            }
            if (dbMessage.SentDate.Year > 1900)
            {
                throw new MdoException("This message has already been sent");
            }
            if (dbMessage.Addressees == null || dbMessage.Addressees.Count != 1)
            {
                throw new MdoException("Data integrity - message appears to be addressed to multiple recipients");
            }
            // set addressee properties for sender
            dbMessage.Addressees[0].Folder = new Folder() { Id = (Int32)domain.sm.enums.SystemFolderEnum.Sent, Name = Enum.GetName(typeof(domain.sm.enums.SystemFolderEnum), domain.sm.enums.SystemFolderEnum.Sent) };
            dbMessage.Addressees[0].FolderId = (Int32)domain.sm.enums.SystemFolderEnum.Sent;
            dbMessage.Addressees[0].Role = domain.sm.enums.AddresseeRoleEnum.SENDER;
            if (message.Addressees != null && message.Addressees[0] != null)
            {
                dbMessage.Addressees[0].Oplock = message.Addressees[0].Oplock;
            }

            dbMessage.SentDate = DateTime.Now;
            dbMessage.Oplock = message.Oplock; // need to copy this over because it came from the client
            // this function should really just update a DRAFT - not also try and update the message first
            //dbMessage.Body = message.Body;
            //dbMessage.Checksum = gov.va.medora.utils.StringUtils.getMD5Hash(message.Body);
            //if (message.MessageThread != null && message.MessageThread.MailGroup != null && message.MessageThread.MailGroup.Id > 0 && message.MessageThread.MailGroup.Id != dbMessage.MessageThread.MailGroup.Id)
            //{
            //    if (message.MessageThread.MessageCategoryType != dbMessage.MessageThread.MessageCategoryType)
            //    {
            //        dbMessage.MessageThread.MessageCategoryType = message.MessageThread.MessageCategoryType;
            //    }
            //    if (!String.IsNullOrEmpty(message.MessageThread.Subject) && !String.Equals(dbMessage.MessageThread.Subject, message.MessageThread.Subject))
            //    {
            //        dbMessage.MessageThread.Subject = message.MessageThread.Subject;
            //    }
            //    if (message.MessageThread.MailGroup != null && message.MessageThread.MailGroup.Id > 0 && dbMessage.MessageThread.MailGroup.Id != message.MessageThread.MailGroup.Id)
            //    {
            //        dbMessage.MessageThread.MailGroup.Id = message.MessageThread.MailGroup.Id;
            //    }
            //    dbMessage.MessageThread.Oplock = message.MessageThread.Oplock;
            //}

            message = prepareMessage(dbMessage);
            message.Addressees.RemoveAt(1); // the prepare message function adds the sender again - we already did that with the call to getMessageComplete. Kinda hokey...

            try
            {
                _cxn.beginTransaction();
                // since not trying to update message, nothing should change in thread
                //dbMessage.MessageThread = updateThread(dbMessage.MessageThread);
                message = updateMessage(dbMessage);
                AddresseeDao addrDao = new AddresseeDao(_cxn);
                addrDao.updateAddressee(dbMessage.Addressees[0]); // update folder for sender
                addrDao.createAddressees(message.Addressees.GetRange(1, message.Addressees.Count - 1), message.Id);
                _cxn.commitTransaction();
            }
            catch (Exception)
            {
                _cxn.rollbackTransaction();
                throw;
            }
            return message;
        }
Example #12
0
        public Message saveDraft(Message message)
        {
            if (message == null || String.IsNullOrEmpty(message.Body) || message.MessageThread == null || message.CompletedDate.Year > 1900)
            {
                throw new MdoException("Invalid message");
            }
            if (message.SenderId <= 0)
            {
                throw new MdoException("Invalid user ID");
            }
            //if (message.MessageThread != null && message.MessageThread.Id > 0)
            //{
            //    throw new MdoException("Can't save more than on draft message to a thread");
            //}
            domain.sm.User sender = new UserDao(_cxn).getUserById(Convert.ToInt32(message.SenderId));
            if (sender == null)
            {
                throw new MdoException("No user found with that ID");
            }

            // is draft new or should we update
            if (message.Id > 0)
            {
                // get message - see if it's ripe for updating
                Message dbMessage = getMessageComplete(message.Id);
                if (dbMessage == null || dbMessage.Id <= 0 || dbMessage.MessageThread == null || dbMessage.MessageThread.Id <= 0 || dbMessage.Addressees == null ||
                    dbMessage.Addressees.Count != 1)
                {
                    throw new MdoException("Invalid message ID");
                }
                if (dbMessage.SenderId != message.SenderId || dbMessage.Addressees[0].Owner.Id != message.SenderId)
                {
                    throw new MdoException("Can't edit another user's messages");
                }
                if (dbMessage.SentDate.Year > 1900 || dbMessage.CompletedDate.Year > 1900)
                {
                    throw new MdoException("This message has already been sent - not a valid draft");
                }
                if (dbMessage.Addressees.Count > 1)
                {
                    throw new MdoException("Data integrity - this message has already been addressed to more than one user");
                }
                // need to copy over important fields before we assign dbMessage to message
                dbMessage.Body = message.Body;
                dbMessage.Checksum = gov.va.medora.utils.StringUtils.getMD5Hash(message.Body);
                dbMessage.Oplock = message.Oplock; // need to copy this over because it came from the client
                // if mail group changed
                if (message.MessageThread != null && message.MessageThread.MailGroup != null && message.MessageThread.MailGroup.Id > 0 && message.MessageThread.MailGroup.Id != dbMessage.MessageThread.MailGroup.Id)
                {
                    dbMessage.MessageThread.MailGroup = message.MessageThread.MailGroup;
                }
                // TODO - figure out copying over of message thread properties
                dbMessage.MessageThread.MessageCategoryType = message.MessageThread.MessageCategoryType;
                dbMessage.MessageThread.Subject = message.MessageThread.Subject;
                dbMessage.MessageThread.Oplock = message.MessageThread.Oplock;

                if (message.RecipientId > 0 && dbMessage.RecipientId != message.RecipientId)
                {
                    checkValidMessageRecipient(message, sender);
                    dbMessage.RecipientId = message.RecipientId;
                    dbMessage.RecipientName = message.RecipientName;
                    dbMessage.RecipientType = message.RecipientType;
                }
                message = dbMessage;

                try
                {
                    _cxn.beginTransaction();
                    updateThread(dbMessage.MessageThread);
                    message = updateMessage(dbMessage);
                    message.MessageThread = dbMessage.MessageThread;
                    _cxn.commitTransaction();
                }
                catch (Exception)
                {
                    _cxn.rollbackTransaction();
                    throw;
                }

            }
            else
            {
                if (message.MessageThread == null)
                {
                    throw new MdoException("No thread defined for new draft message");
                }

                message.SenderId = sender.Id;
                message.SenderName = sender.getName();
                message.SenderType = sender.ParticipantType;

                if (sender.ParticipantType == domain.sm.enums.ParticipantTypeEnum.PATIENT)
                {
                    checkValidMessageRecipientPatient(message);
                }
                else if (sender.ParticipantType == domain.sm.enums.ParticipantTypeEnum.CLINICIAN)
                {
                    checkValidMessageRecipientProvider(message);
                }
                try
                {
                    _cxn.beginTransaction();
                    domain.sm.Thread t = null;
                    if (message.MessageThread.Id <= 0)
                    {
                        t = createThread(message.MessageThread);
                    }
                    else
                    {
                        t = getThread(message.MessageThread.Id);
                        if (t == null || t.Id <= 0)
                        {
                            throw new MdoException("No thread found for that thread ID");
                        }
                    }
                    message = createMessage(message);
                    message.MessageThread = t;
                    AddresseeDao addrDao = new AddresseeDao(_cxn);
                    addrDao.addSenderToMessage(sender, message);
                    addrDao.createAddressees(message.Addressees, message.Id);
                    _cxn.commitTransaction();
                }
                catch (Exception)
                {
                    _cxn.rollbackTransaction();
                    throw;
                }
            }

            return message;
        }
Example #13
0
        internal Message preparePatientReply(Message original, Message reply, domain.sm.User sender)
        {
            if (original.MessageThread == null || original.MessageThread.MailGroup == null || original.MessageThread.MailGroup.Id <= 0)
            {
                throw new MdoException("No message thread or triage group defined");
            }
            reply.SenderType = sender.ParticipantType;
            reply.SenderName = sender.getName();
            reply.RecipientId = original.MessageThread.MailGroup.Id;
            checkValidMessageRecipientPatient(reply); // One would *think* the above line would validate this but, just in case there was some previous data integrity issue, we should check anyways. The helper function also sets other parameters (group name, etc) so not a wasted call

            AddresseeDao addrDao = new AddresseeDao(_cxn);
            addrDao.addSenderToMessage(sender, reply);
            addrDao.addRecipientsToMessage(Convert.ToInt32(reply.RecipientId), reply);

            return reply;
        }
 public void testGetAddresseesForMessageSqlStatement()
 {
     OracleQuery request = new AddresseeDao(_cxn).buildGetAddresseesForMessageQuery(1);
     Assert.IsTrue(String.Equals(request.Command.CommandText, "SELECT ADDRESSEE_ID, ADDRESSEE_ROLE, SECURE_MESSAGE_ID, USER_ID, OPLOCK AS ADDROPLOCK, FOLDER_ID, READ_DATE, REMINDER_DATE FROM SMS.ADDRESSEE WHERE SECURE_MESSAGE_ID=:messageId AND ACTIVE=1"));
 }
 public void testBuildCreateAddresseeSqlStatementExpectedException()
 {
     AddresseeDao dao = new AddresseeDao(_cxn);
     OracleQuery query = dao.buildCreateAddresseeQuery(new domain.sm.Addressee(), 1);
     Assert.Fail("Previous line should have thrown exception");
 }
 public void testBuildCreateAddresseeSqlStatement()
 {
     AddresseeDao dao = new AddresseeDao(_cxn);
     OracleQuery query = dao.buildCreateAddresseeQuery(new domain.sm.Addressee() { Folder = new domain.sm.Folder(), Owner = new domain.sm.User() }, 1);
     Assert.IsTrue(String.Equals(query.Command.CommandText, "INSERT INTO SMS.ADDRESSEE (ADDRESSEE_ROLE, SECURE_MESSAGE_ID, USER_ID, FOLDER_ID) VALUES (:addresseeRole, :smId, :userId, :folderId) RETURNING ADDRESSEE_ID INTO :outId"));
 }