Ejemplo n.º 1
0
        private static void ResetExampleUcTestInstitutionalAgreement1()
        {
            var db = ServiceProviderLocator.Current.GetService<IWrapDataConcerns>();

            var entityId = new Guid("e8b53211-5b60-4b75-9c1a-e82f881a33a0");
            var agreement = db.Commands.Get<InstitutionalAgreement>().SingleOrDefault(a => a.EntityId == entityId);
            if (agreement != null)
            {
                db.Commands.Purge(agreement);
                db.UnitOfWork.SaveChanges();
            }
            var uc = db.Commands.Get<Establishment>().ByEmail("@uc.edu");
            agreement = new InstitutionalAgreement
            {
                EntityId = entityId,
                Type = "Activity Agreement",
                Title = "Agreement, UC 01 test",
                StartsOn = DateTime.Parse("8/1/2009"),
                ExpiresOn = DateTime.Parse("7/31/2014"),
                Status = "Active",
                IsTitleDerived = false,
                IsAutoRenew = false,
                Description = "This multilateral agreement is between four (4) institutions: the University of Cincinnati (U.S. lead institution), the University of Florida, the Universidade Federal do Rio de Janeiro (Brazilian lead institution), and the Universidade Federal do Parana. \r\n\r\nAgreement is for undergraduate and graduate student exchange. \r\n\r\nThis agreement actually contains two different end dates: Page 1, Article 4, cites a four-year span, ending July 31, 2013. Page 5, Article 22, says it is a 5-year span.",
                Participants = new List<InstitutionalAgreementParticipant>
                {
                    new InstitutionalAgreementParticipant{ Establishment = uc, IsOwner = true, },
                    new InstitutionalAgreementParticipant{ Establishment = db.Commands.Get<Establishment>().Single(e => e.WebsiteUrl == "www.ufl.edu"), },
                    new InstitutionalAgreementParticipant{ Establishment = db.Commands.Get<Establishment>().Single(e => e.WebsiteUrl == "www.ufrj.br"), },
                    new InstitutionalAgreementParticipant{ Establishment = db.Commands.Get<Establishment>().Single(e => e.WebsiteUrl == "www.ufpr.br"), },
                },
            };
            db.Commands.Create(agreement);
            db.UnitOfWork.SaveChanges();
        }
 public void HasGetSet()
 {
     var value = new List<InstitutionalAgreement> { new InstitutionalAgreement() };
     var entity = new InstitutionalAgreement { Children = value };
     entity.ShouldNotBeNull();
     entity.Children.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new InstitutionalAgreement();
     var entity = new InstitutionalAgreementNode { Ancestor = value };
     entity.ShouldNotBeNull();
     entity.Ancestor.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new InstitutionalAgreement();
     var entity = new InstitutionalAgreementNode { Offspring = value };
     entity.ShouldNotBeNull();
     entity.Offspring.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new InstitutionalAgreement();
     var entity = new InstitutionalAgreementFile { Agreement = value };
     entity.ShouldNotBeNull();
     entity.Agreement.ShouldEqual(value);
 }
Ejemplo n.º 6
0
        private void ClearNodesRecursive(InstitutionalAgreement umbrella)
        {
            // ensure that the offspring and children properties are not null
            umbrella.Offspring = umbrella.Offspring ?? new List <InstitutionalAgreementNode>();
            umbrella.Children  = umbrella.Children ?? new List <InstitutionalAgreement>();

            // delete all of this umbrella's offspring nodes
            while (umbrella.Offspring.FirstOrDefault() != null)
            {
                _entities.Purge(umbrella.Offspring.First());
            }

            // operate recursively over children
            foreach (var child in umbrella.Children)
            {
                // ensure that the child's ancestor nodes are not null
                child.Ancestors = child.Ancestors ?? new List <InstitutionalAgreementNode>();

                // delete each of the child's ancestor nodes
                while (child.Ancestors.FirstOrDefault() != null)
                {
                    _entities.Purge(child.Ancestors.First());
                }

                // run this method again on the child
                ClearNodesRecursive(child);
            }
        }
