Skip to content

Commit

Permalink
feat(impl):[#359] support new encoded endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Mar 25, 2024
1 parent 788a585 commit 56f8ebd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_

## [Unreleased]
### Changed
- IRS now supports Asset Administration Shell v3.1 - adjusted lookup shells endpoint changes (assetIds query param is encoded)

## [4.8.0] - 2024-03-18
### Changed
- Improved maintainability in EdcSubmodelClientImpl by reduced method visibility and better naming (in context of #448).
- EdcPolicyDefinitionService, EdcContractDefinitionService and EdcAssetService return throw AlreadyExist exceptions when Conflict is returned from
EDC
- EdcPolicyDefinitionService, EdcContractDefinitionService and EdcAssetService return throw AlreadyExist exceptions when Conflict is returned from EDC
- Added AssetAdministrationShellDescriptor specificAssetIds support for externalSubjectId required for data provisioning
- Registering a job - aspects array is now accepting full urn of aspect model instead of name only, eg. 'urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt' instead 'SingleLevelBomAsBuilt'. #439
- Changed the version of irs-registry-client from 1.6.0-SNAPSHOT to 1.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
package org.eclipse.tractusx.irs;

import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.irs.WiremockSupport.createEndpointDataReference;
import static org.eclipse.tractusx.irs.WiremockSupport.encodedAssetIds;
import static org.eclipse.tractusx.irs.WiremockSupport.randomUUID;
import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH;
import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_URL;
Expand Down Expand Up @@ -158,7 +160,7 @@ void shouldStartApplicationAndCollectSemanticModels() throws SchemaNotFoundExcep
void shouldStopJobAfterDepthIsReached() {
// Arrange
final String globalAssetIdLevel1 = "globalAssetId";
final String globalAssetIdLevel2 = "urn:uuid:6d505432-8b31-4966-9514-4b753372683f";
final String globalAssetIdLevel2 = "urn:uuid:7e4541ea-bb0f-464c-8cb3-021abccbfaf5";

WiremockSupport.successfulSemanticModelRequest();
WiremockSupport.successfulSemanticHubRequests();
Expand Down Expand Up @@ -297,7 +299,7 @@ private void successfulRegistryAndDataRequest(final String globalAssetId, final
final String registryEdcAssetId = "registry-asset";
successfulNegotiation(registryEdcAssetId);
stubFor(getLookupShells200(PUBLIC_LOOKUP_SHELLS_PATH, List.of(shellId)).withQueryParam("assetIds",
containing(globalAssetId)));
equalTo(encodedAssetIds(globalAssetId))));
stubFor(getShellDescriptor200(PUBLIC_SHELL_DESCRIPTORS_PATH + WiremockSupport.encodedId(shellId), bpn,
submodelDescriptors, globalAssetId, shellId, idShort));
successfulNegotiation(edcAssetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@
import static org.eclipse.tractusx.irs.util.TestMother.batchAspectName;
import static org.eclipse.tractusx.irs.util.TestMother.singleLevelBomAsBuiltAspectName;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.irs.component.PartChainIdentificationKey;
import org.eclipse.tractusx.irs.component.RegisterJob;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.irs.component.enums.Direction;
import org.eclipse.tractusx.irs.data.StringMapper;
import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration;
Expand Down Expand Up @@ -97,6 +103,27 @@ static String encodedId(final String shellId) {
return encodeBase64String(shellId.getBytes(StandardCharsets.UTF_8));
}

static String encodedAssetIds(final String assetIds) {
final IdentifierKeyValuePair globalAssetId = IdentifierKeyValuePair.builder()
.name("globalAssetId")
.value(assetIds)
.build();
return Base64.getEncoder().encodeToString(serialize(globalAssetId));
}

private static byte[] serialize(final IdentifierKeyValuePair assetIds) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
final ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.writeValue(stream, assetIds);
return stream.toByteArray();
} catch (final IOException e) {
return new byte[0];
}
}

static void verifyDiscoveryCalls(final int times) {
verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH)));
verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.EDC_DISCOVERY_PATH)));
Expand Down

0 comments on commit 56f8ebd

Please sign in to comment.