Ejemplo n.º 1
0
        public override async Task ExecuteAsync(ICommandDeleteUDSData command)
        {
            _logger.WriteInfo(new LogMessage(string.Concat(command.CommandName, " is arrived")), LogCategories);
            UDSEntityModel udsEntityModel = await CancelDataAsync(command.ContentType.ContentTypeValue, command.Identity.User, command.CreationTime);

            IEventDeleteUDSData evt = new EventDeleteUDSData(Guid.NewGuid(), command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                             command.ContentType.ContentTypeValue, null);

            evt.CorrelatedMessages.Add(command);
            if (!await PushEventAsync(evt))
            {
                throw new Exception("EventDeleteUDSData not sent");
            }

            UDSBuildModel udsBuildModel = MapUDSModel(command.ContentType.ContentTypeValue, udsEntityModel);

            IEventCompleteUDSDelete eventCompleteUDSDelete = new EventCompleteUDSDelete(Guid.NewGuid(), command.CorrelationId, command.TenantName, command.TenantId,
                                                                                        command.TenantAOOId, command.Identity, udsBuildModel, null);

            if (!await PushEventAsync(eventCompleteUDSDelete))
            {
                _logger.WriteError(new LogMessage($"EventCompleteUDSDelete {udsBuildModel.UniqueId} has not been sended"), LogCategories);
                throw new Exception("IEventCompleteUDSDelete not sended");
            }
            _logger.WriteInfo(new LogMessage($"EventCompleteUDSDelete {udsBuildModel.UniqueId} has been sended"), LogCategories);
        }
Ejemplo n.º 2
0
        private ICollection <IWorkflowAction> MapWorkflowPECMailLinkActions(UDSEntityModel model)
        {
            if (model.Relations.PECMails == null || !model.Relations.PECMails.Any())
            {
                return(new List <IWorkflowAction>());
            }

            ICollection <IWorkflowAction> workflowActions = new List <IWorkflowAction>();

            foreach (UDSPECMail instance in model.Relations.PECMails)
            {
                PECMail pecInstance = GetPECMailAsync(instance.IdPECMail).Result;
                if (pecInstance != null && !pecInstance.Year.HasValue)
                {
                    workflowActions.Add(new WorkflowActionDocumentUnitLinkModel(
                                            new DocumentUnitModel()
                    {
                        UniqueId = model.IdUDS, Number = model.Number.Value.ToString(), Year = model.Year.Value
                    },
                                            new DocumentUnitModel()
                    {
                        UniqueId = instance.UniqueIdPECMail, EntityId = instance.IdPECMail, Environment = (int)DocSuiteWeb.Model.Entities.Commons.DSWEnvironmentType.PECMail
                    }));
                }
            }
            return(workflowActions);
        }
Ejemplo n.º 3
0
        private async Task BuildCQRSInsertCommand(ICommandInsertUDSData command, UDSEntityModel udsModel)
        {
            IEventInsertUDSData evt = new EventInsertUDSData(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                             command.ContentType.ContentTypeValue);

            if (udsModel.Relations != null && udsModel.Relations.PECMails != null && udsModel.Relations.PECMails.Any())
            {
            }
            evt.CorrelatedMessages.Add(command);
        }
Ejemplo n.º 4
0
        private ICollection <IWorkflowAction> MapWorkflowLinkActions(UDSEntityModel model)
        {
            if (model.Relations == null)
            {
                return(new List <IWorkflowAction>());
            }

            List <IWorkflowAction> workflowActions = new List <IWorkflowAction>();

            workflowActions.AddRange(MapWorkflowPECMailLinkActions(model));
            return(workflowActions);
        }
Ejemplo n.º 5
0
        private ICollection <TResult> PrepareRelationModels <T, TResult>(UDSEntityModel model,
                                                                         Func <IEnumerable <T> > getSourceFunc, Func <T, TResult> mappingFunc)
        {
            ICollection <TResult> results = new List <TResult>();
            IEnumerable <T>       sources = getSourceFunc();

            if (sources != null)
            {
                foreach (T source in sources)
                {
                    results.Add(mappingFunc(source));
                }
            }
            return(results);
        }
