Skip to content

Commit

Permalink
fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Jul 16, 2024
1 parent 5b1d7cb commit e3d24de
Show file tree
Hide file tree
Showing 19 changed files with 1,503 additions and 2,133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.Async;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Web;
using Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.BusinessLogic;
Expand Down Expand Up @@ -249,17 +250,19 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data,
throw new ControllerArgumentException("ExternalCertificateNumber must be alphanumeric and length should not be greater than 36");
}

if (data.Sites != null && data.Sites.Any() && data.Sites!.Any(bpn => !BpnsRegex.IsMatch(bpn)))
if (data.Sites != null && data.Sites.Any(bpn => !BpnsRegex.IsMatch(bpn)))
{
throw new ControllerArgumentException("BPN must contain exactly 16 characters and must be prefixed with BPNS");
}

if (data.ValidFrom?.ToUniversalTime() > DateTimeOffset.Now.ToUniversalTime())
var now = dateTimeProvider.OffsetNow;

if (data.ValidFrom > now)
{
throw new ControllerArgumentException("ValidFrom date should not be greater than current date");
}

if (data.ValidTill?.ToUniversalTime() < DateTimeOffset.Now.ToUniversalTime())
if (data.ValidTill < now)
{
throw new ControllerArgumentException("ValidTill date should be greater than current date");
}
Expand Down Expand Up @@ -300,19 +303,16 @@ private async Task HandleCompanyCertificateCreationAsync(CompanyCertificateTypeI
x.DocumentStatusId = DocumentStatusId.LOCKED;
});

var companyCertificate = companyCertificateRepository.CreateCompanyCertificate(_identityData.CompanyId, companyCertificateTypeId, doc.Id,
var companyCertificate = companyCertificateRepository.CreateCompanyCertificate(_identityData.CompanyId, companyCertificateTypeId, CompanyCertificateStatusId.ACTIVE, doc.Id,
x =>
{
x.ExternalCertificateNumber = externalCertificateNumber;
x.Issuer = issuer;
x.ValidTill = validTill?.ToUniversalTime();
x.ValidFrom = validFrom?.ToUniversalTime();
x.ValidFrom = validFrom;
x.ValidTill = validTill;
});

if (sites != null && sites.Any())
{
companyCertificateRepository.CreateCompanyCertificateAssignedSites(companyCertificate.Id, sites);
}
sites?.IfAny(x => companyCertificateRepository.CreateCompanyCertificateAssignedSites(companyCertificate.Id, x));

await portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public Task<bool> CheckCompanyCertificateType(CompanyCertificateTypeId certifica
x.Id == certificateTypeId);

/// <inheritdoc />
public CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null)
public CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, CompanyCertificateStatusId companyCertificateStatusId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null)
{
var companyCertificate = new CompanyCertificate(Guid.NewGuid(), DateTimeOffset.UtcNow, companyCertificateTypeId, CompanyCertificateStatusId.ACTIVE, companyId, docId);
var companyCertificate = new CompanyCertificate(Guid.NewGuid(), companyCertificateTypeId, companyCertificateStatusId, companyId, docId);
setOptionalFields?.Invoke(companyCertificate);
return _context.CompanyCertificates.Add(companyCertificate).Entity;
}
Expand All @@ -71,7 +71,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui
ccb.ValidFrom,
ccb.ValidTill,
ccb.ExternalCertificateNumber,
ccb.CompaniesCertificateAssignedSites.Select(x => x.Sites),
ccb.CompanyCertificateAssignedSites.Select(x => x.Site),
ccb.Issuer,
ccb.Validator))
.ToAsyncEnumerable();
Expand Down Expand Up @@ -102,7 +102,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui
companyCertificate.ValidFrom,
companyCertificate.ValidTill,
companyCertificate.ExternalCertificateNumber,
companyCertificate.CompaniesCertificateAssignedSites.Select(x => x.Sites),
companyCertificate.CompanyCertificateAssignedSites.Select(x => x.Site),
companyCertificate.Issuer,
companyCertificate.Validator
))
Expand All @@ -128,7 +128,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui

public void AttachAndModifyCompanyCertificateDetails(Guid id, Action<CompanyCertificate>? initialize, Action<CompanyCertificate> updateFields)
{
var entity = new CompanyCertificate(id, default, default, default, Guid.Empty, Guid.Empty);
var entity = new CompanyCertificate(id, default, default, Guid.Empty, Guid.Empty);
initialize?.Invoke(entity);
_context.Attach(entity);
updateFields.Invoke(entity);
Expand All @@ -151,5 +151,5 @@ public void AttachAndModifyCompanyCertificateDocumentDetails(Guid id, Action<Doc
.SingleOrDefaultAsync();

public void CreateCompanyCertificateAssignedSites(Guid companyCertificateId, IEnumerable<string> sites) =>
_context.AddRange(sites.Select(companyCertificateAssignedSite => new CompaniesCertificateAssignedSite(companyCertificateId, companyCertificateAssignedSite)));
_context.AddRange(sites.Select(companyCertificateAssignedSite => new CompanyCertificateAssignedSite(companyCertificateId, companyCertificateAssignedSite)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface ICompanyCertificateRepository
/// <param name="docId">id of the document</param>
/// <param name="setOptionalFields">Action to set optional fields</param>
/// <returns>The created entity</returns>
CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null);
CompanyCertificate CreateCompanyCertificate(Guid companyId, CompanyCertificateTypeId companyCertificateTypeId, CompanyCertificateStatusId companyCertificateStatusId, Guid docId, Action<CompanyCertificate>? setOptionalFields = null);

void CreateCompanyCertificateAssignedSites(Guid companyCertificateId, IEnumerable<string> sites);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
********************************************************************************/

using Microsoft.EntityFrameworkCore.Migrations;
using System;

#nullable disable

Expand Down
Loading

0 comments on commit e3d24de

Please sign in to comment.