private void ProcessCkAttributes(CkModelRoot model, ScopeIds scopeId) { foreach (var modelCkAttribute in model.CkAttributes) { var ckAttribute = new CkAttribute { AttributeId = modelCkAttribute.AttributeId, ScopeId = scopeId, AttributeValueType = (AttributeValueTypes)modelCkAttribute.ValueType, SelectionValues = modelCkAttribute.SelectionValues?.Select(sv => new CkSelectionValue { Key = sv.Key, Name = sv.Name }).ToList(), DefaultValue = modelCkAttribute.DefaultValue, DefaultValues = modelCkAttribute.DefaultValues }; _transientCkModel.CkAttributes.Add(ckAttribute); } }
private async Task ExecuteImport(IOspSession session, CkModelRoot model, ScopeIds scopeId, CancellationToken?cancellationToken) { // Transform to entities ProcessCkAttributes(model, scopeId); if (CheckCancellation(cancellationToken)) { return; } ProcessCkEntitiesAndAssociations(model, scopeId); if (CheckCancellation(cancellationToken)) { return; } // ValidateAsync await _ckModelValidation.Validate(session, _transientCkModel, scopeId, cancellationToken); // Delete the old version if (await DeleteOldVersion(session, scopeId, cancellationToken)) { return; } if (CheckCancellation(cancellationToken)) { return; } // ValidateAsync the Model if (_transientCkModel.CkAttributes.Any()) { ValidateAndThrow( await _databaseContext.CkAttributes.BulkImportAsync(session, _transientCkModel.CkAttributes.ToArray())); if (CheckCancellation(cancellationToken)) { return; } } if (_transientCkModel.CkEntities.Any()) { ValidateAndThrow( await _databaseContext.CkEntities.BulkImportAsync(session, _transientCkModel.CkEntities.ToArray())); if (CheckCancellation(cancellationToken)) { return; } } if (_transientCkModel.CkEntityAssociations.Any()) { ValidateAndThrow( await _databaseContext.CkEntityAssociations.BulkImportAsync(session, _transientCkModel.CkEntityAssociations)); if (CheckCancellation(cancellationToken)) { return; } } if (_transientCkModel.CkEntityInheritances.Any()) { ValidateAndThrow( await _databaseContext.CkEntityInheritances.BulkImportAsync(session, _transientCkModel.CkEntityInheritances)); if (CheckCancellation(cancellationToken)) { return; } } await CreateCollections(session); if (CheckCancellation(cancellationToken)) { return; } await CreateIndex(session); }
private void ProcessCkEntitiesAndAssociations(CkModelRoot model, ScopeIds scopeId) { var associationRoleDefinitions = model.CkAssociationRoles.ToDictionary(k => k.RoleId, v => v); foreach (var entity in model.CkEntities) { List <CkEntityAttribute> ckEntityAttributes = new List <CkEntityAttribute>(); foreach (var attribute in entity.Attributes) { var ckEntityAttribute = new CkEntityAttribute { AttributeId = attribute.AttributeId, AttributeName = attribute.AttributeName, AutoCompleteFilter = attribute.AutoCompleteFilter, AutoCompleteLimit = attribute.AutoCompleteLimit, IsAutoCompleteEnabled = attribute.IsAutoCompleteEnabled, AutoIncrementReference = attribute.AutoIncrementReference }; ckEntityAttributes.Add(ckEntityAttribute); } List <CkEntityIndex> textSearchDefinitions = new List <CkEntityIndex>(); foreach (var entityIndexDto in entity.Indexes) { var entityIndex = new CkEntityIndex { IndexType = (IndexTypes)entityIndexDto.IndexType, Language = entityIndexDto.Language, Fields = entityIndexDto.Fields .Select(x => new CkIndexFields { Weight = x.Weight, AttributeNames = x.AttributeNames }) .ToList() }; textSearchDefinitions.Add(entityIndex); } var ckEntity = new CkEntity { CkId = entity.CkId, ScopeId = scopeId, IsFinal = entity.IsFinal, IsAbstract = entity.IsAbstract, Attributes = ckEntityAttributes, Indexes = textSearchDefinitions }; if (!string.IsNullOrWhiteSpace(entity.CkDerivedId)) { var ckEntityInheritance = new CkEntityInheritance { ScopeId = scopeId, OriginCkId = entity.CkDerivedId, TargetCkId = entity.CkId, }; _transientCkModel.CkEntityInheritances.Add(ckEntityInheritance); } foreach (var association in entity.Associations) { var ckEntityAssociation = new CkEntityAssociation { RoleId = association.RoleId, ScopeId = scopeId, InboundMultiplicity = (Multiplicities)association.InboundMultiplicity, OutboundMultiplicity = (Multiplicities)association.OutboundMultiplicity, OriginCkId = ckEntity.CkId, TargetCkId = association.TargetCkId, InboundName = associationRoleDefinitions[association.RoleId].InboundName, OutboundName = associationRoleDefinitions[association.RoleId].OutboundName }; _transientCkModel.CkEntityAssociations.Add(ckEntityAssociation); } _transientCkModel.CkEntities.Add(ckEntity); } }