Example #1
0
        private async Task CreateBiblosDSArchiveAsync(UDSEntity uds, UDSStorageFacade udsStorageFacade, bool isMainDocument = false)
        {
            try
            {
                await udsStorageFacade.GenerateStorageAsync(async (udsArchive, attributeGroups, attributeModes) =>
                {
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ReadOnly          = attributeModes.Single(f => f.IdMode == 0);
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ModifyAlways      = attributeModes.Single(f => f.IdMode == 3);
                    BiblosDS.BiblosDSManagement.AttributeMode attributeMode_ModifyNotArchived = attributeModes.Single(f => f.IdMode == 2);

                    BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_chain   = attributeGroups.SingleOrDefault(a => a.GroupType.Equals(BiblosDS.BiblosDSManagement.AttributeGroupType.Chain));
                    BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_default = attributeGroups.SingleOrDefault(a => a.GroupType.Equals(BiblosDS.BiblosDSManagement.AttributeGroupType.Undefined));

                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ReadOnly, AttributeHelper.AttributeName_Signature, "System.String", true);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ReadOnly, AttributeHelper.AttributeName_Filename, "System.String", true);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ModifyAlways, AttributeHelper.AttributeName_PrivacyLevel, "System.Int64", false);
                    await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_default, attributeMode_ModifyAlways, AttributeHelper.AttributeName_SignModels, "System.String", false);

                    if (isMainDocument)
                    {
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ModifyNotArchived, "Subject", "System.String", false);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Year", "System.Int64", true);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Number", "System.Int64", true);
                        await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ReadOnly, "Date", "System.DateTime", true, isMainDate: true);

                        foreach (Metadata metadata in uds.MetaData)
                        {
                            await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain,
                                                                             metadata.Required ? attributeMode_ReadOnly : attributeMode_ModifyNotArchived,
                                                                             metadata.PropertyName, metadata.BiblosPropertyType.FullName, metadata.Required);
                        }
                    }
                }, BiblosDS_Storage_MainPath, BiblosDS_Storage_StorageType, isMainDocument);
            }
            catch (Exception ex)
            {
                _logger.WriteError(ex, LogCategories);
                throw ex;
            }
        }
