Esempio n. 1
0
 public ModifyRecordEventDectection(AmplaRecord amplaRecord, AmplaAuditRecord amplaAuditRecord, IAmplaViewProperties <TModel> viewProperties)
     : base("Modify Record")
 {
     this.amplaRecord      = amplaRecord;
     this.amplaAuditRecord = amplaAuditRecord;
     this.viewProperties   = viewProperties;
 }
Esempio n. 2
0
        public void GetVersionsSingleRecord()
        {
            Assert.That(Records, Is.Empty);

            DateTime localHour = DateTime.Now.TrimToHour();

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100, Sample = localHour
            };

            Repository.Add(model);

            ModelVersions versions = Repository.GetVersions(model.Id);

            Assert.That(versions, Is.Not.Null);
            Assert.That(versions.Versions, Is.Not.Empty);
            Assert.That(versions.Versions.Count, Is.EqualTo(1));

            ModelVersion <AreaValueModel> version = (ModelVersion <AreaValueModel>)versions.Versions[0];

            Assert.That(version.Display, Is.EqualTo("User created record"));
            Assert.That(version.Model.Id, Is.EqualTo(model.Id));
            Assert.That(version.Model.Area, Is.EqualTo(model.Area));
            Assert.That(version.Model.Sample, Is.EqualTo(model.Sample));
            Assert.That(version.Model.Value, Is.EqualTo(model.Value));

            AmplaAuditRecord history = Repository.GetHistory(model.Id);

            Assert.That(history.Changes, Is.Empty);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the versions of the model
        /// </summary>
        /// <param name="id">The unique identifier.</param>
        /// <returns></returns>
        public ModelVersions GetVersions(int id)
        {
            IAmplaViewProperties <TModel> amplaViewProperties = GetViewProperties(null);

            amplaViewProperties.Enforce.CanView();

            FilterValue     idFilter      = new FilterValue("Id", Convert.ToString(id));
            FilterValue     deletedFilter = new FilterValue("Deleted", "");
            GetDataRequest  dataRequest   = GetDataRequest(false, idFilter, deletedFilter);
            GetDataResponse dataResponse  = webServiceClient.GetData(dataRequest);
            TModel          model;
            AmplaRecord     amplaRecord = FindAmplaRecord(dataResponse, ModelProperties, amplaViewProperties, out model);

            if (amplaRecord != null)
            {
                var request = GetAuditDataRequest(amplaRecord);
                GetAuditDataResponse    response     = webServiceClient.GetAuditData(request);
                List <AmplaAuditRecord> auditRecords = new List <AmplaAuditRecord>();
                IAmplaBinding           binding      = new AmplaGetAuditDataRecordBinding <TModel>(response, amplaRecord, auditRecords, modelProperties);
                if (binding.Validate() && binding.Bind())
                {
                    AmplaAuditRecord auditRecord    = auditRecords.Count > 0 ? auditRecords[0] : null;
                    ModelVersions    modelVersions  = new ModelVersions(amplaRecord);
                    IAmplaBinding    historyBinding = new AmplaGetDataVersionsBinding <TModel>(amplaRecord, auditRecord, model, modelVersions, modelProperties, amplaViewProperties);
                    if (historyBinding.Validate() && historyBinding.Bind())
                    {
                        return(modelVersions);
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        public void SingleRecordThatHasBeenDeleted()
        {
            DateTime         createdTime = DateTime.Today.AddDays(-1);
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("Deleted", typeof(bool));

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(createdTime));
            record.SetValue("Deleted", "True");
            auditRecord.Changes.Add
            (
                AddSession("User", DateTime.Today, "IsDeleted", "False", "True")
            );

            AmplaRecordHistory <ProductionModel> amplaRecordHistory = new AmplaRecordHistory <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges>            changes            = amplaRecordHistory.Reconstruct();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(2));
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("System"));
            Assert.That(changes[0].Changes, Is.Empty);
            Assert.That(changes[1].Operation, Is.EqualTo("Delete Record"));
            Assert.That(changes[1].User, Is.EqualTo("User"));
            Assert.That(changes[1].Changes, Is.Not.Empty);
            AmplaAuditField deleted = changes[1].Changes[0];

            Assert.That(deleted.Name, Is.EqualTo("IsDeleted"));
        }
Esempio n. 5
0
        public void DetectChangesWithAuditTrailWithNoChangesInValues()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            auditRecord.Changes = new List <AmplaAuditSession>
            {
                AddSession("User", DateTime.Today, "Value", "100", "100"),
                AddSession("Admin", DateTime.Today.AddHours(1),
                           new[] { "One", "Two" },
                           new[] { "11", "222" },
                           new[] { "111", "222" })
            };

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(1));

            Assert.That(changes[0].User, Is.EqualTo("Admin"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(DateTime.Today.AddHours(1)));
            Assert.That(changes[0].Operation, Is.EqualTo("Modify Record"));
            Assert.That(changes[0].Changes, Is.Not.Empty);
            Assert.That(changes[0].Changes.Length, Is.EqualTo(1));
            Assert.That(changes[0].Changes[0].Name, Is.EqualTo("One"));
            Assert.That(changes[0].Changes[0].OriginalValue, Is.EqualTo("11"));
            Assert.That(changes[0].Changes[0].EditedValue, Is.EqualTo("111"));
        }
