Exemplo n.º 1
0
        /// <summary>
        /// Deserializza una struttura JSON di tipo UDSWorkflowModel recuperata da Workflow (property).
        /// </summary>
        /// <returns>oggetto UDSDto</returns>
        public UDSDto ReadUDSWorkflowJson(string udsWorkflowJson, Data.Entity.UDS.UDSRepository repository)
        {
            if (string.IsNullOrEmpty(udsWorkflowJson))
            {
                throw new ArgumentNullException("udsWorkflowJson");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            UDSModel         udsModel = UDSModel.LoadXml(repository.ModuleXML);
            UDSWorkflowModel model    = JsonConvert.DeserializeObject <UDSWorkflowModel>(udsWorkflowJson, DocSuiteContext.DefaultWebAPIJsonSerializerSettings);
            UDSModelField    udsField;

            foreach (Section metadata in udsModel.Model.Metadata)
            {
                foreach (FieldBaseType item in metadata.Items)
                {
                    udsField = new UDSModelField(item);
                    foreach (KeyValuePair <string, string> data in model.DynamicDatas)
                    {
                        if (data.Key.Eq(udsField.ColumnName))
                        {
                            udsField.Value = data.Value;
                        }
                    }
                }
            }

            if (udsModel.Model.Contacts != null && model.Contact != null)
            {
                //todo: sarà sempre e solo un singolo contatto?
                Contacts contact = udsModel.Model.Contacts.FirstOrDefault();
                if (model.Contact.HasId())
                {
                    ContactInstance newInstance = new ContactInstance()
                    {
                        IdContact = model.Contact.Id.Value
                    };
                    contact.ContactInstances = (contact.ContactInstances ?? Enumerable.Empty <ContactInstance>()).Concat(new ContactInstance[] { newInstance }).ToArray();
                }
                else if (!string.IsNullOrEmpty(model.Contact.Description))
                {
                    ContactManualInstance newManualInstance = new ContactManualInstance()
                    {
                        ContactDescription = model.Contact.Description
                    };
                    contact.ContactManualInstances = (contact.ContactManualInstances ?? Enumerable.Empty <ContactManualInstance>()).Concat(new ContactManualInstance[] { newManualInstance }).ToArray();
                }
            }

            UDSDto udsDto = new UDSDto()
            {
                UDSModel = udsModel
            };

            return(udsDto);
        }
Exemplo n.º 2
0
        public static string GetUDSMailBody(UDSDto uds)
        {
            string tempBody = GetUDSMailSubject(uds);
            string link     = string.Format("<a href=\"{0}?Tipo=UDS&Azione=Apri&IdUDSRepository={1}&IdUDS={2}\">{3}</a>", DocSuiteContext.Current.CurrentTenant.DSWUrl, uds.UDSRepository.UniqueId, uds.Id, GetUDSMailSubject(uds));

            tempBody = string.Concat(tempBody, string.Format("<br>Contenitore: {0} <br> Oggetto: {1} <br> Classificazione: {2} <br><br> {3} <br>", uds.UDSRepository.Container.Name, uds.UDSModel.Model.Subject.Value, uds.Category.Name, link));
            return(tempBody);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserializza una struttura JSON dinamica recuperata da WebAPI.
        /// </summary>
        /// <returns>oggetto UDSDto</returns>
        public UDSDto ReadUDSJson(string udsJson, Data.Entity.UDS.UDSRepository repository)
        {
            if (string.IsNullOrEmpty(udsJson))
            {
                throw new ArgumentNullException("udsJson");
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            UDSModel     udsModel   = UDSModel.LoadXml(repository.ModuleXML);
            string       jsonParsed = ParseJson(udsJson);
            UDSEntityDto entityDto  = JsonConvert.DeserializeObject <IList <UDSEntityDto> >(jsonParsed, DocSuiteContext.DefaultUDSJsonSerializerSettings).FirstOrDefault();

            if (entityDto == null)
            {
                return(null);
            }
            FillBaseData(entityDto, udsModel);
            FillMetadata(jsonParsed, udsModel);
            FillDocuments(entityDto, udsModel);
            FillContacts(entityDto, udsModel);
            FillAuthorization(entityDto, udsModel);
            FillMessages(entityDto, udsModel);
            FillPECMails(entityDto, udsModel);
            FillProtocols(entityDto, udsModel);
            FillCollaborations(entityDto, udsModel);

            UDSDto dto = new UDSDto()
            {
                Id               = entityDto.Id.Value,
                Year             = entityDto.Year.Value,
                Number           = entityDto.Number.Value,
                Status           = entityDto.Status,
                CancelMotivation = entityDto.CancelMotivation,
                RegistrationDate = entityDto.RegistrationDate.Value,
                RegistrationUser = entityDto.RegistrationUser,
                LastChangedDate  = entityDto.LastChangedDate,
                LastChangedUser  = entityDto.LastChangedUser,
                Subject          = entityDto.Subject,
                Category         = entityDto.Category,
                UDSRepository    = entityDto.UDSRepository,
                Authorizations   = entityDto.Authorizations,
                Contacts         = entityDto.Contacts,
                Documents        = entityDto.Documents,
                Messages         = entityDto.Messages,
                PecMails         = entityDto.PecMails,
                Collaborations   = entityDto.Collaborations,
                DocumentUnits    = entityDto.DocumentUnits,
                UDSModel         = udsModel
            };

            return(dto);
        }
 public static List <BuildValueModel> BuildValueUDS(UDSDto udsDto, List <BuildValueModel> buildValueModels)
 {
     if (udsDto != null)
     {
         buildValueModels.AddRange(udsDto.UDSModel.Model.Metadata
                                   .SelectMany(f => f.Items.Select(x => new
         {
             Key = x.ColumnName,
             Val = GetUDSValue(x)
         }))
                                   .Select(f => new BuildValueModel()
         {
             IsHTML = false,
             Name   = f.Key,
             Value  = f.Val
         }));
     }
     return(buildValueModels);
 }
 public UDSRepositoryRightsUtil(Data.Entity.UDS.UDSRepository udsRepository, string userName, UDSDto udsDto)
     : this(userName, udsDto)
 {
     CurrentUDSRepository = udsRepository;
 }
 private UDSRepositoryRightsUtil(string userName, UDSDto udsDto)
 {
     _UDSDto   = udsDto;
     _userName = userName;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Ritorna un nuovo oggetto ProtocolInitializer per la protocollazione automatica di una UDS
        /// </summary>
        public ProtocolInitializer GetProtocolInitializer(UDSDto dto)
        {
            ProtocolInitializer protInitializer = new ProtocolInitializer();

            // Oggetto
            protInitializer.Subject = dto.UDSModel.Model.Subject.Value;
            if (dto.UDSModel.Model.ProtocolDirectionSpecified)
            {
                switch (dto.UDSModel.Model.ProtocolDirection)
                {
                case ProtocolDirectionType.None:
                    break;

                case ProtocolDirectionType.In:
                {
                    protInitializer.ProtocolType = -1;
                    break;
                }

                case ProtocolDirectionType.Out:
                {
                    protInitializer.ProtocolType = 1;
                    break;
                }

                case ProtocolDirectionType.InternalOffice:
                {
                    protInitializer.ProtocolType = 0;
                    break;
                }

                default:
                    break;
                }
            }

            // Classificazione
            if (dto.UDSModel.Model.Category.DefaultEnabled)
            {
                int idCategory = int.Parse(dto.UDSModel.Model.Category.IdCategory);
                protInitializer.Category = FacadeFactory.Instance.CategoryFacade.GetById(idCategory);
            }

            // Gestione documenti
            if (dto.UDSModel.Model.Documents != null)
            {
                // Documento principale
                ICollection <BiblosDocumentInfo> mainDocuments = FillUDSDocuments(dto.UDSModel.Model.Documents.Document);
                if (mainDocuments.Count > 0)
                {
                    protInitializer.MainDocument = mainDocuments.FirstOrDefault();
                }

                // Allegati
                ICollection <BiblosDocumentInfo> attachments = FillUDSDocuments(dto.UDSModel.Model.Documents.DocumentAttachment);
                if (attachments.Any())
                {
                    protInitializer.Attachments = attachments.Cast <DocumentInfo>().ToList();
                }

                // Annessi
                ICollection <BiblosDocumentInfo> annexed = FillUDSDocuments(dto.UDSModel.Model.Documents.DocumentAnnexed);
                if (annexed.Any())
                {
                    protInitializer.Annexed = annexed.Cast <DocumentInfo>().ToList();
                }
            }

            // Contatti
            protInitializer.Senders    = new List <ContactDTO>();
            protInitializer.Recipients = new List <ContactDTO>();
            if (dto.UDSModel.Model.Contacts != null)
            {
                foreach (Contacts contact in dto.UDSModel.Model.Contacts)
                {
                    ICollection <ContactDTO> contactDtos = FillUDSContacts(contact.ContactInstances).Concat(FillUDSContacts(contact.ContactManualInstances)).ToList();
                    if (contact.ContactType.Equals(Helpers.UDS.ContactType.Sender))
                    {
                        protInitializer.Senders.AddRange(contactDtos);
                    }
                    else
                    {
                        protInitializer.Recipients.AddRange(contactDtos);
                    }
                }
            }

            // Settori
            if (dto.UDSModel.Model.Authorizations != null && dto.UDSModel.Model.Authorizations.Instances != null)
            {
                IList <Data.Role> roles = new List <Data.Role>();
                foreach (AuthorizationInstance auth in dto.UDSModel.Model.Authorizations.Instances)
                {
                    Data.Role role = FacadeFactory.Instance.RoleFacade.GetById(auth.IdAuthorization);
                    roles.Add(role);
                }

                protInitializer.Roles = roles;
            }

            return(protInitializer);
        }
        public ProtocolInitializer GetProtocolInitializer(IReadOnlyCollection <TenantModel> tenantModels, ProtocolModel protocolModel,
                                                          Collaboration collaboration, WorkflowProperty dsw_p_CollaborationSignSummaryTemplateId, WorkflowProperty dsw_a_Collaboration_GenerateSignSummary,
                                                          WorkflowProperty dsw_p_ProposerRole, UDSDto udsDto)
        {
            ProtocolInitializer protInitializer = new ProtocolInitializer();

            // Oggetto
            protInitializer.Subject = protocolModel.Object;
            // Protocol Type
            protInitializer.ProtocolType = protocolModel.ProtocolType.EntityShortId;
            //Note
            protInitializer.Notes = protocolModel.Note;
            //Protocollo
            protInitializer.DocumentProtocol = protocolModel.DocumentProtocol;
            //Date
            protInitializer.DocumentDate = protocolModel.DocumentDate;
            // Classificazione
            if (protocolModel.Category != null && protocolModel.Category.IdCategory.HasValue)
            {
                protInitializer.Category = FacadeFactory.Instance.CategoryFacade.GetById(protocolModel.Category.IdCategory.Value);
            }
            if (protocolModel.Container != null && protocolModel.Container.IdContainer.HasValue)
            {
                protInitializer.Containers = new List <Data.Container> {
                    FacadeFactory.Instance.ContainerFacade.GetById(Convert.ToInt32(protocolModel.Container.IdContainer))
                };
            }
            if (protocolModel.DocumentTypeCode != null)
            {
                protInitializer.DocumentTypeLabel = FacadeFactory.Instance.TableDocTypeFacade.GetByCode(protocolModel.DocumentTypeCode).Description;
            }

            string owner = DocSuiteContext.Current.User.UserName;

            // Gestione documenti
            if (protocolModel.MainDocument != null && !string.IsNullOrEmpty(protocolModel.MainDocument.FileName) &&
                (protocolModel.MainDocument.ContentStream != null || protocolModel.MainDocument.DocumentId.HasValue))
            {
                protInitializer.MainDocument = SaveStream(owner, protocolModel.MainDocument);
            }

            // Allegati
            IEnumerable <DocumentModel> results = null;

            if (protocolModel.Attachments != null && (results = protocolModel.Attachments.Where(f => !string.IsNullOrEmpty(f.FileName) && (f.ContentStream != null || f.DocumentId.HasValue))).Any())
            {
                protInitializer.Attachments = SaveStream(owner, results);
            }

            if (collaboration != null && dsw_p_CollaborationSignSummaryTemplateId != null && dsw_a_Collaboration_GenerateSignSummary != null &&
                dsw_a_Collaboration_GenerateSignSummary.ValueBoolean.HasValue && dsw_a_Collaboration_GenerateSignSummary.ValueBoolean.Value &&
                dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.HasValue && dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.Value != Guid.Empty)
            {
                TemplateDocumentRepository templateDocumentRepository = WebAPIImpersonatorFacade.ImpersonateFinder(new TemplateDocumentRepositoryFinder(tenantModels),
                                                                                                                   (impersonationType, finder) =>
                {
                    finder.UniqueId     = dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.Value;
                    finder.EnablePaging = false;
                    return(finder.DoSearch().SingleOrDefault()?.Entity);
                });

                if (templateDocumentRepository != null)
                {
                    BiblosChainInfo        biblosChainInfo    = new BiblosChainInfo(templateDocumentRepository.IdArchiveChain);
                    DocumentInfo           biblosDocumentInfo = biblosChainInfo.Documents.Single(f => !f.IsRemoved);
                    List <BuildValueModel> buildValueModels   = new List <BuildValueModel>();
                    buildValueModels.Add(new BuildValueModel()
                    {
                        IsHTML = false,
                        Name   = "oggetto",
                        Value  = protInitializer.Subject,
                    });
                    DateTime signDate;
                    string   token;
                    foreach (CollaborationSign item in collaboration.CollaborationSigns)
                    {
                        signDate = item.SignDate ?? item.LastChangedDate.Value.DateTime;
                        token    = signDate.DayOfWeek == DayOfWeek.Sunday ? "la" : "il";
                        buildValueModels.Add(new BuildValueModel()
                        {
                            IsHTML = false,
                            Name   = $"signer_info_{item.Incremental}",
                            Value  = $"{item.SignName} {token} {signDate.ToLongDateString()}",
                        });
                    }
                    buildValueModels = BuildValueProposerRole(dsw_p_ProposerRole, buildValueModels);
                    buildValueModels = BuildValueUDS(udsDto, buildValueModels);
                    byte[] pdf = Services.StampaConforme.Service.BuildPDF(biblosDocumentInfo.Stream, buildValueModels.ToArray(), string.Empty);
                    if (protInitializer.Attachments == null)
                    {
                        protInitializer.Attachments = new List <DocumentInfo>();
                    }
                    protInitializer.Attachments.Add(SaveStream(owner, pdf, "riepilogo_firmatari.pdf"));
                }
            }
            // Annessi
            results = null;
            if (protocolModel.Annexes != null && (results = protocolModel.Annexes.Where(f => !string.IsNullOrEmpty(f.FileName) && (f.ContentStream != null || f.DocumentId.HasValue))).Any())
            {
                protInitializer.Annexed = SaveStream(owner, results);
            }

            // Contatti
            protInitializer.Senders    = new List <Data.ContactDTO>();
            protInitializer.Recipients = new List <Data.ContactDTO>();
            if (protocolModel.ContactManuals != null && protocolModel.ContactManuals.Any())
            {
                foreach (ProtocolContactManualModel protocolContactManualModel in protocolModel.ContactManuals)
                {
                    Data.Contact contact = new Data.Contact();
                    contact.ContactType   = new Data.ContactType(Data.ContactType.Aoo);
                    contact.Description   = protocolContactManualModel.Description;
                    contact.CertifiedMail = protocolContactManualModel.CertifiedEmail;
                    contact.EmailAddress  = protocolContactManualModel.EMail;
                    if (!string.IsNullOrEmpty(protocolContactManualModel.Address))
                    {
                        contact.Address         = new Data.Address();
                        contact.Address.Address = protocolContactManualModel.Address;
                    }

                    if (protocolContactManualModel.ComunicationType == ComunicationType.Sender)
                    {
                        protInitializer.Senders.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Manual));
                    }
                    else
                    {
                        protInitializer.Recipients.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Manual));
                    }
                }
            }
            if (protocolModel.Contacts != null && protocolModel.Contacts.Any())
            {
                foreach (ProtocolContactModel protocolContactModel in protocolModel.Contacts)
                {
                    Data.Contact contact = FacadeFactory.Instance.ContactFacade.GetById(protocolContactModel.IdContact);
                    if (protocolContactModel.ComunicationType == ComunicationType.Sender)
                    {
                        protInitializer.Senders.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Address));
                    }
                    else
                    {
                        protInitializer.Recipients.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Address));
                    }
                }
            }
            return(protInitializer);
        }
