Пример #1
0
        public async Task <object> UpdateObject([NotNull] string objectIdentifier, [NotNull][FromBody] object obj)
        {
            var type      = schemaRegistry.GetTypeByTypeIdentifier(objectIdentifier);
            var schema    = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier);
            var typeInfo  = TypeInfoExtractor.Extract(obj, type, schema.PropertyDescriptionBuilder, schema.CustomPropertyConfigurationProvider);
            var stored    = ObjectsConverter.ApiToStored(typeInfo, type, obj, schema.CustomPropertyConfigurationProvider);
            var newObject = await schemaRegistry.GetConnector(objectIdentifier).Write(stored).ConfigureAwait(false);

            return(ObjectsConverter.StoredToApi(typeInfo, type, newObject, schema.CustomPropertyConfigurationProvider));
        }
Пример #2
0
        public async Task <ObjectDetailsModel> Read(string typeIdentifier, [FromBody] ReadModel filters)
        {
            var type   = schemaRegistry.GetTypeByTypeIdentifier(typeIdentifier);
            var schema = schemaRegistry.GetSchemaByTypeIdentifier(typeIdentifier);
            var result = await schemaRegistry.GetConnector(typeIdentifier).Read(filters.Filters).ConfigureAwait(false);

            var typeInfo = TypeInfoExtractor.Extract(result, type, schema.PropertyDescriptionBuilder, schema.CustomPropertyConfigurationProvider);
            var obj      = ObjectsConverter.StoredToApi(typeInfo, type, result, schema.CustomPropertyConfigurationProvider);

            return(new ObjectDetailsModel
            {
                Object = obj,
                TypeInfo = typeInfo,
            });
        }
Пример #3
0
        public async Task <SearchResult <object> > SearchObjects([NotNull] string objectIdentifier, [NotNull][FromBody] ObjectSearchRequest query)
        {
            var type       = schemaRegistry.GetTypeByTypeIdentifier(objectIdentifier);
            var schema     = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier);
            var countLimit = schema.Description.CountLimit;
            var connector  = schemaRegistry.GetConnector(objectIdentifier);
            var counts     = await connector.Count(query.GetFilters(), countLimit + 1).ConfigureAwait(false);

            var results = await connector.Search(query.GetFilters(), query.GetSorts(), query.Offset ?? 0, query.Count ?? 20).ConfigureAwait(false);

            var typeInfo = TypeInfoExtractor.Extract(type, schema.PropertyDescriptionBuilder, schema.CustomPropertyConfigurationProvider);
            var objects  = results.Select(x => ObjectsConverter.StoredToApi(typeInfo, type, x, schema.CustomPropertyConfigurationProvider)).ToArray();

            return(new SearchResult <object>
            {
                Count = counts ?? objects.Length,
                CountLimit = countLimit,
                Items = objects,
            });
        }
Пример #4
0
        public async Task <ObjectDetails> ReadObject([NotNull] string objectIdentifier, [NotNull][FromBody] ObjectSearchRequest query)
        {
            var type     = schemaRegistry.GetTypeByTypeIdentifier(objectIdentifier);
            var schema   = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier);
            var typeMeta = PropertyHelpers.BuildTypeMetaInformation(type, schema.PropertyDescriptionBuilder, schema.CustomPropertyConfigurationProvider);
            var result   = await schemaRegistry.GetConnector(objectIdentifier).Read(query.GetFilters()).ConfigureAwait(false);

            var typeInfo = TypeInfoExtractor.Extract(result, type, schema.PropertyDescriptionBuilder, schema.CustomPropertyConfigurationProvider);
            var obj      = ObjectsConverter.StoredToApi(typeInfo, type, result, schema.CustomPropertyConfigurationProvider);

            return(new ObjectDetails
            {
                Object = obj,
                Meta = new ObjectDescription
                {
                    Identifier = objectIdentifier,
                    SchemaDescription = schema.Description,
                    TypeMetaInformation = typeMeta,
                }
            });
        }
Пример #5
0
        public async Task <SearchResult> SearchObjects(string objectIdentifier, ObjectSearchRequest query, bool isSuperUser)
        {
            var type   = schemaRegistry.GetTypeByTypeIdentifier(objectIdentifier);
            var schema = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier);

            if (!schema.Description.AllowReadAll && !query.Conditions.Any())
            {
                throw new InvalidOperationException($"Reading without filters is not allowed for {objectIdentifier}");
            }
            if (!schema.Description.AllowSort && query.Sorts.Any())
            {
                throw new InvalidOperationException($"Sorting is not allowed for {objectIdentifier}");
            }

            var offset     = query.Offset ?? 0;
            var count      = query.Count ?? 20;
            var countLimit = isSuperUser ? schema.Description.CountLimitForSuperUser : schema.Description.CountLimit;

            if (offset + count > countLimit)
            {
                throw new InvalidOperationException($"Expected offset ({offset}) + count ({count}) to be less than countLimit ({countLimit})");
            }

            var connector = schemaRegistry.GetConnector(objectIdentifier);
            var counts    = await connector.Count(query.Conditions, countLimit + 1).ConfigureAwait(false);

            var results = counts == null
                              ? await connector.Search(query.Conditions, query.Sorts, 0, countLimit + 1).ConfigureAwait(false)
                              : await connector.Search(query.Conditions, query.Sorts, offset, count).ConfigureAwait(false);

            var objects = results.Select(x => ObjectsConverter.StoredToApi(type, x, schema.CustomPropertyConfigurationProvider)).ToArray();

            return(new SearchResult
            {
                Count = counts,
                CountLimit = countLimit,
                Items = objects,
            });
        }