Ejemplo n.º 7
0
        private static void BuildNodesRecursive(InstitutionalAgreement umbrella)
        {
            // operate recursively over children
            foreach (var child in umbrella.Children)
            {
                // create & add ancestor node for this child
                var node = new InstitutionalAgreementNode
                {
                    Ancestor   = umbrella,
                    Offspring  = child,
                    Separation = 1,
                };
                child.Ancestors.Add(node);

                // ensure the umbrella's ancestors nodes are not null
                umbrella.Ancestors = umbrella.Ancestors ?? new List <InstitutionalAgreementNode>();

                // loop over the umbrella's ancestors
                foreach (var ancestor in umbrella.Ancestors)
                {
                    // create & add ancestor node for this child
                    node = new InstitutionalAgreementNode
                    {
                        Ancestor   = ancestor.Ancestor,
                        Offspring  = child,
                        Separation = ancestor.Separation + 1,
                    };
                    child.Ancestors.Add(node);
                }

                // run this method again on the child
                BuildNodesRecursive(child);
            }
        }
 public void HasGetSet()
 {
     const string value = "text";
     var entity = new InstitutionalAgreement { Status = value };
     entity.ShouldNotBeNull();
     entity.Status.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     const bool value = true;
     var entity = new InstitutionalAgreement { IsExpirationEstimated = value };
     entity.ShouldNotBeNull();
     entity.IsExpirationEstimated.ShouldEqual(value);
 }
Ejemplo n.º 10
0
 public UpdateInstitutionalAgreementHierarchyCommand(InstitutionalAgreement institutionalAgreement)
 {
     if (institutionalAgreement == null)
     {
         throw new ArgumentNullException("institutionalAgreement");
     }
     InstitutionalAgreement = institutionalAgreement;
 }
 private void DeriveNodes(InstitutionalAgreement agreement, InstitutionalAgreement previousUmbrella)
 {
     _hierarchyHandler.Handle(new UpdateInstitutionalAgreementHierarchyCommand(agreement));
     if (previousUmbrella != null &&
         (agreement.Umbrella == null || agreement.Umbrella.EntityId != previousUmbrella.EntityId))
     {
         _hierarchyHandler.Handle(new UpdateInstitutionalAgreementHierarchyCommand(previousUmbrella));
     }
 }
Ejemplo n.º 12
0
            public void HasGetSet()
            {
                const string value  = "text";
                var          entity = new InstitutionalAgreement {
                    Status = value
                };

                entity.ShouldNotBeNull();
                entity.Status.ShouldEqual(value);
            }
Ejemplo n.º 13
0
            public void HasGetSet()
            {
                const bool value  = true;
                var        entity = new InstitutionalAgreement {
                    IsExpirationEstimated = value
                };

                entity.ShouldNotBeNull();
                entity.IsExpirationEstimated.ShouldEqual(value);
            }
            public void HasGetSet()
            {
                var value  = new InstitutionalAgreement();
                var entity = new InstitutionalAgreementNode {
                    Offspring = value
                };

                entity.ShouldNotBeNull();
                entity.Offspring.ShouldEqual(value);
            }
            public void HasGetSet()
            {
                var value  = new InstitutionalAgreement();
                var entity = new InstitutionalAgreementNode {
                    Ancestor = value
                };

                entity.ShouldNotBeNull();
                entity.Ancestor.ShouldEqual(value);
            }
Ejemplo n.º 16
0
            public void HasGetSet()
            {
                var value  = new InstitutionalAgreement();
                var entity = new InstitutionalAgreementContact {
                    Agreement = value
                };

                entity.ShouldNotBeNull();
                entity.Agreement.ShouldEqual(value);
            }
Ejemplo n.º 17
0
            public void HasGetSet()
            {
                var value = new List <InstitutionalAgreementFile> {
                    new InstitutionalAgreementFile()
                };
                var entity = new InstitutionalAgreement {
                    Files = value
                };

                entity.ShouldNotBeNull();
                entity.Files.ShouldEqual(value);
            }
Ejemplo n.º 18
0
            public void HasGetSet()
            {
                var value = new List <InstitutionalAgreement> {
                    new InstitutionalAgreement()
                };
                var entity = new InstitutionalAgreement {
                    Children = value
                };

                entity.ShouldNotBeNull();
                entity.Children.ShouldEqual(value);
            }