Esempio n. 6
0
        public void DetectChangesWithOneFieldAuditTrail()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            auditRecord.Changes = new List <AmplaAuditSession>
            {
                AddSession("User", DateTime.Today, "Value", "100", "200")
            };

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);

            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(1));

            Assert.That(changes[0].User, Is.EqualTo("User"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(DateTime.Today));
            Assert.That(changes[0].Operation, Is.EqualTo("Modify Record"));
            Assert.That(changes[0].Changes, Is.Not.Empty);
            Assert.That(changes[0].Changes[0].Name, Is.EqualTo("Value"));
            Assert.That(changes[0].Changes[0].OriginalValue, Is.EqualTo("100"));
            Assert.That(changes[0].Changes[0].EditedValue, Is.EqualTo("200"));
        }
        public void GetHistory_NoChanges()
        {
            Assert.That(Records, Is.Empty);

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);
            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(model.Value));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AmplaAuditRecord auditRecord = Repository.GetHistory(model.Id);

            Assert.That(auditRecord, Is.Not.Null);

            Assert.That(auditRecord.Id, Is.EqualTo(model.Id));
            Assert.That(auditRecord.Location, Is.EqualTo(location));
            Assert.That(auditRecord.Module, Is.EqualTo(module));
            Assert.That(auditRecord.Changes, Is.Empty);
        }
        public void GetHistory_WrongId()
        {
            Assert.That(Records, Is.Empty);

            AmplaAuditRecord auditRecord = Repository.GetHistory(101);

            Assert.That(auditRecord, Is.Null);
        }
 public AmplaGetDataVersionsBinding(AmplaRecord amplaRecord, AmplaAuditRecord auditRecord, TModel currentModel, ModelVersions versions, IModelProperties <TModel> modelProperties, IAmplaViewProperties <TModel> viewProperties)
 {
     this.amplaRecord     = amplaRecord;
     this.auditRecord     = auditRecord;
     this.currentModel    = currentModel;
     this.versions        = versions;
     this.modelProperties = modelProperties;
     this.viewProperties  = viewProperties;
 }
Esempio n. 10
0
        /// <summary>
        ///     GET /{Model}/History/{id}
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult History(int id = 0)
        {
            AmplaAuditRecord record = Repository.GetHistory(id);

            if (record == null)
            {
                return(HttpNotFound());
            }
            return(View("History", record));
        }
