Skip to content
Merged

Dev #2228

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
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ jobs:
echo "$JFROG_PASSWORD" | docker login -u "$JFROG_USERNAME" --password-stdin $JFROG_SERVICE
- name: Push application images to Artifactory container registry
run: |
docker tag unity-grantmanager-dbmigrator $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker tag unity-grantmanager-web $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
docker tag unity-grantmanager-dbmigrator $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator:latest
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator:latest
docker tag unity-grantmanager-web $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web:latest
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web:latest
- name: Disconnect docker from JFrog Artifactory
run: |
docker logout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ jobs:
echo "$JFROG_PASSWORD" | docker login -u "$JFROG_USERNAME" --password-stdin $JFROG_SERVICE
- name: Push application images to Artifactory container registry
run: |
docker tag unity-grantmanager-dbmigrator $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker tag unity-grantmanager-web $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
docker tag unity-grantmanager-dbmigrator $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator:latest
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator:latest
docker tag unity-grantmanager-web $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web:latest
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web:latest
- name: Disconnect docker from JFrog Artifactory
run: |
docker logout
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-check-dev-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: actions/setup-dotnet@v4
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "9.0.x"

Expand All @@ -85,7 +85,7 @@ jobs:
--logger "trx;LogFileName=${NAME}.trx" \
--results-directory TestResults

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: test-output-${{ strategy.job-index }}
path: TestResults/
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
echo "failed=$FAILED" >> $GITHUB_OUTPUT
echo "skipped=$SKIPPED" >> $GITHUB_OUTPUT

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: merged-test-results
path: merged/
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-check-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: actions/setup-dotnet@v4
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "9.0.x"

Expand All @@ -81,7 +81,7 @@ jobs:
--logger "trx;LogFileName=${NAME}.trx" \
--results-directory TestResults

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: test-output-${{ strategy.job-index }}
path: TestResults/
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
echo "failed=$FAILED" >> $GITHUB_OUTPUT
echo "skipped=$SKIPPED" >> $GITHUB_OUTPUT

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: merged-test-results
path: merged/
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-check-test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
steps:
- uses: actions/checkout@v6

- uses: actions/setup-dotnet@v4
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "9.0.x"

Expand All @@ -83,7 +83,7 @@ jobs:
--logger "trx;LogFileName=${NAME}.trx" \
--results-directory TestResults

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: test-output-${{ strategy.job-index }}
path: TestResults/
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
echo "failed=$FAILED" >> $GITHUB_OUTPUT
echo "skipped=$SKIPPED" >> $GITHUB_OUTPUT

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v5
with:
name: merged-test-results
path: merged/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
Expand All @@ -12,17 +12,17 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Local;
namespace Unity.Payments.Handlers
{

namespace Unity.Payments.Handlers
{
public class UpsertSupplierHandler(ISupplierAppService supplierAppService,
SiteAppService siteAppService,
ILogger<UpsertSupplierHandler> logger,
ILocalEventBus localEventBus,
IApplicationRepository applicationRepository) : ILocalEventHandler<UpsertSupplierEto>, ITransientDependency
{

public async Task HandleEventAsync(UpsertSupplierEto eventData)
public async Task HandleEventAsync(UpsertSupplierEto eventData)
{
SupplierDto supplierDto = await GetSupplierFromEvent(eventData);
var existingSites = await siteAppService.GetSitesBySupplierIdAsync(supplierDto.Id);
Expand All @@ -35,34 +35,40 @@ public async Task HandleEventAsync(UpsertSupplierEto eventData)
await localEventBus.PublishAsync(
new ApplicantSupplierEto
{
SupplierId = supplierDto.Id,
ApplicantId = eventData.CorrelationId,
ExistingSitesDictionary = existingSitesDictionary,
SiteEtos = eventData.SiteEtos
}
);
}
SupplierId = supplierDto.Id,
ApplicantId = eventData.CorrelationId,
ExistingSitesDictionary = existingSitesDictionary,
SiteEtos = eventData.SiteEtos
}
);
}

private async Task<Dictionary<string, Site>> UpsertSitesFromEventDtoAsync(
Dictionary<string, Site> existingSitesDictionary,
Guid supplierId,
UpsertSupplierEto upsertSupplierEto,
PaymentGroup defaultPaymentGroup)
{
foreach (var siteEto in upsertSupplierEto.SiteEtos)
// Deduplicate incoming SiteEtos by SupplierSiteCode — CAS can return duplicate site codes
var uniqueSiteEtos = upsertSupplierEto.SiteEtos
.GroupBy(s => s.SupplierSiteCode)
.Select(g => g.First())
.ToList();

foreach (var siteEto in uniqueSiteEtos)
{
var siteDto = supplierAppService.GetSiteDtoFromSiteEto(siteEto, supplierId, defaultPaymentGroup);

if (existingSitesDictionary.TryGetValue(siteDto.Number, out var existingSite))
{
siteDto.Id = existingSite.Id;
await siteAppService.UpdateAsync(siteDto);
}
else
{
await siteAppService.InsertAsync(siteDto);
}
}
if (existingSitesDictionary.TryGetValue(siteDto.Number, out var existingSite))
{
siteDto.Id = existingSite.Id;
await siteAppService.UpdateAsync(siteDto);
}
else
{
await siteAppService.InsertAsync(siteDto);
}
}