Ejemplo n.º 6
0
        protected string PrepareRelations(UDSEntityModel model, Guid udsRepositoryId, int environment, string userName, DateTimeOffset creationTime, BuildActionType buildActionType)
        {
            WebApiModel.UDSRelationModel relationModel = new WebApiModel.UDSRelationModel
            {
                Roles = PrepareRelationModels(model, () => model.Relations?.Authorizations,
                                              (item) => MapAuthorization(item, creationTime, userName, environment)),

                Users = PrepareRelationModels(model, () => model.Users,
                                              (item) => MapUser(item, creationTime, userName, environment, model.IdUDS)),

                Collaborations = PrepareRelationModels(model, () => model.Relations?.Collaborations,
                                                       (item) => MapCollaboration(item, creationTime, userName, environment, model.IdUDS)),

                Contacts = PrepareRelationModels(model, () => model.Relations?.Contacts,
                                                 (item) => MapContact(item, creationTime, userName, environment)),

                Messages = PrepareRelationModels(model, () => model.Relations?.Messages,
                                                 (item) => MapMessage(item, creationTime, userName, environment)),

                PECMails = PrepareRelationModels(model, () => model.Relations?.PECMails,
                                                 (item) => MapPECMail(item, creationTime, userName, environment))
            };

            ICollection <WebApiModel.UDSDocumentUnitModel> documentUnits = new List <WebApiModel.UDSDocumentUnitModel>();

            documentUnits = PrepareRelationModels(model, () => model.Relations?.Protocols,
                                                  (item) => MapProtocol(item, creationTime, userName, environment, buildActionType));

            documentUnits = documentUnits.Concat(PrepareRelationModels(model, () => model.Relations?.Resolutions,
                                                                       (item) => MapResolution(item, creationTime, userName, environment))).ToList();

            ICollection <WebApiEntity.UDSDocumentUnit> udsDocumentUnits = GetUDSDocumentUnitRelationByID(model.IdUDS).Result;

            documentUnits = documentUnits.Concat(PrepareRelationModels(model, () => udsDocumentUnits,
                                                                       (item) => MapUDSDocumentUnits(item, creationTime, userName))).ToList();

            relationModel.DocumentUnits = documentUnits;

            return(JsonConvert.SerializeObject(relationModel));
        }
Ejemplo n.º 7
0
        protected async Task InsertLogAsync(UDSEntityModel model, Guid udsRepositoryId, int environment)
        {
            if (model == null || model.Logs == null || !model.Logs.Any())
            {
                return;
            }

            try
            {
                foreach (UDSLogModel log in model.Logs)
                {
                    WebApiEntity.UDSLog webApiLog = MapLog(log);
                    webApiLog.Entity      = new WebApiEntity.UDSRepository(udsRepositoryId);
                    webApiLog.Environment = environment;
                    await InsertLogAsync(webApiLog);
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage(string.Format("InsertLogAsync -> Errore in inserimento log: {0}", ex.Message)), LogCategories);
                throw ex;
            }
        }
