/// <summary>
        /// Initializes a new instance of the <see cref="UpdateLoadBalancerNodeRequest"/> class
        /// with the specified configuration.
        /// </summary>
        /// <param name="nodeUpdate">The updated configuration for the load balancer node.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="nodeUpdate"/> is <see langword="null"/>.</exception>
        public UpdateLoadBalancerNodeRequest(NodeUpdate nodeUpdate)
        {
            if (nodeUpdate == null)
                throw new ArgumentNullException("nodeUpdate");

            _nodeUpdate = nodeUpdate;
        }
示例#2
0
        public async Task <NodeEntry> UpdateDocument([FromRoute] NodeUpdate nodeBody, [FromQuery] IncludeFieldsQueryParams queryParams)
        {
            var documentEntryBeforeUpdate = await _alfrescoHttpClient.GetNodeInfo(nodeBody?.NodeId);

            var documentEntryAfterUpdate = await _nodesService.Update(nodeBody, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams));

            try
            {
                var documentId  = documentEntryBeforeUpdate?.Entry?.Id;
                var documentPid = documentEntryBeforeUpdate?.GetPid();

                var difference = _alfrescoModelComparer.CompareProperties(
                    documentEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(),
                    documentEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary());

                try
                {
                    var componentsJson = difference.FirstOrDefault(x => x.Key == SpisumNames.Properties.ComponentVersionJSON);
                    if (componentsJson != null)
                    {
                        difference.Remove(componentsJson);
                    }
                }
                catch { }

                string messageDocument = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentUpdateDocument, difference);
                string messageFile     = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentUpdateFile, difference);

                await _auditLogService.Record(
                    documentId,
                    SpisumNames.NodeTypes.Document,
                    documentPid,
                    NodeTypeCodes.Dokument,
                    EventCodes.Uprava,
                    documentEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(),
                    documentEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(),
                    messageDocument);

                var fileId = await _documentService.GetDocumentFileId(documentId);

                if (fileId != null)
                {
                    await _auditLogService.Record(
                        fileId,
                        SpisumNames.NodeTypes.Document,
                        documentPid,
                        NodeTypeCodes.Dokument,
                        EventCodes.Uprava,
                        documentEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(),
                        documentEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(),
                        messageFile);
                }
            }
            catch (Exception ex)
            {
                Log.Logger?.Error(ex, "Audit log failed");
            }

            return(documentEntryAfterUpdate);
        }