Esempio n. 11
0
        public void GetHistory_WithChanges()
        {
            Assert.That(Records, Is.Empty);

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100
            };

            Repository.Add(model);
            Assert.That(Records.Count, Is.EqualTo(1));

            AmplaRecord record = Repository.FindRecord(model.Id);

            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(model.Value));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AreaValueModel updated = new AreaValueModel {
                Id = model.Id, Area = "ROM", Value = 200
            };

            DateTime before = DateTime.Now.AddMinutes(-1);
            DateTime after  = DateTime.Now.AddMinutes(+1);

            Repository.Update(updated);
            record = Repository.FindRecord(model.Id);
            Assert.That(record, Is.Not.Null);

            Assert.That(record.GetValue("Area"), Is.EqualTo(model.Area));
            Assert.That(record.GetValue("Value"), Is.EqualTo(200));
            Assert.That(record.Location, Is.EqualTo(location));
            Assert.That(record.Id, Is.EqualTo(model.Id));

            AmplaAuditRecord auditRecord = Repository.GetHistory(model.Id);

            Assert.That(auditRecord, Is.Not.Null);

            Assert.That(auditRecord.Id, Is.EqualTo(model.Id));
            Assert.That(auditRecord.Location, Is.EqualTo(location));
            Assert.That(auditRecord.Module, Is.EqualTo(module));
            Assert.That(auditRecord.Changes, Is.Not.Empty);
            Assert.That(auditRecord.Changes.Count, Is.EqualTo(1));

            AmplaAuditSession session = auditRecord.Changes[0];

            Assert.That(session.User, Is.EqualTo("User"));
            Assert.That(session.EditedTime, Is.InRange(before, after));
            Assert.That(session.Fields, Is.Not.Empty);

            AssertAuditField(session, "Value", "100", "200");
        }
Esempio n. 12
0
        public void DetectChangesWithNoAuditTrail()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Empty);
        }
        protected AmplaAuditRecord CreateAuditRecord(AmplaRecord record)
        {
            AmplaAuditRecord auditRecord = new AmplaAuditRecord
            {
                Id       = record.Id,
                Location = record.Location,
                Module   = record.Module,
                Changes  = new List <AmplaAuditSession>()
            };

            return(auditRecord);
        }
Esempio n. 14
0
        public void DetectChangesWithAuditTrailWithNoChangeInValue()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            auditRecord.Changes = new List <AmplaAuditSession>
            {
                AddSession("User", DateTime.Today, "Value", "100", "100")
            };

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Empty);
        }
Esempio n. 15
0
        public void SingleRecordWithNoHistory()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            AmplaRecordHistory <ProductionModel> amplaRecordHistory = new AmplaRecordHistory <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges>            changes            = amplaRecordHistory.Reconstruct();

            Assert.That(changes, Is.Not.Empty);

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(1));
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("System"));
            Assert.That(changes[0].Changes, Is.Empty);
        }
        public bool Bind()
        {
            if (response.RowSets.Length == 0)
            {
                return(false);
            }

            GetAuditDataRowSet rowSet = response.RowSets[0];

            AmplaAuditRecord model = new AmplaAuditRecord {
                Id = record.Id, Location = record.Location, Module = record.Module
            };

            List <AmplaAuditSession> changes = new List <AmplaAuditSession>();

            foreach (GetAuditDataRow row in rowSet.Rows)
            {
                if (row.Field != "LastModified")
                {
                    DateTime editTime = Iso8601DateTimeConverter.ConvertToLocalDateTime(row.EditedDateTime);
                    string   user     = row.EditedBy.StartsWith(systemConfigUsers)
                                      ? row.EditedBy.Substring(systemConfigUsers.Length)
                                      : row.EditedBy;
                    AmplaAuditSession session = changes.Find(s => s.EditedTime == editTime && s.User == user);
                    if (session == null)
                    {
                        session = new AmplaAuditSession(user, editTime);
                        changes.Add(session);
                    }

                    session.Fields.Add(new AmplaAuditField
                    {
                        Name          = row.Field,
                        OriginalValue = row.OriginalValue,
                        EditedValue   = row.EditedValue
                    });
                }
            }

            changes.Sort();

            model.Changes = changes;
            records.Add(model);
            return(true);
        }