Ejemplo n.º 8
0
        private async Task PostRelationsAsync(UDSEntityModel model, Guid udsRepositoryId, int environment, string userName, DateTimeOffset creationTime, BuildActionType buildActionType)
        {
            if (model == null || model.Relations == null || (model.Relations == null && (model.Users == null || !model.Users.Any())))
            {
                return;
            }

            try
            {
                BuildActionModel actionModel = new BuildActionModel
                {
                    ReferenceId = model.IdUDS,
                    BuildType   = buildActionType,
                    Model       = PrepareRelations(model, udsRepositoryId, environment, userName, creationTime, buildActionType)
                };

                await _webApiClient.PostBuilderAsync(actionModel, udsRepositoryId);
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage(string.Format("PostRelationsAsync -> Errore in inserimento relazioni: {0}", ex.Message)), LogCategories);
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public override async Task ExecuteAsync(ICommandInsertUDSData command)
        {
            _logger.WriteInfo(new LogMessage(string.Concat(command.CommandName, " is arrived")), LogCategories);

            Guid?  collaborationUniqueId;
            string collaborationTemplateName;
            int?   collaborationId;

            try
            {
                _logger.WriteInfo(new LogMessage(string.Concat(command.ContentType.Id, " model evaluating ... ")), LogCategories);
                UDSEntityModel udsEntityModel = await InsertDataAsync(command.ContentType.ContentTypeValue, command.Identity.User, command.CreationTime);

                command.ContentType.ContentTypeValue.UniqueId = udsEntityModel.IdUDS;
                ResetModelXML(command.ContentType.ContentTypeValue);

                collaborationId           = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.IdCollaboration;
                collaborationUniqueId     = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationUniqueId;
                collaborationTemplateName = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationTemplateName;

                IEventInsertUDSData evt = new EventInsertUDSData(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                                 command.ContentType.ContentTypeValue);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventInsertUDSData not sent");
                }

                UDSBuildModel    udsBuildModel    = MapUDSModel(command.ContentType.ContentTypeValue, udsEntityModel);
                CategoryFascicle categoryFascicle = await GetPeriodicCategoryFascicleByEnvironment(udsEntityModel.IdCategory.Value, command.ContentType.ContentTypeValue.UDSRepository.DSWEnvironment);

                if (categoryFascicle == null)
                {
                    categoryFascicle = await GetDefaultCategoryFascicle(udsEntityModel.IdCategory.Value);
                }
                ICommandCQRSCreateUDSData commandCQRS = new CommandCQRSCreateUDSData(command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                                                     collaborationUniqueId, collaborationId, collaborationTemplateName);
                if (command.CorrelationId.HasValue)
                {
                    commandCQRS = new CommandCQRSCreateUDSData(command.CorrelationId.Value, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                               collaborationUniqueId, collaborationId, collaborationTemplateName);
                }
                if (udsBuildModel.WorkflowActions != null)
                {
                    foreach (IWorkflowAction workflowAction in udsBuildModel.WorkflowActions)
                    {
                        commandCQRS.WorkflowActions.Add(workflowAction);
                    }
                }
                if (!await PushCommandAsync(commandCQRS))
                {
                    throw new Exception("CommandCQRSCreateUDSData not sent");
                }
                #region [ EventCompleteUDSBuild ]
                IEventCompleteUDSBuild eventCompleteUDSBuild = new EventCompleteUDSBuild(Guid.NewGuid(), command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId,
                                                                                         command.Identity, udsBuildModel, null);
                if (!await PushEventAsync(eventCompleteUDSBuild))
                {
                    _logger.WriteError(new LogMessage($"EventCompleteUDSBuild {udsBuildModel.UniqueId} has not been sended"), LogCategories);
                    throw new Exception("IEventCompleteUDSBuild not sended");
                }
                _logger.WriteInfo(new LogMessage($"EventCompleteUDSBuild {udsBuildModel.UniqueId} has been sended"), LogCategories);
                #endregion
            }
            catch (Exception ex)
            {
                ResetModelXML(command.ContentType.ContentTypeValue);
                IEventError evt = new EventError(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                 new ContentTypeString($"Errore in fase di inserimento nell'archivio [{ex.Message}]"), null);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventError not sent");
                }
                throw ex;
            }

            _logger.WriteInfo(new LogMessage("message completed."), LogCategories);
        }
