Example #1
0
        public async Task <ResultSet <RtEntity> > GetRtEntitiesByIdAsync(IOspSession session, string ckId,
                                                                         IReadOnlyList <ObjectId> rtIds,
                                                                         DataQueryOperation dataQueryOperation, int?skip = null, int?take = null)
        {
            ArgumentValidation.ValidateString(nameof(ckId), ckId);
            ArgumentValidation.Validate(nameof(rtIds), rtIds);
            ArgumentValidation.Validate(nameof(dataQueryOperation), dataQueryOperation);

            if (!rtIds.Any())
            {
                return(new ResultSet <RtEntity>(new List <RtEntity>(), 0));
            }

            var  resultSet       = new List <RtEntity>();
            long totalCount      = 0;
            var  entityCacheItem = GetEntityCacheItem(ckId);

            var statementCreator =
                new RtStatementCreator(entityCacheItem, _databaseContext, dataQueryOperation.Language);

            statementCreator.AddFieldFilters(dataQueryOperation.FieldFilters);
            statementCreator.AddIdFilter(rtIds);
            statementCreator.AddTextSearchFilter(dataQueryOperation.TextSearchFilter);
            statementCreator.AddAttributeSearchFilter(dataQueryOperation.AttributeSearchFilter);
            statementCreator.AddSort(dataQueryOperation.SortOrders);

            var tempResultSet = await statementCreator.ExecuteQuery(session, skip, take);

            resultSet.AddRange(tempResultSet.Result);
            totalCount += tempResultSet.TotalCount;

            return(new ResultSet <RtEntity>(resultSet, totalCount));
        }
Example #2
0
        public async Task <ResultSet <TEntity> > GetRtEntitiesByTypeAsync <TEntity>(IOspSession session,
                                                                                    DataQueryOperation dataQueryOperation,
                                                                                    int?skip = null, int?take = null) where TEntity : RtEntity, new()
        {
            var ckId = GetCkId <TEntity>();

            return(await GetRtEntitiesByTypeAsync <TEntity>(session, ckId, dataQueryOperation, skip, take));
        }
Example #3
0
        private async Task <ResultSet <TEntity> > GetRtEntitiesByTypeAsync <TEntity>(IOspSession session, string ckId,
                                                                                     DataQueryOperation dataQueryOperation, int?skip = null, int?take = null) where TEntity : RtEntity, new()
        {
            ArgumentValidation.Validate(nameof(dataQueryOperation), dataQueryOperation);

            var entityCacheItem  = GetEntityCacheItem(ckId);
            var statementCreator =
                new RtStatementCreator <TEntity>(entityCacheItem, _databaseContext, dataQueryOperation.Language);

            statementCreator.AddFieldFilters(dataQueryOperation.FieldFilters);
            statementCreator.AddTextSearchFilter(dataQueryOperation.TextSearchFilter);
            statementCreator.AddAttributeSearchFilter(dataQueryOperation.AttributeSearchFilter);
            statementCreator.AddSort(dataQueryOperation.SortOrders);

            return(await statementCreator.ExecuteQuery(session, skip, take));
        }
