Skip to content

Commit

Permalink
CON-1187-remove legal entity id
Browse files Browse the repository at this point in the history
  • Loading branch information
shomavg committed Aug 25, 2020
1 parent 0a46196 commit 021744e
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class CloneVacancyOrchestratorTestBase
internal Vacancy SourceVacancy => new Vacancy
{
Id = SourceVacancyId,
LegalEntityId = 1,
AccountLegalEntityPublicHashedId = "1",
EmployerAccountId = EmployerAccountId,
Status = VacancyStatus.Live,
StartDate = SourceStartDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task GivenRequest_WhenNoMatchingVacanciesToTransfer_AndProviderHasM
await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, Guid.NewGuid(), string.Empty, string.Empty, TransferReason.EmployerRevokedPermission);

_mockRecruitQueueService.Verify(x => x.AddMessageAsync(It.IsAny<TransferVacancyToLegalEntityQueueMessage>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
}

[Fact]
Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task GivenRequest_WhenMatchingVacanciesToTransfer_AndProviderHasSin
_mockQueryStoreReader.Setup(q => q.GetProviderEmployerVacancyDataAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(employerInfo);

_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(Ukprn, EmployerAccountId))
_mockVacancyQuery.Setup(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(Ukprn, EmployerAccountId))
.ReturnsAsync(new Fixture().CreateMany<Vacancy>(NoOfVacanciesWithoutLegalEntity));

await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);
Expand Down Expand Up @@ -137,7 +137,7 @@ public async Task GivenRequest_WhenMatchingVacanciesToTransfer_AndProviderHasMan

await _sut.Run(Ukprn, EmployerAccountId, AccountLegalEntityPublicHashedId, userRef, UserEmail, UserName, TransferReason.EmployerRevokedPermission);

_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockVacancyQuery.Verify(x => x.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(It.IsAny<long>(), It.IsAny<string>()), Times.Never);
_mockRecruitQueueService.Verify(x => x.AddMessageAsync(It.IsAny<TransferVacancyToLegalEntityQueueMessage>()), Times.Exactly(NoOfMatchingVacancies));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private async Task<IEnumerable<Vacancy>> GetProviderOwnerVacanciesWithoutLegalEn

//We should only transfer vacancies without a legalEntityId when the provider cannot choose another legal entity
if (remainingLegalEntitiesCount == 0)
return await _vacanciesQuery.GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(ukprn, employerAccountId);
return await _vacanciesQuery.GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(ukprn, employerAccountId);

return Enumerable.Empty<Vacancy>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ private async Task PerformVacancyALEIdMigration(DataMigrationQueueMessage messag
return;
}

if (vacancy.LegalEntityId == 0)
if (vacancy.AccountLegalEntityPublicHashedId == "0")
{
_logger.LogWarning($"{message.SerialNumber}: Missing legalEntity - Bypassing vacancy {vacancyId}");
_logger.LogWarning($"{message.SerialNumber}: Missing AccountLegalEntityPublicHashedId - Bypassing vacancy {vacancyId}");
return;
}

