Ejemplo n.º 1
0
        public async Task <EntityNode> VerifyEntity(Guid entitiyId, EntityNodesCollection edgesCollection, Guid permission)
        {
            var entities = await VerifyEntities(new List <Guid> {
                entitiyId
            }, edgesCollection, permission);

            return(entities.FirstOrDefault());
        }
        public TreeEdgesCollection_QueryableTests()
        {
            _propertyResolver
            .Setup(x => x.GetEntityId(It.IsAny <EntityNode>()))
            .Returns((EntityNode t) => t.Id);

            _inMemoryCollection  = new InMemoryCollection <FakeEntityContext, EntityNode>(_propertyResolver.Object, "fake-entity-context");
            _treeEdgesCollection = new EntityNodesCollection(_inMemoryCollection);
        }
        private void ValidateTreeEdges(EntityNodesCollection edgesCollection, IEnumerable <EntityNode> treeEdges)
        {
            var newNodesId = treeEdges
                             .Select(x => x.EntityId)
                             .ToList();

            var existingNodes = edgesCollection.GetNodes(newNodesId);

            if (existingNodes.Any())
            {
                throw new NodeAlreadyExistsException($"Node {string.Join(", ", existingNodes.Select(x => x.EntityId))} already exists");
            }
        }
        private async Task <EntityNode> GetParentNode(EntityNodesCollection edgesCollection, Guid parentId)
        {
            if (parentId == Guid.Empty)
            {
                await _commandsHelper.VerifyRootNodePermission(SecurityRight.Create);

                return(null);
            }

            var parent = await _commandsHelper.VerifyEntity(parentId, edgesCollection, SecurityRight.Create);

            if (parent == null)
            {
                throw new ParentNodeNotFoundException($"Parent node {parentId} not found");
            }

            return(parent);
        }
Ejemplo n.º 5
0
        private async Task <IEnumerable <EntityNode> > DeleteEntityAndDescendants(EntityNode deleteRoot, EntityNodesCollection edgesCollection)
        {
            var descendants = edgesCollection.GetDescendants(deleteRoot);

            var groupedEntities = descendants.GroupBy(x => x.CollectionId);

            foreach (var entityGroup in groupedEntities)
            {
                var entitiesIdToDelete = entityGroup
                                         .Select(x => x.EntityId)
                                         .ToList();

                var entityCollection = _transactionService.GetCollection(typeof(object), entityGroup.Key);
                await entityCollection.Delete(entitiesIdToDelete);
            }

            await edgesCollection.DeleteNodes(descendants.Select(x => x.EntityId));

            return(descendants);
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <EntityNode> > VerifyEntities(IEnumerable <Guid> entitiesId, EntityNodesCollection edgesCollection, Guid permission)
        {
            var existingNodes = edgesCollection
                                .AsQueryable()
                                .Where(x => entitiesId.Contains(x.EntityId))
                                .ToList();

            var existingNodesId = existingNodes
                                  .Select(x => x.EntityId);

            var missingNodesId = entitiesId
                                 .Except(existingNodesId)
                                 .ToList();

            if (missingNodesId.Any())
            {
                throw new EntitiesNotFoundException($"Entities not found {string.Join(", ", missingNodesId)}");
            }

            await VerifyEntitiesAuthorization(entitiesId, permission);

            return(existingNodes);
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <EntityNode> > VerifyEntities(IEnumerable <object> entities, EntityNodesCollection edgesCollection, Guid permission)
        {
            var entitiesId = GetEntitiesId(entities);

            return(await VerifyEntities(entitiesId, edgesCollection, permission));
        }
Ejemplo n.º 8
0
 public async Task <IEnumerable <EntityNode> > VerifyEntities <TEntity>(IEnumerable <TEntity> entities, EntityNodesCollection edgesCollection, Guid permission)
 {
     return(await VerifyEntities(entities.Cast <object>(), edgesCollection, permission));
 }