Skip to content

Commit

Permalink
feat(status): change document status as locked while uploading certif…
Browse files Browse the repository at this point in the history
…icate (#551)

* adjust company certificate status to INACTIVE
----------
Refs: #468
Reviewed-By: Phil Schneider <[email protected]>
  • Loading branch information
AnuragNagpure authored Mar 5, 2024
1 parent fa5073f commit 4a9c426
Show file tree
Hide file tree
Showing 10 changed files with 9,297 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private async Task HandleCompanyCertificateCreationAsync(CompanyCertificateTypeI
hash, mediaTypeId, DocumentTypeId.COMPANY_CERTIFICATE, x =>
{
x.CompanyUserId = _identityData.IdentityId;
x.DocumentStatusId = DocumentStatusId.PENDING;
x.DocumentStatusId = DocumentStatusId.LOCKED;
});

companyCertificateRepository.CreateCompanyCertificate(_identityData.CompanyId, companyCertificateTypeId, doc.Id,
Expand Down Expand Up @@ -640,7 +640,7 @@ public async Task<int> DeleteCompanyCertificateAsync(Guid documentId)
{
companyCertificateRepository.AttachAndModifyCompanyCertificateDetails(details.CompanyCertificateId.SingleOrDefault(), null, c =>
{
c.CompanyCertificateStatusId = CompanyCertificateStatusId.INACTVIE;
c.CompanyCertificateStatusId = CompanyCertificateStatusId.INACTIVE;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public IAsyncEnumerable<CompanyCertificateBpnData> GetCompanyCertificateData(Gui
.Select(document => new ValueTuple<Guid, DocumentStatusId, IEnumerable<Guid>, bool>(
document.Id,
document.DocumentStatusId,
document.CompanyCertificates.Where(x => x.CompanyCertificateStatusId != CompanyCertificateStatusId.INACTVIE).Select(x => x.Id),
document.CompanyCertificates.Where(x => x.CompanyCertificateStatusId != CompanyCertificateStatusId.INACTIVE).Select(x => x.Id),
document.CompanyUser!.Identity!.CompanyId == companyId))
.SingleOrDefaultAsync();

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/********************************************************************************
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.Migrations.Migrations
{
/// <inheritdoc />
public partial class companycertificateupdate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
schema: "portal",
table: "company_certificate_statuses",
keyColumn: "id",
keyValue: 2,
column: "label",
value: "INACTIVE");

migrationBuilder.UpdateData(
schema: "portal",
table: "company_certificate_type_statuses",
keyColumn: "id",
keyValue: 2,
column: "label",
value: "INACTIVE");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
schema: "portal",
table: "company_certificate_statuses",
keyColumn: "id",
keyValue: 2,
column: "label",
value: "INACTVIE");

migrationBuilder.UpdateData(
schema: "portal",
table: "company_certificate_type_statuses",
keyColumn: "id",
keyValue: 2,
column: "label",
value: "INACTVIE");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/********************************************************************************
/********************************************************************************
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
Expand Down Expand Up @@ -2213,7 +2213,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
new
{
Id = 2,
Label = "INACTVIE"
Label = "INACTIVE"
});
});

Expand Down Expand Up @@ -2367,7 +2367,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
new
{
Id = 2,
Label = "INACTVIE"
Label = "INACTIVE"
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums
public enum CompanyCertificateStatusId
{
ACTIVE = 1,
INACTVIE = 2
INACTIVE = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums
public enum CompanyCertificateTypeStatusId
{
ACTIVE = 1,
INACTVIE = 2
INACTIVE = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ public async Task CheckCompanyCertificate_WithValidCall_CreatesExpected()
A.CallTo(() => _documentRepository.CreateDocument(A<string>._, A<byte[]>._, A<byte[]>._, MediaTypeId.PDF, DocumentTypeId.COMPANY_CERTIFICATE, A<Action<Document>>._))
.Invokes((string documentName, byte[] documentContent, byte[] hash, MediaTypeId mediaTypeId, DocumentTypeId documentTypeId, Action<Document>? setupOptionalFields) =>
{
var document = new Document(documentId, documentContent, hash, documentName, mediaTypeId, DateTimeOffset.UtcNow, DocumentStatusId.PENDING, documentTypeId);
var document = new Document(documentId, documentContent, hash, documentName, mediaTypeId, DateTimeOffset.UtcNow, DocumentStatusId.LOCKED, documentTypeId);
setupOptionalFields?.Invoke(document);
documents.Add(document);
})
Expand All @@ -1041,7 +1041,7 @@ public async Task CheckCompanyCertificate_WithValidCall_CreatesExpected()
documents.Should().ContainSingle();
var document = documents.Single();
document.DocumentTypeId.Should().Be(DocumentTypeId.COMPANY_CERTIFICATE);
document.DocumentStatusId.Should().Be(DocumentStatusId.PENDING);
document.DocumentStatusId.Should().Be(DocumentStatusId.LOCKED);
A.CallTo(() => _companyCertificateRepository.CreateCompanyCertificate(_identity.CompanyId, CompanyCertificateTypeId.IATF, document.Id, A<Action<CompanyCertificate>>._))
.MustHaveHappenedOnceExactly();
companyCertificates.Should().ContainSingle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task GetAllCertificates_ReturnsExpectedResult(CertificateSorting so
[Theory]
[InlineData(CompanyCertificateStatusId.ACTIVE, CompanyCertificateTypeId.AEO_CTPAT_Security_Declaration, 0, 2, 1, 1)]
[InlineData(CompanyCertificateStatusId.ACTIVE, CompanyCertificateTypeId.ISO_9001, 0, 2, 1, 1)]
[InlineData(CompanyCertificateStatusId.INACTVIE, CompanyCertificateTypeId.IATF, 0, 2, 0, 0)]
[InlineData(CompanyCertificateStatusId.INACTIVE, CompanyCertificateTypeId.IATF, 0, 2, 0, 0)]
public async Task GetAllCertificates_WithExistingCompanyCertificateAndCertificateType_ReturnsExpectedResult(CompanyCertificateStatusId companyCertificateStatusId, CompanyCertificateTypeId companyCertificateTypeId, int page, int size, int count, int numData)
{
// Arrange
Expand Down Expand Up @@ -288,7 +288,7 @@ public async Task CompanyCertificateDetailsModify_WithValidData_ReturnsExpected(
// Act
sut.AttachAndModifyCompanyCertificateDetails(new("9f5b9934-4014-4099-91e9-7b1aee696c12"), null, x =>
{
x.CompanyCertificateStatusId = CompanyCertificateStatusId.INACTVIE;
x.CompanyCertificateStatusId = CompanyCertificateStatusId.INACTIVE;
});

// Assert
Expand All @@ -297,7 +297,7 @@ public async Task CompanyCertificateDetailsModify_WithValidData_ReturnsExpected(
changeTracker.HasChanges().Should().BeTrue();
changedEntries.Should().ContainSingle()
.Which.Entity.Should().BeOfType<CompanyCertificate>()
.And.Match<CompanyCertificate>(x => x.CompanyCertificateStatusId == CompanyCertificateStatusId.INACTVIE);
.And.Match<CompanyCertificate>(x => x.CompanyCertificateStatusId == CompanyCertificateStatusId.INACTIVE);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task GetCertificateTypes_WithInactiveCertificateType_ReturnsExpecte
// Arrange
var (context, sut) = await CreateSutWithContext().ConfigureAwait(false);
var active = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.ACTIVE);
var inactive = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.INACTVIE);
var inactive = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.INACTIVE);
context.Remove(active);
context.Add(inactive);
await context.SaveChangesAsync().ConfigureAwait(false);
Expand Down

0 comments on commit 4a9c426

Please sign in to comment.