Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/vih 4200 create conference from booking #1

Merged
merged 16 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace BookingQueueSubscriber.Common.ApiHelper
{
public static class ApiRequestHelper
{
public static string SerialiseRequestToSnakeCaseJson(object request)
{
DefaultContractResolver contractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};

return JsonConvert.SerializeObject(request, new JsonSerializerSettings
{
ContractResolver = contractResolver,
Formatting = Formatting.Indented
});
}

public static T DeserialiseSnakeCaseJsonToResponse<T>(string response)
{
var contractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};

return JsonConvert.DeserializeObject<T>(response, new JsonSerializerSettings
{
ContractResolver = contractResolver,
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Objects
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace BookingQueueSubscriber.Common.ApiHelper
{
public class ApiUriFactory
{
public ParticipantsEndpoints ParticipantsEndpoints { get; }
public ConferenceEndpoints ConferenceEndpoints { get; }

public ApiUriFactory()
{
ParticipantsEndpoints = new ParticipantsEndpoints();
ConferenceEndpoints = new ConferenceEndpoints();
}
}

public class ParticipantsEndpoints
{
private string ApiRoot => "conferences";

public string AddParticipantsToConference(Guid conferenceId) => $"{ApiRoot}/{conferenceId}/participants";

public string RemoveParticipantFromConference(Guid conferenceId, Guid participantId) =>
$"{ApiRoot}/{conferenceId}/participants/{participantId}";
}

public class ConferenceEndpoints
{
private string ApiRoot => "conferences";
public string BookNewConference => $"{ApiRoot}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.13.0.8313" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BookingQueueSubscriber.Common.Configuration
{
public class AzureAdConfiguration
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Authority { get; set; }
public string TenantId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace BookingQueueSubscriber.Common.Configuration
{
public class ConfigLoader
{
public readonly IConfigurationRoot ConfigRoot;

public ConfigLoader()
{
var configRootBuilder = new ConfigurationBuilder()
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
ConfigRoot = configRootBuilder.Build();
}

public IOptions<AzureAdConfiguration> ReadAzureAdSettings()
{
return Options.Create(ConfigRoot.GetSection("AzureAd").Get<AzureAdConfiguration>());
}

public IOptions<HearingServicesConfiguration> ReadHearingServiceSettings()
{
return Options.Create(ConfigRoot.GetSection("VhServices").Get<HearingServicesConfiguration>());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BookingQueueSubscriber.Common.Configuration
{
public class HearingServicesConfiguration
{
public string VideoApiUrl { get; set; }
public string VideoApiResourceId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using BookingQueueSubscriber.Common.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

namespace BookingQueueSubscriber.Common.Security
{
public interface IAzureTokenProvider
{
string GetClientAccessToken(string clientId, string clientSecret, string clientResource);
AuthenticationResult GetAuthorisationResult(string clientId, string clientSecret, string clientResource);
}

public class AzureAzureTokenProvider : IAzureTokenProvider
{
private readonly AzureAdConfiguration _azureAdConfiguration;

public AzureAzureTokenProvider(IOptions<AzureAdConfiguration> azureAdConfiguration)
{
_azureAdConfiguration = azureAdConfiguration.Value;
}

public string GetClientAccessToken(string clientId, string clientSecret, string clientResource)
{
var result = GetAuthorisationResult(clientId, clientSecret, clientResource);
return result.AccessToken;
}

public AuthenticationResult GetAuthorisationResult(string clientId, string clientSecret, string clientResource)
{
AuthenticationResult result;
var credential = new ClientCredential(clientId, clientSecret);
var authContext =
new AuthenticationContext($"{_azureAdConfiguration.Authority}{_azureAdConfiguration.TenantId}");

try
{
result = authContext.AcquireTokenAsync(clientResource, credential).Result;
}
catch (AdalException)
{
throw new UnauthorizedAccessException();
}

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BookingQueueSubscriber.Common\BookingQueueSubscriber.Common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using BookingQueueSubscriber.Services.MessageHandlers;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class HearingCancelledIntegrationEvent : IntegrationEvent
{
public Guid HearingId { get; set; }
public override IntegrationEventType EventType => IntegrationEventType.HearingCancelled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using BookingQueueSubscriber.Services.MessageHandlers;
using BookingQueueSubscriber.Services.MessageHandlers.Dtos;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class HearingDetailsUpdatedIntegrationEvent : IntegrationEvent
{
public HearingDto Hearing { get; set; }
public override IntegrationEventType EventType => IntegrationEventType.HearingDetailsUpdated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using BookingQueueSubscriber.Services.MessageHandlers;
using BookingQueueSubscriber.Services.MessageHandlers.Dtos;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class HearingIsReadyForVideoIntegrationEvent : IntegrationEvent
{
public HearingDto Hearing { get; set; }
public IList<ParticipantDto> Participants { get; set; }
public override IntegrationEventType EventType => IntegrationEventType.HearingIsReadyForVideo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using BookingQueueSubscriber.Services.MessageHandlers;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class IntegrationEvent
{
public virtual IntegrationEventType EventType { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using BookingQueueSubscriber.Services.MessageHandlers;
using BookingQueueSubscriber.Services.MessageHandlers.Dtos;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class ParticipantAddedIntegrationEvent: IntegrationEvent
{

public Guid HearingId { get; }
public ParticipantDto Participant { get; }
public override IntegrationEventType EventType => IntegrationEventType.ParticipantAdded;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using BookingQueueSubscriber.Services.MessageHandlers;

namespace BookingQueueSubscriber.Services.IntegrationEvents
{
public class ParticipantRemovedIntegrationEvent : IntegrationEvent
{
public ParticipantRemovedIntegrationEvent(Guid hearingId, Guid participantId)
{
HearingId = hearingId;
ParticipantId = participantId;
}

public Guid HearingId { get; }
public Guid ParticipantId { get; }

public override IntegrationEventType EventType => IntegrationEventType.ParticipantRemoved;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Linq;
using BookingQueueSubscriber.Services.MessageHandlers.Dtos;
using BookingQueueSubscriber.Services.VideoApi.Contracts;

namespace BookingQueueSubscriber.Services.Mappers
{
public class HearingToBookConferenceMapper
{
public BookNewConferenceRequest MapToBookNewConferenceRequest(HearingDto hearingDto, IEnumerable<ParticipantDto> participantDtos)
{
var participantMapper = new ParticipantToParticipantRequestMapper();
var participants = participantDtos.Select(participantMapper.MapToParticipantRequest).ToList();

var request = new BookNewConferenceRequest
{
CaseNumber = hearingDto.CaseNumber,
CaseName = hearingDto.CaseName,
CaseType = hearingDto.CaseType,
ScheduledDuration = hearingDto.ScheduledDuration,
ScheduledDateTime = hearingDto.ScheduledDateTime,
HearingRefId = hearingDto.HearingId,
Participants = participants
};
return request;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using BookingQueueSubscriber.Services.MessageHandlers.Dtos;
using BookingQueueSubscriber.Services.VideoApi.Contracts;

namespace BookingQueueSubscriber.Services.Mappers
{
public class ParticipantToParticipantRequestMapper
{
public ParticipantRequest MapToParticipantRequest(ParticipantDto participantDto)
{
var request = new ParticipantRequest
{
Name = participantDto.Fullname,
Username = participantDto.Username,
DisplayName = participantDto.DisplayName,
UserRole = Enum.Parse<UserRole>(participantDto.UserRole),
CaseTypeGroup = participantDto.CaseGroupType.ToString(),
ParticipantRefId = participantDto.ParticipantId
};

return request;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using BookingQueueSubscriber.Services.IntegrationEvents;

namespace BookingQueueSubscriber.Services.MessageHandlers
{
public class BookingsMessage
{
public Guid Id { get; set; }
public DateTime Timestamp { get; set; }
public IntegrationEvent IntegrationEvent { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using BookingQueueSubscriber.Services.IntegrationEvents;

namespace BookingQueueSubscriber.Services.MessageHandlers.Core
{
public interface IMessageHandler
{
IntegrationEventType IntegrationEventType { get; }
Type BodyType { get; }
Task HandleAsync(IntegrationEvent integrationEvent);
}

public abstract class MessageHandlerBase : IMessageHandler
{
protected IVideoApiService VideoApiService { get; }
public abstract IntegrationEventType IntegrationEventType { get; }
public abstract Type BodyType { get; }

public abstract Task HandleAsync(IntegrationEvent integrationEvent);

protected MessageHandlerBase(IVideoApiService videoApiService)
{
VideoApiService = videoApiService;
}
}
}
Loading