Ejemplo n.º 19
0
            public void HasGetSet()
            {
                var value = new List <InstitutionalAgreementContact> {
                    new InstitutionalAgreementContact()
                };
                var entity = new InstitutionalAgreement {
                    Contacts = value
                };

                entity.ShouldNotBeNull();
                entity.Contacts.ShouldEqual(value);
            }
Ejemplo n.º 20
0
            public void HasGetSet()
            {
                var value = new List <InstitutionalAgreementParticipant> {
                    new InstitutionalAgreementParticipant()
                };
                var entity = new InstitutionalAgreement {
                    Participants = value
                };

                entity.ShouldNotBeNull();
                entity.Participants.ShouldEqual(value);
            }
Ejemplo n.º 21
0
        internal AddParticipantToAgreementCommand(IPrincipal principal, Guid establishmentGuid, InstitutionalAgreement agreement)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }
            Principal = principal;

            if (establishmentGuid == Guid.Empty)
            {
                throw new ArgumentException("Cannot be empty", "establishmentGuid");
            }
            EstablishmentGuid = establishmentGuid;

            if (agreement == null)
            {
                throw new ArgumentNullException("agreement");
            }
            Agreement = agreement;
        }
Ejemplo n.º 22
0
        internal AttachFileToAgreementCommand(IPrincipal principal, Guid fileGuid, InstitutionalAgreement agreement)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }
            Principal = principal;

            if (fileGuid == Guid.Empty)
            {
                throw new ArgumentException("Cannot be empty", "fileGuid");
            }
            FileGuid = fileGuid;

            if (agreement == null)
            {
                throw new ArgumentNullException("agreement");
            }
            Agreement = agreement;
        }
        public void Handle(CreateOrUpdateInstitutionalAgreementCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // start with an agreement entity
            var entity = _entities.Get <InstitutionalAgreement>()
                         .EagerLoad(_entities, new Expression <Func <InstitutionalAgreement, object> >[]
            {
                a => a.Umbrella,
            })
                         .By(command.RevisionId);

            if (entity == null && command.RevisionId == 0)
            {
                entity = new InstitutionalAgreement();
            }
            if (entity == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Agreement with id '{0}' does not exist", command.RevisionId));
            }

            // update scalars
            CopyScalars(command, entity);

            // scenario 1: no previous umbrella, no current umbrella.
            // scenario 2: no previous umbrella, with current umbrella.
            // scenario 3: with previous umbrella, same current umbrella.
            // scenario 4: with previous umbrella, different current umbrella.
            // scenario 5: with previous umbrella, no current umbrella.
            var previousUmbrella = entity.Umbrella;

            if (command.UmbrellaEntityId.HasValue &&
                (previousUmbrella == null || previousUmbrella.EntityId != command.UmbrellaEntityId.Value))
            {
                entity.Umbrella = _entities.Get <InstitutionalAgreement>().By(command.UmbrellaEntityId.Value);
                ++command.ChangeCount;
            }
            else if (previousUmbrella != null && !command.UmbrellaEntityId.HasValue)
            {
                entity.Umbrella = null;
                ++command.ChangeCount;
            }

            #region Participants

            if (command.RemoveParticipantEstablishmentEntityIds != null)
            {
                foreach (var removedParticipantEstablishmentId in command.RemoveParticipantEstablishmentEntityIds)
                {
                    var remove = new RemoveParticipantFromAgreementCommand(
                        command.Principal, removedParticipantEstablishmentId, entity.EntityId);
                    _participantRemover.Handle(remove);
                    if (remove.IsNewlyRemoved)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            if (command.AddParticipantEstablishmentEntityIds != null)
            {
                foreach (var addedParticipantEstablishmentId in command.AddParticipantEstablishmentEntityIds)
                {
                    var add = new AddParticipantToAgreementCommand(command.Principal, addedParticipantEstablishmentId, entity);
                    _participantAdder.Handle(add);
                    if (add.IsNewlyAdded)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            #endregion
            #region Contacts

            if (command.RemoveContactEntityIds != null)
            {
                foreach (var removedContactEntityId in command.RemoveContactEntityIds.Where(v => v != Guid.Empty))
                {
                    var remove = new RemoveContactFromAgreementCommand(
                        command.Principal, removedContactEntityId, entity.EntityId);
                    _contactRemover.Handle(remove);
                    if (remove.IsNewlyRemoved)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            if (command.AddContactCommands != null)
            {
                foreach (var add in command.AddContactCommands)
                {
                    add.Agreement = entity;
                    _contactAdder.Handle(add);
                    if (add.IsNewlyAdded)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            #endregion
            #region Files

            if (command.DetachFileEntityIds != null)
            {
                foreach (var removedFileEntityId in command.DetachFileEntityIds)
                {
                    var detach = new DetachFileFromAgreementCommand(
                        command.Principal, removedFileEntityId, entity.EntityId);
                    _fileDetacher.Handle(detach);
                    if (detach.IsNewlyDetached)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            if (command.AttachFileEntityIds != null)
            {
                foreach (var attachedFileIds in command.AttachFileEntityIds)
                {
                    var attach = new AttachFileToAgreementCommand(command.Principal, attachedFileIds, entity);
                    _fileAttacher.Handle(attach);
                    if (attach.IsNewlyAttached)
                    {
                        ++command.ChangeCount;
                    }
                }
            }

            #endregion

            command.EntityId = entity.EntityId;
            if (entity.RevisionId == 0 || command.ChangeCount > 0)
            {
                if (entity.RevisionId == 0)
                {
                    _entities.Create(entity);
                }
                else if (command.ChangeCount > 0)
                {
                    _entities.Update(entity);
                }
                DeriveNodes(entity, previousUmbrella);
                command.RevisionId = entity.RevisionId;
            }
        }
        private static void CopyScalars(CreateOrUpdateInstitutionalAgreementCommand command, InstitutionalAgreement entity)
        {
            if (command.Title != entity.Title)
            {
                ++command.ChangeCount;
            }
            if (command.IsTitleDerived != entity.IsTitleDerived)
            {
                ++command.ChangeCount;
            }
            if (command.Type != entity.Type)
            {
                ++command.ChangeCount;
            }
            if (command.Status != entity.Status)
            {
                ++command.ChangeCount;
            }
            if (command.Description != entity.Description)
            {
                ++command.ChangeCount;
            }
            if (command.IsAutoRenew != entity.IsAutoRenew)
            {
                ++command.ChangeCount;
            }
            if (command.StartsOn != entity.StartsOn)
            {
                ++command.ChangeCount;
            }
            if (command.ExpiresOn != entity.ExpiresOn)
            {
                ++command.ChangeCount;
            }
            if (command.IsExpirationEstimated != entity.IsExpirationEstimated)
            {
                ++command.ChangeCount;
            }
            if (command.Visibility != entity.Visibility)
            {
                ++command.ChangeCount;
            }

            entity.Title                 = command.Title;
            entity.IsTitleDerived        = command.IsTitleDerived;
            entity.Type                  = command.Type;
            entity.Status                = command.Status;
            entity.Description           = command.Description;
            entity.IsAutoRenew           = command.IsAutoRenew;
            entity.StartsOn              = command.StartsOn;
            entity.ExpiresOn             = command.ExpiresOn;
            entity.IsExpirationEstimated = command.IsExpirationEstimated;
            entity.Visibility            = command.Visibility;
        }
 public void HasGetSet()
 {
     var value = new List<InstitutionalAgreementFile> { new InstitutionalAgreementFile() };
     var entity = new InstitutionalAgreement { Files = value };
     entity.ShouldNotBeNull();
     entity.Files.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new List<InstitutionalAgreementContact> { new InstitutionalAgreementContact() };
     var entity = new InstitutionalAgreement { Contacts = value };
     entity.ShouldNotBeNull();
     entity.Contacts.ShouldEqual(value);
 }
 public void HasGetSet()
 {
     var value = new List<InstitutionalAgreementParticipant> { new InstitutionalAgreementParticipant() };
     var entity = new InstitutionalAgreement { Participants = value };
     entity.ShouldNotBeNull();
     entity.Participants.ShouldEqual(value);
 }