diff --git a/ACUtils.AXRepository/ACUtils.AXRepository.csproj b/ACUtils.AXRepository/ACUtils.AXRepository.csproj index 589901a..94ebd70 100644 --- a/ACUtils.AXRepository/ACUtils.AXRepository.csproj +++ b/ACUtils.AXRepository/ACUtils.AXRepository.csproj @@ -1,12 +1,12 @@ - + net461 Andrea Cattaneo true false - 1.0.0.138 - 1.0.0.138 + 1.0.0.139 + 1.0.0.139 Utility per gestione classi documentali Arxivar it true diff --git a/ACUtils.AXRepository/ArxivarRepository.cs b/ACUtils.AXRepository/ArxivarRepository.cs index 3770c72..f7c3693 100644 --- a/ACUtils.AXRepository/ArxivarRepository.cs +++ b/ACUtils.AXRepository/ArxivarRepository.cs @@ -223,7 +223,7 @@ public ACUtils.AXRepository.ArxivarNext.Model.UserProfileDTO GetAddressBookEntry externalId: addressBook.ExternalCode, description: addressBook.BusinessName, docNumber: "-1", - type: (int) type, + type: (int)type, contactId: addressBook.Id, fax: addressBook.Fax, address: addressBook.Address, @@ -334,20 +334,19 @@ public void DeleteWorkflow(int? processId) var classeDocumento = docTypes.First(i => i.Key == classeDoc); - var filterSearch = searchApi.SearchesGet(); + var filterSearch = searchApi.SearchesGet() + .Set("DOCUMENTTYPE", new ACUtils.AXRepository.ArxivarNext.Model.DocumentTypeSearchFilterDto(classeDocumento.DocumentType, classeDocumento.Type2, classeDocumento.Type3)); ; //var defaultSelect = searchApi.SearchesGetSelect_0(classeDocumento.Id); - var defaultSelect = searchApi.SearchesGetSelect_1(classeDocumento.DocumentType, classeDocumento.Type2, classeDocumento.Type3); + var defaultSelect = searchApi.SearchesGetSelect_1(classeDocumento.DocumentType, classeDocumento.Type2, classeDocumento.Type3) + .Select("WORKFLOW") + .Select("DOCNUMBER"); /* foreach (var axfield in model.GetArxivarFields()) { - defaultSelect.Fields.Select(axfield.Key); + defaultSelect.Select(axfield.Key); } */ - defaultSelect.Fields.Select("WORKFLOW"); - defaultSelect.Fields.Select("DOCNUMBER"); - - filterSearch.Fields.Set("DOCUMENTTYPE", new ACUtils.AXRepository.ArxivarNext.Model.DocumentTypeSearchFilterDto(classeDocumento.DocumentType, classeDocumento.Type2, classeDocumento.Type3)); var additionals = searchApi.SearchesGetAdditionalByClasse(classeDocumento.DocumentType, classeDocumento.Type2, classeDocumento.Type3, aoo.Code); filterSearch.Fields.AddRange(additionals); @@ -356,7 +355,7 @@ public void DeleteWorkflow(int? processId) { foreach (var kv in searchValues) { - filterSearch.Fields.Set(kv.Key, kv.Value); + filterSearch.Set(kv.Key, kv.Value); } } @@ -365,14 +364,14 @@ public void DeleteWorkflow(int? processId) foreach (var field in defaultSelect.Fields) { if (field.FieldType == 2) - defaultSelect.Fields.Select(field.Name); + defaultSelect.Select(field.Name); } } if (!eliminato) { - filterSearch.Fields.Set("Stato", STATO_ELIMINATO, 2); // diverso da ELIMINATO + filterSearch.Set("Stato", STATO_ELIMINATO, 2); // diverso da ELIMINATO } var values = searchApi.SearchesPostSearch(new SearchCriteriaDto(filterSearch, defaultSelect)); @@ -397,8 +396,8 @@ public int GetDocumentNumber(string classeDoc, Dictionary search // Intero con segno che indica i valori relativi di x e y, come illustrato nella // tabella seguente. Valore Significato Minore di zero x è minore di y. Zero x è // uguale a y. Maggiore di zero x è maggiore di y. - var xVal = (int)x.Columns.Get("DOCNUMBER").Value; - var yVal = (int)y.Columns.Get("DOCNUMBER").Value; + var xVal = x.GetValue("DOCNUMBER"); + var yVal = y.GetValue("DOCNUMBER"); return xVal.CompareTo(yVal); }); } @@ -413,7 +412,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary search throw new NotFoundException($"La ricerca ha ricevuto nessun risultato"); } - var docNumber = (int)values.First().Columns.Get("DOCNUMBER").Value; + var docNumber = (int)values.First().Get("DOCNUMBER").Value; return docNumber; } public int GetDocumentNumber(AXModel model, bool eliminato = false, bool getFirst = false) where T : AXModel, new() @@ -462,7 +461,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary search var taskworkhistoryapi = new ArxivarNext.Api.TaskWorkHistoryApi(configuration); var history = taskworkhistoryapi.TaskWorkHistoryGetHistoryByProcessId(processId); - if (!history.Where(r => !r.Columns.GetValue("CONCLUSO").HasValue).Any()) // WTF? controllare questa condizione + if (!history.Where(r => !r.GetValue("CONCLUSO").HasValue).Any()) // WTF? controllare questa condizione { DeleteWorkflow(processId); } @@ -481,12 +480,12 @@ public int GetDocumentNumber(string classeDoc, Dictionary search if (model.DataDoc.HasValue) { - profileDto.Fields.SetField("DataDoc", model.DataDoc.Value); + profileDto.SetField("DataDoc", model.DataDoc.Value); } if (!string.IsNullOrEmpty(model.STATO)) { - profileDto.Fields.SetState(model.STATO); + profileDto.SetState(model.STATO); } /* @@ -499,7 +498,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary search foreach (var field in model.GetArxivarFields()) { - profileDto.Fields.SetField(field.Key, field.Value); + profileDto.SetField(field.Key, field.Value); } if (!string.IsNullOrEmpty(model.FilePath)) @@ -575,7 +574,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary search var profilesApi = new ArxivarNext.Api.ProfilesApi(configuration); var profileDto = profilesApi.ProfilesGetSchema(docNumber, true); - profileDto.Fields.SetState(STATO_ELIMINATO); + profileDto.SetState(STATO_ELIMINATO); profilesApi.ProfilesPut(docNumber, new ProfileDTO() { Fields = profileDto.Fields @@ -647,10 +646,10 @@ public bool HardDeleteProfile(int docNumber) } } - var classeDoc = profileDto.Fields.SetDocumentType(configuration, aoo.Code, documentType); + var classeDoc = profileDto.SetDocumentType(configuration, aoo.Code, documentType); var status = statesApi.StatesGet(classeDoc.Id); - profileDto.Fields.SetState(model.GetArxivarAttribute().Stato ?? status.First().Id); + profileDto.SetState(model.GetArxivarAttribute().Stato ?? status.First().Id); var additional = profileApi.ProfilesGetAdditionalByClasse( @@ -661,19 +660,19 @@ public bool HardDeleteProfile(int docNumber) ); profileDto.Fields.AddRange(additional); - profileDto.Fields.SetField("DOCNAME", model.DOCNAME); + profileDto.SetField("DOCNAME", model.DOCNAME); if (model.DataDoc.HasValue) { - profileDto.Fields.SetField("DataDoc", model.DataDoc.Value); + profileDto.SetField("DataDoc", model.DataDoc.Value); } if (!string.IsNullOrEmpty(model.User)) - profileDto.Fields.SetFromField(GetUserAddressBookEntry(model.User, 1)); + profileDto.SetFromField(GetUserAddressBookEntry(model.User, 1)); if (!string.IsNullOrEmpty(model.MittenteCodiceRubrica)) { - profileDto.Fields.SetFromField(GetAddressBookEntry( + profileDto.SetFromField(GetAddressBookEntry( model.MittenteCodiceRubrica, model.MittenteIdRubrica.GetValueOrDefault(), type: UserProfileType.From @@ -684,7 +683,7 @@ public bool HardDeleteProfile(int docNumber) { foreach (var destinatario in model.DestinatariCodiceRubrica) { - profileDto.Fields.SetToField(GetAddressBookEntry( + profileDto.SetToField(GetAddressBookEntry( destinatario, model.DestinatariIdRubrica.GetValueOrDefault(), type: UserProfileType.To @@ -695,11 +694,11 @@ public bool HardDeleteProfile(int docNumber) foreach (var field in model.GetArxivarFields()) { - profileDto.Fields.SetField(field.Key, field.Value); + profileDto.SetField(field.Key, field.Value); } var stato = model.STATO ?? statesApi.StatesGet(classeDoc.Id).First().Id; - profileDto.Fields.SetState(stato); + profileDto.SetState(stato); var newProfile = new ProfileDTO() { @@ -833,7 +832,7 @@ public int Task_ProcessIdFromTaskid(int taskid) try { var profile = profileApi.ProfilesGetSchema(docnumber, false); - var cDocType = profile.Fields.GetDocumentType(); + var cDocType = profile.GetDocumentType(); if (!targetDocRx.Match(cDocType).Success) continue; } catch @@ -877,7 +876,7 @@ public int Task_ProcessIdFromTaskid(int taskid) { var docnumber = (int)row[docnumber_pos]; var profile = profileApi.ProfilesGetSchema(docnumber, false); - var cDocType = profile.Fields.GetDocumentType(); + var cDocType = profile.GetDocumentType(); if (targetDocType != cDocType) continue; yield return (docnumber, this.GetProfile(docnumber)); } @@ -900,7 +899,7 @@ public long Task_GetUserIdOfTaskId(int processId, int taskWorkId) Login(); var taskHistoryApi = new ArxivarNext.Api.TaskWorkHistoryApi(configuration); var taskHistory = taskHistoryApi.TaskWorkHistoryGetHistoryByProcessId(processId); - var userId = (from task in taskHistory where task.Columns.GetValue("ID") == taskWorkId select task.Columns.GetValue("UTENTE")).First(); + var userId = (from task in taskHistory where task.GetValue("ID") == taskWorkId select task.Columns.GetValue("UTENTE")).First(); return userId; } #endregion @@ -1072,7 +1071,6 @@ public bool UserExists_Wcf(string aoo, string username) } - public bool UserCreate_Wcf( string username, string aoo, @@ -1154,21 +1152,22 @@ public UserInfoDTO UserGet(string aoo, string username) { Login(); var userSearchApi = new ArxivarNext.Api.UserSearchApi(configuration); - var select = userSearchApi.UserSearchGetSelect(); - select.Fields.Select("UTENTE"); - var search = userSearchApi.UserSearchGetSearch(); - search.StringFields.Set("DESCRIPTION", username); - search.StringFields.Set("AOO", aoo); + + var select = userSearchApi.UserSearchGetSelect() + .Select("UTENTE"); + + var search = userSearchApi.UserSearchGetSearch() + .SetString("DESCRIPTION", username) + .SetString("AOO", aoo); + var result = userSearchApi.UserSearchPostSearch(new UserSearchCriteriaDTO(selectDto: select, searchDto: search)).FirstOrDefault(); if (result == null) { throw new NotFoundException($"user '{aoo}\\{username}' not found"); } - var userApi = new ArxivarNext.Api.UsersApi(configuration); - return userApi.UsersGet(System.Convert.ToInt32( - result.Columns.First(e => e.Id == "USER").Value - )); + var userId = result.Columns.GetValue("UTENTE"); + return userApi.UsersGet(userId); } public bool UserExists(string aoo, string username) diff --git a/ACUtils.AXRepository/AxExt.cs b/ACUtils.AXRepository/AxExt.cs index 6f1b34d..ffd0a82 100644 --- a/ACUtils.AXRepository/AxExt.cs +++ b/ACUtils.AXRepository/AxExt.cs @@ -9,6 +9,17 @@ namespace ACUtils.AXRepository { public static class AxExt { + + public static EditProfileSchemaDTO SetState(this EditProfileSchemaDTO self, string stateName) + { + self.SetState(stateName); + return self; + } + public static MaskProfileSchemaDTO SetState(this MaskProfileSchemaDTO self, string stateName) + { + self.SetState(stateName); + return self; + } public static void SetState(this List fields, string stateName) { var stateFiled = ((StateFieldDTO)fields.FirstOrDefault(i => @@ -17,21 +28,29 @@ public static void SetState(this List fields, string stateName) stateFiled.Value = stateName; } - public static DocumentTypeBaseDTO SetDocumentType(this List fields, ArxivarNext.Client.Configuration configuration, string aooCode, string doc_type) + public static DocumentTypeBaseDTO SetDocumentType(this MaskProfileSchemaDTO self, ArxivarNext.Client.Configuration configuration, string aooCode, string docType) + { + return self.Fields.SetDocumentType( + configuration: configuration, + aooCode: aooCode, + docType: docType + ); + } + public static DocumentTypeBaseDTO SetDocumentType(this List fields, ArxivarNext.Client.Configuration configuration, string aooCode, string docType) { var docTypesApi = new ArxivarNext.Api.DocumentTypesApi(configuration); var doctypes = docTypesApi.DocumentTypesGetOld(1, aooCode); // TODO: deprecated method try { DocumentTypeBaseDTO classeDoc = doctypes.First(i => - i.Key.Equals(doc_type, StringComparison.CurrentCultureIgnoreCase) + i.Key.Equals(docType, StringComparison.CurrentCultureIgnoreCase) ); fields.SetDocumentType(classeDoc.Id.Value); return classeDoc; } catch (InvalidOperationException e) { - throw new ApiError($"classe doc '{doc_type}' non trovata", e); + throw new ApiError($"classe doc '{docType}' non trovata", e); } } @@ -41,6 +60,10 @@ public static void SetDocumentType(this List fields, int doc_type) docTypeField.Value = doc_type; } + public static string GetDocumentType(this EditProfileSchemaDTO self) + { + return self.Fields.GetDocumentType(); + } public static string GetDocumentType(this List fields) { @@ -115,6 +138,17 @@ public static T GetFieldValue(this List fields, string name) } } + public static EditProfileSchemaDTO SetField(this EditProfileSchemaDTO self, string name, object value) + { + self.Fields.SetField(name, value); + return self; + } + public static MaskProfileSchemaDTO SetField(this MaskProfileSchemaDTO self, string name, object value) + { + self.Fields.SetField(name, value); + return self; + } + public static void SetField(this List fields, string name, object value) { if (name == "DOCNUMBER") @@ -174,6 +208,12 @@ public static void SetField(this List fields, string name, object } } + public static MaskProfileSchemaDTO SetToField(this MaskProfileSchemaDTO self, UserProfileDTO value) + { + self.SetToField(value); + return self; + } + public static void SetToField(this List fields, UserProfileDTO value) { var field = ((ToFieldDTO)fields.FirstOrDefault(i => @@ -186,12 +226,21 @@ public static void SetToField(this List fields, UserProfileDTO val field.Value.Add(value); } + public static MaskProfileSchemaDTO SetFromField(this MaskProfileSchemaDTO self, UserProfileDTO value) + { + self.SetFromField(value); + return self; + } public static void SetFromField(this List fields, UserProfileDTO value) { fields.SetField("From", value); } - + public static UserSearchDTO SetString(this UserSearchDTO self, string name, object value, int operator_ = 3) + { + self.StringFields.Set(name: name, value: value, operator_: operator_); + return self; + } public static void Set(this List fields, string name, object value, int operator_ = 3) { var field = fields.First(i => i.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -199,6 +248,11 @@ public static void Set(this List fields, string nam field.Valore1 = Convert.ToString(value); } + public static SearchDTO Set(this SearchDTO self, string name, object value, int operator_ = 3) + { + self.Set(name: name, value: value, operator_: operator_); + return self; + } public static void Set(this List fields, string name, object value, int operator_ = 3) { var field = fields.First(i => i.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); @@ -225,10 +279,19 @@ public static void Set(this List fields, string name, obj } } + public static ColumnSearchResult Get(this RowSearchResult self, string name) + { + return self.Columns.Get(name); + } public static ColumnSearchResult Get(this List results, string name) { return results.First(i => i.Id.Equals(name, StringComparison.CurrentCultureIgnoreCase)); } + + public static T GetValue(this RowSearchResult self, string name) + { + return self.Columns.GetValue(name); + } public static T GetValue(this List results, string name) { try @@ -241,6 +304,12 @@ public static T GetValue(this List results, string name) } } + public static SelectDTO Select(this SelectDTO self, string name) + { + self.Fields.Select(name); + return self; + } + public static List Select(this List fields, string name) { fields.First(i => i.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Selected = true;