Consume ticket overview capabilities separately
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using C4IT.FASD.Cockpit.Communication;
|
||||||
using FasdDesktopUi.Basics.Services;
|
using FasdDesktopUi.Basics.Services;
|
||||||
using FasdDesktopUi.Basics.Services.Models;
|
using FasdDesktopUi.Basics.Services.Models;
|
||||||
|
|
||||||
@@ -117,7 +118,6 @@ public class TicketOverviewUpdateServiceTest
|
|||||||
var communication = new FakeCommunication();
|
var communication = new FakeCommunication();
|
||||||
communication.SetCounts(TileScope.Personal, new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
communication.SetCounts(TileScope.Personal, new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
||||||
{
|
{
|
||||||
["TicketAndServiceRequestsEnabled"] = 1,
|
|
||||||
["ServiceRequestsNew"] = 2
|
["ServiceRequestsNew"] = 2
|
||||||
});
|
});
|
||||||
communication.SetCounts(TileScope.Role, new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
communication.SetCounts(TileScope.Role, new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
||||||
@@ -150,10 +150,7 @@ public class TicketOverviewUpdateServiceTest
|
|||||||
Assert.True(service.TicketAndServiceRequestsEnabled);
|
Assert.True(service.TicketAndServiceRequestsEnabled);
|
||||||
Assert.Equal(0, availabilityChanges);
|
Assert.Equal(0, availabilityChanges);
|
||||||
|
|
||||||
communication.SetCounts(TileScope.Personal, new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
communication.SetCapability(TileScope.Personal, false);
|
||||||
{
|
|
||||||
["TicketAndServiceRequestsEnabled"] = 0
|
|
||||||
});
|
|
||||||
await service.FetchAsync(TileScope.Personal);
|
await service.FetchAsync(TileScope.Personal);
|
||||||
|
|
||||||
Assert.False(service.TicketAndServiceRequestsEnabled);
|
Assert.False(service.TicketAndServiceRequestsEnabled);
|
||||||
@@ -199,18 +196,27 @@ public class TicketOverviewUpdateServiceTest
|
|||||||
|
|
||||||
private sealed class FakeCommunication : ITicketOverviewCommunication
|
private sealed class FakeCommunication : ITicketOverviewCommunication
|
||||||
{
|
{
|
||||||
private Dictionary<string, int> _personalCounts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
private cF4sdTicketOverviewCountsResult _personalResult = new cF4sdTicketOverviewCountsResult();
|
||||||
private Dictionary<string, int> _roleCounts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
private cF4sdTicketOverviewCountsResult _roleResult = new cF4sdTicketOverviewCountsResult();
|
||||||
|
|
||||||
public bool IsDemo()
|
public bool IsDemo()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Dictionary<string, int>> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope)
|
public Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope)
|
||||||
{
|
{
|
||||||
var source = useRoleScope ? _roleCounts : _personalCounts;
|
var source = useRoleScope ? _roleResult : _personalResult;
|
||||||
return Task.FromResult(new Dictionary<string, int>(source, StringComparer.OrdinalIgnoreCase));
|
return Task.FromResult(new cF4sdTicketOverviewCountsResult
|
||||||
|
{
|
||||||
|
Counts = new Dictionary<string, int>(source.Counts, StringComparer.OrdinalIgnoreCase),
|
||||||
|
Capabilities = source.Capabilities == null
|
||||||
|
? null
|
||||||
|
: new cF4sdTicketOverviewCapabilities
|
||||||
|
{
|
||||||
|
TicketAndServiceRequestsEnabled = source.Capabilities.TicketAndServiceRequestsEnabled
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterGeneratedTicket(FasdCockpitCommunicationDemo.DemoTicketRecord record)
|
public void RegisterGeneratedTicket(FasdCockpitCommunicationDemo.DemoTicketRecord record)
|
||||||
@@ -225,13 +231,22 @@ public class TicketOverviewUpdateServiceTest
|
|||||||
|
|
||||||
if (scope == TileScope.Role)
|
if (scope == TileScope.Role)
|
||||||
{
|
{
|
||||||
_roleCounts = copy;
|
_roleResult.Counts = copy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_personalCounts = copy;
|
_personalResult.Counts = copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetCapability(TileScope scope, bool enabled)
|
||||||
|
{
|
||||||
|
var result = scope == TileScope.Role ? _roleResult : _personalResult;
|
||||||
|
result.Capabilities = new cF4sdTicketOverviewCapabilities
|
||||||
|
{
|
||||||
|
TicketAndServiceRequestsEnabled = enabled
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class FakeDispatcher : ITicketOverviewDispatcher
|
private sealed class FakeDispatcher : ITicketOverviewDispatcher
|
||||||
|
|||||||
@@ -163,6 +163,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Models\RemoteDesktopConnection\IRemoteDesktopClientInfo.cs" />
|
<Compile Include="Models\RemoteDesktopConnection\IRemoteDesktopClientInfo.cs" />
|
||||||
<Compile Include="Models\RemoteDesktopConnection\RemoteDesktopConnectionStatusResult.cs" />
|
<Compile Include="Models\RemoteDesktopConnection\RemoteDesktopConnectionStatusResult.cs" />
|
||||||
|
<Compile Include="Models\TicketOverview\TicketOverviewCountsResult.cs" />
|
||||||
<Compile Include="RemoteDesktopCommunicationBase.cs" />
|
<Compile Include="RemoteDesktopCommunicationBase.cs" />
|
||||||
<Compile Include="ExternalToolExecutor.cs" />
|
<Compile Include="ExternalToolExecutor.cs" />
|
||||||
<Compile Include="F4sdCockpitCommunicationM42Base.cs" />
|
<Compile Include="F4sdCockpitCommunicationM42Base.cs" />
|
||||||
@@ -183,4 +184,4 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
#region Ticketübersicht
|
#region Ticketübersicht
|
||||||
|
|
||||||
public abstract Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count);
|
public abstract Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count);
|
||||||
public abstract Task<Dictionary<string, int>> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope);
|
public abstract Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace C4IT.FASD.Cockpit.Communication
|
||||||
|
{
|
||||||
|
public sealed class cF4sdTicketOverviewCountsResult
|
||||||
|
{
|
||||||
|
public Dictionary<string, int> Counts { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
public cF4sdTicketOverviewCapabilities Capabilities { get; set; } = new cF4sdTicketOverviewCapabilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class cF4sdTicketOverviewCapabilities
|
||||||
|
{
|
||||||
|
public bool TicketAndServiceRequestsEnabled { get; set; } = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1147,7 +1147,7 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
|
|
||||||
#region Ticketübersicht
|
#region Ticketübersicht
|
||||||
|
|
||||||
public override async Task<Dictionary<string, int>> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope)
|
public override async Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope)
|
||||||
{
|
{
|
||||||
var CM = MethodBase.GetCurrentMethod();
|
var CM = MethodBase.GetCurrentMethod();
|
||||||
LogMethodBegin(CM);
|
LogMethodBegin(CM);
|
||||||
@@ -1182,13 +1182,13 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
await CheckConnectionStatus.Invoke();
|
await CheckConnectionStatus.Invoke();
|
||||||
|
|
||||||
LogEntry($"Error on requesting ticket overview counts ({scope}). Status: {result.Status}", LogLevels.Warning);
|
LogEntry($"Error on requesting ticket overview counts ({scope}). Status: {result.Status}", LogLevels.Warning);
|
||||||
return new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
return new cF4sdTicketOverviewCountsResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debug_apiValues) SaveApiResultValueJson("TicketOverview.GetCounts", result.Result, url);
|
if (Debug_apiValues) SaveApiResultValueJson("TicketOverview.GetCounts", result.Result, url);
|
||||||
|
|
||||||
var response = JsonConvert.DeserializeObject<TicketOverviewCountsResponse>(result.Result);
|
var response = JsonConvert.DeserializeObject<TicketOverviewCountsResponse>(result.Result);
|
||||||
return response?.ToDictionary(normalizedKeys) ?? new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
return response?.ToResult(normalizedKeys) ?? new cF4sdTicketOverviewCountsResult();
|
||||||
}
|
}
|
||||||
catch (Exception E)
|
catch (Exception E)
|
||||||
{
|
{
|
||||||
@@ -1204,7 +1204,7 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
LogMethodEnd(CM);
|
LogMethodEnd(CM);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
return new cF4sdTicketOverviewCountsResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count)
|
public override async Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using C4IT.FASD.Cockpit.Communication;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace FasdCockpitCommunication.TicketOverview
|
namespace FasdCockpitCommunication.TicketOverview
|
||||||
@@ -10,7 +11,10 @@ namespace FasdCockpitCommunication.TicketOverview
|
|||||||
[JsonProperty("counts")]
|
[JsonProperty("counts")]
|
||||||
public Dictionary<string, int> Counts { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
public Dictionary<string, int> Counts { get; set; } = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public Dictionary<string, int> ToDictionary(IEnumerable<string> expectedKeys)
|
[JsonProperty("capabilities")]
|
||||||
|
public TicketOverviewCapabilitiesResponse Capabilities { get; set; } = new TicketOverviewCapabilitiesResponse();
|
||||||
|
|
||||||
|
public cF4sdTicketOverviewCountsResult ToResult(IEnumerable<string> expectedKeys)
|
||||||
{
|
{
|
||||||
var comparer = StringComparer.OrdinalIgnoreCase;
|
var comparer = StringComparer.OrdinalIgnoreCase;
|
||||||
var output = new Dictionary<string, int>(comparer);
|
var output = new Dictionary<string, int>(comparer);
|
||||||
@@ -28,7 +32,7 @@ namespace FasdCockpitCommunication.TicketOverview
|
|||||||
output[key] = 0;
|
output[key] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return CreateResult(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Counts != null)
|
if (Counts != null)
|
||||||
@@ -42,7 +46,25 @@ namespace FasdCockpitCommunication.TicketOverview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return CreateResult(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
private cF4sdTicketOverviewCountsResult CreateResult(Dictionary<string, int> counts)
|
||||||
|
{
|
||||||
|
return new cF4sdTicketOverviewCountsResult
|
||||||
|
{
|
||||||
|
Counts = counts,
|
||||||
|
Capabilities = new cF4sdTicketOverviewCapabilities
|
||||||
|
{
|
||||||
|
TicketAndServiceRequestsEnabled = Capabilities?.TicketAndServiceRequestsEnabled ?? true
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal sealed class TicketOverviewCapabilitiesResponse
|
||||||
|
{
|
||||||
|
[JsonProperty("ticketAndServiceRequestsEnabled")]
|
||||||
|
public bool TicketAndServiceRequestsEnabled { get; set; } = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Dictionary<string, int>> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope)
|
public override Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(IEnumerable<string> keys, bool useRoleScope)
|
||||||
{
|
{
|
||||||
var scopeKey = useRoleScope ? "Role" : "Personal";
|
var scopeKey = useRoleScope ? "Role" : "Personal";
|
||||||
var comparer = StringComparer.OrdinalIgnoreCase;
|
var comparer = StringComparer.OrdinalIgnoreCase;
|
||||||
@@ -286,12 +286,6 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
if (string.IsNullOrWhiteSpace(key))
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (string.Equals(key, "TicketAndServiceRequestsEnabled", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
result[key] = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TicketOverviewRelations.TryGetValue(key, out var scopeDictionary) &&
|
if (TicketOverviewRelations.TryGetValue(key, out var scopeDictionary) &&
|
||||||
scopeDictionary != null &&
|
scopeDictionary != null &&
|
||||||
scopeDictionary.TryGetValue(scopeKey, out var definitions) &&
|
scopeDictionary.TryGetValue(scopeKey, out var definitions) &&
|
||||||
@@ -305,7 +299,10 @@ namespace C4IT.FASD.Cockpit.Communication
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(result);
|
return Task.FromResult(new cF4sdTicketOverviewCountsResult
|
||||||
|
{
|
||||||
|
Counts = result
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count)
|
public override async Task<List<cF4sdApiSearchResultRelation>> GetTicketOverviewRelations(string key, bool useRoleScope, int count)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace FasdDesktopUi.Basics.Services.Models
|
|||||||
{
|
{
|
||||||
bool IsDemo();
|
bool IsDemo();
|
||||||
|
|
||||||
Task<Dictionary<string, int>> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope);
|
Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope);
|
||||||
|
|
||||||
#if isDemo
|
#if isDemo
|
||||||
void RegisterGeneratedTicket(DemoTicketRecord record);
|
void RegisterGeneratedTicket(DemoTicketRecord record);
|
||||||
@@ -47,12 +47,15 @@ namespace FasdDesktopUi.Basics.Services.Models
|
|||||||
return _communication.IsDemo();
|
return _communication.IsDemo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope)
|
public async Task<cF4sdTicketOverviewCountsResult> GetTicketOverviewCounts(string[] overviewKeys, bool useRoleScope)
|
||||||
{
|
{
|
||||||
var rawCounts = await _communication.GetTicketOverviewCounts(overviewKeys, useRoleScope).ConfigureAwait(false);
|
var result = await _communication.GetTicketOverviewCounts(overviewKeys, useRoleScope).ConfigureAwait(false)
|
||||||
return rawCounts == null
|
?? new cF4sdTicketOverviewCountsResult();
|
||||||
|
result.Counts = result.Counts == null
|
||||||
? new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
? new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
|
||||||
: new Dictionary<string, int>(rawCounts, StringComparer.OrdinalIgnoreCase);
|
: new Dictionary<string, int>(result.Counts, StringComparer.OrdinalIgnoreCase);
|
||||||
|
result.Capabilities = result.Capabilities ?? new cF4sdTicketOverviewCapabilities();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if isDemo
|
#if isDemo
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace FasdDesktopUi.Basics.Services
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
private const string TicketAndServiceRequestsEnabledKey = "TicketAndServiceRequestsEnabled";
|
|
||||||
private const bool TicketAndServiceRequestsEnabledDefault = true;
|
private const bool TicketAndServiceRequestsEnabledDefault = true;
|
||||||
private readonly ITicketOverviewCommunicationSource _communicationSource;
|
private readonly ITicketOverviewCommunicationSource _communicationSource;
|
||||||
private static readonly string[] OverviewKeys = new[]
|
private static readonly string[] OverviewKeys = new[]
|
||||||
@@ -339,12 +338,11 @@ namespace FasdDesktopUi.Basics.Services
|
|||||||
|
|
||||||
_isDemo = communication.IsDemo();
|
_isDemo = communication.IsDemo();
|
||||||
|
|
||||||
var requestedKeys = scope == TileScope.Personal
|
var result = await communication.GetTicketOverviewCounts(OverviewKeys, scope == TileScope.Role).ConfigureAwait(false);
|
||||||
? OverviewKeys.Concat(new[] { TicketAndServiceRequestsEnabledKey }).ToArray()
|
var rawCounts = result?.Counts;
|
||||||
: OverviewKeys;
|
|
||||||
var rawCounts = await communication.GetTicketOverviewCounts(requestedKeys, scope == TileScope.Role).ConfigureAwait(false);
|
|
||||||
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
var counts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||||
var ticketAndServiceRequestsEnabled = TicketAndServiceRequestsEnabledDefault;
|
var ticketAndServiceRequestsEnabled =
|
||||||
|
result?.Capabilities?.TicketAndServiceRequestsEnabled ?? TicketAndServiceRequestsEnabledDefault;
|
||||||
|
|
||||||
if (rawCounts != null)
|
if (rawCounts != null)
|
||||||
{
|
{
|
||||||
@@ -353,13 +351,6 @@ namespace FasdDesktopUi.Basics.Services
|
|||||||
if (string.IsNullOrWhiteSpace(kvp.Key))
|
if (string.IsNullOrWhiteSpace(kvp.Key))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (string.Equals(kvp.Key, TicketAndServiceRequestsEnabledKey, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
if (scope == TileScope.Personal)
|
|
||||||
ticketAndServiceRequestsEnabled = _isDemo || kvp.Value > 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
counts[kvp.Key] = Math.Max(0, kvp.Value);
|
counts[kvp.Key] = Math.Max(0, kvp.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user