Esempio n. 17
0
        public void DetectChangesWithDeletedRecords()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("Sample Period", typeof(DateTime));
            record.SetValue("Sample Period", Iso8601DateTimeConverter.ConvertFromLocalDateTime(DateTime.Today.AddDays(-1)));
            auditRecord.Changes = new List <AmplaAuditSession>
            {
                AddSession("User", DateTime.Today, "IsDeleted", "False", "True")
            };

            ModifyRecordEventDectection <ProductionModel> recordEventDectection = new ModifyRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Empty);
        }
Esempio n. 18
0
        public void GetVersionsWithEdit()
        {
            Assert.That(Records, Is.Empty);

            DateTime localHour = DateTime.Now.TrimToHour();

            AreaValueModel model = new AreaValueModel {
                Area = "ROM", Value = 100, Sample = localHour
            };

            Repository.Add(model);

            AreaValueModel update = new AreaValueModel {
                Id = model.Id, Area = "ROM", Value = 100, Sample = model.Sample.AddMinutes(1)
            };

            Repository.Update(update);

            ModelVersions versions = Repository.GetVersions(model.Id);

            AmplaAuditRecord history = Repository.GetHistory(model.Id);

            Assert.That(versions, Is.Not.Null);
            Assert.That(versions.Versions, Is.Not.Empty);
            Assert.That(versions.Versions.Count, Is.EqualTo(2));

            ModelVersion <AreaValueModel> last    = (ModelVersion <AreaValueModel>)versions.Versions[0];
            ModelVersion <AreaValueModel> current = (ModelVersion <AreaValueModel>)versions.Versions[1];

            Assert.That(last.Display, Is.EqualTo("User created record"));
            Assert.That(last.Model.Id, Is.EqualTo(model.Id));
            Assert.That(last.Model.Area, Is.EqualTo(model.Area));
            Assert.That(last.Model.Sample, Is.EqualTo(model.Sample));
            Assert.That(last.Model.Value, Is.EqualTo(model.Value));

            Assert.That(current.Display, Is.EqualTo("User modified record (Sample Period)"));
            Assert.That(current.Model.Id, Is.EqualTo(update.Id));
            Assert.That(current.Model.Area, Is.EqualTo(update.Area));
            Assert.That(current.Model.Sample, Is.EqualTo(update.Sample));
            Assert.That(current.Model.Value, Is.EqualTo(update.Value));

            Assert.That(history.Changes, Is.Not.Empty);
            Assert.That(history.Changes[0].Fields[0].Name, Is.EqualTo("SampleDateTime"));
        }
Esempio n. 19
0
        public void SingleRecordWithCreateHistory()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("CreatedBy", typeof(string));

            record.SetValue("CreatedBy", "Admin");
            DateTime created = DateTime.Today.AddHours(1);

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(created));

            AmplaRecordHistory <ProductionModel> amplaRecordHistory = new AmplaRecordHistory <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges>            changes            = amplaRecordHistory.Reconstruct();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes.Count, Is.EqualTo(1));
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("Admin"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(created));
            Assert.That(changes[0].Changes, Is.Empty);
        }
