Skip to content

Commit

Permalink
establish training env (#683)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- Reorg Manager
- add training pipeline
  • Loading branch information
peggy-quartech authored Jan 16, 2024
1 parent 3a0a1a3 commit b9b81f7
Show file tree
Hide file tree
Showing 75 changed files with 534 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/Spd.Engine.Search/Contract.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Spd.Manager.Common.ManagerContract;
using Spd.Manager.Shared;

namespace Spd.Engine.Search
{
Expand Down
2 changes: 1 addition & 1 deletion src/Spd.Engine.Search/Spd.Engine.Search.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Spd.Manager.Common\Spd.Manager.Common.csproj" />
<ProjectReference Include="..\Spd.Manager.Shared\Spd.Manager.Shared.csproj" />
<ProjectReference Include="..\Spd.Resource.Applicants\Spd.Resource.Applicants.csproj" />
<ProjectReference Include="..\Spd.Resource.Organizations\Spd.Resource.Organizations.csproj" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Spd.Manager.Common/ServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Spd.Manager.Common.Admin;
using Spd.Manager.Common.Payment;
using Spd.Utilities.Hosting;

namespace Spd.Manager.Common
Expand All @@ -10,7 +9,6 @@ public class ServiceExtension : IConfigureComponentServices
public void ConfigureServices(ConfigurationServices configurationServices)
{
configurationServices.Services.AddTransient<IAdminManager, AdminManager>();
configurationServices.Services.AddTransient<IPaymentManager, PaymentManager>();
}
}
}
12 changes: 2 additions & 10 deletions src/Spd.Manager.Licence/PersonalLicenceAppContract.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using GenderCode = Spd.Manager.Common.ManagerContract.GenderCode;
using GenderCode = Spd.Manager.Shared.GenderCode;

namespace Spd.Manager.Licence;
public interface IPersonalLicenceAppManager
Expand Down Expand Up @@ -118,15 +118,7 @@ public record AdditionalGovIdDocument : Document;
public record IdPhotoDocument : Document;
public record ResidentialAddress : Address;
public record MailingAddress : Address;
public abstract record Address
{
public string? AddressLine1 { get; set; }
public string? AddressLine2 { get; set; }
public string? City { get; set; }
public string? Country { get; set; }
public string? PostalCode { get; set; }
public string? Province { get; set; }
}