Example #2
0
        private async Task UpdateArchiveAsync(UDSEntity uds, UDSStorageFacade udsStorageFacade, bool isMainDocument = false)
        {
            _logger.WriteInfo(new LogMessage("starting update archive"), LogCategories);

            if (udsStorageFacade.UDS.Model.Documents != null)
            {
                IList <BiblosDS.BiblosDSManagement.Archive> archives = _administrationClient.GetArchives().ToList();
                string miscellaneousArchiveName = string.Concat("Archive_UDS_Miscellaneous_", udsStorageFacade.UDS.Model.Title);
                BiblosDS.BiblosDSManagement.Archive miscellaneousArchive = new BiblosDS.BiblosDSManagement.Archive
                {
                    Name = miscellaneousArchiveName
                };

                if (udsStorageFacade.UDS.Model.Documents.Document != null)
                {
                    BiblosDS.BiblosDSManagement.Archive udsArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.Document.BiblosArchive));
                    if (udsArchive == null)
                    {
                        if (udsStorageFacade.UDS.Model.Documents.Document.CreateBiblosArchive)
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade, true);

                            _logger.WriteInfo(new LogMessage("Archive created successfully"), LogCategories);
                        }
                        else
                        {
                            _logger.WriteError(new LogMessage(string.Format("Archive {0} to update not found", udsStorageFacade.UDS.Model.Documents.Document.BiblosArchive)), LogCategories);
                        }
                    }
                    else
                    {
                        BiblosDS.BiblosDSManagement.Attribute[]            attributes                      = _administrationClient.GetAttributesFromArchive(udsArchive.IdArchive);
                        Task <BiblosDS.BiblosDSManagement.AttributeMode[]> task_attributeModes             = _administrationClient.GetAttributeModesAsync();
                        BiblosDS.BiblosDSManagement.AttributeMode[]        attributeModes                  = await task_attributeModes;
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ReadOnly          = attributeModes.Single(f => f.IdMode == 0);
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ModifyAlways      = attributeModes.Single(f => f.IdMode == 3);
                        BiblosDS.BiblosDSManagement.AttributeMode          attributeMode_ModifyNotArchived = attributeModes.Single(f => f.IdMode == 2);

                        Metadata[] addedMetadata = uds.MetaData.Where(m => !attributes.Any(a => a.Name.Equals(m.PropertyName))).ToArray();

                        string[] requiredAttributes = { AttributeHelper.AttributeName_Signature, AttributeHelper.AttributeName_Filename,  AttributeHelper.AttributeName_UDSSubject,
                                                        AttributeHelper.AttributeName_UDSYear,   AttributeHelper.AttributeName_UDSNumber, AttributeHelper.AttributeName_Date, AttributeHelper.AttributeName_SignModels };
                        BiblosDS.BiblosDSManagement.Attribute[] dynamicAttributes   = attributes.Where(a => !requiredAttributes.Any(r => r.Equals(a.Name))).ToArray();
                        BiblosDS.BiblosDSManagement.Attribute[] deprecatedAttribute = dynamicAttributes.Where(a => !uds.MetaData.Any(m => m.PropertyName.Equals(a.Name))).ToArray();

                        //creo i nuovi attributi aggiunti all'archivio
                        foreach (Metadata metadata in addedMetadata)
                        {
                            BiblosDS.BiblosDSManagement.Attribute      attribute            = attributes.FirstOrDefault(a => a.AttributeGroup.GroupType == BiblosDS.BiblosDSManagement.AttributeGroupType.Chain);
                            BiblosDS.BiblosDSManagement.AttributeGroup attributeGroup_chain = attribute.AttributeGroup;
                            await udsStorageFacade.GenerateBiblosDSAttribute(udsArchive, attributeGroup_chain, attributeMode_ModifyAlways,
                                                                             metadata.PropertyName, metadata.BiblosPropertyType.FullName, metadata.Required);
                        }
                        //disabilito gli attributi tolti dall'archivio
                        foreach (BiblosDS.BiblosDSManagement.Attribute item in deprecatedAttribute)
                        {
                            item.IsRequired       = false;
                            item.IsVisible        = false;
                            item.IsVisibleForUser = false;
                            item.Mode             = attributeMode_ReadOnly;
                            _logger.WriteInfo(new LogMessage(string.Concat("Updating biblosds attribute ", item.Name)), LogCategories);
                            await _administrationClient.UpdateAttributeAsync(item);
                        }
                    }
                }

                if (udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null && udsStorageFacade.UDS.Model.Documents.DocumentAttachment.CreateBiblosArchive)
                {
                    BiblosDS.BiblosDSManagement.Archive udsAttachmentArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.DocumentAttachment.BiblosArchive));

                    if (udsAttachmentArchive == null)
                    {
                        udsStorageFacade.UDS.Model.Documents.DocumentAttachment.BiblosArchive = miscellaneousArchiveName;
                        if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                            archives.Add(miscellaneousArchive);
                            _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                        }
                    }
                }

                if (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null && udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.CreateBiblosArchive)
                {
                    BiblosDS.BiblosDSManagement.Archive udsAnnexedArchive = archives.SingleOrDefault(a => a.Name.Equals(udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.BiblosArchive));

                    if (udsAnnexedArchive == null)
                    {
                        udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.BiblosArchive = miscellaneousArchiveName;
                        if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                        {
                            await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                            archives.Add(miscellaneousArchive);
                            _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                        }
                    }
                }

                if ((udsStorageFacade.UDS.Model.Documents.Document != null && udsStorageFacade.UDS.Model.Documents.Document.DematerialisationEnabled) ||
                    (udsStorageFacade.UDS.Model.Documents.DocumentAttachment != null && udsStorageFacade.UDS.Model.Documents.DocumentAttachment.DematerialisationEnabled) ||
                    (udsStorageFacade.UDS.Model.Documents.DocumentAnnexed != null && udsStorageFacade.UDS.Model.Documents.DocumentAnnexed.DematerialisationEnabled))
                {
                    if (!archives.Any(a => a.Name.Equals(miscellaneousArchiveName)))
                    {
                        await CreateBiblosDSArchiveAsync(uds, udsStorageFacade);

                        archives.Add(miscellaneousArchive);
                        _logger.WriteInfo(new LogMessage("Archive Miscellaneous created successfully"), LogCategories);
                    }

                    if (udsStorageFacade.UDS.Model.Documents.DocumentDematerialisation == null || !udsStorageFacade.UDS.Model.Documents.DocumentDematerialisation.Instances.Any())
                    {
                        udsStorageFacade.AddDocumentDematerialisation(udsStorageFacade.UDS.Model.Documents, miscellaneousArchiveName);
                    }
                }
            }
        }