Exemplo n.º 9
0
        public static DocumentInfo GetUDSTreeDocuments(UDSDto udsSource, Action <BiblosDocumentInfo, Helpers.UDS.UDSDocumentType> documentOptionsAction)
        {
            UDSModel   udsModel   = udsSource.UDSModel;
            FolderInfo mainFolder = new FolderInfo()
            {
                Name = string.Concat(udsModel.Model.Title, " ", udsSource.FullNumber), ID = JsonConvert.SerializeObject(new KeyValuePair <string, Guid>(udsModel.Model.Title, udsSource.Id))
            };

            // Documento principale
            BiblosDocumentInfo[] docs = FillUDSDocuments(udsModel.Model.Documents.Document);
            if (documentOptionsAction != null)
            {
                docs.ToList().ForEach(f => documentOptionsAction(f, Helpers.UDS.UDSDocumentType.Main));
            }

            if (docs.Length > 0)
            {
                FolderInfo folderDoc = new FolderInfo()
                {
                    Name = udsModel.Model.Documents.Document.Label, Parent = mainFolder
                };
                folderDoc.AddChildren(docs);
            }

            // Allegati
            BiblosDocumentInfo[] attachments = FillUDSDocuments(udsModel.Model.Documents.DocumentAttachment);
            if (documentOptionsAction != null)
            {
                attachments.ToList().ForEach(f => documentOptionsAction(f, Helpers.UDS.UDSDocumentType.Attachment));
            }

            if (attachments.Length > 0)
            {
                FolderInfo folderAtt = new FolderInfo()
                {
                    Name = udsModel.Model.Documents.DocumentAttachment.Label, Parent = mainFolder
                };
                folderAtt.AddChildren(attachments);
            }

            // Allegati non parte integrante (Annessi)
            BiblosDocumentInfo[] annexes = FillUDSDocuments(udsModel.Model.Documents.DocumentAnnexed);
            if (documentOptionsAction != null)
            {
                annexes.ToList().ForEach(f => documentOptionsAction(f, Helpers.UDS.UDSDocumentType.Annexed));
            }

            if (annexes.Length > 0)
            {
                FolderInfo folderAnnexed = new FolderInfo()
                {
                    Name = udsModel.Model.Documents.DocumentAnnexed.Label, Parent = mainFolder
                };
                folderAnnexed.AddChildren(annexes);
            }

            // Dematerializzazione (Attestazione di conformità)
            BiblosDocumentInfo[] dematerialisation = FillUDSDocuments(udsModel.Model.Documents.DocumentDematerialisation);
            if (documentOptionsAction != null)
            {
                dematerialisation.ToList().ForEach(f => documentOptionsAction(f, Helpers.UDS.UDSDocumentType.Dematerialisation));
            }

            if (dematerialisation.Length > 0)
            {
                FolderInfo folderDematerialisation = new FolderInfo()
                {
                    Name = udsModel.Model.Documents.DocumentDematerialisation.Label, Parent = mainFolder
                };
                folderDematerialisation.AddChildren(dematerialisation);
            }

            return(mainFolder);
        }
Exemplo n.º 10
0
 public static string GetUDSMailSubject(UDSDto uds)
 {
     return(String.Format("Archivio: {0} n. {1}/{2:0000000} del {3:dd/MM/yyyy} - {4}",
                          uds.UDSRepository.Name, uds.Year, uds.Number, uds.RegistrationDate, uds.UDSModel.Model.Subject.Value));
 }