Esempio n. 20
0
        public void ShowSimpleUsersName()
        {
            AmplaRecord      record      = CreateRecord(100);
            AmplaAuditRecord auditRecord = CreateAuditRecord(record);
            IAmplaViewProperties <ProductionModel> viewProperties = GetViewProperties();

            record.AddColumn("CreatedDateTime", typeof(DateTime));
            record.AddColumn("CreatedBy", typeof(string));

            record.SetValue("CreatedBy", "System Configuration.Users.User");
            DateTime created = DateTime.Today.AddHours(1);

            record.SetValue("CreatedDateTime", Iso8601DateTimeConverter.ConvertFromLocalDateTime(created));

            CreateRecordEventDectection <ProductionModel> recordEventDectection = new CreateRecordEventDectection <ProductionModel>(record, auditRecord, viewProperties);
            List <AmplaRecordChanges> changes = recordEventDectection.DetectChanges();

            Assert.That(changes, Is.Not.Empty);
            Assert.That(changes[0].Operation, Is.EqualTo("Create Record"));
            Assert.That(changes[0].User, Is.EqualTo("User"));
            Assert.That(changes[0].VersionDateTime, Is.EqualTo(created));
            Assert.That(changes[0].Changes, Is.Empty);
            Assert.That(changes[0].Display, Is.EqualTo("User created record"));
        }
Esempio n. 21
0
        public void BindWithEmptyOriginalValue_double()
        {
            AmplaRecord amplaRecord = new AmplaRecord(100)
            {
                Location = location, Module = module, ModelName = ""
            };

            amplaRecord.AddColumn("Value", typeof(double));
            amplaRecord.AddColumn("Area", typeof(string));
            amplaRecord.SetValue("Value", "100.0");
            amplaRecord.SetValue("Area", "ROM");

            AmplaAuditRecord auditRecord = new AmplaAuditRecord
            {
                Id       = amplaRecord.Id,
                Location = amplaRecord.Location,
                Module   = amplaRecord.Module,
                Changes  = new List <AmplaAuditSession>
                {
                    new AmplaAuditSession("User", DateTime.Today)
                }
            };

            auditRecord.Changes[0].Fields.Add(new AmplaAuditField
            {
                Name          = "Value",
                OriginalValue = "",
                EditedValue   = "100"
            });

            AreaValueModel model = new AreaValueModel {
                Id = 100, Area = "ROM", Value = 100.0d
            };
            ModelVersions modelVersions = new ModelVersions(amplaRecord);
            IModelProperties <AreaValueModel> modelProperties = new ModelProperties <AreaValueModel>();

            AmplaViewProperties <AreaValueModel> viewProperties = new AmplaViewProperties <AreaValueModel>(modelProperties);
            GetViewsResponse view = new GetViewsResponse
            {
                Context = new GetViewsResponseContext(),
                Views   = new[] { ProductionViews.AreaValueModelView() }
            };

            viewProperties.Initialise(view);
            AmplaGetDataVersionsBinding <AreaValueModel> binding =
                new AmplaGetDataVersionsBinding <AreaValueModel>(amplaRecord, auditRecord, model, modelVersions,
                                                                 modelProperties, viewProperties);

            Assert.That(binding.Validate(), Is.True);
            Assert.That(binding.Bind(), Is.True);

            Assert.That(modelVersions.Versions, Is.Not.Empty);
            Assert.That(modelVersions.Versions.Count, Is.EqualTo(2));

            ModelVersion <AreaValueModel> last    = (ModelVersion <AreaValueModel>)modelVersions.Versions[0];
            ModelVersion <AreaValueModel> current = (ModelVersion <AreaValueModel>)modelVersions.Versions[1];

            Assert.That(last.IsCurrentVersion, Is.False);
            Assert.That(current.IsCurrentVersion, Is.True);

            Assert.That(last.Model.Area, Is.EqualTo(model.Area));
            Assert.That(current.Model.Area, Is.EqualTo(model.Area));

            Assert.That(last.Model.Value, Is.EqualTo(0d));
            Assert.That(current.Model.Value, Is.EqualTo(100d));

            Assert.That(last.Model.Id, Is.EqualTo(100));
            Assert.That(current.Model.Id, Is.EqualTo(100));
        }
Esempio n. 22
0
 public AmplaRecordHistory(AmplaRecord amplaRecord, AmplaAuditRecord auditRecord, IAmplaViewProperties <TModel> viewProperties)
 {
     this.amplaRecord    = amplaRecord;
     this.auditRecord    = auditRecord;
     this.viewProperties = viewProperties;
 }