Skip to content

Commit

Permalink
release(1.6.0-RC3): merge main to dev #167
Browse files Browse the repository at this point in the history
Reviewed-By: Martin Rohrmeier <[email protected]>
  • Loading branch information
Phil91 authored Jul 25, 2023
2 parents 13abfa4 + 6c435e3 commit 0e21972
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

New features, fixed bugs, known defects and other noteworthy changes to each release of the Catena-X Portal Backend.

## 1.6.0-RC3

### Change
* Apps Service
* whenever updating the offer or a related entity the offer LastDateChanged column is updated
* Services Service
* whenever updating the offer or a related entity the offer LastDateChanged column is updated
* Application Checklist Worker
* enhance the logging of a successful create wallet process step
* Administration Service
* GET /companydata/ownCompanyDetails enhanced the response with CompanyRoles

## 1.6.0-RC2

### Change
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionSuffix>RC1</VersionSuffix>
<VersionSuffix>RC3</VersionSuffix>
</PropertyGroup>
</Project>
16 changes: 14 additions & 2 deletions src/externalsystems/Custodian.Library/CustodianService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,26 @@ public async Task<string> CreateWalletAsync(string bpn, string name, Cancellatio
const string walletUrl = "/api/wallets";
var httpClient = await _tokenService.GetAuthorizedClient<CustodianService>(_settings, cancellationToken).ConfigureAwait(false);
var requestBody = new { name = name, bpn = bpn };

async ValueTask<(bool, string?)> CreateErrorMessage(HttpResponseMessage errorResponse) =>
(false, (await errorResponse.Content.ReadFromJsonAsync<WalletErrorResponse>(Options, cancellationToken).ConfigureAwait(false))?.Message);

var result = await httpClient.PostAsJsonAsync(walletUrl, requestBody, Options, cancellationToken)
.CatchingIntoServiceExceptionFor("custodian-post", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, CreateErrorMessage).ConfigureAwait(false);

return await result.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
try
{
var walletResponse = await result.Content.ReadFromJsonAsync<WalletCreationResponse>(Options, cancellationToken).ConfigureAwait(false);
if (walletResponse == null)
{
return "Service Response for custodian-post is null";
}

return JsonSerializer.Serialize(walletResponse, Options);
}
catch (JsonException)
{
return "Service Response deSerialization failed for custodian-post";
}
}

/// <inhertidoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Custodian.Library.Models;
public record WalletErrorResponse([property: JsonPropertyName("message")] string Message);

public record MembershipErrorResponse([property: JsonPropertyName("title")] string Title);

public record WalletCreationResponse([property: JsonPropertyName("DID")] string Did, [property: JsonPropertyName("CreatedAt")] DateTimeOffset CreatedAt);
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ private async Task<IEnumerable<AppRoleData>> InsertActiveAppUserRoleAsync(Guid a
await _provisioningManager.AddRolesToClientAsync(clientId, userRoles.Select(x => x.Role)).ConfigureAwait(false);
}

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