示例#3
0
        public async Task <NodeEntry> Register(NodeUpdate body, EmailOrDataboxEnum type)
        {
            var nodeInfo = await _alfrescoHttpClient.GetNodeInfo(body.NodeId, ImmutableList <Parameter> .Empty
                                                                 .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            var archiveFolder = string.Empty;
            var nodeType      = string.Empty;

            switch (type)
            {
            case EmailOrDataboxEnum.Email:
                archiveFolder = SpisumNames.Paths.MailRoomEmailArchived;
                nodeType      = SpisumNames.NodeTypes.Email;
                break;

            case EmailOrDataboxEnum.Databox:
                archiveFolder = SpisumNames.Paths.MailRoomDataBoxArchived;
                nodeType      = SpisumNames.NodeTypes.DataBox;
                break;
            }

            var pathRegex = new Regex($"({SpisumNames.Paths.MailRoomUnfinished})$", RegexOptions.IgnoreCase);

            if (pathRegex.IsMatch(nodeInfo?.Entry?.Path?.Name ?? ""))
            {
                return(await CreateArhiveAndMoveAllFiles(body, archiveFolder, nodeType));
            }
            throw new BadRequestException("", "Node is not in expected path");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UpdateLoadBalancerNodeRequest"/> class
        /// with the specified configuration.
        /// </summary>
        /// <param name="nodeUpdate">The updated configuration for the load balancer node.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="nodeUpdate"/> is <see langword="null"/>.</exception>
        public UpdateLoadBalancerNodeRequest(NodeUpdate nodeUpdate)
        {
            if (nodeUpdate == null)
            {
                throw new ArgumentNullException("nodeUpdate");
            }

            _nodeUpdate = nodeUpdate;
        }
示例#5
0
        private AbstractBilancio GetStructure(NodeUpdate item)
        {
            AbstractBilancio structure = null;

            if (item.UpdateType == "Bilancio")
            {
                structure = _bilancio;
            }
            else if (item.UpdateType == "Preventivo")
            {
                structure = _preventivo;
            }
            return(structure);
        }
示例#6
0
        private async Task <bool> CheckMainComponent(NodeUpdate body, CancellationToken cancellation)
        {
            if (body.Body.Properties == null)
            {
                return(true);
            }

            if (body.Body.Properties.ContainsKey(SpisumNames.Properties.ComponentType))
            {
                var inputValue = body.Body.Properties.GetNestedValueOrDefault(SpisumNames.Properties.ComponentType)?.ToString();
                if (!inputValue.Equals("main"))
                {
                    return(true);
                }

                var response = await _alfrescoHttpClient.GetNodeParents(body.NodeId, ImmutableList <Parameter> .Empty
                                                                        .Add(new Parameter(AlfrescoNames.Headers.Where, $"(assocType='{SpisumNames.Associations.Components}')", ParameterType.QueryString)));

                foreach (var parent in response.List.Entries)
                {
                    var childrens = await _documentService.GetComponents(parent.Entry.Id, false, true);

                    foreach (var children in childrens)
                    {
                        if (children.Entry.Id == body.NodeId)
                        {
                            continue;
                        }

                        var properties   = children.Entry.Properties?.As <JObject>().ToDictionary();
                        var fileMetaType = properties.GetNestedValueOrDefault(SpisumNames.Properties.ComponentType)?.ToString();

                        if (fileMetaType != null && fileMetaType == SpisumNames.Component.Main)
                        {
                            throw new BadRequestException(ErrorCodes.V_COMPONENT_TYPE);
                        }
                    }
                }
            }

            return(true);
        }
示例#7
0
        public async Task <NodeEntry> Register([FromRoute] NodeUpdate nodeBody)
        {
            var documentEntry = await _documentService.Register(nodeBody, new GenerateSsid
            {
                Pattern          = _spisUmConfiguration.Ssid.Pattern,
                Shortcut         = _spisUmConfiguration.Ssid.Shortcut,
                SsidNumberPlaces = _spisUmConfiguration.Ssid.SsidNumberPlaces
            });

            try
            {
                await _auditLogService.Record(documentEntry?.Entry?.Id, SpisumNames.NodeTypes.Document, documentEntry?.GetPid(), NodeTypeCodes.Dokument, EventCodes.PripojeniCJ, TransactinoHistoryMessages.DocumentRegister);
            }
            catch (Exception ex)
            {
                Log.Logger?.Error(ex, "Audit log failed");
            }

            return(documentEntry);
        }
示例#8
0
        private void OnNodeUpdateReceived(NodeUpdate update)
        {
            if (update == null)
            {
                throw new ArgumentNullException(nameof(update));
            }

            var handler = NodeUpdateReceived;

            if (handler != null)
            {
                foreach (var invocation in handler.GetInvocationList().Cast <EventHandler <NodeUpdateEventArgs> >())
                {
                    try
                    {
                        invocation(this, new NodeUpdateEventArgs(update.NodeID));
                    }
                    catch (Exception ex)
                    {
                        LogMessage(ex.ToString());
                    }
                }
            }
        }
示例#9
0
 public async Task <NodeEntry> UpdateFile([FromRoute] NodeUpdate nodeBody, [FromQuery] IncludeFieldsQueryParams queryParams)
 {
     return(await _fileService.Update(nodeBody, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams)));
 }
示例#10
0
 public virtual void OnThresholdReached(object sender, EventArgs e)
 {
     NodeUpdate?.Invoke(sender, e);
 }
示例#11
0
        private void NodeUpdateMessageHandler(Server server, Client client, Session session, NodeUpdate message)
        {
            // Update internal state.

            Node node = session.Node.GetNode(new NodePath(message.Selector));

            if (node == null)
            {
                return;
            }

            if (message.Properties == null)
            {
                return;
            }

            message.Properties.ForEach(p =>
            {
                Node propertyNode = node.GetProperty(p.Name);;

                if (propertyNode == null)
                {
                    return;
                }

                propertyNode.SetData(p.Data);
            });

            // Forward the update message to all clients.

            server.SendBroadcastWithExcept(message, client);
        }
示例#12
0
        private bool UpdateBilancio(NodeUpdate item)
        {
            AbstractBilancio structure = GetStructure(item);

            if (structure == null)//c'è un errore nel file
            {
                return(false);
            }


            //il parent non può essere una stringa nulla poichè rappresenterebbe
            //la radice dell'albero che può avere solo le voci di spesa, entrate e finanza
            if (string.IsNullOrEmpty(item.ParentId))
            {
                return(false);
            }

            //se devo aggiungere o modificare un nodo esso deve avere un
            //id ed una descrizione  non nulli
            if (string.IsNullOrEmpty(item.Id))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(item.Description))
            {
                return(false);
            }



            //a questo punto verifico per prima cosa l'esistenza del parent
            //se non esiste c'è un errore nel file.
            //anche se teoricamente il processo potrebbe continuare è bene che il file sia sempre corretto
            AbstractBilancio parent = structure.FindNodeById(item.ParentId);

            if (parent == null)
            {
                return(false);
            }

            //a questo punto il parent esiste.
            //rimane da verifica che il nodo da aggiornare se esiste esiste sotto il parent
            // altrimenti si tratta di una imprecisione nel file di aggiornamento
            AbstractBilancio nodeInStructure = structure.FindNodeById(item.Id);
            AbstractBilancio nodeInParent    = structure.FindNodeById(item.Id);

            //se non sono nulli vuol dire che il nodo è al di sotto del parent
            //ed è pronto per essere modificato
            if (nodeInParent != null && nodeInStructure != null)
            {
                nodeInParent.Description = item.Description;
                return(true);
            }
            else if (nodeInParent == null && nodeInStructure == null)//il nodo non esiste e va creato
            {
                AbstractBilancio b = CreateStructureItem(item.ContoType, item.Id, item.Description, item.ParentId);
                b.ParentName = parent.Description;
                parent.Add(b);
                return(true);
            }
            else // c'è un errore nel file
            {
                return(false);
            }
        }