Example #4
0
        private async Task RunAutoIncrementAsync(IOspSession session, string ckId, IEnumerable <RtEntity> rtEntities)
        {
            var entityCacheItem = CkCache.GetEntityCacheItem(ckId);

            if (entityCacheItem == null)
            {
                throw new InvalidCkIdException($"Construction Kit Id '{ckId}' is invalid.");
            }

            var autoIncrementReferences = entityCacheItem.Attributes.Values
                                          .Where(a => !string.IsNullOrEmpty(a.AutoIncrementReference)).ToList();


            var dataQueryOperation = new DataQueryOperation
            {
                FieldFilters = new[]
                {
                    new FieldFilter(nameof(RtEntity.WellKnownName), FieldFilterOperator.In,
                                    autoIncrementReferences.Select(x => x.AutoIncrementReference))
                }
            };

            var autoIncrementerSet = await GetRtEntitiesByTypeAsync <RtSystemAutoIncrement>(session, dataQueryOperation);

            foreach (var rtEntity in rtEntities)
            {
                foreach (var autoIncrementReference in autoIncrementReferences)
                {
                    var attributeCacheItem = entityCacheItem.Attributes[autoIncrementReference.AttributeName];
                    if (attributeCacheItem == null)
                    {
                        throw new InvalidAttributeException(
                                  $"Attribute with name '{autoIncrementReference.AttributeName}' does not exist at Ck-Id {ckId}");
                    }

                    var autoIncrement = autoIncrementerSet.Result.FirstOrDefault(x =>
                                                                                 x.WellKnownName == autoIncrementReference.AutoIncrementReference);

                    rtEntity.SetAttributeValue(autoIncrementReference.AttributeName,
                                               attributeCacheItem.AttributeValueType,
                                               await ExecuteAutoIncrementAsync(session, autoIncrement));
                }
            }
        }
Example #5
0
        public async Task <ResultSet <CkEntity> > GetCkEntityAsync(IOspSession session, IReadOnlyList <string> ckIds,
                                                                   DataQueryOperation dataQueryOperation, int?skip = null, int?take = null)
        {
            var  resultSet  = new List <CkEntity>();
            long totalCount = 0;

            var statementCreator = new CkEntityStatementCreator(_databaseContext);

            statementCreator.AddFieldFilters(dataQueryOperation.FieldFilters);
            statementCreator.AddIdFilter(ckIds);
            statementCreator.AddTextSearchFilter(dataQueryOperation.TextSearchFilter);
            statementCreator.AddAttributeSearchFilter(dataQueryOperation.AttributeSearchFilter);
            statementCreator.AddSort(dataQueryOperation.SortOrders);

            var tempResultSet = await statementCreator.ExecuteQuery(session, skip, take);

            resultSet.AddRange(tempResultSet.Result);
            totalCount += tempResultSet.TotalCount;

            return(new ResultSet <CkEntity>(resultSet, totalCount));
        }
Example #6
0
 public async Task <ResultSet <RtEntity> > GetRtEntitiesByTypeAsync(IOspSession session, string ckId,
                                                                    DataQueryOperation dataQueryOperation, int?skip = null, int?take = null)
 {
     return(await GetRtEntitiesByTypeAsync <RtEntity>(session, ckId, dataQueryOperation, skip, take));
 }
Example #7
0
        public async Task <ResultSet <RtEntity> > GetRtAssociationTargetsAsync(IOspSession session, ObjectId rtId,
                                                                               string roleId,
                                                                               string targetCkId,
                                                                               GraphDirections graphDirection, DataQueryOperation dataQueryOperation, int?skip = null, int?take = null)
        {
            ArgumentValidation.Validate(nameof(rtId), rtId);
            ArgumentValidation.ValidateString(nameof(roleId), roleId);
            ArgumentValidation.ValidateString(nameof(targetCkId), targetCkId);
            ArgumentValidation.Validate(nameof(dataQueryOperation), dataQueryOperation);

            var entityCacheItem = GetEntityCacheItem(targetCkId);

            var hierarchicalRtStatementCreator =
                new HierarchicalRtStatementCreator(entityCacheItem, _databaseContext, dataQueryOperation.Language, rtId, graphDirection, targetCkId);

            hierarchicalRtStatementCreator.AddFieldFilters(dataQueryOperation.FieldFilters);
            hierarchicalRtStatementCreator.AddTextSearchFilter(dataQueryOperation.TextSearchFilter);
            hierarchicalRtStatementCreator.AddAttributeSearchFilter(dataQueryOperation.AttributeSearchFilter);
            hierarchicalRtStatementCreator.AddSort(dataQueryOperation.SortOrders);

            return(await hierarchicalRtStatementCreator.ExecuteQuery(session, skip, take));
        }