Expand All @@ -78,7 +78,7 @@ private async Task PerformVacancyALEIdMigration(DataMigrationQueueMessage messag
var legalEntities = await retryPolicy.ExecuteAsync(context =>
_employerAccountProvider.GetLegalEntitiesConnectedToAccountAsync(vacancy.EmployerAccountId),
new Dictionary<string, object>() {{ "apiCall", "employer details" }});
selectedLegalEntity = legalEntities.FirstOrDefault(l => l.LegalEntityId == vacancy.LegalEntityId);
selectedLegalEntity = legalEntities.FirstOrDefault(l => l.AccountLegalEntityPublicHashedId == vacancy.AccountLegalEntityPublicHashedId);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class CloneVacancyOrchestratorTestBase
internal Vacancy SourceVacancy => new Vacancy
{
Id = SourceVacancyId,
LegalEntityId = 1,
AccountLegalEntityPublicHashedId = "1",
TrainingProvider = TrainingProvider,
Status = VacancyStatus.Live,
StartDate = SourceStartDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public async Task SubmitVacancyAsync_ShouldNotSubmitWhenMissingAgreements(
vacancy.IsDeleted = false;
vacancy.EmployerAccountId = employerAccountId;
vacancy.AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId;
vacancy.LegalEntityId = legalEntityId;
vacancy.OwnerType = OwnerType.Provider;

var client = new Mock<IProviderVacancyClient>();
Expand Down
2 changes: 1 addition & 1 deletion src/QA/QA.Web/Mappings/ReviewMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task<ReviewViewModel> Map(VacancyReview review)
var reviewSummaryTask = _reviewSummaryService.GetReviewSummaryViewModelAsync(review.Id,
ReviewFieldMappingLookups.GetPreviewReviewFieldIndicators());

var anonymousApprovedCountTask = vacancy.IsAnonymous ? _vacancyClient.GetAnonymousApprovedCountAsync(vacancy.LegalEntityId) : Task.FromResult(0);
var anonymousApprovedCountTask = vacancy.IsAnonymous ? _vacancyClient.GetAnonymousApprovedCountAsync(vacancy.AccountLegalEntityPublicHashedId) : Task.FromResult(0);

await Task.WhenAll(
currentVacancy,programmeTask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal static IRuleBuilderInitial<Vacancy, Vacancy> TrainingProviderVacancyMus
if (vacancy.OwnerType != OwnerType.Provider)
return;

var hasPermission = await providerRelationshipService.HasProviderGotEmployersPermissionAsync(vacancy.TrainingProvider.Ukprn.Value, vacancy.EmployerAccountId, vacancy.LegalEntityId);
var hasPermission = await providerRelationshipService.HasProviderGotEmployersPermissionAsync(vacancy.TrainingProvider.Ukprn.Value, vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId);

if (hasPermission)
return;
Expand Down
15 changes: 0 additions & 15 deletions src/Shared/Recruit.Vacancies.Client/Domain/Entities/Vacancy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@ public class Vacancy
public string EmployerAccountId { get; set; }
public long? VacancyReference { get; set; }
public VacancyStatus Status { get; set; }

public OwnerType OwnerType { get; set; }
public SourceOrigin SourceOrigin { get; set; }
public SourceType SourceType { get; set; }
public long? SourceVacancyReference { get; set; }

public DateTime? ClosedDate { get; set; }
public VacancyUser ClosedByUser { get; set; }

public DateTime? CreatedDate { get; set; }
public VacancyUser CreatedByUser { get; set; }

public DateTime? SubmittedDate { get; set; }
public VacancyUser SubmittedByUser { get; set; }

public DateTime? ApprovedDate { get; set; }

public DateTime? LiveDate { get; set; }

public DateTime? LastUpdatedDate { get; set; }
public VacancyUser LastUpdatedByUser { get; set; }

public bool IsDeleted { get; set; }
public DateTime? DeletedDate { get; set; }
public VacancyUser DeletedByUser { get; set; }

public string AnonymousReason { get; set; }
public string ApplicationInstructions { get; set; }
public ApplicationMethod? ApplicationMethod { get; set; }
Expand All @@ -50,7 +42,6 @@ public class Vacancy
public string LegalEntityName { get; set; }
public string EmployerWebsiteUrl { get; set; }
public GeoCodeMethod? GeoCodeMethod { get; set; }
public long LegalEntityId { get; set; }
public string AccountLegalEntityPublicHashedId { get; set; }
public int? NumberOfPositions { get; set; }
public string OutcomeDescription { get; set; }
Expand All @@ -68,27 +59,21 @@ public class Vacancy
public ClosureReason? ClosureReason { get; set; }
public string ClosureExplanation { get; set; }
public TransferInfo TransferInfo { get; set; }

public bool CanClose => Status == VacancyStatus.Live;

public bool CanClone => Status ==
VacancyStatus.Live || Status == VacancyStatus.Closed || Status == VacancyStatus.Submitted;


/// <summary>
/// We can only delete draft vacancies that have not been deleted
/// </summary>
public bool CanDelete => (Status == VacancyStatus.Draft ||
Status == VacancyStatus.Referred)
&& IsDeleted == false;

/// <summary>
/// We can only edit draft & referred vacancies that have not been deleted
/// </summary>
public bool CanEdit => (Status == VacancyStatus.Draft ||
Status == VacancyStatus.Referred )
&& IsDeleted == false;

/// <summary>
/// The vacancy is being edited
/// We can only submit draft & referred vacancies that have not been deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IVacancyQuery
Task<IEnumerable<Guid>> GetAllVacancyIdsAsync();
Task<IEnumerable<ProviderVacancySummary>> GetVacanciesAssociatedToProvider(long ukprn);
Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForLegalEntityAsync(long ukprn, string accountLegalEntityPublicHashedId);
Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(long ukprn, string employerAccountId);
Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(long ukprn, string employerAccountId);
Task<IEnumerable<T>> GetDraftVacanciesCreatedBeforeAsync<T>(DateTime staleDate);
Task<IEnumerable<T>> GetReferredVacanciesSubmittedBeforeAsync<T>(DateTime staleDate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface IVacancyReviewQuery
Task<int> GetApprovedFirstTimeCountAsync(string submittedByUserId);
Task<List<VacancyReview>> GetAssignedForUserAsync(string userId, DateTime assignationExpiryDateTime);
Task<VacancyReview> GetCurrentReferredVacancyReviewAsync(long vacancyReference);
Task<int> GetAnonymousApprovedCountAsync(long legalEntityId);
Task<int> GetAnonymousApprovedCountAsync(string accountLegalEntityPublicHashedId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IQaVacancyClient
Task UnassignVacancyReviewAsync(Guid reviewId);
Task<VacancyReview> GetCurrentReferredVacancyReviewAsync(long vacancyReference);
Task<List<VacancyReview>> GetVacancyReviewHistoryAsync(long vacancyReference);
Task<int> GetAnonymousApprovedCountAsync(long legalEntityId);
Task<int> GetAnonymousApprovedCountAsync(string accountLegalEntityPublicHashedId);
Task<Guid> CreateApplicationsReportAsync(DateTime fromDate, DateTime toDate, VacancyUser user, string reportName);
Task<List<ReportSummary>> GetReportsAsync();
Task<Report> GetReportAsync(Guid reportId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public async Task<List<VacancyReview>> GetVacancyReviewHistoryAsync(long vacancy
.ToList();
}

public Task<int> GetAnonymousApprovedCountAsync(long legalEntityId)
public Task<int> GetAnonymousApprovedCountAsync(string accountLegalEntityPublicHashedId)
{
return _vacancyReviewQuery.GetAnonymousApprovedCountAsync(legalEntityId);
return _vacancyReviewQuery.GetAnonymousApprovedCountAsync(accountLegalEntityPublicHashedId);
}

public async Task<Guid> CreateApplicationsReportAsync(DateTime fromDate, DateTime toDate, VacancyUser user, string reportName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,22 @@ public async Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForLegalEntityA
return result;
}

public async Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync(long ukprn, string employerAccountId)
public async Task<IEnumerable<Vacancy>> GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync(long ukprn, string employerAccountId)
{
var builder = Builders<Vacancy>.Filter;
var filter = builder.Eq(v => v.IsDeleted, false) &
builder.Eq(v => v.OwnerType, OwnerType.Provider) &
builder.Eq(v => v.TrainingProvider.Ukprn, ukprn) &
builder.Eq(v => v.EmployerAccountId, employerAccountId) &
builder.Eq(v => v.LegalEntityId, 0);
builder.Eq(v => v.AccountLegalEntityPublicHashedId, "0");

var collection = GetCollection<Vacancy>();

var result = await RetryPolicy.ExecuteAsync(_ =>
collection.Aggregate()
.Match(filter)
.ToListAsync(),
new Context(nameof(GetProviderOwnedVacanciesForEmployerWithoutLegalEntityAsync)));
new Context(nameof(GetProviderOwnedVacanciesForEmployerWithoutAccountLegalEntityPublicHashedIdAsync)));

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public async Task<VacancyReview> GetCurrentReferredVacancyReviewAsync(long vacan
return vacancyReview;
}

public async Task<int> GetAnonymousApprovedCountAsync(long legalEntityId)
public async Task<int> GetAnonymousApprovedCountAsync(string accountLegalEntityPublicHashedId)
{
var filterBuilder = Builders<VacancyReview>.Filter;
var filter = filterBuilder.Eq(r => r.VacancySnapshot.LegalEntityId, legalEntityId) &
var filter = filterBuilder.Eq(r => r.VacancySnapshot.AccountLegalEntityPublicHashedId, accountLegalEntityPublicHashedId) &
filterBuilder.Eq(r => r.VacancySnapshot.EmployerNameOption, EmployerNameOption.Anonymous) &
filterBuilder.Eq(r => r.Status, ReviewStatus.Closed) &
filterBuilder.Eq(r => r.ManualOutcome, ManualQaOutcome.Approved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Esfa.Recruit.Vacancies.Client.Infrastructure.Services.ProviderRelation
public interface IProviderRelationshipsService
{
Task<IEnumerable<EmployerInfo>> GetLegalEntitiesForProviderAsync(long ukprn);
Task<bool> HasProviderGotEmployersPermissionAsync(long ukprn, string accountPublicHashedId, long legalEntityId);
Task<bool> HasProviderGotEmployersPermissionAsync(long ukprn, string accountPublicHashedId, string accountLegalEntityPublicHashedId);
Task RevokeProviderPermissionToRecruitAsync(long ukprn, string accountLegalEntityPublicHashedId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<IEnumerable<EmployerInfo>> GetLegalEntitiesForProviderAsync(lo
return await GetEmployerInfosAsync(providerPermissions);
}

public async Task<bool> HasProviderGotEmployersPermissionAsync(long ukprn, string accountHashedId, long legalEntityId)
public async Task<bool> HasProviderGotEmployersPermissionAsync(long ukprn, string accountHashedId, string accountLegalEntityPublicHashedId)
{
var accountDetails = await _accountApiClient.GetAccount(accountHashedId);
var permittedLegalEntities = await GetProviderPermissionsforEmployer(ukprn, accountDetails.PublicHashedAccountId);
Expand All @@ -56,7 +56,7 @@ public async Task<bool> HasProviderGotEmployersPermissionAsync(long ukprn, strin
ple => ple.AccountLegalEntityPublicHashedId,
ale => ale.AccountLegalEntityPublicHashedId,
(ple, ale) => ale)
.Any(l => l.LegalEntityId == legalEntityId);
.Any(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId);

return hasPermission;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private static void AssertKnownProperties(Vacancy original, Vacancy clone)
{nameof(Vacancy.LegalEntityName), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.EmployerWebsiteUrl), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.GeoCodeMethod), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.LegalEntityId), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.NumberOfPositions), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.OutcomeDescription), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
{nameof(Vacancy.ProviderContact), (o, c, s) => AssertProperty(o, c, s, CloneAssertType.Cloned)},
Expand Down
Loading

0 comments on commit 021744e

Please sign in to comment.