internal override async Task <DocumentUnit> MappingUpdateAsync(IContentBase entity, DocumentUnit documentUnit, IIdentityContext identity) { try { UDSBuildModel udsBuildModel = (UDSBuildModel)entity; #region [ Base ] documentUnit.LastChangedDate = udsBuildModel.LastChangedDate; documentUnit.LastChangedUser = udsBuildModel.LastChangedUser; documentUnit.Subject = udsBuildModel.Subject; documentUnit.Title = documentUnit.Title; documentUnit.Status = DocumentUnitStatus.Active; #endregion #region [ Navigation Properties ] Category category = await _webApiClient.GetCategoryAsync(udsBuildModel.Category.IdCategory.Value); if (category.UniqueId != Guid.Empty && documentUnit.Category.UniqueId != udsBuildModel.Category.UniqueId) { documentUnit.Category = category; } Container container = await _webApiClient.GetContainerAsync(udsBuildModel.Container.IdContainer.Value); if (container.UniqueId != Guid.Empty && documentUnit.Container.UniqueId != udsBuildModel.Container.UniqueId) { documentUnit.Container = container; } documentUnit.Fascicle = await _webApiClient.GetFascicleAsync(udsBuildModel.UniqueId); if (udsBuildModel.Roles == null || !udsBuildModel.Roles.Any()) { documentUnit.DocumentUnitRoles.Clear(); } if (udsBuildModel.Roles != null) { IList <Role> roles = new List <Role>(); foreach (RoleModel item in udsBuildModel.Roles) { roles.Add(await _webApiClient.GetRoleAsync(item)); } foreach (Role item in roles.Where(t => !documentUnit.DocumentUnitRoles.Any(x => x.UniqueIdRole == t.UniqueId))) { documentUnit.DocumentUnitRoles.Add(new DocumentUnitRole() { UniqueIdRole = item.UniqueId, RoleLabel = udsBuildModel.Roles.SingleOrDefault(r => r.UniqueId.HasValue ? r.UniqueId.Value.Equals(item.UniqueId) : r.IdRole.Equals(item.EntityShortId))?.RoleLabel, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = identity.User, AuthorizationRoleType = GetRoleType(string.Empty) }); } foreach (DocumentUnitRole item in documentUnit.DocumentUnitRoles.Where(t => !roles.Any(x => x.UniqueId == t.UniqueIdRole)).ToList()) { documentUnit.DocumentUnitRoles.Remove(item); } } if (udsBuildModel.Users == null || !udsBuildModel.Users.Any()) { documentUnit.DocumentUnitUsers.Clear(); } if (udsBuildModel.Users != null) { IList <DocumentUnitUser> users = new List <DocumentUnitUser>(); foreach (UserModel item in udsBuildModel.Users) { if (item.Account != null && !documentUnit.DocumentUnitUsers.Where(x => x.Account != item.Account).Any()) { users.Add(new DocumentUnitUser() { Account = item.Account, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = identity.User, AuthorizationType = AuthorizationRoleType.Accounted }); } } foreach (DocumentUnitUser item in users.Where(t => !documentUnit.DocumentUnitUsers.Any(x => x.Account == t.Account))) { documentUnit.DocumentUnitUsers.Add(new DocumentUnitUser() { Account = item.Account, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = identity.User, AuthorizationType = AuthorizationRoleType.Accounted }); } foreach (DocumentUnitUser item in documentUnit.DocumentUnitUsers.Where(t => !users.Any(x => x.Account == t.Account)).ToList()) { documentUnit.DocumentUnitUsers.Remove(item); } } if (udsBuildModel.Documents.Count == 0) { documentUnit.DocumentUnitChains.Clear(); } if (udsBuildModel.Documents.Count > 0) { //Elimino le chain che non esistono più foreach (DocumentUnitChain item in documentUnit.DocumentUnitChains.Where(t => !udsBuildModel.Documents.Any(x => x.IdChain == t.IdArchiveChain)).ToList()) { documentUnit.DocumentUnitChains.Remove(item); } foreach (UDSDocumentModel document in udsBuildModel.Documents) { switch (document.DocumentType) { case UDSDocumentType.Document: { DocumentUnitChain mainDocument = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.MainChain).FirstOrDefault(); if (mainDocument != null) { if (document.IdChain != Guid.Empty) { if (mainDocument.IdArchiveChain != document.IdChain || (mainDocument.ChainType == ChainType.MainChain && !mainDocument.DocumentName.Equals(document.DocumentName))) { documentUnit.DocumentUnitChains.Remove(mainDocument); AddUDSDocumentUnitChain(documentUnit, document, ChainType.MainChain, identity); } } else { documentUnit.DocumentUnitChains.Remove(mainDocument); } } else { AddUDSDocumentUnitChain(documentUnit, document, ChainType.MainChain, identity); } break; } case UDSDocumentType.DocumentAttachment: { DocumentUnitChain attachment = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AttachmentsChain).FirstOrDefault(); if (attachment != null) { if (document.IdChain != Guid.Empty) { if (attachment.IdArchiveChain != document.IdChain) { documentUnit.DocumentUnitChains.Remove(attachment); AddUDSDocumentUnitChain(documentUnit, document, ChainType.AttachmentsChain, identity); } } else { documentUnit.DocumentUnitChains.Remove(attachment); } } else { AddUDSDocumentUnitChain(documentUnit, document, ChainType.AttachmentsChain, identity); } break; } case UDSDocumentType.DocumentAnnexed: { DocumentUnitChain annexed = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).FirstOrDefault(); if (annexed != null) { if (document.IdChain != Guid.Empty) { if (annexed.IdArchiveChain != document.IdChain) { documentUnit.DocumentUnitChains.Remove(annexed); AddUDSDocumentUnitChain(documentUnit, document, ChainType.AnnexedChain, identity); } } else { documentUnit.DocumentUnitChains.Remove(annexed); } } else { AddUDSDocumentUnitChain(documentUnit, document, ChainType.AnnexedChain, identity); } break; } case UDSDocumentType.DocumentDematerialisation: { DocumentUnitChain dematerialisation = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).FirstOrDefault(); if (dematerialisation != null) { if (document.IdChain != Guid.Empty) { if (dematerialisation.IdArchiveChain != document.IdChain) { documentUnit.DocumentUnitChains.Remove(dematerialisation); AddUDSDocumentUnitChain(documentUnit, document, ChainType.DematerialisationChain, identity); } } else { documentUnit.DocumentUnitChains.Remove(dematerialisation); } } else { AddUDSDocumentUnitChain(documentUnit, document, ChainType.DematerialisationChain, identity); } break; } } } } #endregion } catch (Exception ex) { _logger.WriteError(new LogMessage("UDS, MappingUpdateAsync Error: "), ex, LogCategories); throw ex; } return(documentUnit); }
internal override async Task <DocumentUnit> MappingUpdateAsync(IContentBase entity, DocumentUnit documentUnit, IIdentityContext identity) { try { Protocol protocol = (Protocol)entity; #region [ Base ] documentUnit.LastChangedDate = protocol.LastChangedDate; documentUnit.LastChangedUser = protocol.LastChangedUser; documentUnit.Subject = protocol.Object; documentUnit.Title = documentUnit.Title; documentUnit.Status = protocol.IdStatus == 0 ? DocumentUnitStatus.Active : DocumentUnitStatus.Inactive; #endregion #region [ Navigation Properties ] if (documentUnit.Category.UniqueId != protocol.Category.UniqueId) { documentUnit.Category = protocol.Category; } if (documentUnit.Container.UniqueId != protocol.Container.UniqueId) { documentUnit.Container = protocol.Container; } documentUnit.Fascicle = await _webApiClient.GetFascicleAsync(protocol.UniqueId); if (protocol.ProtocolRoles == null || !protocol.ProtocolRoles.Any()) { documentUnit.DocumentUnitRoles.Clear(); } if (protocol.ProtocolRoles != null) { //Aggiorno i settori della documentunit esistenti con il type che arriva dai settori del protocollo foreach (DocumentUnitRole docRole in documentUnit.DocumentUnitRoles.Where(t => protocol.ProtocolRoles.Any(x => x.Role.UniqueId == t.UniqueIdRole)).ToList()) { if (protocol.ProtocolRoles.Any(r => r.Role.UniqueId == docRole.UniqueIdRole)) { docRole.AuthorizationRoleType = GetRoleType(protocol.ProtocolRoles.First(r => r.Role.UniqueId == docRole.UniqueIdRole).Type); } } foreach (ProtocolRole item in protocol.ProtocolRoles.Where(t => !documentUnit.DocumentUnitRoles.Any(x => x.UniqueIdRole == t.Role.UniqueId)).ToList()) { documentUnit.DocumentUnitRoles.Add(new DocumentUnitRole() { UniqueIdRole = item.Role.UniqueId, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = item.RegistrationUser, AuthorizationRoleType = GetRoleType(item.Type) }); } foreach (DocumentUnitRole item in documentUnit.DocumentUnitRoles.Where(t => !protocol.ProtocolRoles.Any(x => x.Role.UniqueId == t.UniqueIdRole)).ToList()) { documentUnit.DocumentUnitRoles.Remove(item); } } if (protocol.ProtocolUsers != null) { foreach (ProtocolUser item in protocol.ProtocolUsers.Where(t => !documentUnit.DocumentUnitUsers.Any(x => x.Account == t.Account)).ToList()) { documentUnit.DocumentUnitUsers.Add(new DocumentUnitUser() { UniqueId = item.UniqueId, Account = item.Account, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = item.RegistrationUser, AuthorizationType = AuthorizationRoleType.Accounted }); } foreach (DocumentUnitUser item in documentUnit.DocumentUnitUsers.Where(t => !protocol.ProtocolUsers.Any(x => x.Account == t.Account)).ToList()) { documentUnit.DocumentUnitUsers.Remove(item); } } if (protocol.IdAnnexed.HasValue && protocol.IdAnnexed.Value != Guid.Empty) { DocumentUnitChain annexed = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).FirstOrDefault(); if (annexed != null) { if (annexed.IdArchiveChain != protocol.IdAnnexed.Value) { documentUnit.DocumentUnitChains.Remove(annexed); AddDocumentUnitChain(documentUnit, protocol.IdAnnexed.Value, ChainType.AnnexedChain, identity, protocol.Container.ProtLocation.ProtocolArchive); } } else { AddDocumentUnitChain(documentUnit, protocol.IdAnnexed.Value, ChainType.AnnexedChain, identity, protocol.Container.ProtLocation.ProtocolArchive); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } if (protocol.DematerialisationChainId.HasValue && protocol.DematerialisationChainId.Value != Guid.Empty) { DocumentUnitChain dematerialisation = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).FirstOrDefault(); if (dematerialisation != null) { if (dematerialisation.IdArchiveChain != protocol.DematerialisationChainId.Value) { documentUnit.DocumentUnitChains.Remove(dematerialisation); AddDocumentUnitChain(documentUnit, protocol.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity, protocol.Container.ProtLocation.ProtocolArchive); } } else { AddDocumentUnitChain(documentUnit, protocol.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity, protocol.Container.ProtLocation.ProtocolArchive); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } #endregion } catch (Exception ex) { _logger.WriteError(new LogMessage("Protocol, MappingUpdateAsync Error: "), ex, LogCategories); throw ex; } return(documentUnit); }
internal override async Task <DocumentUnit> MappingUpdateAsync(IContentBase entity, DocumentUnit documentUnit, IIdentityContext identity) { try { ResolutionModel resolutionModel = (ResolutionModel)entity; #region [ Base ] documentUnit.Subject = resolutionModel.Subject; documentUnit.Title = documentUnit.Title; documentUnit.LastChangedDate = resolutionModel.LastChangedDate; documentUnit.LastChangedUser = resolutionModel.LastChangedUser; #endregion #region [ Navigation Properties ] if (resolutionModel.Category.UniqueId.HasValue && resolutionModel.Category.UniqueId.Value != Guid.Empty && documentUnit.Category.UniqueId != resolutionModel.Category.UniqueId) { documentUnit.Category = MapCategoryModel(new Category(), resolutionModel.Category); } if (resolutionModel.Container.UniqueId.HasValue && resolutionModel.Container.UniqueId.Value != Guid.Empty && documentUnit.Container.UniqueId != resolutionModel.Container.UniqueId) { documentUnit.Container = MapContainerModel(new Container(), resolutionModel.Container); } documentUnit.Fascicle = await _webAPIClient.GetFascicleAsync(resolutionModel.UniqueId); if (resolutionModel.ResolutionRoles == null || !resolutionModel.ResolutionRoles.Any()) { documentUnit.DocumentUnitRoles.Clear(); } if (resolutionModel.ResolutionRoles != null) { foreach (ResolutionRoleModel item in resolutionModel.ResolutionRoles.Where(t => !documentUnit.DocumentUnitRoles.Any(x => x.UniqueIdRole == t.Role.UniqueId)).ToList()) { documentUnit.DocumentUnitRoles.Add(new DocumentUnitRole() { UniqueIdRole = item.Role.UniqueId.Value, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = identity.User, AuthorizationRoleType = GetRoleType(string.Empty) }); } foreach (DocumentUnitRole item in documentUnit.DocumentUnitRoles.Where(t => !resolutionModel.ResolutionRoles.Any(x => x.Role.UniqueId == t.UniqueIdRole)).ToList()) { documentUnit.DocumentUnitRoles.Remove(item); } } //Annessi if (resolutionModel.FileResolution.IdAnnexes.HasValue && resolutionModel.FileResolution.IdAnnexes.Value != Guid.Empty) { DocumentUnitChain annexed = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).FirstOrDefault(); if (annexed != null) { if (annexed.IdArchiveChain != resolutionModel.FileResolution.IdAnnexes.Value) { documentUnit.DocumentUnitChains.Remove(annexed); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdAnnexes.Value, ChainType.AnnexedChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdAnnexes.Value, ChainType.AnnexedChain, identity); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } //Allegati if (resolutionModel.FileResolution.IdAttachments.HasValue && resolutionModel.FileResolution.IdAttachments.Value != 0) { DocumentUnitChain attachment = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AttachmentsChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdAttachments.Value); if (attachment != null) { if (attachment.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(attachment); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.AttachmentsChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.AttachmentsChain, identity); } } //AttachmentOmissis if (resolutionModel.FileResolution.IdAttachmentsOmissis.HasValue && resolutionModel.FileResolution.IdAttachmentsOmissis.Value != Guid.Empty) { DocumentUnitChain attachmentOmissis = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AttachmentOmissisChain).FirstOrDefault(); if (attachmentOmissis != null) { if (attachmentOmissis.IdArchiveChain != resolutionModel.FileResolution.IdAttachmentsOmissis.Value) { documentUnit.DocumentUnitChains.Remove(attachmentOmissis); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdAttachmentsOmissis.Value, ChainType.AttachmentOmissisChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdAttachmentsOmissis.Value, ChainType.AttachmentOmissisChain, identity); } } //ResolutionFile if (resolutionModel.FileResolution.IdResolutionFile.HasValue && resolutionModel.FileResolution.IdResolutionFile.Value != 0) { DocumentUnitChain resolutionFile = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.MainChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdResolutionFile.Value); if (resolutionFile != null) { if (resolutionFile.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(resolutionFile); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.MainChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.MainChain, identity); } } //Frontespizio if (resolutionModel.FileResolution.IdFrontespizio.HasValue && resolutionModel.FileResolution.IdFrontespizio.Value != 0) { DocumentUnitChain frontespizio = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.FrontespizioChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdFrontespizio.Value); if (frontespizio != null) { if (frontespizio.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(frontespizio); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.FrontespizioChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.FrontespizioChain, identity); } } //ControllerFile if (resolutionModel.FileResolution.IdControllerFile.HasValue && resolutionModel.FileResolution.IdControllerFile.Value != 0) { DocumentUnitChain controllerFile = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.ControllerChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdControllerFile.Value); if (controllerFile != null) { if (controllerFile.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(controllerFile); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.ControllerChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.ControllerChain, identity); } } //FrontalinoRitiro if (resolutionModel.FileResolution.IdFrontalinoRitiro.HasValue && resolutionModel.FileResolution.IdFrontalinoRitiro.Value != 0) { DocumentUnitChain frontalinoRitiro = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.FrontalinoRitiroChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdFrontalinoRitiro.Value); if (frontalinoRitiro != null) { if (frontalinoRitiro.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(frontalinoRitiro); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.FrontalinoRitiroChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.FrontalinoRitiroChain, identity); } } //MainDocumentOmissis if (resolutionModel.FileResolution.IdMainDocumentsOmissis.HasValue && resolutionModel.FileResolution.IdMainDocumentsOmissis.Value != Guid.Empty) { DocumentUnitChain mainDocumentOmissis = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.MainOmissisChain).FirstOrDefault(); if (mainDocumentOmissis != null) { if (mainDocumentOmissis.IdArchiveChain != resolutionModel.FileResolution.IdMainDocumentsOmissis.Value) { documentUnit.DocumentUnitChains.Remove(mainDocumentOmissis); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdMainDocumentsOmissis.Value, ChainType.MainOmissisChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.IdMainDocumentsOmissis.Value, ChainType.MainOmissisChain, identity); } } //PrivacyAttachments if (resolutionModel.FileResolution.IdPrivacyAttachments.HasValue && resolutionModel.FileResolution.IdPrivacyAttachments.Value != 0) { DocumentUnitChain privacyAttachemnt = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.PrivacyAttachmentChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdPrivacyAttachments.Value); if (privacyAttachemnt != null) { if (privacyAttachemnt.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(privacyAttachemnt); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.PrivacyAttachmentChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.PrivacyAttachmentChain, identity); } } //PrivacyPublicationDocument if (resolutionModel.FileResolution.IdPrivacyPublicationDocument.HasValue && resolutionModel.FileResolution.IdPrivacyPublicationDocument.Value != 0) { DocumentUnitChain privacyPublicationAttachemnt = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.PrivacyPublicationDocumentChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdPrivacyAttachments.Value); if (privacyPublicationAttachemnt != null) { if (privacyPublicationAttachemnt.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(privacyPublicationAttachemnt); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.PrivacyPublicationDocumentChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.PrivacyPublicationDocumentChain, identity); } } //SupervisoryBoard if (resolutionModel.FileResolution.IdSupervisoryBoardFile.HasValue && resolutionModel.FileResolution.IdSupervisoryBoardFile.Value != 0) { DocumentUnitChain supervisoryBoard = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.SupervisoryBoardChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdSupervisoryBoardFile.Value); if (supervisoryBoard != null) { if (supervisoryBoard.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(supervisoryBoard); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.SupervisoryBoardChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.SupervisoryBoardChain, identity); } } //UltimaPagina if (resolutionModel.FileResolution.IdUltimaPaginaFile.HasValue && resolutionModel.FileResolution.IdUltimaPaginaFile.Value != 0) { DocumentUnitChain lastPage = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.UltimaPaginaChain).FirstOrDefault(); Guid chainId = _biblosClient.Document.GetDocumentId(resolutionModel.Container.ReslLocation.ResolutionArchive, resolutionModel.FileResolution.IdUltimaPaginaFile.Value); if (lastPage != null) { if (lastPage.IdArchiveChain != chainId) { documentUnit.DocumentUnitChains.Remove(lastPage); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.UltimaPaginaChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, chainId, ChainType.UltimaPaginaChain, identity); } } //Dematerialisation if (resolutionModel.FileResolution.DematerialisationChainId.HasValue && resolutionModel.FileResolution.DematerialisationChainId.Value != Guid.Empty) { DocumentUnitChain dematerialisation = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).FirstOrDefault(); if (dematerialisation != null) { if (dematerialisation.IdArchiveChain != resolutionModel.FileResolution.DematerialisationChainId.Value) { documentUnit.DocumentUnitChains.Remove(dematerialisation); AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity); } } else { AddResolutionDocumentUnitChain(documentUnit, resolutionModel, resolutionModel.FileResolution.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } #endregion } catch (Exception ex) { _logger.WriteError(new LogMessage("Resolution, MappingUpdateAsync Error: "), ex, LogCategories); throw ex; } return(documentUnit); }
public void ElaborateDocument(HttpContext context) { Guid idResolution = context.Request.QueryString.GetValueOrDefault("UniqueId", Guid.Empty); byte[] stream = { }; try { Resolution resolution = GetResolution(idResolution); if (!CheckValidity(context, resolution)) { return; } string cached_file_path = Path.Combine(CachePath, string.Concat(resolution.UniqueId.ToString(), ".pdf")); if (!File.Exists(cached_file_path)) { DocumentUnitChain documentChain = GetDocumentUnitChain(idResolution, ChainType.MainOmissisChain); if (documentChain == null) { documentChain = GetDocumentUnitChain(idResolution, ChainType.MainChain); } if (documentChain == null) { ElaborateException(context); return; } IList <BiblosDocumentInfo> documents = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, documentChain.IdArchiveChain); if (documents == null || !documents.Any()) { ElaborateException(context); return; } IEnumerable <byte[]> streams = documents.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf")); if (MergeAllChainDocuments) { //recupero gli allegati DocumentUnitChain attachmentsChain = GetDocumentUnitChain(idResolution, ChainType.AttachmentOmissisChain); if (attachmentsChain == null) { attachmentsChain = GetDocumentUnitChain(idResolution, ChainType.AttachmentsChain); } if (attachmentsChain != null) { IList <BiblosDocumentInfo> attachmentDocuments = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, attachmentsChain.IdArchiveChain); if (attachmentDocuments != null && attachmentDocuments.Any()) { streams = streams.Concat(attachmentDocuments.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf"))); } } //recupero il frontalino di pubblicazione DocumentUnitChain frontespieceChain = GetDocumentUnitChain(idResolution, ChainType.FrontespizioChain); if (frontespieceChain != null) { IList <BiblosDocumentInfo> frontespieceDocuments = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, frontespieceChain.IdArchiveChain); if (frontespieceDocuments != null && frontespieceDocuments.Any()) { streams = streams.Concat(frontespieceDocuments.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf"))); } } } stream = MergePDF(streams); if (ViewLockedPdf) { using (MemoryDocumentInfo mdi = new MemoryDocumentInfo(stream, cached_file_path)) { stream = mdi.GetPdfLocked(documents.First().Signature, PdfWatermark); } } if (!Encoding.Default.GetString(stream, 0, 4).Equals("%PDF")) { throw new Exception("Il pdf non può essere visualizzato a causa di un errore di conversione.", new Exception("Lo stream non inizia con '%PDF'")); } File.WriteAllBytes(cached_file_path, stream); } else { stream = File.ReadAllBytes(cached_file_path); } ElaborateStream(context, stream, string.Empty); } catch (Exception ex) { FileLogger.Error(LogName.BiblosServiceLog, ex.Message, ex); ElaborateException(context); return; } }
internal override async Task <DocumentUnit> MappingUpdateAsync(IContentBase entity, DocumentUnit documentUnit, IIdentityContext identity) { try { DocumentSeriesItem documentSeriesItem = (DocumentSeriesItem)entity; #region [ Base ] documentUnit.LastChangedDate = documentSeriesItem.LastChangedDate; documentUnit.LastChangedUser = documentSeriesItem.LastChangedUser; documentUnit.Subject = documentSeriesItem.Subject; documentUnit.Title = documentUnit.Title; documentUnit.Status = documentSeriesItem.Status == DocumentSeriesItemStatus.Active ? DocumentUnitStatus.Active : DocumentUnitStatus.Inactive; #endregion #region [ Navigation Properties ] if (documentUnit.Category.UniqueId != documentSeriesItem.Category.UniqueId) { documentUnit.Category = documentSeriesItem.Category; } if (documentUnit.Container.UniqueId != documentSeriesItem.DocumentSeries.Container.UniqueId) { documentUnit.Container = documentSeriesItem.DocumentSeries.Container; } documentUnit.Fascicle = await _webApiClient.GetFascicleAsync(documentSeriesItem.UniqueId); if (documentSeriesItem.DocumentSeriesItemRoles == null || !documentSeriesItem.DocumentSeriesItemRoles.Any()) { documentSeriesItem.DocumentSeriesItemRoles.Clear(); } if (documentSeriesItem.DocumentSeriesItemRoles != null) { foreach (DocumentSeriesItemRole item in documentSeriesItem.DocumentSeriesItemRoles.Where(t => !documentUnit.DocumentUnitRoles.Any(x => x.UniqueIdRole == t.Role.UniqueId)).ToList()) { documentUnit.DocumentUnitRoles.Add(new DocumentUnitRole() { UniqueIdRole = item.Role.UniqueId, RegistrationDate = DateTimeOffset.UtcNow, RegistrationUser = identity.User, AuthorizationRoleType = GetRoleType(string.Empty) }); } foreach (DocumentUnitRole item in documentUnit.DocumentUnitRoles.Where(t => !documentSeriesItem.DocumentSeriesItemRoles.Any(x => x.Role.UniqueId == t.UniqueIdRole)).ToList()) { documentUnit.DocumentUnitRoles.Remove(item); } } if (documentSeriesItem.IdAnnexed.HasValue && documentSeriesItem.IdAnnexed.Value != Guid.Empty) { DocumentUnitChain annexed = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).FirstOrDefault(); if (annexed != null) { if (annexed.IdArchiveChain != documentSeriesItem.IdAnnexed.Value) { documentUnit.DocumentUnitChains.Remove(annexed); AddDocumentUnitChain(documentUnit, documentSeriesItem.IdAnnexed.Value, ChainType.AnnexedChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesAnnexedLocation.ProtocolArchive); } } else { AddDocumentUnitChain(documentUnit, documentSeriesItem.IdAnnexed.Value, ChainType.AnnexedChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesAnnexedLocation.ProtocolArchive); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.AnnexedChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } if (documentSeriesItem.IdUnpublishedAnnexed.HasValue && documentSeriesItem.IdUnpublishedAnnexed.Value != Guid.Empty) { DocumentUnitChain unpublishedAnnexed = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.UnpublishedAnnexedChain).FirstOrDefault(); if (unpublishedAnnexed != null) { if (unpublishedAnnexed.IdArchiveChain != documentSeriesItem.IdUnpublishedAnnexed.Value) { documentUnit.DocumentUnitChains.Remove(unpublishedAnnexed); AddDocumentUnitChain(documentUnit, documentSeriesItem.IdUnpublishedAnnexed.Value, ChainType.UnpublishedAnnexedChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesUnpublishedAnnexedLocation.ProtocolArchive); } } else { AddDocumentUnitChain(documentUnit, documentSeriesItem.IdUnpublishedAnnexed.Value, ChainType.UnpublishedAnnexedChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesUnpublishedAnnexedLocation.ProtocolArchive); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.UnpublishedAnnexedChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } if (documentSeriesItem.IdMain.HasValue && documentSeriesItem.IdMain.Value != Guid.Empty) { DocumentUnitChain main = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.MainChain).FirstOrDefault(); if (main != null) { if (main.IdArchiveChain != documentSeriesItem.IdMain.Value) { documentUnit.DocumentUnitChains.Remove(main); BiblosDS.BiblosDS.Document document = _biblosClient.Document.GetDocumentChildren(documentSeriesItem.IdMain.Value).FirstOrDefault(); AddDocumentUnitChain(documentUnit, documentSeriesItem.IdMain.Value, ChainType.MainChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesLocation.ProtocolArchive, document != null ? document.Name : null); } } else { BiblosDS.BiblosDS.Document document = _biblosClient.Document.GetDocumentChildren(documentSeriesItem.IdMain.Value).FirstOrDefault(); AddDocumentUnitChain(documentUnit, documentSeriesItem.IdMain.Value, ChainType.MainChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesLocation.ProtocolArchive, document != null ? document.Name : null); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.MainChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } if (documentSeriesItem.DematerialisationChainId.HasValue && documentSeriesItem.DematerialisationChainId.Value != Guid.Empty) { DocumentUnitChain dematerialisation = documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).FirstOrDefault(); if (dematerialisation != null) { if (dematerialisation.IdArchiveChain != documentSeriesItem.DematerialisationChainId.Value) { documentUnit.DocumentUnitChains.Remove(dematerialisation); AddDocumentUnitChain(documentUnit, documentSeriesItem.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesAnnexedLocation.ProtocolArchive); } } else { AddDocumentUnitChain(documentUnit, documentSeriesItem.DematerialisationChainId.Value, ChainType.DematerialisationChain, identity, documentSeriesItem.DocumentSeries.Container.DocumentSeriesAnnexedLocation.ProtocolArchive); } } else { foreach (DocumentUnitChain chain in documentUnit.DocumentUnitChains.Where(t => t.ChainType == ChainType.DematerialisationChain).ToList()) { documentUnit.DocumentUnitChains.Remove(chain); } } #endregion } catch (Exception ex) { _logger.WriteError(new LogMessage("DocumentSeriesItem, MappingUpdateAsync Error: "), ex, LogCategories); throw ex; } return(documentUnit); }