public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts) { var newConcepts = new List<IConceptInfo>(); // Expand the base entity: var activeSinceProperty = new DateTimePropertyInfo { DataStructure = Entity, Name = "ActiveSince" }; // TODO: SystemRequired, Default 1.1.1900. var activeSinceHistory = new EntityHistoryPropertyInfo { Property = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { activeSinceProperty, activeSinceHistory }); // InvalidData for base entity: it is not allowed to save with ActiveSince older than last one used in History var denyFilter = new ComposableFilterByInfo { Parameter = "Common.OlderThanHistoryEntries", Source = Entity, Expression = String.Format( @"(items, repository, parameter) => items.Where(item => repository.{0}.{1}_Changes.Subquery.Where(his => his.ActiveSince >= item.ActiveSince && his.Entity == item).Count() > 0)", Entity.Module.Name, Entity.Name) }; var invalidDataValidation = new InvalidDataMarkPropertyInfo { FilterType = "Common.OlderThanHistoryEntries", Source = Entity, ErrorMessage = "ActiveSince is not allowed to be older than last entry in history.", DependedProperty = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilter, invalidDataValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" } }); // Create a new entity for history data: var currentProperty = new ReferencePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = "Entity", Referenced = Entity }; var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = activeSinceProperty.Name }; newConcepts.AddRange(new IConceptInfo[] { currentProperty, new ReferenceDetailInfo { Reference = currentProperty }, new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired new PropertyFromInfo { Destination = Dependency_ChangesEntity, Source = activeSinceProperty }, historyActiveSinceProperty, new UniquePropertiesInfo { DataStructure = Dependency_ChangesEntity, Property1 = currentProperty, Property2 = historyActiveSinceProperty } }); // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity var denyFilterHistory = new ComposableFilterByInfo { Parameter = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)" }; var invalidDataValidationHistory = new InvalidDataMarkPropertyInfo { FilterType = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry.", DependedProperty = historyActiveSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, invalidDataValidationHistory, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "NewerThanCurrentEntry" } }); // Create ActiveUntil SqlQueryable: var activeUntilSqlQueryable = new SqlQueryableInfo { Module = Entity.Module, Name = Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet() }; newConcepts.AddRange(new IConceptInfo[] { activeUntilSqlQueryable, new DateTimePropertyInfo { DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil" }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Entity }, new DataStructureExtendsInfo { Base = Dependency_ChangesEntity, Extension = activeUntilSqlQueryable } }); // Configure History SqlQueryable: newConcepts.AddRange(new IConceptInfo[] { new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Entity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = activeUntilSqlQueryable }, new DateTimePropertyInfo { DataStructure = Dependency_HistorySqlQueryable, Name = "ActiveUntil" }, new AllPropertiesFromInfo { Source = Dependency_ChangesEntity, Destination = Dependency_HistorySqlQueryable } }); // Configure AtTime SqlFunction: newConcepts.Add(new SqlDependsOnDataStructureInfo { Dependent = Dependency_AtTimeSqlFunction, DependsOn = Dependency_HistorySqlQueryable }); return newConcepts; }
public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts) { var newConcepts = new List <IConceptInfo>(); // Expand the base entity: var activeSinceProperty = new DateTimePropertyInfo { DataStructure = Entity, Name = "ActiveSince" }; // TODO: SystemRequired, Default 1.1.1900. var activeSinceHistory = new EntityHistoryPropertyInfo { Property = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { activeSinceProperty, activeSinceHistory }); // InvalidData for base entity: it is not allowed to save with ActiveSince older than last one used in History var denyFilter = new ComposableFilterByInfo { Parameter = "Common.OlderThanHistoryEntries", Source = Entity, Expression = String.Format( @"(items, repository, parameter) => items.Where(item => repository.{0}.{1}_Changes.Subquery.Where(his => his.ActiveSince >= item.ActiveSince && his.Entity == item).Count() > 0)", Entity.Module.Name, Entity.Name) }; var invalidDataValidation = new InvalidDataMarkPropertyInfo { FilterType = "Common.OlderThanHistoryEntries", Source = Entity, ErrorMessage = "ActiveSince is not allowed to be older than last entry in history.", DependedProperty = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilter, invalidDataValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" } }); // Create a new entity for history data: var currentProperty = new ReferencePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = "Entity", Referenced = Entity }; var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = Dependency_ChangesEntity, Name = activeSinceProperty.Name }; newConcepts.AddRange(new IConceptInfo[] { currentProperty, new ReferenceDetailInfo { Reference = currentProperty }, new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired new PropertyFromInfo { Destination = Dependency_ChangesEntity, Source = activeSinceProperty }, historyActiveSinceProperty, new UniquePropertiesInfo { DataStructure = Dependency_ChangesEntity, Property1 = currentProperty, Property2 = historyActiveSinceProperty } }); // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity var denyFilterHistory = new ComposableFilterByInfo { Parameter = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, Expression = @"(items, repository, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)" }; var invalidDataValidationHistory = new InvalidDataMarkPropertyInfo { FilterType = "Common.NewerThanCurrentEntry", Source = Dependency_ChangesEntity, ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry.", DependedProperty = historyActiveSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, invalidDataValidationHistory, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "NewerThanCurrentEntry" } }); // Create ActiveUntil SqlQueryable: var activeUntilSqlQueryable = new SqlQueryableInfo { Module = Entity.Module, Name = Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet() }; newConcepts.AddRange(new IConceptInfo[] { activeUntilSqlQueryable, new DateTimePropertyInfo { DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil" }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = Entity }, new DataStructureExtendsInfo { Base = Dependency_ChangesEntity, Extension = activeUntilSqlQueryable } }); // Configure History SqlQueryable: newConcepts.AddRange(new IConceptInfo[] { new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Entity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = Dependency_HistorySqlQueryable, DependsOn = activeUntilSqlQueryable }, new DateTimePropertyInfo { DataStructure = Dependency_HistorySqlQueryable, Name = "ActiveUntil" }, new AllPropertiesFromInfo { Source = Dependency_ChangesEntity, Destination = Dependency_HistorySqlQueryable } }); // Configure AtTime SqlFunction: newConcepts.Add(new SqlDependsOnDataStructureInfo { Dependent = Dependency_AtTimeSqlFunction, DependsOn = Dependency_HistorySqlQueryable }); return(newConcepts); }
public IEnumerable <IConceptInfo> CreateNewConcepts(EntityHistoryInfo conceptInfo, IDslModel existingConcepts) { var newConcepts = new List <IConceptInfo>(); var atTimeSqlFunction = new SqlFunctionInfo { Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_AtTime", Arguments = $"@ContextTime {_dateTimeSqlColumnType}", Source = AtTimeSqlSnippet(conceptInfo) }; newConcepts.Add(atTimeSqlFunction); var historySqlQueryable = new SqlQueryableInfo { Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_History", SqlSource = HistorySqlSnippet(conceptInfo) }; newConcepts.Add(historySqlQueryable); var write = new WriteInfo { DataStructure = historySqlQueryable, SaveImplementation = HistorySaveFunction(conceptInfo) }; newConcepts.Add(write); // Expand the base entity: var activeSinceProperty = new DateTimePropertyInfo { DataStructure = conceptInfo.Entity, Name = "ActiveSince" }; // TODO: SystemRequired, Default 1.1.1900., after implementing optimization for multiple simple property validations. var activeSinceHistory = new EntityHistoryPropertyInfo { Property = activeSinceProperty }; newConcepts.AddRange(new IConceptInfo[] { activeSinceProperty, activeSinceHistory }); // InvalidData for base entity: it is not allowed to save with ActiveSince older than last one used in History var denyFilter = new QueryFilterExpressionInfo { Parameter = "Common.OlderThanHistoryEntries", Source = conceptInfo.Entity, Expression = String.Format( @"(items, parameter) => items.Where(item => _domRepository.{0}.{1}_Changes.Subquery.Where(his => his.ActiveSince >= item.ActiveSince && his.Entity == item).Count() > 0)", conceptInfo.Entity.Module.Name, conceptInfo.Entity.Name) }; var invalidDataValidation = new InvalidDataInfo { FilterType = "Common.OlderThanHistoryEntries", Source = conceptInfo.Entity, ErrorMessage = "ActiveSince is not allowed to be older than last entry in history." }; newConcepts.AddRange(new IConceptInfo[] { denyFilter, invalidDataValidation, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "OlderThanHistoryEntries" }, new InvalidDataMarkProperty2Info { InvalidData = invalidDataValidation, MarkProperty = activeSinceProperty } }); // Create a new entity for history data: var currentProperty = new ReferencePropertyInfo { DataStructure = conceptInfo.Dependency_ChangesEntity, Name = "Entity", Referenced = conceptInfo.Entity }; var historyActiveSinceProperty = new DateTimePropertyInfo { DataStructure = conceptInfo.Dependency_ChangesEntity, Name = activeSinceProperty.Name }; newConcepts.AddRange(new IConceptInfo[] { currentProperty, new ReferenceDetailInfo { Reference = currentProperty }, new RequiredPropertyInfo { Property = currentProperty }, // TODO: SystemRequired, after implementing optimization for multiple simple property validations. new PropertyFromInfo { Destination = conceptInfo.Dependency_ChangesEntity, Source = activeSinceProperty }, historyActiveSinceProperty, new UniqueMultiplePropertiesInfo { DataStructure = conceptInfo.Dependency_ChangesEntity, PropertyNames = $"{currentProperty.Name} {historyActiveSinceProperty.Name}" } }); // InvalidData for history entity: it is not allowed to save with ActiveSince newer than current entity var denyFilterHistory = new QueryFilterExpressionInfo { Parameter = "Common.NewerThanCurrentEntry", Source = conceptInfo.Dependency_ChangesEntity, Expression = @"(items, parameter) => items.Where(item => item.ActiveSince > item.Entity.ActiveSince)" }; var invalidDataValidationHistory = new InvalidDataInfo { FilterType = "Common.NewerThanCurrentEntry", Source = conceptInfo.Dependency_ChangesEntity, ErrorMessage = "ActiveSince of history entry is not allowed to be newer than current entry." }; newConcepts.AddRange(new IConceptInfo[] { denyFilterHistory, invalidDataValidationHistory, new ParameterInfo { Module = new ModuleInfo { Name = "Common" }, Name = "NewerThanCurrentEntry" }, new InvalidDataMarkProperty2Info { InvalidData = invalidDataValidationHistory, MarkProperty = historyActiveSinceProperty } }); // Create ActiveUntil SqlQueryable: var activeUntilSqlQueryable = new SqlQueryableInfo { Module = conceptInfo.Entity.Module, Name = conceptInfo.Entity.Name + "_ChangesActiveUntil", SqlSource = ActiveUntilSqlSnippet(conceptInfo) }; newConcepts.AddRange(new IConceptInfo[] { activeUntilSqlQueryable, new DateTimePropertyInfo { DataStructure = activeUntilSqlQueryable, Name = "ActiveUntil" }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = conceptInfo.Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = activeUntilSqlQueryable, DependsOn = conceptInfo.Entity }, new DataStructureExtendsInfo { Base = conceptInfo.Dependency_ChangesEntity, Extension = activeUntilSqlQueryable } }); // Configure History SqlQueryable: newConcepts.AddRange(new IConceptInfo[] { new SqlDependsOnDataStructureInfo { Dependent = historySqlQueryable, DependsOn = conceptInfo.Entity }, new SqlDependsOnDataStructureInfo { Dependent = historySqlQueryable, DependsOn = conceptInfo.Dependency_ChangesEntity }, new SqlDependsOnDataStructureInfo { Dependent = historySqlQueryable, DependsOn = activeUntilSqlQueryable }, new DateTimePropertyInfo { DataStructure = historySqlQueryable, Name = "ActiveUntil" }, new AllPropertiesFromInfo { Source = conceptInfo.Dependency_ChangesEntity, Destination = historySqlQueryable } }); // Configure AtTime SqlFunction: newConcepts.Add(new SqlDependsOnDataStructureInfo { Dependent = atTimeSqlFunction, DependsOn = historySqlQueryable }); return(newConcepts); }