Ejemplo n.º 10
0
        public override async Task ExecuteAsync(ICommandUpdateUDSData command)
        {
            _logger.WriteInfo(new LogMessage($"{command.CommandName} is arrived"), LogCategories);

            Guid?  collaborationUniqueId;
            string collaborationTemplateName;
            int?   collaborationId;

            try
            {
                UDSEntityModel udsEntityModel = await UpdateData(command.ContentType.ContentTypeValue, command.Identity.User, command.CreationTime);

                ResetModelXML(command.ContentType.ContentTypeValue);

                collaborationId           = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.IdCollaboration;
                collaborationUniqueId     = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationUniqueId;
                collaborationTemplateName = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationTemplateName;

                IEventUpdateUDSData evt = new EventUpdateUDSData(Guid.NewGuid(), command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                                 command.ContentType.ContentTypeValue, null);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventUpdateUDSData not sent");
                }

                CategoryFascicle categoryFascicle = await GetPeriodicCategoryFascicleByEnvironment(udsEntityModel.IdCategory.Value, command.ContentType.ContentTypeValue.UDSRepository.DSWEnvironment);

                if (categoryFascicle == null)
                {
                    categoryFascicle = await GetDefaultCategoryFascicle(udsEntityModel.IdCategory.Value);
                }

                UDSBuildModel udsBuildModel = MapUDSModel(command.ContentType.ContentTypeValue, udsEntityModel);

                ICommandCQRSUpdateUDSData commandCQRS = new CommandCQRSUpdateUDSData(command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                                                     collaborationUniqueId, collaborationId, collaborationTemplateName);

                if (command.CorrelationId.HasValue)
                {
                    commandCQRS = new CommandCQRSUpdateUDSData(command.CorrelationId.Value, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                               collaborationUniqueId, collaborationId, collaborationTemplateName);
                }

                if (udsBuildModel.WorkflowActions != null)
                {
                    foreach (IWorkflowAction workflowAction in udsBuildModel.WorkflowActions)
                    {
                        commandCQRS.WorkflowActions.Add(workflowAction);
                    }
                }
                if (!await PushCommandAsync(commandCQRS))
                {
                    throw new Exception("CommandCQRSUpdateUDSData not sent");
                }
            }
            catch (Exception ex)
            {
                ResetModelXML(command.ContentType.ContentTypeValue);
                IEventError evt = new EventError(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                 new ContentTypeString($"Errore in fase di aggiornamento nell'archivio [{ex.Message}]"), null);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventError not sent");
                }
                throw ex;
            }
        }
Ejemplo n.º 11
0
        protected WebApiModel.UDSBuildModel MapUDSModel(WebApiModel.UDSBuildModel model, UDSEntityModel entityModel)
        {
            model.Year             = entityModel.Year;
            model.Number           = entityModel.Number;
            model.RegistrationDate = entityModel.RegistrationDate;
            model.LastChangedDate  = entityModel.LastChangedDate;
            model.LastChangedUser  = entityModel.LastChangedUser;
            model.Subject          = entityModel.Subject;
            model.Title            = entityModel.Title;
            model.Category         = entityModel.IdCategory.HasValue ? new CategoryModel(entityModel.IdCategory) : null;
            model.Container        = entityModel.IdContainer.HasValue ? new ContainerModel(entityModel.IdContainer) : null;
            model.Roles            = entityModel.Relations != null?MapUDSRoles(entityModel.Relations.Authorizations) : new List <RoleModel>();

            model.Users     = MapUDSUsers(entityModel.Users);
            model.Documents = entityModel.Relations != null?MapUDSDocuments(entityModel.Relations.Documents) : new List <WebApiModel.UDSDocumentModel>();

            if (model.WorkflowActions == null)
            {
                model.WorkflowActions = new List <IWorkflowAction>();
            }
            model.WorkflowActions = model.WorkflowActions.Concat(MapWorkflowLinkActions(entityModel)).ToList();
            return(model);
        }
Ejemplo n.º 12
0
 protected async Task UpdateRelationsAsync(UDSEntityModel model, Guid udsRepositoryId, int environment, string userName, DateTimeOffset creationTime)
 {
     await PostRelationsAsync(model, udsRepositoryId, environment, userName, creationTime, BuildActionType.Synchronize);
 }