Ejemplo n.º 1
0
        private async Task CreateChilds <T, U>(List <ChildrenARM <T, U> > childs, string parentId)
        {
            foreach (var child in childs)
            {
                string name = null;

                if (typeof(T) == typeof(NodeBodyCreate))
                {
                    name = (child as ChildrenARM <NodeBodyCreate, U>)?.Body?.Name;
                }
                else if (typeof(T) == typeof(RootCategoryBodyCreate))
                {
                    name = (child as ChildrenARM <RootCategoryBodyCreate, U>)?.Body?.Name;
                }
                else if (typeof(T) == typeof(RMNodeBodyCreateWithRelativePath))
                {
                    name = (child as ChildrenARM <RMNodeBodyCreateWithRelativePath, U>)?.Body?.Name;
                }

                if (name == null)
                {
                    continue;
                }

                string nodeId = null;

                try
                {
                    var node = await _alfrescoHttpClient.GetNodeInfo(parentId, ImmutableList <Parameter> .Empty
                                                                     .Add(new Parameter(AlfrescoNames.Headers.RelativePath, name, ParameterType.QueryString)));

                    nodeId = node?.Entry?.Id;
                }
                catch
                {
                }

                if (nodeId == null)
                {
                    try
                    {
                        child.FillQueryParams();

                        if (typeof(T) == typeof(NodeBodyCreate))
                        {
                            var createdChild = await _alfrescoHttpClient.CreateNode(parentId, child.Body);

                            nodeId = createdChild?.Entry?.Id;
                        }
                        else if (typeof(T) == typeof(RootCategoryBodyCreate))
                        {
                            var createdChild = await _alfrescoHttpClient.CreateRecordCategory(parentId, child.Body);

                            nodeId = createdChild?.Entry?.Id;
                        }
                        else if (typeof(T) == typeof(RMNodeBodyCreateWithRelativePath))
                        {
                            var createdChild = await _alfrescoHttpClient.CreateRecordCategoryChild(parentId, child.Body);

                            nodeId = createdChild?.Entry?.Id;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "CreateChilds Fail");
                    }
                }

                if (typeof(T) == typeof(RootCategoryBodyCreate) || typeof(T) == typeof(RMNodeBodyCreateWithRelativePath))
                {
                    // update permissions
                    await SetPermissionInheritence(nodeId);
                }

                await CheckCreatePermissions(nodeId, child.Permissions);

                if (child?.Childs?.Count > 0 && nodeId != null)
                {
                    await CreateChilds(child.Childs, nodeId);
                }
            }
        }