return existingSitesDictionary;
}
Expand Down Expand Up @@ -107,57 +113,57 @@ private async Task<SupplierDto> GetSupplierFromEvent(UpsertSupplierEto eventData
{
var existing = await supplierAppService.GetBySupplierNumberAsync(eventData.Number);
logger.LogInformation("Upserting supplier from event data: {Existing}", existing);
// This is subject to some business rules and a domain implementation
if (existing != null)
{
existing.Number = eventData.Number;
UpdateSupplierDto updateSupplierDto = GetUpdateSupplierDtoFromEvent(eventData);
SupplierDto updatedSupplierDto = await supplierAppService.UpdateAsync(existing.Id, updateSupplierDto);
return updatedSupplierDto;
}
CreateSupplierDto createSupplierDto = GetCreateSupplierDtoFromEvent(eventData);
SupplierDto supplierDto = await supplierAppService.CreateAsync(createSupplierDto);
return supplierDto;
}
private static UpdateSupplierDto GetUpdateSupplierDtoFromEvent(UpsertSupplierEto eventData)
{
return new UpdateSupplierDto()
{
Name = eventData.Name,
Number = eventData.Number,
Subcategory = eventData.Subcategory,
ProviderId = eventData.ProviderId,
BusinessNumber = eventData.BusinessNumber,
Status = eventData.Status,
SupplierProtected = eventData.SupplierProtected,
StandardIndustryClassification = eventData.StandardIndustryClassification,
LastUpdatedInCAS = eventData.LastUpdatedInCAS,
CorrelationId = eventData.CorrelationId,
CorrelationProvider = eventData.CorrelationProvider,
};
}
private static CreateSupplierDto GetCreateSupplierDtoFromEvent(UpsertSupplierEto eventData)
{
return new CreateSupplierDto()
{
Name = eventData.Name,
Number = eventData.Number,
Subcategory = eventData.Subcategory,
ProviderId = eventData.ProviderId,
BusinessNumber = eventData.BusinessNumber,
Status = eventData.Status,
SupplierProtected = eventData.SupplierProtected,
StandardIndustryClassification = eventData.StandardIndustryClassification,
LastUpdatedInCAS = eventData.LastUpdatedInCAS,
CorrelationId = eventData.CorrelationId,
CorrelationProvider = eventData.CorrelationProvider,
};
}
}
}

// This is subject to some business rules and a domain implementation
if (existing != null)
{
existing.Number = eventData.Number;
UpdateSupplierDto updateSupplierDto = GetUpdateSupplierDtoFromEvent(eventData);
SupplierDto updatedSupplierDto = await supplierAppService.UpdateAsync(existing.Id, updateSupplierDto);
return updatedSupplierDto;
}

CreateSupplierDto createSupplierDto = GetCreateSupplierDtoFromEvent(eventData);
SupplierDto supplierDto = await supplierAppService.CreateAsync(createSupplierDto);

return supplierDto;
}


private static UpdateSupplierDto GetUpdateSupplierDtoFromEvent(UpsertSupplierEto eventData)
{
return new UpdateSupplierDto()
{
Name = eventData.Name,
Number = eventData.Number,
Subcategory = eventData.Subcategory,
ProviderId = eventData.ProviderId,
BusinessNumber = eventData.BusinessNumber,
Status = eventData.Status,
SupplierProtected = eventData.SupplierProtected,
StandardIndustryClassification = eventData.StandardIndustryClassification,
LastUpdatedInCAS = eventData.LastUpdatedInCAS,
CorrelationId = eventData.CorrelationId,
CorrelationProvider = eventData.CorrelationProvider,
};
}

private static CreateSupplierDto GetCreateSupplierDtoFromEvent(UpsertSupplierEto eventData)
{
return new CreateSupplierDto()
{
Name = eventData.Name,
Number = eventData.Number,
Subcategory = eventData.Subcategory,
ProviderId = eventData.ProviderId,
BusinessNumber = eventData.BusinessNumber,
Status = eventData.Status,
SupplierProtected = eventData.SupplierProtected,
StandardIndustryClassification = eventData.StandardIndustryClassification,
LastUpdatedInCAS = eventData.LastUpdatedInCAS,
CorrelationId = eventData.CorrelationId,
CorrelationProvider = eventData.CorrelationProvider,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public virtual async Task<Guid> InsertAsync(SiteDto siteDto)
{
try
{
// Guard against duplicates — if a site with the same Number already exists
// for this supplier, update it instead of creating a second row
var existing = (await siteRepository.GetBySupplierAsync(siteDto.SupplierId))
.Find(s => s.Number == siteDto.Number);

if (existing != null)
{
logger.LogWarning("Site with Number {Number} already exists for SupplierId {SupplierId}. Updating instead of inserting.", siteDto.Number, siteDto.SupplierId);
siteDto.Id = existing.Id;
return await UpdateAsync(siteDto);
}

Site site = new Site(siteDto);
await siteRepository.InsertAsync(site, true);
return site.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ $(function () {
return;
}

const $btn = $(this);
$btn.attr('disabled', 'disabled');

const applicantId = $('#PaymentInfo_ApplicantId').val();
const applicationId = $('#PaymentInfoViewApplicationId').val() || '';
$.ajax({
Expand All @@ -222,6 +225,9 @@ $(function () {
console.error('Error loading sites:', error);
abp.notify.error('Failed to refresh sites');
},
complete: function () {
$btn.removeAttr('disabled');
},
});
});
}
Expand Down
Loading
Loading