var notificationContent = new
{
AppName = result.AppName,
Expand Down Expand Up @@ -125,6 +128,8 @@ public async Task CreateOrUpdateAppDescriptionByIdAsync(Guid appId, Guid company
await ValidateAndGetAppDescription(appId, companyId, offerRepository),
offerDescriptionDatas.Select(od => new ValueTuple<string, string, string>(od.LanguageCode, od.LongDescription, od.ShortDescription)));

offerRepository.AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -189,6 +194,8 @@ public async Task UploadOfferAssignedAppLeadImageDocumentByIdAsync(Guid appId, (
offerRepository.RemoveOfferAssignedDocuments(result.documentStatusDatas.Select(data => (appId, data.DocumentId)));
documentRepository.RemoveDocuments(result.documentStatusDatas.Select(data => data.DocumentId));

offerRepository.AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -246,6 +253,9 @@ private async Task UpdateTenantUrlAsyncInternal(Guid offerId, Guid subscriptionI
os.AppSubscriptionUrl = url;
});

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

if (!string.IsNullOrEmpty(detailData.ClientClientId))
{
await _provisioningManager.UpdateClient(detailData.ClientClientId, url, url.AppendToPathEncoded("*")).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ private async Task<IEnumerable<AppRoleData>> InsertAppUserRoleAsync(Guid appId,
throw new ForbiddenException($"Company {companyId} is not the provider company of app {appId}");
}
var roleData = AppExtensions.CreateUserRolesWithDescriptions(_portalRepositories.GetInstance<IUserRolesRepository>(), appId, userRoles);

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
return roleData;
}
Expand Down Expand Up @@ -259,6 +262,7 @@ private async Task<Guid> CreateAppAsync(AppRequestModel appRequestModel, Guid co
app.ContactNumber = appRequestModel.ContactNumber;
app.MarketingUrl = appRequestModel.ProviderUri;
app.LicenseTypeId = LicenseTypeId.COTS;
app.DateLastChanged = DateTimeOffset.UtcNow;
}).Id;
appRepository.AddOfferDescriptions(appRequestModel.Descriptions.Select(d =>
(appId, d.LanguageCode, d.LongDescription, d.ShortDescription)));
Expand Down Expand Up @@ -339,6 +343,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo
app.ContactEmail = appData.ContactEmail;
app.ContactNumber = appData.ContactNumber;
app.MarketingUrl = appData.MarketingUrl;
app.DateLastChanged = DateTimeOffset.UtcNow;
});

_offerService.UpsertRemoveOfferDescription(appId, appRequestModel.Descriptions, appData.OfferDescriptions);
Expand Down
4 changes: 4 additions & 0 deletions src/marketplace/Offers.Library.Web/OfferDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public async Task UploadDocumentAsync(Guid id, DocumentTypeId documentTypeId, IF
x.CompanyUserId = identity.UserId;
});
_portalRepositories.GetInstance<IOfferRepository>().CreateOfferAssignedDocument(id, doc.Id);

offerRepository.AttachAndModifyOffer(id, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
}
}
13 changes: 12 additions & 1 deletion src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public async Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgr
companyUserId,
DateTimeOffset.UtcNow)
.Select(consent => new ConsentStatusData(consent.AgreementId, consent.ConsentStatusId));

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
return ConsentStatusdata;
}
Expand Down Expand Up @@ -233,6 +237,7 @@ public async Task<Guid> CreateServiceOfferingAsync(ServiceOfferingData data, (Gu
service.ProviderCompanyId = identity.CompanyId;
service.MarketingUrl = data.ProviderUri;
service.LicenseTypeId = LicenseTypeId.COTS;
service.DateLastChanged = DateTimeOffset.UtcNow;
});
var licenseId = offerRepository.CreateOfferLicenses(data.Price).Id;
offerRepository.CreateOfferAssignedLicense(service.Id, licenseId);
Expand Down Expand Up @@ -629,7 +634,10 @@ public async Task DeactivateOfferIdAsync(Guid offerId, Guid companyId, OfferType
throw new ConflictException($"offerStatus is in Incorrect State");
}
offerRepository.AttachAndModifyOffer(offerId, offer =>
offer.OfferStatusId = OfferStatusId.INACTIVE);
{
offer.OfferStatusId = OfferStatusId.INACTIVE;
offer.DateReleased = DateTime.UtcNow;
});
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -784,6 +792,9 @@ public async Task UpdateTechnicalUserProfiles(Guid offerId, OfferTypeId offerTyp
x => x.TechnicalUserProfileId)
.Select(x => x.TechnicalUserProfileId));

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public async Task UpdateServiceAsync(Guid serviceId, ServiceUpdateRequestData da
offer =>
{
offer.SalesManagerId = serviceData.SalesManagerId;
offer.DateLastChanged = DateTimeOffset.UtcNow;
});

