Skip to content

Commit

Permalink
AXRepository - fix UsersGet function and refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
cattaneoinfoesse committed Jul 25, 2022
1 parent 62ebed2 commit 9a33c47
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 48 deletions.
6 changes: 3 additions & 3 deletions ACUtils.AXRepository/ACUtils.AXRepository.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
<Authors>Andrea Cattaneo</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Version>1.0.0.138</Version>
<PackageVersion>1.0.0.138</PackageVersion>
<Version>1.0.0.139</Version>
<PackageVersion>1.0.0.139</PackageVersion>
<Description>Utility per gestione classi documentali Arxivar</Description>
<NeutralLanguage>it</NeutralLanguage>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
81 changes: 40 additions & 41 deletions ACUtils.AXRepository/ArxivarRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand All @@ -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));
Expand All @@ -397,8 +396,8 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> 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<int>("DOCNUMBER");
var yVal = y.GetValue<int>("DOCNUMBER");
return xVal.CompareTo(yVal);
});
}
Expand All @@ -413,7 +412,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> 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<T>(AXModel<T> model, bool eliminato = false, bool getFirst = false) where T : AXModel<T>, new()
Expand Down Expand Up @@ -462,7 +461,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> search

var taskworkhistoryapi = new ArxivarNext.Api.TaskWorkHistoryApi(configuration);
var history = taskworkhistoryapi.TaskWorkHistoryGetHistoryByProcessId(processId);
if (!history.Where(r => !r.Columns.GetValue<DateTime?>("CONCLUSO").HasValue).Any()) // WTF? controllare questa condizione
if (!history.Where(r => !r.GetValue<DateTime?>("CONCLUSO").HasValue).Any()) // WTF? controllare questa condizione
{
DeleteWorkflow(processId);
}
Expand All @@ -481,12 +480,12 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> 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);
}

/*
Expand All @@ -499,7 +498,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> 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))
Expand Down Expand Up @@ -575,7 +574,7 @@ public int GetDocumentNumber(string classeDoc, Dictionary<string, object> 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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<T>(docnumber));
}
Expand All @@ -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<long>("ID") == taskWorkId select task.Columns.GetValue<long>("UTENTE")).First();
var userId = (from task in taskHistory where task.GetValue<long>("ID") == taskWorkId select task.Columns.GetValue<long>("UTENTE")).First();
return userId;
}
#endregion
Expand Down Expand Up @@ -1072,7 +1071,6 @@ public bool UserExists_Wcf(string aoo, string username)
}



public bool UserCreate_Wcf(
string username,
string aoo,
Expand Down Expand Up @@ -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<int>("UTENTE");
return userApi.UsersGet(userId);
}

public bool UserExists(string aoo, string username)
Expand Down
Loading

0 comments on commit 9a33c47

Please sign in to comment.