示例#13
0
        private async Task <NodeEntry> CreateArhiveAndMoveAllFiles(NodeUpdate body, string archiveFolder, string nodeType)
        {
            var copiedNodes  = new List <NodeEntry>();
            var updatedNodes = new List <NodeEntry>();
            var connections  = new List <Tuple <string, string> >();

            var alfrescoBody = _mapper.Map <NodeBodyUpdate>(body);
            var documentInfo = await _alfrescoHttpClient.UpdateNode(body.NodeId, alfrescoBody, ImmutableList <Parameter> .Empty
                                                                    .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Path, ParameterType.QueryString)));

            var parentFolderInfo = await _alfrescoHttpClient.GetNodeInfo(documentInfo.Entry.ParentId);

            // create folder in archive because copy folder violation
            var copyFolderInfo = await _nodesService.CreateFolder(archiveFolder);

            AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry> request;

            // copy and remove all associations - Copies .eml/.zfo and all it's children to the archive folder
            var entries = (await _alfrescoHttpClient.GetNodeChildren(body.NodeId, ImmutableList <Parameter> .Empty
                                                                     .Add(new Parameter(AlfrescoNames.Headers.MaxItems, 1, ParameterType.QueryString))
                                                                     .Add(new Parameter(AlfrescoNames.Headers.Where, $"(nodeType='{nodeType}')", ParameterType.QueryString))))
                          ?.List?.Entries?.ToList();

            if (entries?.Count > 0)
            {
                var nodeId = entries[0]?.Entry?.Id;

                request = new AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry>(
                    parameters => _alfrescoHttpClient.GetNodeSecondaryChildren(nodeId, parameters)
                    );

                while (await request.Next())
                {
                    var response = request.Response();
                    if (!(response?.List?.Entries?.Count > 0))
                    {
                        break;
                    }

                    foreach (var item in response.List.Entries.ToList())
                    {
                        await _alfrescoHttpClient.DeleteSecondaryChildren(nodeId, item.Entry.Id);

                        var copyInfo = await _alfrescoHttpClient.NodeCopy(item.Entry.Id, new NodeBodyCopy
                        {
                            TargetParentId = copyFolderInfo.Entry.Id
                        });

                        var properties = copyInfo.Entry.Properties.As <JObject>().ToDictionary();
                        var pid        = properties.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();
                        await _alfrescoHttpClient.UpdateNode(copyInfo.Entry.Id, new NodeBodyUpdate()
                                                             .AddProperty(SpisumNames.Properties.Pid, null)
                                                             .AddProperty(SpisumNames.Properties.PidRef, pid)
                                                             .AddProperty(SpisumNames.Properties.Ref, item.Entry.Id));

                        copiedNodes.Add(copyInfo);
                    }
                }

                // Copy .eml / .zfo
                var copyEmlZfo = await _alfrescoHttpClient.NodeCopy(nodeId, new NodeBodyCopy
                {
                    TargetParentId = copyFolderInfo.Entry.Id
                });

                var propertiesEmlZfo = copyEmlZfo.Entry.Properties.As <JObject>().ToDictionary();
                var pidEmlZfo        = propertiesEmlZfo.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();

                await _alfrescoHttpClient.UpdateNode(copyEmlZfo?.Entry?.Id, new NodeBodyUpdate()
                                                     .AddProperty(SpisumNames.Properties.Pid, null)
                                                     .AddProperty(SpisumNames.Properties.PidRef, pidEmlZfo)
                                                     .AddProperty(SpisumNames.Properties.Ref, nodeId));

                copiedNodes.Add(copyEmlZfo);
            }

            // Take all files and move them to the new location
            // find all children and rename + change node type
            request = new AlfrescoPagingRequest <NodeChildAssociationPagingFixed, List19Fixed, NodeChildAssociationEntry>(
                parameters => _alfrescoHttpClient.GetNodeSecondaryChildren(body.NodeId, parameters)
                );

            while (await request.Next())
            {
                var response = request.Response();
                if (!(response?.List?.Entries?.Count > 0))
                {
                    break;
                }

                foreach (var item in response.List.Entries.ToList())
                {
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.Component)
                    {
                        continue;
                    }

                    connections.Add(new Tuple <string, string>(item.Entry.Id, copiedNodes.FirstOrDefault(x => x.Entry.Name == item.Entry.Name)?.Entry?.Id));

                    var updateBody = new NodeBodyUpdate();

                    if (item.Entry.NodeType == AlfrescoNames.ContentModel.Content)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.Component;
                    }
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.Email)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.EmailComponent;
                    }
                    if (item.Entry.NodeType == SpisumNames.NodeTypes.DataBox)
                    {
                        updateBody.NodeType = SpisumNames.NodeTypes.DataBoxComponent;
                    }

                    var personGroup = await GetCreateUserGroup();

                    updateBody.Permissions = _nodesService.SetPermissions(personGroup.GroupPrefix, _identityUser.Id).Permissions;

                    updateBody.Properties = new Dictionary <string, object>
                    {
                        { AlfrescoNames.ContentModel.Owner, _identityUser.Id },
                        { SpisumNames.Properties.Group, _identityUser.RequestGroup }
                    };

                    updatedNodes.Add(await _alfrescoHttpClient.UpdateNode(item.Entry.Id, updateBody));

                    if (item.Entry.NodeType == AlfrescoNames.ContentModel.Content)
                    {
                    }
                }
            }

            // Set PID to archive
            List <NodeEntry> movedNodes = new List <NodeEntry>();

            movedNodes.Add(await _nodesService.MoveByPath(body.NodeId, SpisumNames.Paths.EvidenceDocumentsForProcessing(_identityUser.RequestGroup)));
            movedNodes.AddRange(await _nodesService.MoveAllComponets(body.NodeId));

            foreach (var copy in copiedNodes)
            {
                var id = connections.First(x => x.Item2 == copy.Entry.Id);

                var node = movedNodes.FirstOrDefault(x => x.Entry.Id == id.Item1);

                if (node == null)
                {
                    continue;
                }

                var properties = node.Entry.Properties.As <JObject>().ToDictionary();
                var pid        = properties.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString();

                if (string.IsNullOrWhiteSpace(pid))
                {
                    continue;
                }

                await _alfrescoHttpClient.UpdateNode(copy.Entry.Id, new NodeBodyUpdate
                {
                    Properties = new Dictionary <string, object>
                    {
                        { SpisumNames.Properties.PidArchive, pid }
                    }
                });
            }

            return(await _alfrescoHttpClient.GetNodeInfo(body.NodeId));
        }