_offerService.UpsertRemoveOfferDescription(serviceId, data.Descriptions, serviceData.Descriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using System.Text.Json.Serialization;

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
Expand All @@ -33,5 +34,6 @@ public record CompanyAddressDetailData(
string? Region,
string? StreetAdditional,
string? StreetNumber,
string? ZipCode
string? ZipCode,
IEnumerable<CompanyRoleId> CompanyRole
);
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public void CreateUpdateDeleteIdentifiers(Guid companyId, IEnumerable<(UniqueIde
company.Address.Region,
company.Address.Streetadditional,
company.Address.Streetnumber,
company.Address!.Zipcode))
company.Address!.Zipcode,
company.CompanyAssignedRoles.Select(car => car.CompanyRoleId)
))
.SingleOrDefaultAsync();

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class CustodianServiceTests
{
#region Initialization

private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };

private readonly ITokenService _tokenService;
private readonly IOptions<CustodianSettings> _options;
private readonly IFixture _fixture;
Expand Down Expand Up @@ -66,14 +68,18 @@ public CustodianServiceTests()

#region Create Wallet

[Fact]
public async Task CreateWallet_WithValidData_DoesNotThrowException()
[Theory]
[InlineData("did:sov:GamAMqXnXr1chS4viYXoxB", true)]
[InlineData(null, false)]
public async Task CreateWallet_WithValidData_DoesNotThrowException(string DID, bool IsCreatedAt)
{
// Arrange
const string bpn = "123";
const string name = "test";
var data = JsonSerializer.Serialize(
new WalletCreationResponse(DID, IsCreatedAt ? DateTimeOffset.UtcNow : default), JsonOptions);
var httpMessageHandlerMock =
new HttpMessageHandlerMock(HttpStatusCode.OK);
new HttpMessageHandlerMock(HttpStatusCode.OK, data.ToFormContent("application/json"));
var httpClient = new HttpClient(httpMessageHandlerMock)
{
BaseAddress = new Uri("https://base.address.com")
Expand All @@ -83,10 +89,11 @@ public async Task CreateWallet_WithValidData_DoesNotThrowException()
var sut = new CustodianService(_tokenService, _options);

// Act
await sut.CreateWalletAsync(bpn, name, CancellationToken.None).ConfigureAwait(false);
var result = await sut.CreateWalletAsync(bpn, name, CancellationToken.None).ConfigureAwait(false);

// Assert
true.Should().BeTrue(); // One Assert is needed - just checking for no exception
result.Should().NotBeNull();
result.Should().Be(data);
}

[Theory]
Expand Down Expand Up @@ -120,6 +127,31 @@ public async Task CreateWallet_WithConflict_ThrowsServiceExceptionWithErrorConte
ex.StatusCode.Should().Be(statusCode);
}

[Fact]
public async Task CreateWallet_withSuccessStatusCode_JsonException()
{
// Arrange
const string bpn = "123";
const string name = "test";
var content = "this is no json data";
var httpMessageHandlerMock =
new HttpMessageHandlerMock(HttpStatusCode.OK, new StringContent(content));
var httpClient = new HttpClient(httpMessageHandlerMock)
{
BaseAddress = new Uri("https://base.address.com")
};
A.CallTo(() => _tokenService.GetAuthorizedClient<CustodianService>(_options.Value, A<CancellationToken>._))
.Returns(httpClient);
var sut = new CustodianService(_tokenService, _options);

// Act
var result = await sut.CreateWalletAsync(bpn, name, CancellationToken.None).ConfigureAwait(false);

// Assert
result.Should().NotBeNull();
result.Should().Be("Service Response deSerialization failed for custodian-post");
}

#endregion

#region GetWallet By Bpn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public async Task AddFavouriteAppForUser_ExecutesSuccessfully()
{
// Arrange
var appId = _fixture.Create<Guid>();

var sut = new AppsBusinessLogic(_portalRepositories, null!, null!, null!, Options.Create(new AppsSettings()), null!);

// Act
Expand Down
Loading

0 comments on commit 0e21972

Please sign in to comment.