From 52508a5e7ec3f1d2aaffcb3f542d5021e1c319f3 Mon Sep 17 00:00:00 2001 From: Andrea Cattaneo Date: Tue, 2 Aug 2022 12:39:36 +0200 Subject: [PATCH] AXRepository - gestione campi rubrica su profilo --- .../ACUtils.AXRepository.csproj | 4 +- ACUtils.AXRepository/AXModel.cs | 27 +-- ACUtils.AXRepository/ArxivarRepository.cs | 181 ++++++++++++------ .../AxCcExternalIdFieldAttribute.cs | 11 ++ .../Attributes/AxDbFieldAttribute.cs | 4 +- .../Attributes/AxFieldAttribute.cs | 4 +- .../AxFromExternalIdFieldAttribute.cs | 11 ++ .../AxToExternalIdFieldAttribute.cs | 11 ++ ACUtils.AXRepository/AxExt.cs | 8 + 9 files changed, 183 insertions(+), 78 deletions(-) create mode 100644 ACUtils.AXRepository/Attributes/AxCcExternalIdFieldAttribute.cs create mode 100644 ACUtils.AXRepository/Attributes/AxFromExternalIdFieldAttribute.cs create mode 100644 ACUtils.AXRepository/Attributes/AxToExternalIdFieldAttribute.cs diff --git a/ACUtils.AXRepository/ACUtils.AXRepository.csproj b/ACUtils.AXRepository/ACUtils.AXRepository.csproj index 5c5931a..40f6dfa 100644 --- a/ACUtils.AXRepository/ACUtils.AXRepository.csproj +++ b/ACUtils.AXRepository/ACUtils.AXRepository.csproj @@ -5,8 +5,8 @@ Andrea Cattaneo true false - 1.0.0.141 - 1.0.0.141 + 1.0.0.142 + 1.0.0.142 Utility per gestione classi documentali Arxivar it true diff --git a/ACUtils.AXRepository/AXModel.cs b/ACUtils.AXRepository/AXModel.cs index be387d5..74f42ce 100644 --- a/ACUtils.AXRepository/AXModel.cs +++ b/ACUtils.AXRepository/AXModel.cs @@ -28,7 +28,7 @@ public virtual string STATO [AxField(ax_field: "From")] public virtual string User { get; set; } - [AxField(ax_field: "From_ExternalId")] + [AxFromExternalIdField] public virtual string MittenteCodiceRubrica { get; set; } [AxField(ax_field: "From")] @@ -37,7 +37,7 @@ public virtual string STATO //[AxField(ax_field: "From_IdRubrica")] public virtual int? MittenteIdRubrica { get; set; } - [AxField(ax_field: "To_ExternalId")] + [AxToExternalIdField] public virtual IEnumerable DestinatariCodiceRubrica { get; set; } [AxField(ax_field: "To")] @@ -159,14 +159,14 @@ public static T Idrate(ArxivarNext.Model.EditProfileSchemaDTO model) obj.SetPropertyIfExists(field.Name, dfiled.Value); } } - + obj.SetPropertyIfExists("DOCNUMBER", model.ProfileInfo.DocNumber); - + var mittente = model.Fields.GetField("TO"); - obj.SetPropertyIfExists("To_ExternalId", mittente.Value?.Select(m => m.ExternalId)); - + obj.SetPropertyIfExists(AxToExternalIdFieldAttribute.AX_KEY, mittente.Value?.Select(m => m.ExternalId)); + var destinatario = model.Fields.GetField("FROM"); - obj.SetPropertyIfExists("From_ExternalId", destinatario.Value?.ExternalId); + obj.SetPropertyIfExists(AxFromExternalIdFieldAttribute.AX_KEY, destinatario.Value?.ExternalId); return obj; } @@ -210,9 +210,9 @@ public static List Idrate(List results) return (from result in results select Idrate(result)).ToList(); } -#endregion + #endregion -#region testers + #region testers public new bool HasDbField(string field) { return this.GetType().GetProperties().Where(property => @@ -224,9 +224,9 @@ public bool HasAXField(string field) { return this.GetType().GetProperties().Where(property => GetArxivarAttribute(property.Name)?.AXField == field).Any(); } -#endregion + #endregion -#region getters + #region getters public AxClassAttribute GetArxivarAttribute() { @@ -298,7 +298,8 @@ public Dictionary GetArxivarFields() var ax = GetArxivarAttribute(property.Name); if (ax != null && !string.IsNullOrEmpty(ax.AXField)) { - fields.Add(ax.AXField, this[ax.AXField]); + if (!fields.Keys.Contains(ax.AXField)) + fields.Add(ax.AXField, this[ax.AXField]); } } return fields; @@ -343,6 +344,6 @@ public Dictionary GetPrimaryKeys() return fields; } -#endregion + #endregion } } diff --git a/ACUtils.AXRepository/ArxivarRepository.cs b/ACUtils.AXRepository/ArxivarRepository.cs index 4dfff97..c0eb31f 100644 --- a/ACUtils.AXRepository/ArxivarRepository.cs +++ b/ACUtils.AXRepository/ArxivarRepository.cs @@ -36,32 +36,11 @@ public class ArxivarRepository private string _tokenManagement; private string _refreshTokenManagement; - private WCFConnectorManager GetWcf() - { - - var logonRequest = new ArxLogonRequest - { - ClientId = _appId, - ClientSecret = _appSecret, - EnablePushEvents = true, - Username = _username, - Password = _password, - ImpersonateUserId = _impersonateUserId.HasValue ? System.Convert.ToInt32(_impersonateUserId) : default(int?) - }; - var manager = new WCFConnectorManager(_wcfUrl, logonRequest) - { - AutoChunk = true, //default a true - AutoReconnect = true, //default a true - Lang = "IT" - }; - manager.ChannelOpening += _manager_ChannelOpening; - manager.ChannelOpened += _manager_ChannelOpened; - return manager; - - } ACUtils.ILogger _logger = null; + #region configuration + private ArxivarNext.Client.Configuration configuration => new ArxivarNext.Client.Configuration() { @@ -86,6 +65,10 @@ private WCFConnectorManager GetWcf() BasePath = _workflowUrl, }; + #endregion + + #region constructor + public ArxivarRepository( string apiUrl, string managementUrl, string workflowUrl, string username, string password, string appId, string appSecret, string wcf_url = "net.tcp://127.0.0.1:8740/Arxivar/Push", @@ -121,6 +104,8 @@ public ArxivarRepository( _token = authToken; } + #endregion + #region file upload public List UploadFile(Stream stream) { @@ -205,20 +190,25 @@ public ACUtils.AXRepository.ArxivarNext.Model.UserProfileDTO GetAddressBookEntry var addressBookApi = new ArxivarNext.Api.AddressBookApi(configuration); var filter = addressBookApi.AddressBookGetSearchField(); - var select = addressBookApi.AddressBookGetSelectField(); - select.Select("DM_RUBRICA_CODICE"); - select.Select("DM_RUBRICA_AOO"); - select.Select("DM_RUBRICA_CODICE"); - select.Select("ID"); - - var result = addressBookApi.AddressBookPostSearch(new AddressBookSearchCriteriaDTO( + var select = addressBookApi.AddressBookGetSelectField() + .Select("DM_RUBRICA_CODICE") + .Select("DM_RUBRICA_AOO") + .Select("DM_RUBRICA_CODICE") + .Select("DM_RUBRICA_SYSTEM_ID") + .Select("ID"); + + var results = addressBookApi.AddressBookPostSearch(new AddressBookSearchCriteriaDTO( filter: codice, addressBookCategoryId: addressBookCategoryId, filterFields: filter, selectFields: select )); - var addressBookId = result.Data.First().Columns.GetValue("ID"); + var result = results.Data.First(); + + var contactId = result.GetValue("ID"); + var addressBookId = result.GetValue("DM_RUBRICA_SYSTEM_ID"); + var addressBook = addressBookApi.AddressBookGetById(addressBookId: addressBookId); return new ArxivarNext.Model.UserProfileDTO( id: addressBook.Id, @@ -226,7 +216,7 @@ public ACUtils.AXRepository.ArxivarNext.Model.UserProfileDTO GetAddressBookEntry description: addressBook.BusinessName, docNumber: "-1", type: (int)type, - contactId: addressBook.Id, + contactId: contactId, fax: addressBook.Fax, address: addressBook.Address, postalCode: addressBook.PostalCode, @@ -282,7 +272,7 @@ private AuthenticationTokenDTO _login(List scopeList = null) ); return auth; } - + private void Login() { @@ -309,16 +299,7 @@ private void LoginManagment() #endregion - - - public void DeleteWorkflow(int? processId) - { - var workflowApi = new ArxivarNext.Api.WorkflowApi(configuration); - workflowApi.WorkflowStopWorkflow(processId.Value); - workflowApi.WorkflowDeleteWorkflow(processId, true); - workflowApi.WorkflowFreeUserConstraint(processId.Value); - } - + #region profile - get public T GetProfile(int docnumber) where T : AXModel, new() { @@ -662,7 +643,6 @@ public bool HardDeleteProfile(int docNumber) profileDto.PostProfilationActions = new List(); profileDto.Document = new FileDTO() { BufferIds = bufferId }; - if (model.Allegati != null) { foreach (var allegato in model.Allegati) @@ -676,7 +656,6 @@ public bool HardDeleteProfile(int docNumber) var status = statesApi.StatesGet(classeDoc.Id); profileDto.SetState(model.GetArxivarAttribute().Stato ?? status.First().Id); - var additional = profileApi.ProfilesGetAdditionalByClasse( classeDoc.DocumentType, classeDoc.Type2, @@ -693,7 +672,9 @@ public bool HardDeleteProfile(int docNumber) } if (!string.IsNullOrEmpty(model.User)) + { profileDto.SetFromField(GetUserAddressBookEntry(model.User, 1)); + } if (!string.IsNullOrEmpty(model.MittenteCodiceRubrica)) { @@ -716,14 +697,33 @@ public bool HardDeleteProfile(int docNumber) } } - + model.STATO = model.STATO ?? statesApi.StatesGet(classeDoc.Id).First().Id; foreach (var field in model.GetArxivarFields()) { - profileDto.SetField(field.Key, field.Value); + if (new[] { "FROM", "TO", "CC" }.Contains(field.Key.ToUpper())) + { + // TODO: ricercare il profilo in base al dato passato + } + else if (field.Key.Equals(Attributes.AxFromExternalIdFieldAttribute.AX_KEY)) + { + + } + else if (field.Key.Equals(Attributes.AxToExternalIdFieldAttribute.AX_KEY)) + { + + } + else if (field.Key.Equals(Attributes.AxCcExternalIdFieldAttribute.AX_KEY)) + { + + } + else + { + profileDto.SetField(field.Key, field.Value); + } } - var stato = model.STATO ?? statesApi.StatesGet(classeDoc.Id).First().Id; - profileDto.SetState(stato); + + //profileDto.SetState(model.STATO); var newProfile = new ProfileDTO() { @@ -793,19 +793,49 @@ public string[] DownloadAttachments(int docnumber, string outputFolder, bool ign #region download documento - public string DownloadDocument(long docnumber, string outputFolder, bool forView = false) + public (Stream stream, string filename) GetDocumentFileStream(long docnumber, bool forView = false) { Login(); var documentsApi = new ArxivarNext.Api.DocumentsApi(configuration); + var response = documentsApi.DocumentsGetForProfileWithHttpInfo(System.Convert.ToInt32(docnumber), forView); - var fileNameInfo = response.Headers["Content-Disposition"]; - //var filename = (new Regex("filename=\"(.*)\"", RegexOptions.IgnoreCase)).Match(fileNameInfo).Groups[0].Value; - var filename = new System.Net.Mime.ContentDisposition(fileNameInfo).FileName ?? "file.dat"; - var fullPath = Path.Combine(outputFolder, filename); - _write_stream_to_file(response.Data, fullPath); - return fullPath; + + if (response.Data is FileStream) + { + using (response.Data) + { + var fileStream = response.Data as FileStream; + var fileName = System.IO.Path.GetFileName(fileStream.Name); + MemoryStream memoryStream = new MemoryStream(); + fileStream.CopyTo(fileStream); + fileStream.Close(); + + if (System.IO.File.Exists(fileStream.Name)) + System.IO.File.Delete(fileStream.Name); + return (memoryStream, fileName); + } + } + else + { + var fileNameInfo = response.Headers["Content-Disposition"]; + var filename = (new Regex("filename=\"(.*)\"", RegexOptions.IgnoreCase)).Match(fileNameInfo).Groups[0].Value; + return (response.Data, filename); + } + } + public string DownloadDocument(long docnumber, string outputFolder, bool forView = false) + { + (Stream stream, string filename) = GetDocumentFileStream(docnumber, forView); + using (stream) + { + var fullPath = Path.Combine(outputFolder, filename); + _write_stream_to_file(stream, fullPath).Close(); + return fullPath; + } + } + + #endregion #region Tasks @@ -1038,6 +1068,29 @@ public int FascicoliMoveToSubfolder(int parentFolder, string subfolderName, int #endregion #region wfc functions + private WCFConnectorManager GetWcf() + { + + var logonRequest = new ArxLogonRequest + { + ClientId = _appId, + ClientSecret = _appSecret, + EnablePushEvents = true, + Username = _username, + Password = _password, + ImpersonateUserId = _impersonateUserId.HasValue ? System.Convert.ToInt32(_impersonateUserId) : default(int?) + }; + var manager = new WCFConnectorManager(_wcfUrl, logonRequest) + { + AutoChunk = true, //default a true + AutoReconnect = true, //default a true + Lang = "IT" + }; + manager.ChannelOpening += _manager_ChannelOpening; + manager.ChannelOpened += _manager_ChannelOpened; + return manager; + + } private void _manager_ChannelOpened(string message) { this._logger?.Debug($"WCF ChannelOpened: {message}"); @@ -1177,7 +1230,7 @@ public UserInfoDTO UserGet(string aoo, string username) { Login(); var userSearchApi = new ArxivarNext.Api.UserSearchApi(configuration); - + var select = userSearchApi.UserSearchGetSelect() .Select("UTENTE"); @@ -1249,7 +1302,7 @@ public bool UserCreate( } ); - + if (groups != null) { @@ -1387,6 +1440,18 @@ public void UserUpdate(ACUtils.AXRepository.ArxivarNext.Model.UserCompleteDTO us #endregion + #region workflow + + public void DeleteWorkflow(int? processId) + { + var workflowApi = new ArxivarNext.Api.WorkflowApi(configuration); + workflowApi.WorkflowStopWorkflow(processId.Value); + workflowApi.WorkflowDeleteWorkflow(processId, true); + workflowApi.WorkflowFreeUserConstraint(processId.Value); + } + + #endregion + public Stream _write_stream_to_file(Stream stream, string filepath) { var fileStream = File.Create(filepath); diff --git a/ACUtils.AXRepository/Attributes/AxCcExternalIdFieldAttribute.cs b/ACUtils.AXRepository/Attributes/AxCcExternalIdFieldAttribute.cs new file mode 100644 index 0000000..f05a2c7 --- /dev/null +++ b/ACUtils.AXRepository/Attributes/AxCcExternalIdFieldAttribute.cs @@ -0,0 +1,11 @@ +namespace ACUtils.AXRepository.Attributes +{ + public class AxCcExternalIdFieldAttribute : AxDbFieldAttribute + { + public const string AX_KEY = "Cc_ExternalId"; + public AxCcExternalIdFieldAttribute(string db_field = null, string description = null, int key = 0) : base(ax_field: AX_KEY, db_field: db_field, description: description, key: key) + { + + } + } +} diff --git a/ACUtils.AXRepository/Attributes/AxDbFieldAttribute.cs b/ACUtils.AXRepository/Attributes/AxDbFieldAttribute.cs index b503fbc..a8feebe 100644 --- a/ACUtils.AXRepository/Attributes/AxDbFieldAttribute.cs +++ b/ACUtils.AXRepository/Attributes/AxDbFieldAttribute.cs @@ -2,11 +2,9 @@ { public class AxDbFieldAttribute: AxFieldAttribute { - private readonly string db_field; - public string DbField => db_field; public AxDbFieldAttribute(string ax_field = null, string db_field = null, string description = null, int key = 0): base(ax_field: ax_field, description: description, key: key) { - this.db_field = db_field; + this.DbField = db_field; } } } diff --git a/ACUtils.AXRepository/Attributes/AxFieldAttribute.cs b/ACUtils.AXRepository/Attributes/AxFieldAttribute.cs index 5abfde3..71aeda4 100644 --- a/ACUtils.AXRepository/Attributes/AxFieldAttribute.cs +++ b/ACUtils.AXRepository/Attributes/AxFieldAttribute.cs @@ -1,7 +1,7 @@ namespace ACUtils.AXRepository.Attributes { [System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple = false)] - public class AxFieldAttribute : System.Attribute, IAxFieldAttribute + public class AxFieldAttribute : DbFieldAttribute, IAxFieldAttribute { readonly string ax_field; readonly string description; @@ -11,7 +11,7 @@ public class AxFieldAttribute : System.Attribute, IAxFieldAttribute public int? Key => _key; public bool IsPrimaryKey => Key.GetValueOrDefault() > 0; - public AxFieldAttribute(string ax_field = null, string description = null, int key = 0) + public AxFieldAttribute(string ax_field = null, string description = null, int key = 0): base() { this.ax_field = ax_field; this.description = description; diff --git a/ACUtils.AXRepository/Attributes/AxFromExternalIdFieldAttribute.cs b/ACUtils.AXRepository/Attributes/AxFromExternalIdFieldAttribute.cs new file mode 100644 index 0000000..8241183 --- /dev/null +++ b/ACUtils.AXRepository/Attributes/AxFromExternalIdFieldAttribute.cs @@ -0,0 +1,11 @@ +namespace ACUtils.AXRepository.Attributes +{ + public class AxFromExternalIdFieldAttribute: AxDbFieldAttribute + { + public const string AX_KEY = "From_ExternalId"; + public AxFromExternalIdFieldAttribute(string db_field = null, string description = null, int key = 0) : base(ax_field: AX_KEY , db_field: db_field, description: description, key: key) + { + + } + } +} diff --git a/ACUtils.AXRepository/Attributes/AxToExternalIdFieldAttribute.cs b/ACUtils.AXRepository/Attributes/AxToExternalIdFieldAttribute.cs new file mode 100644 index 0000000..4eb5df1 --- /dev/null +++ b/ACUtils.AXRepository/Attributes/AxToExternalIdFieldAttribute.cs @@ -0,0 +1,11 @@ +namespace ACUtils.AXRepository.Attributes +{ + public class AxToExternalIdFieldAttribute : AxDbFieldAttribute + { + public const string AX_KEY = "To_ExternalId"; + public AxToExternalIdFieldAttribute(string db_field = null, string description = null, int key = 0) : base(ax_field: AX_KEY, db_field: db_field, description: description, key: key) + { + + } + } +} diff --git a/ACUtils.AXRepository/AxExt.cs b/ACUtils.AXRepository/AxExt.cs index a459390..63843b4 100644 --- a/ACUtils.AXRepository/AxExt.cs +++ b/ACUtils.AXRepository/AxExt.cs @@ -151,6 +151,10 @@ public static MaskProfileSchemaDTO SetField(this MaskProfileSchemaDTO self, stri public static void SetField(this List fields, string name, object value) { + if (name == "WORKFLOW") + { + return; + } if (name == "DOCNUMBER") { return; @@ -202,6 +206,10 @@ public static void SetField(this List fields, string name, object { (field as FromFieldDTO).Value = (UserProfileDTO)value; } + else if (field?.ClassName == "StateFieldDTO") + { + (field as StateFieldDTO).Value = (string)value; + } else { throw new Exception($"'{name}' - type '{field?.ClassName}': not permitted ");