예제 #1
0
        private async Task ValidateCkModel(IOspSession session, GraphRuleEngineResult graphRuleEngineResult, IReadOnlyList <EntityUpdateInfo> entityUpdateInfoList, IReadOnlyList <AssociationUpdateInfo> associationUpdateInfoList)
        {
            await ValidateOrigin(session, entityUpdateInfoList, associationUpdateInfoList);
            await ValidateTarget(session, entityUpdateInfoList, associationUpdateInfoList);

            // Ensure that all associations exists when creating an entity
            // Currently, the only mandatory association has multiplicity of One
            foreach (var entityUpdateInfo in entityUpdateInfoList.Where(x => x.ModOption == EntityModOptions.Create))
            {
                var cacheItem = _ckCache.GetEntityCacheItem(entityUpdateInfo.RtEntity.CkId);

                var inboundAssociationCacheItems = cacheItem.InboundAssociations.Values.SelectMany(x => x.Where(a => a.InboundMultiplicity == Multiplicities.One));
                foreach (var inboundAssociationCacheItem in inboundAssociationCacheItems)
                {
                    if (!associationUpdateInfoList.Any(x => x.ModOption == AssociationModOptionsDto.Create && x.RoleId == inboundAssociationCacheItem.RoleId))
                    {
                        throw new CkModelViolationException($"Inbound association '{inboundAssociationCacheItem.RoleId}' has multiplicity of 'One', but create statement is missing. Error occurred at CK type '{entityUpdateInfo.RtEntity.CkId}' (from RtId '{entityUpdateInfo.RtEntity.RtId}').");
                    }
                }
            }

            // Delete all corresponding associations if an entity is deleted
            foreach (var entityUpdateInfo in entityUpdateInfoList.Where(x => x.ModOption == EntityModOptions.Delete))
            {
                var result = await _tenantRepository.GetRtAssociationsAsync(session, entityUpdateInfo.RtEntity.RtId.ToString(), GraphDirections.Any);

                graphRuleEngineResult.RtAssociationsToDelete.AddRange(result);
            }
        }
예제 #2
0
        private void RtEntityFromInputObject(RtEntity rtEntity, RtEntityDto rtEntityDto, List <AssociationUpdateInfo> associations)
        {
            var metaEntityCacheItem = _ckCache.GetEntityCacheItem(rtEntity.CkId);

            rtEntity.WellKnownName = rtEntityDto.WellKnownName;

            if (rtEntityDto.Properties != null)
            {
                foreach (var item in rtEntityDto.Properties)
                {
                    if (TryHandleAttribute(rtEntity, metaEntityCacheItem, item))
                    {
                        continue;
                    }
                    if (TryHandleInboundAssoc(rtEntity, metaEntityCacheItem, item, associations))
                    {
                        continue;
                    }
                    TryHandleOutboundAssoc(rtEntity, metaEntityCacheItem, item, associations);
                }
            }
        }