public record Alias
{
public string? GivenName { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions src/Spd.Manager.Licence/SharedContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ public enum ApplicationPortalStatusCode
CancelledByApplicant,
CancelledByOrganization
}

public record Address
{
public string? AddressLine1 { get; set; }
public string? AddressLine2 { get; set; }
public string? City { get; set; }
public string? Country { get; set; }
public string? PostalCode { get; set; }
public string? Province { get; set; }
}
3 changes: 2 additions & 1 deletion src/Spd.Manager.Licence/Spd.Manager.Licence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Spd.Manager.Common\Spd.Manager.Common.csproj" />
<ProjectReference Include="..\Spd.Manager.Shared\Spd.Manager.Shared.csproj" />
<ProjectReference Include="..\Spd.Resource.Applicants\Spd.Resource.Applicants.csproj" />
<ProjectReference Include="..\Spd.Resource.Organizations\Spd.Resource.Organizations.csproj" />
<ProjectReference Include="..\Spd.Utilities.Cache\Spd.Utilities.Cache.csproj" />
<ProjectReference Include="..\Spd.Utilities.LogonUser\Spd.Utilities.LogonUser.csproj" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions src/Spd.Manager.Licence/UserProfileContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using MediatR;
using Spd.Manager.Shared;
using Spd.Utilities.LogonUser;

namespace Spd.Manager.Licence
{
public interface IUserProfileManager
{
public Task<OrgUserProfileResponse> Handle(GetCurrentUserProfileQuery request, CancellationToken ct);
public Task<ApplicantProfileResponse> Handle(GetApplicantProfileQuery request, CancellationToken ct);
public Task<ApplicantProfileResponse> Handle(ManageApplicantProfileCommand request, CancellationToken ct); //used for worker licensing portal
}

#region UserProfile
public record GetCurrentUserProfileQuery(PortalUserIdentity PortalUserIdentity) : IRequest<OrgUserProfileResponse>;

public class OrgUserProfileResponse
{
public Guid? UserGuid { get; set; }//from token
public string? UserDisplayName { get; set; } //from token
public IdentityProviderTypeCode? IdentityProviderType { get; set; }
public IEnumerable<UserInfo> UserInfos { get; set; } = Array.Empty<UserInfo>();
}

public record UserInfo
{
public Guid UserId { get; set; }//from spd, portal user id
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? Email { get; set; }
//public ContactAuthorizationTypeCode? ContactAuthorizationTypeCode { get; set; } = null;//from spd
public OrgSettings? OrgSettings { get; set; }
public Guid? OrgId { get; set; }
public Guid? OrgRegistrationId { get; set; } = null;
//public OrgRegistrationStatusCode? OrgRegistrationStatusCode { get; set; } = null;
public string? OrgRegistrationNumber { get; set; } = null;
public string? OrgName { get; set; }
public Guid? UserGuid { get; set; }
public UserInfoMsgTypeCode? UserInfoMsgType { get; set; }
}

public enum UserInfoMsgTypeCode
{
REGISTRATION_DENIED,
ACCOUNT_NOT_MATCH_RECORD,
NO_ACTIVE_ACCOUNT_FOR_ORG
}

public record OrgSettings
{
public PayerPreferenceTypeCode PayerPreference { get; set; }
public BooleanTypeCode ContractorsNeedVulnerableSectorScreening { get; set; }
public BooleanTypeCode LicenseesNeedVulnerableSectorScreening { get; set; }
public bool GenericUploadEnabled { get; set; }
}

public class PortalUserIdentity
{
public string? BCeIDUserName { get; set; }
public string? DisplayName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? PreferredUserName { get; set; }
public Guid? UserGuid { get; set; }
public Guid BizGuid { get; set; }
public string? BizName { get; set; }
public string? Issuer { get; set; }
public bool? EmailVerified { get; set; }
public string? Email { get; set; }
}
#endregion

#region ApplicantProfile
public record GetApplicantProfileQuery(string BcscSub) : IRequest<ApplicantProfileResponse>;
public class ApplicantProfileResponse
{
public Guid ApplicantId { get; set; } //which is contact id in db
public string? FirstName { get; set; } // which is contact firstname
public string? LastName { get; set; } // which is contact lastname
public string? Email { get; set; }
public GenderCode? Gender { get; set; }
public string Sub { get; set; } = null!;
public DateOnly BirthDate { get; set; }
public string? MiddleName1 { get; set; }
public string? MiddleName2 { get; set; }
public IdentityProviderTypeCode IdentityProviderTypeCode { get; set; } = IdentityProviderTypeCode.BcServicesCard;
public Address? ResidentialAddress { get; set; }
}
public record ManageApplicantProfileCommand(BcscIdentityInfo BcscIdentityInfo) : IRequest<ApplicantProfileResponse>;

#endregion


}
126 changes: 126 additions & 0 deletions src/Spd.Manager.Licence/UserProfileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using AutoMapper;
using MediatR;
using Microsoft.Extensions.Logging;
using Spd.Manager.Shared;
using Spd.Resource.Applicants.Application;
using Spd.Resource.Applicants.Contact;
using Spd.Resource.Applicants.PortalUser;
using Spd.Resource.Organizations.Identity;
using Spd.Resource.Organizations.Org;
using Spd.Resource.Organizations.Registration;
using Spd.Resource.Organizations.User;

namespace Spd.Manager.Licence
{
internal class UserProfileManager
: IRequestHandler<GetCurrentUserProfileQuery, OrgUserProfileResponse>,
IRequestHandler<GetApplicantProfileQuery, ApplicantProfileResponse>,
IRequestHandler<ManageApplicantProfileCommand, ApplicantProfileResponse>,
IUserProfileManager
{
private readonly IOrgUserRepository _orgUserRepository;
private readonly IIdentityRepository _idRepository;
private readonly IOrgRepository _orgRepository;
private readonly IPortalUserRepository _portalUserRepository;
private readonly IContactRepository _contactRepository;
private readonly IMapper _mapper;
private readonly ILogger<IUserProfileManager> _logger;

public UserProfileManager(
IOrgUserRepository orgUserRepository,
IIdentityRepository idRepository,
IOrgRepository orgRepository,
IPortalUserRepository portalUserRepository,
IContactRepository contactRepository,
IMapper mapper,
ILogger<IUserProfileManager> logger)
{
_orgUserRepository = orgUserRepository;
_idRepository = idRepository;
_orgRepository = orgRepository;
_mapper = mapper;
_logger = logger;
_portalUserRepository = portalUserRepository;
_contactRepository = contactRepository;
}

public async Task<OrgUserProfileResponse> Handle(GetCurrentUserProfileQuery request, CancellationToken ct)
{
Guid orgGuid = request.PortalUserIdentity.BizGuid;
Guid? userGuid = request.PortalUserIdentity.UserGuid;
List<UserInfo> userInfos = new();

//get all orgs
var orgResult = (OrgsQryResult)await _orgRepository.QueryOrgAsync(
new OrgsQry(orgGuid, ServiceTypes: IApplicationRepository.ScreeningServiceTypes),
ct);
foreach (OrgResult org in orgResult.OrgResults)
{
UserInfo ui = new UserInfo();
var orgUsers = (OrgUsersResult)await _orgUserRepository.QueryOrgUserAsync(new OrgUsersSearch(org.Id), ct);
var u = orgUsers.UserResults.FirstOrDefault(u => u.UserGuid == userGuid && u.IsActive);
if (u != null)
ui = _mapper.Map<UserInfo>(u);
else
ui = new UserInfo() { UserInfoMsgType = UserInfoMsgTypeCode.NO_ACTIVE_ACCOUNT_FOR_ORG };
ui.OrgName = org.OrganizationName;
ui.OrgId = org.Id;
ui.OrgSettings = _mapper.Map<OrgSettings>(org);
userInfos.Add(ui);
}

return new OrgUserProfileResponse()
{
IdentityProviderType = IdentityProviderTypeCode.BusinessBceId,
UserDisplayName = request.PortalUserIdentity.DisplayName,
UserGuid = request.PortalUserIdentity.UserGuid,
UserInfos = userInfos
};
}

public async Task<ApplicantProfileResponse> Handle(GetApplicantProfileQuery request, CancellationToken ct)
{
var result = await _idRepository.Query(new IdentityQry(request.BcscSub, null, IdentityProviderTypeEnum.BcServicesCard), ct);
return _mapper.Map<ApplicantProfileResponse>(result.Items.FirstOrDefault());
}

public async Task<ApplicantProfileResponse> Handle(ManageApplicantProfileCommand cmd, CancellationToken ct)
{
ContactResp contactResp = null;
var result = await _idRepository.Query(new IdentityQry(cmd.BcscIdentityInfo.Sub, null, IdentityProviderTypeEnum.BcServicesCard), ct);

if (result == null || !result.Items.Any()) //first time to use system
{
//add identity
var id = await _idRepository.Manage(new CreateIdentityCmd(cmd.BcscIdentityInfo.Sub, null, IdentityProviderTypeEnum.BcServicesCard), ct);
CreateContactCmd createContactCmd = _mapper.Map<CreateContactCmd>(cmd);
createContactCmd.IdentityId = id.Id;
contactResp = await _contactRepository.ManageAsync(createContactCmd, ct);
//add address
}
else
{
Identity id = result.Items.FirstOrDefault();
if (id.ContactId != null)
{
//depends on requirement, probably update later when user select "yes" in user profile for licensing portal.
UpdateContactCmd updateContactCmd = _mapper.Map<UpdateContactCmd>(cmd);
updateContactCmd.Id = (Guid)id.ContactId;
updateContactCmd.IdentityId = id.Id;
contactResp = await _contactRepository.ManageAsync(updateContactCmd, ct);
}
else
{
//there is identity, but no contact
CreateContactCmd createContactCmd = _mapper.Map<CreateContactCmd>(cmd);
createContactCmd.IdentityId = id.Id;
contactResp = await _contactRepository.ManageAsync(createContactCmd, ct);
}
//update address
}

return _mapper.Map<ApplicantProfileResponse>(contactResp);
}
}
}

61 changes: 61 additions & 0 deletions src/Spd.Manager.Licence/UserProfileMappings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using AutoMapper;
using Spd.Resource.Applicants.Contact;
using Spd.Resource.Organizations.Identity;
using Spd.Resource.Organizations.Org;
using Spd.Resource.Organizations.User;
using Spd.Utilities.Shared.ResourceContracts;

namespace Spd.Manager.Licence
{
internal class UserProfileMappings : Profile
{
public UserProfileMappings()
{
CreateMap<OrgResult, OrgSettings>();
CreateMap<UserResult, UserInfo>()
.ForMember(d => d.OrgName, opt => opt.Ignore())
.ForMember(d => d.OrgSettings, opt => opt.Ignore())
.ForMember(d => d.UserId, opt => opt.MapFrom(s => s.Id))
.ForMember(d => d.OrgRegistrationId, opt => opt.Ignore())
.ForMember(d => d.OrgId, opt => opt.MapFrom(s => s.OrganizationId));

CreateMap<Identity, ApplicantProfileResponse>()
.ForMember(d => d.ApplicantId, opt => opt.MapFrom(s => s.ContactId))
.ForMember(d => d.Email, opt => opt.MapFrom(s => s.EmailAddress))
;

CreateMap<ManageApplicantProfileCommand, CreateContactCmd>()
.ForMember(d => d.Sub, opt => opt.MapFrom(s => s.BcscIdentityInfo.Sub))
.IncludeBase<ManageApplicantProfileCommand, ContactCmd>();

CreateMap<ManageApplicantProfileCommand, UpdateContactCmd>()
.IncludeBase<ManageApplicantProfileCommand, ContactCmd>();

CreateMap<ManageApplicantProfileCommand, ContactCmd>()
.ForMember(d => d.FirstName, opt => opt.MapFrom(s => s.BcscIdentityInfo.FirstName))
.ForMember(d => d.LastName, opt => opt.MapFrom(s => s.BcscIdentityInfo.LastName))
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.BcscIdentityInfo.Email))
.ForMember(d => d.MiddleName1, opt => opt.MapFrom(s => s.BcscIdentityInfo.MiddleName1))
.ForMember(d => d.MiddleName2, opt => opt.MapFrom(s => s.BcscIdentityInfo.MiddleName2))
.ForMember(d => d.BirthDate, opt => opt.MapFrom(s => s.BcscIdentityInfo.BirthDate))
.ForMember(d => d.Gender, opt => opt.MapFrom(s => GetGenderEnum(s.BcscIdentityInfo.Gender)));

CreateMap<ContactResp, ApplicantProfileResponse>()
.ForMember(d => d.ApplicantId, opt => opt.MapFrom(s => s.Id));
}

public static GenderEnum? GetGenderEnum(string? bscsGender)
{
if (bscsGender == null) return null;
string? str = bscsGender?.ToLower();
GenderEnum? gender = str switch
{
"female" => GenderEnum.F,
"male" => GenderEnum.M,
"diverse" => GenderEnum.U,
_ => null,
};
return gender;
}
}
}
20 changes: 0 additions & 20 deletions src/Spd.Manager.Membership/ServiceExtensions.cs

This file was deleted.

Loading

0 comments on commit b9b81f7

Please sign in to comment.