From ed223cd0e9cd17e5e88b5bfe48b4511f0e167db3 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Sat, 12 Aug 2023 23:06:29 +0200 Subject: [PATCH 01/33] feature: TRACEFOSS-XXX upgrade IRS version --- charts/traceability-foss/Chart.yaml | 2 +- dev/README.md | 12 ++++++------ tx-backend/pom.xml | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/traceability-foss/Chart.yaml b/charts/traceability-foss/Chart.yaml index 84f215418c..b6248a55fc 100644 --- a/charts/traceability-foss/Chart.yaml +++ b/charts/traceability-foss/Chart.yaml @@ -42,7 +42,7 @@ dependencies: condition: pgadmin4.enabled - name: irs-helm repository: https://eclipse-tractusx.github.io/item-relationship-service - version: 6.3.1 + version: 6.4.1 condition: irs-helm.enabled - name: tractusx-connector repository: https://eclipse-tractusx.github.io/tractusx-edc diff --git a/dev/README.md b/dev/README.md index 976473f2cc..26eb48f317 100644 --- a/dev/README.md +++ b/dev/README.md @@ -32,37 +32,37 @@ Keep in mind to always update DEV and TEST since they are dependend on each othe Sample invocation (DEV) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server.dev.demo.catena-x.net -edc https://trace-x-edc.dev.demo.catena-x.net -a https://trace-x-registry.dev.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server.dev.demo.catena-x.net -edc https://trace-x-edc.dev.demo.catena-x.net -a https://trace-x-registry.dev.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-edc-dataplane.dev.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` Sample invocation (TEST) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-test.dev.demo.catena-x.net -edc https://trace-x-test-edc.dev.demo.catena-x.net -a https://trace-x-registry-test.dev.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-test.dev.demo.catena-x.net -edc https://trace-x-test-edc.dev.demo.catena-x.net -a https://trace-x-registry-test.dev.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-test-edc-dataplane.dev.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` Sample invocation (E2E A) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-e2e-a.dev.demo.catena-x.net -edc https://trace-x-edc-e2e-a.dev.demo.catena-x.net -a https://trace-x-registry-e2e-a.dev.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-e2e-a.dev.demo.catena-x.net -edc https://trace-x-edc-e2e-a.dev.demo.catena-x.net -a https://trace-x-registry-e2e-a.dev.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-edc-e2e-a-dataplane.dev.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` Sample invocation (E2E B) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-e2e-b.dev.demo.catena-x.net -edc https://trace-x-edc-e2e-b.dev.demo.catena-x.net -a https://trace-x-registry-e2e-b.dev.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-e2e-b.dev.demo.catena-x.net -edc https://trace-x-edc-e2e-b.dev.demo.catena-x.net -a https://trace-x-registry-e2e-b.dev.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-edc-e2e-b-dataplane.dev.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` Sample invocation (INT A) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-int-a.int.demo.catena-x.net -edc https://trace-x-edc-int-a.int.demo.catena-x.net -a https://trace-x-registry-int-a.int.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-int-a.int.demo.catena-x.net -edc https://trace-x-edc-int-a.int.demo.catena-x.net -a https://trace-x-registry-int-a.int.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-edc-int-a-dataplane.int.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` Sample invocation (INT B) ``` -python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-int-b.int.demo.catena-x.net -edc https://trace-x-edc-int-b.int.demo.catena-x.net -a https://trace-x-registry-int-b.int.demo.catena-x.net/semantics/registry/api/v3.0 -p id-3.0-trace -k --aas3 +python transform-and-upload.py -f CX_Testdata_MessagingTest_v0.0.7.json -s https://tracex-submodel-server-int-b.int.demo.catena-x.net -edc https://trace-x-edc-int-b.int.demo.catena-x.net -a https://trace-x-registry-int-b.int.demo.catena-x.net/semantics/registry/api/v3.0 -d https://trace-x-edc-int-b-dataplane.int.demo.catena-x.net -p id-3.0-trace -k --aas3 ``` where: diff --git a/tx-backend/pom.xml b/tx-backend/pom.xml index ceb725fa51..a1bd0df689 100644 --- a/tx-backend/pom.xml +++ b/tx-backend/pom.xml @@ -36,7 +36,7 @@ org.eclipse.tractusx.irs irs-registry-client - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT From 58f515b6c468a12b6ce711120488f4f87330e1a5 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 10:04:29 +0200 Subject: [PATCH 02/33] feature: TRACEFOSS-XXX add log to shellDescriptorMapping --- .../rest/registry/shelldescriptor/RegistryShellDescriptor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java index 207b9b82e7..2ea8b1d4d5 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java @@ -19,6 +19,7 @@ package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; +import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; @@ -31,6 +32,7 @@ import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.MANUFACTURER_PART_ID; import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.PART_INSTANCE_ID; +@Slf4j public record RegistryShellDescriptor( GlobalAssetId globalAssetId, String identification, @@ -42,6 +44,7 @@ public ShellDescriptor toShellDescriptor() { String globalAssetId = globalAssetId().value().stream() .findFirst() .orElse(null); + log.info("toShellDescriptor: {}", specificAssetIds); Map assetIdsMap = specificAssetIds().stream() .collect(Collectors.toMap(entry -> entry.key().toLowerCase(), SpecificAssetId::value)); From 512a896d6bccdd6c3e193fcff316841c2905a56a Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 10:59:09 +0200 Subject: [PATCH 03/33] feature: TRACEFOSS-XXX remove duplicate keys before mapping --- .../rest/registry/shelldescriptor/RegistryShellDescriptor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java index 2ea8b1d4d5..16fa4f609f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java @@ -46,6 +46,7 @@ public ShellDescriptor toShellDescriptor() { .orElse(null); log.info("toShellDescriptor: {}", specificAssetIds); Map assetIdsMap = specificAssetIds().stream() + .distinct() .collect(Collectors.toMap(entry -> entry.key().toLowerCase(), SpecificAssetId::value)); String manufacturerPartId = assetIdsMap.get(MANUFACTURER_PART_ID.asKey()); From b8b2857ad6d947a0d4e3d1ad0293ee3a508b58d7 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 18:45:44 +0200 Subject: [PATCH 04/33] feature: TRACEFOSS-XXX --- .../repository/rest/registry/RegistryService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index d5e49281d0..712da6fed8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -85,11 +85,11 @@ public List findOwnShellDescriptors() throws RegistryServiceExc Collection registryKeys = null; try { - registryKeys = decentralDigitalTwinRegistryService.lookupShells(applicationBPN); + registryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers(applicationBPN); registryKeys.forEach(digitalTwinRegistryKey -> { log.info("DTR Key" + digitalTwinRegistryKey); }); - } catch (FeignException e) { + } catch (Exception e) { endMetric(registryLookupMetric); log.error("Fetching shell ownShellsRegistryResponse failed", e); } From 78e848ae21bda96a25ea05bd505e7a62aaac5098 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 20:27:52 +0200 Subject: [PATCH 05/33] feature: TRACEFOSS-XXX --- .../repository/rest/registry/RegistryServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index 9803fbaaa8..56b2f4e985 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -86,7 +86,7 @@ void testFindAssets() throws RegistryServiceException { List registryKeys = List.of( new DigitalTwinRegistryKey("assetId", "test-bpn") ); - when(decentralDigitalTwinRegistryService.lookupShells("test-bpn")).thenReturn(registryKeys); + when(decentralDigitalTwinRegistryService.lookupShellIdentifiers("test-bpn")).thenReturn(registryKeys); final String globalAssetId = "GLOBAL_ASSET_ID"; final String idShort = "ID_SHORT"; final String identification = "IDENTIFICATION"; From b1374c3bdee06968a8e7fcc0ec32686134b2316d Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 20:53:16 +0200 Subject: [PATCH 06/33] feature: TRACEFOSS-XXX test policies provider --- .../common/config/ApplicationConfig.java | 12 ++++++++++++ .../common/config/ApplicationStartupConfig.java | 5 ----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java index c805fde221..49e7956b23 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java @@ -121,6 +121,18 @@ public void registerDecentralRegistryPermissions() { } + @Bean + public AcceptedPoliciesProvider acceptedPoliciesProvider() { + return new AcceptedPoliciesProvider() { + OffsetDateTime offsetDateTime = OffsetDateTime.now().plusMonths(1); + AcceptedPolicy acceptedPolicy = new AcceptedPolicy(ID_TRACE_CONSTRAINT, offsetDateTime); + @Override + public List getAcceptedPolicies() { + return List.of(acceptedPolicy); + } + }; + } + @Bean public RegistryEventConsumer myRetryRegistryEventConsumer() { final Logger logger = LoggerFactory.getLogger("RetryLogger"); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java index 02df2c1ac6..c4e5eced84 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java @@ -21,17 +21,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPoliciesProvider; -import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; import org.eclipse.tractusx.traceability.assets.domain.base.IrsRepository; import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; -import java.time.OffsetDateTime; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; From 351a1adcc3fadcdbea5c5e7456bf2c45082ca311 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 23:44:45 +0200 Subject: [PATCH 07/33] feature: TRACEFOSS-XXX test policies provider --- .../common/config/ApplicationConfig.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java index 49e7956b23..2e8ccb88e8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationConfig.java @@ -114,25 +114,12 @@ public void registerDecentralRegistryPermissions() { OffsetDateTime offsetDateTime = OffsetDateTime.now().plusMonths(1); AcceptedPolicy acceptedPolicy = new AcceptedPolicy(ID_TRACE_CONSTRAINT, offsetDateTime); defaultAcceptedPoliciesProvider.addAcceptedPolicies(List.of(acceptedPolicy)); - log.info("Successfully added permission to irs client lib provider"); + log.info("Successfully added permission to irs client lib provider: {}", acceptedPolicy); } catch (Exception exception) { log.error("Failed to create Irs Policies : ", exception); } } - - @Bean - public AcceptedPoliciesProvider acceptedPoliciesProvider() { - return new AcceptedPoliciesProvider() { - OffsetDateTime offsetDateTime = OffsetDateTime.now().plusMonths(1); - AcceptedPolicy acceptedPolicy = new AcceptedPolicy(ID_TRACE_CONSTRAINT, offsetDateTime); - @Override - public List getAcceptedPolicies() { - return List.of(acceptedPolicy); - } - }; - } - @Bean public RegistryEventConsumer myRetryRegistryEventConsumer() { final Logger logger = LoggerFactory.getLogger("RetryLogger"); From e9af1756147c8e2badb7ec63b2ca09465193ed69 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 14 Aug 2023 23:57:32 +0200 Subject: [PATCH 08/33] feature: TRACEFOSS-XXX idsc: removed as IRS no longer processes it --- tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.7.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.7.json b/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.7.json index 652d27843b..08dc0150ea 100644 --- a/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.7.json +++ b/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.7.json @@ -16,7 +16,7 @@ "odrl:or" : [ { "@type" : "Constraint", - "odrl:leftOperand" : "idsc:PURPOSE", + "odrl:leftOperand" : "PURPOSE", "odrl:operator" : { "@id" : "odrl:eq" }, From cee175c1b2e45e9a39ee7932070c00571d720060 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 15 Aug 2023 00:22:05 +0200 Subject: [PATCH 09/33] feature: TRACEFOSS-XXX test --- .github/workflows/pull-request_backend.yml | 45 ------------------- .../EdcRestTemplateConfiguration.java | 23 ++++++++++ .../rest/registry/RegistryService.java | 3 +- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index 7267266f3c..33396c7e56 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -10,53 +10,8 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: - Test-and-Sonar: - permissions: - checks: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '${{ env.JAVA_VERSION }}' - distribution: 'temurin' - cache: 'maven' - - - name: Run unit & integration tests - run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify - - - name: Publish integration test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" - check_name: "Integration Test Results" - - - name: Publish unit test results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: "**/surefire-reports/TEST-*.xml" - check_name: "Unit Test Results" - - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Verify Sonar Scan - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} - SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} - run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} Publish-docker-image: - needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java index 6e03cbd497..115b33e5ca 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java @@ -22,9 +22,17 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.edc.client.EdcSubmodelFacade; +import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryClient; +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; +import org.eclipse.tractusx.irs.registryclient.decentral.EdcRetrieverException; +import org.eclipse.tractusx.irs.registryclient.decentral.EndpointDataForConnectorsService; +import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -64,6 +72,21 @@ public RestTemplate edcTemplate() { .build(); } + @Bean +// @ConditionalOnProperty(prefix = "digitalTwinRegistry", name = "type", havingValue = "decentral") + public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( + @Qualifier("edcClientRestTemplate") final RestTemplate edcRestTemplate, + final ConnectorEndpointsService connectorEndpointsService, final EdcSubmodelFacade facade) { + return new DecentralDigitalTwinRegistryService(connectorEndpointsService, + new EndpointDataForConnectorsService((edcConnectorEndpoint, assetType, assetValue) -> { + try { + return facade.getEndpointReferenceForAsset(edcConnectorEndpoint, assetType, assetValue); + } catch (EdcClientException e) { + throw new EdcRetrieverException(e); + } + }), new DecentralDigitalTwinRegistryClient(edcRestTemplate)); + } + @Bean public RestTemplate digitalTwinRegistryRestTemplate( final RestTemplateBuilder restTemplateBuilder, diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index 712da6fed8..8daa17f1c1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -64,7 +64,8 @@ public RegistryService(ObjectMapper objectMapper, RegistryApiClient registryApiClient, @Value("${traceability.bpn}") String applicationBPN, @Value("${traceability.registry.manufacturerIdKey}") String manufacturerIdKey, - ShellDescriptorLookupMetricRepository registryLookupMeterRegistry, Clock clock, DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { + ShellDescriptorLookupMetricRepository registryLookupMeterRegistry, Clock clock, + DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { this.objectMapper = objectMapper; this.registryApiClient = registryApiClient; this.applicationBPN = applicationBPN; From 0f9fa96c79c4afb3dc1895ebff311c1da5842fa3 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 15 Aug 2023 01:00:20 +0200 Subject: [PATCH 10/33] feature: TRACEFOSS-XXX test --- .../EdcRestTemplateConfiguration.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java index 115b33e5ca..6e03cbd497 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/edc/notificationcontract/configuration/EdcRestTemplateConfiguration.java @@ -22,17 +22,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.edc.client.EdcSubmodelFacade; -import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryClient; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; -import org.eclipse.tractusx.irs.registryclient.decentral.EdcRetrieverException; -import org.eclipse.tractusx.irs.registryclient.decentral.EndpointDataForConnectorsService; -import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService; import org.eclipse.tractusx.traceability.infrastructure.edc.properties.EdcProperties; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -72,21 +64,6 @@ public RestTemplate edcTemplate() { .build(); } - @Bean -// @ConditionalOnProperty(prefix = "digitalTwinRegistry", name = "type", havingValue = "decentral") - public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( - @Qualifier("edcClientRestTemplate") final RestTemplate edcRestTemplate, - final ConnectorEndpointsService connectorEndpointsService, final EdcSubmodelFacade facade) { - return new DecentralDigitalTwinRegistryService(connectorEndpointsService, - new EndpointDataForConnectorsService((edcConnectorEndpoint, assetType, assetValue) -> { - try { - return facade.getEndpointReferenceForAsset(edcConnectorEndpoint, assetType, assetValue); - } catch (EdcClientException e) { - throw new EdcRetrieverException(e); - } - }), new DecentralDigitalTwinRegistryClient(edcRestTemplate)); - } - @Bean public RestTemplate digitalTwinRegistryRestTemplate( final RestTemplateBuilder restTemplateBuilder, From 3d2c515399e355a8d455a290d08cca1e6c7cc094 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 15 Aug 2023 01:06:20 +0200 Subject: [PATCH 11/33] feature: TRACEFOSS-XXX test --- tx-backend/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/resources/application.yml b/tx-backend/src/main/resources/application.yml index 73dff38526..f37a16eb08 100644 --- a/tx-backend/src/main/resources/application.yml +++ b/tx-backend/src/main/resources/application.yml @@ -74,7 +74,7 @@ irs-edc-client: catalog: policies: acceptedRightOperands: active # List of comma separated names of the rightOperands to accept. - acceptedLeftOperands: idsc:PURPOSE # List of comma separated names of the leftOperands to accept. + acceptedLeftOperands: PURPOSE # List of comma separated names of the leftOperands to accept. server: servlet: From 8e3478e6d6128a8a13989740d0d69a99bf9ba2a0 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 15 Aug 2023 01:46:34 +0200 Subject: [PATCH 12/33] feature: TRACEFOSS-XXX tests --- .github/workflows/pull-request_backend.yml | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index 33396c7e56..7267266f3c 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -10,8 +10,53 @@ env: DOCKER_HUB_REGISTRY_NAMESPACE: tractusx jobs: + Test-and-Sonar: + permissions: + checks: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '${{ env.JAVA_VERSION }}' + distribution: 'temurin' + cache: 'maven' + + - name: Run unit & integration tests + run: mvn -pl tx-models,tx-backend,tx-coverage -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B verify + + - name: Publish integration test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml" + check_name: "Integration Test Results" + + - name: Publish unit test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: "**/surefire-reports/TEST-*.xml" + check_name: "Unit Test Results" + + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Verify Sonar Scan + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} + SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} + run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} Publish-docker-image: + needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: From 65f56271a8be3c9c2fe140da6643777e73289ded Mon Sep 17 00:00:00 2001 From: ds-mwesener Date: Tue, 15 Aug 2023 05:48:09 +0000 Subject: [PATCH 13/33] Update Dependencies Backend Action --- DEPENDENCIES_BACKEND | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index 27b664a605..78b12f0956 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -134,7 +134,7 @@ maven/mavencentral/org.eclipse.edc/transfer-spi/0.1.3, Apache-2.0, approved, tec maven/mavencentral/org.eclipse.edc/transform-spi/0.1.3, Apache-2.0, approved, technology.edc maven/mavencentral/org.eclipse.edc/validator-spi/0.1.3, Apache-2.0, approved, technology.edc maven/mavencentral/org.eclipse.edc/web-spi/0.1.3, Apache-2.0, approved, technology.edc -maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.0.0-20230731.142230-8, Apache-2.0, approved, automotive.tractusx +maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.1.0-20230811.110730-1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx.traceability/tx-backend/0.0.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx.traceability/tx-models/0.0.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.flywaydb/flyway-core/9.5.1, Apache-2.0, approved, #7296 From 71d77d68385e2ce523d2619931880592786a424d Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 08:24:40 +0200 Subject: [PATCH 14/33] chore: TRACEFOSS-2404 removing registryApiClient. --- .../charts/backend/templates/deployment.yaml | 2 - .../domain/RegistryFacade.java | 12 ++--- .../rest/registry/RegistryApiClient.java | 46 ----------------- .../rest/registry/RegistryService.java | 49 ++----------------- tx-backend/src/main/resources/application.yml | 2 - .../rest/registry/RegistryServiceTest.java | 11 +---- 6 files changed, 7 insertions(+), 115 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryApiClient.java diff --git a/charts/traceability-foss/charts/backend/templates/deployment.yaml b/charts/traceability-foss/charts/backend/templates/deployment.yaml index 3cdc45e42e..83fdfae47f 100644 --- a/charts/traceability-foss/charts/backend/templates/deployment.yaml +++ b/charts/traceability-foss/charts/backend/templates/deployment.yaml @@ -82,8 +82,6 @@ spec: value: {{ .Values.edc.providerUrl | quote }} - name: IRS_URL value: {{ .Values.irs.baseUrl | quote }} - - name: REGISTRY_URL_WITH_PATH - value: {{ .Values.registry.urlWithPath | quote }} - name: PORTAL_URL value: {{ .Values.portal.baseUrl | quote }} - name: EDC_CALLBACK_URL diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java index e3dd4dac61..c44cb8f8e7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java @@ -23,7 +23,6 @@ import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; -import org.eclipse.tractusx.traceability.assets.domain.base.BpnRepository; import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; @@ -43,8 +42,9 @@ public class RegistryFacade { @Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR) public void updateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { - List ownShellDescriptors = updateOwnShellDescriptors(); - synchronizeAssetsByDescriptors(ownShellDescriptors); + List shellDescriptorList = registryService.findOwnShellDescriptors(); + List updatedShellDescriptorList = shellDescriptorsService.update(shellDescriptorList); + synchronizeAssetsByDescriptors(updatedShellDescriptorList); } private void synchronizeAssetsByDescriptors(List descriptors) { @@ -52,10 +52,4 @@ private void synchronizeAssetsByDescriptors(List descriptors) { .map(ShellDescriptor::getGlobalAssetId) .forEach(assetService::synchronizeAssetsAsync); } - - private List updateOwnShellDescriptors() throws RegistryServiceException { - List ownShellDescriptors = registryService.findOwnShellDescriptors(); - return shellDescriptorsService.update(ownShellDescriptors); - } - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryApiClient.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryApiClient.java deleted file mode 100644 index e5ad2065eb..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryApiClient.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry; - -import feign.QueryMap; -import feign.RequestLine; -import org.eclipse.tractusx.traceability.common.config.CatenaApiConfig; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptorResponse; -import org.springframework.cloud.openfeign.FeignClient; - -import java.util.List; -import java.util.Map; - -@FeignClient( - name = "aasApi", - url = "${feign.registryApi.url}", - configuration = {CatenaApiConfig.class} -) -public interface RegistryApiClient { - - @RequestLine("GET /lookup/shells?assetIds={assetIds}") - List getShellsByAssetIds(@QueryMap Map queryParams); - - @RequestLine("POST /registry/shell-descriptors/fetch") - RegistryShellDescriptorResponse fetchShellDescriptors(List requestBody); - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index 8daa17f1c1..190005f39d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -21,7 +21,6 @@ package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import feign.FeignException; import lombok.extern.slf4j.Slf4j; @@ -30,8 +29,6 @@ import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupMetric; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorLookupMetricRepository; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptorResponse; import org.springframework.beans.factory.annotation.Value; @@ -49,34 +46,23 @@ @Slf4j @Component public class RegistryService { - - private final ObjectMapper objectMapper; - private final RegistryApiClient registryApiClient; private final String applicationBPN; private final String manufacturerIdKey; - private final ShellDescriptorLookupMetricRepository registryLookupMeterRegistry; - private final Clock clock; private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; public RegistryService(ObjectMapper objectMapper, - RegistryApiClient registryApiClient, @Value("${traceability.bpn}") String applicationBPN, @Value("${traceability.registry.manufacturerIdKey}") String manufacturerIdKey, - ShellDescriptorLookupMetricRepository registryLookupMeterRegistry, Clock clock, + Clock clock, DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { - this.objectMapper = objectMapper; - this.registryApiClient = registryApiClient; this.applicationBPN = applicationBPN; this.manufacturerIdKey = manufacturerIdKey; - this.registryLookupMeterRegistry = registryLookupMeterRegistry; - this.clock = clock; this.decentralDigitalTwinRegistryService = decentralDigitalTwinRegistryService; } public List findOwnShellDescriptors() throws RegistryServiceException { - RegistryLookupMetric registryLookupMetric = RegistryLookupMetric.start(clock); log.info("Fetching all shell descriptor IDs for BPN {}.", applicationBPN); @@ -91,7 +77,7 @@ public List findOwnShellDescriptors() throws RegistryServiceExc log.info("DTR Key" + digitalTwinRegistryKey); }); } catch (Exception e) { - endMetric(registryLookupMetric); + log.error("Fetching shell ownShellsRegistryResponse failed", e); } @@ -108,7 +94,6 @@ public List findOwnShellDescriptors() throws RegistryServiceExc ownShellsRegistryResponse = RegistryShellDescriptorResponse.fromCollection(assetAdministrationShellDescriptors); } catch (FeignException e) { - endMetric(registryLookupMetric); log.error("Fetching shell ownShellsRegistryResponse failed", e); @@ -121,42 +106,14 @@ public List findOwnShellDescriptors() throws RegistryServiceExc List ownShellDescriptors = ownShellsRegistryResponse.items().stream() .filter(it -> Objects.nonNull(it.globalAssetId())) - .map(aasDescriptor -> { - logIncomingDescriptor(aasDescriptor, registryLookupMetric); - return aasDescriptor.toShellDescriptor(); - }) - .peek(it -> registryLookupMetric.incrementSuccessShellDescriptorsFetchCount()) + .map(RegistryShellDescriptor::toShellDescriptor) .toList(); log.info("Found {} shell ownShellsRegistryResponse containing a global asset ID.", ownShellDescriptors.size()); - registryLookupMetric.end(clock); - - registryLookupMeterRegistry.save(registryLookupMetric); - return ownShellDescriptors; } - - private void endMetric(RegistryLookupMetric registryLookupMetric) { - registryLookupMetric.incrementFailedShellDescriptorsFetchCount(); - registryLookupMetric.end(clock); - - registryLookupMeterRegistry.save(registryLookupMetric); - } - - private void logIncomingDescriptor(RegistryShellDescriptor descriptor, RegistryLookupMetric registryLookupMetric) { - if (log.isDebugEnabled()) { - try { - String rawDescriptor = objectMapper.writeValueAsString(descriptor); - log.debug("Received shell descriptor: {}", rawDescriptor); - } catch (JsonProcessingException e) { - log.warn("Failed to write rawDescriptor {} as string", descriptor, e); - registryLookupMetric.incrementFailedShellDescriptorsFetchCount(); - } - } - } - private String getFilterValue(String key, String value) { return URLEncoder.encode(String.format("{\"key\":\"%s\",\"value\":\"%s\"}", key, value), StandardCharsets.UTF_8); } diff --git a/tx-backend/src/main/resources/application.yml b/tx-backend/src/main/resources/application.yml index f37a16eb08..4e14f4386e 100644 --- a/tx-backend/src/main/resources/application.yml +++ b/tx-backend/src/main/resources/application.yml @@ -131,8 +131,6 @@ jwt: feign: irsApi: url: ${IRS_URL} - registryApi: - url: ${REGISTRY_URL_WITH_PATH} portalApi: url: ${PORTAL_URL} okhttp: diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index 56b2f4e985..1741e6e091 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -24,13 +24,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey; import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorLookupMetricRepository; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryApiClient; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptorResponse; @@ -54,12 +51,6 @@ class RegistryServiceTest { @InjectMocks private RegistryService registryService; - @Mock - private RegistryApiClient registryApiClient; - - @Mock - private ShellDescriptorLookupMetricRepository registryLookupMeterRegistry; - @Mock private RegistryShellDescriptorResponse registryShellDescriptorResponse; @@ -76,7 +67,7 @@ void setUp() { String bpn = "test-bpn"; String manufacturerIdKey = "test-manufacturer-id-key"; - registryService = new RegistryService(objectMapper, registryApiClient, bpn, manufacturerIdKey, registryLookupMeterRegistry, Clock.systemUTC(), decentralDigitalTwinRegistryService); + registryService = new RegistryService(objectMapper, bpn, manufacturerIdKey, Clock.systemUTC(), decentralDigitalTwinRegistryService); } From 1309af7c24113cb30bad3d9a2b2f48dc8377fa9e Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 08:34:01 +0200 Subject: [PATCH 15/33] chore: TRACEFOSS-2404 removing metric. --- .../RegistryLookupMetricsController.java | 99 ------------ ...PersistentRegistryLookupMeterRegistry.java | 77 ---------- .../model/metrics/RegistryLookupMetric.java | 145 ------------------ .../model/metrics/RegistryLookupStatus.java | 26 ---- ...ShellDescriptorLookupMetricRepository.java | 32 ---- .../JpaRegistryLookupMetricRepository.java | 29 ---- .../RegistryLookupMetricEntity.java | 71 --------- .../rest/registry/RegistryService.java | 8 +- .../shelldescriptor/SpecificAssetId.java | 4 +- .../V29__drop_registry_lookup_metrics.sql | 1 + .../RegistryLookupMetricsControllerTest.java | 56 ------- .../metrics/RegistryLookupMetricTest.java | 122 --------------- .../rest/registry/RegistryServiceTest.java | 3 +- 13 files changed, 5 insertions(+), 668 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryLookupMetricsController.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/PersistentRegistryLookupMeterRegistry.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupMetric.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupStatus.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorLookupMetricRepository.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/JpaRegistryLookupMetricRepository.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/RegistryLookupMetricEntity.java create mode 100644 tx-backend/src/main/resources/db/migration/V29__drop_registry_lookup_metrics.sql delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryLookupMetricsControllerTest.java delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/domain/metrics/RegistryLookupMetricTest.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryLookupMetricsController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryLookupMetricsController.java deleted file mode 100644 index 358ec1eecc..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryLookupMetricsController.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.application; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.constraints.Size; -import lombok.RequiredArgsConstructor; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.common.request.OwnPageable; -import org.eclipse.tractusx.traceability.common.response.ErrorResponse; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupMetric; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorLookupMetricRepository; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping(path = "/metrics", produces = "application/json", consumes = "application/json") -@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR')") -@Tag(name = "Registry") -@RequiredArgsConstructor -public class RegistryLookupMetricsController { - - private final ShellDescriptorLookupMetricRepository registryLookupMeterRegistry; - - @Operation(operationId = "metrics", - summary = "Gets Metrics", - tags = {"Registry"}, - description = "The endpoint gets metrics for database.", - security = @SecurityRequirement(name = "oAuth2", scopes = "profile email")) - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns the paged result found for Asset", content = @Content( - mediaType = "application/json", - array = @ArraySchema(arraySchema = @Schema(description = "RegistryLookupMetric", implementation = RegistryLookupMetric.class, additionalProperties = Schema.AdditionalPropertiesValue.FALSE), maxItems = Integer.MAX_VALUE) - )), - @ApiResponse( - responseCode = "400", - description = "Bad request.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse( - responseCode = "401", - description = "Authorization failed.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponse.class))), - - @ApiResponse( - responseCode = "403", - description = "Forbidden.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse( - responseCode = "429", - description = "Too many requests.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse( - responseCode = "500", - description = "Internal server error.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = ErrorResponse.class)))}) - @GetMapping("/registry-lookup") - public @Size(max = 1000) - @ArraySchema(arraySchema = @Schema(description = "RegistryLookupMetric", implementation = RegistryLookupMetric.class, additionalProperties = Schema.AdditionalPropertiesValue.FALSE), maxItems = Integer.MAX_VALUE) - PageResult metrics(OwnPageable ownPageable) { - return registryLookupMeterRegistry.getMetrics(OwnPageable.toPageable(ownPageable)); - } -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/PersistentRegistryLookupMeterRegistry.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/PersistentRegistryLookupMeterRegistry.java deleted file mode 100644 index d2a6c67bec..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/PersistentRegistryLookupMeterRegistry.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics; - -import lombok.RequiredArgsConstructor; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorLookupMetricRepository; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup.JpaRegistryLookupMetricRepository; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup.RegistryLookupMetricEntity; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -@RequiredArgsConstructor -public class PersistentRegistryLookupMeterRegistry implements ShellDescriptorLookupMetricRepository { - - private final JpaRegistryLookupMetricRepository jpaRegistryLookupMetricRepository; - - @Override - public void save(RegistryLookupMetric registryLookupMetric) { - RegistryLookupMetricEntity registryLookupMetricEntity = registryLookupMetric.toEntity(); - - jpaRegistryLookupMetricRepository.save(registryLookupMetricEntity); - } - - @Override - public PageResult getMetrics(Pageable pageable) { - Pageable pageableWithSorting = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "startDate")); - - List registryLookupMetrics = jpaRegistryLookupMetricRepository.findAll(pageableWithSorting).stream() - .map(RegistryLookupMetricEntity::toDomain) - .toList(); - - for (int i = 0; i < registryLookupMetrics.size(); i++) { - RegistryLookupMetric registryLookupMetric = registryLookupMetrics.get(i); - - if (isLastElement(i, registryLookupMetrics)) { - registryLookupMetric.firstElementDelta(); - } else { - RegistryLookupMetric nextMetric = registryLookupMetrics.get(i + 1); - - registryLookupMetric.addDelta(nextMetric); - } - } - - return new PageResult<>(registryLookupMetrics); - } - - private boolean isLastElement(int index, List registryLookupMetrics) { - return index == registryLookupMetrics.size() - 1; - } - - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupMetric.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupMetric.java deleted file mode 100644 index 0a28a86b8d..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupMetric.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup.RegistryLookupMetricEntity; - -import java.time.Clock; -import java.time.Instant; - -@Data -@ArraySchema(arraySchema = @Schema(description = "RegistryLookupMetric", implementation = RegistryLookupMetric.class, additionalProperties = Schema.AdditionalPropertiesValue.FALSE), maxItems = Integer.MAX_VALUE) -public class RegistryLookupMetric { - - private final Instant startDate; - - private RegistryLookupStatus registryLookupStatus; - - private Long successShellDescriptorsFetchCount; - - private Long failedShellDescriptorsFetchCount; - - private Long shellDescriptorsFetchDelta; - - private Instant endDate; - - @JsonCreator - public RegistryLookupMetric(@JsonFormat(shape = JsonFormat.Shape.STRING) @JsonProperty("startDate") Instant startDate, - @JsonProperty("registryLookupStatus") RegistryLookupStatus registryLookupStatus, - @JsonProperty("successShellDescriptorsFetchCount") Long successShellDescriptorsFetchCount, - @JsonProperty("failedShellDescriptorsFetchCount") Long failedShellDescriptorsFetchCount, - @JsonProperty("shellDescriptorsFetchDelta") Long shellDescriptorsFetchDelta, - @JsonFormat(shape = JsonFormat.Shape.STRING) @JsonProperty("endDate") Instant endDate) { - this.startDate = startDate; - this.registryLookupStatus = registryLookupStatus; - this.successShellDescriptorsFetchCount = successShellDescriptorsFetchCount; - this.failedShellDescriptorsFetchCount = failedShellDescriptorsFetchCount; - this.shellDescriptorsFetchDelta = shellDescriptorsFetchDelta; - this.endDate = endDate; - } - - public RegistryLookupMetric(Instant startDate) { - this.startDate = startDate; - this.successShellDescriptorsFetchCount = 0L; - this.failedShellDescriptorsFetchCount = 0L; - } - - public static RegistryLookupMetric start(Clock clock) { - return new RegistryLookupMetric(clock.instant()); - } - - public RegistryLookupMetric(Instant startDate, - RegistryLookupStatus registryLookupStatus, - Long successShellDescriptorsFetchCount, - Long failedShellDescriptorsFetchCount, - Instant endDate) { - this.startDate = startDate; - this.registryLookupStatus = registryLookupStatus; - this.successShellDescriptorsFetchCount = successShellDescriptorsFetchCount; - this.failedShellDescriptorsFetchCount = failedShellDescriptorsFetchCount; - this.endDate = endDate; - } - - public void incrementSuccessShellDescriptorsFetchCount() { - this.successShellDescriptorsFetchCount += 1; - } - - public void incrementFailedShellDescriptorsFetchCount() { - this.failedShellDescriptorsFetchCount += 1; - } - - public void end(Clock clock) { - if (this.endDate != null) { - throw new IllegalStateException("RegistryLookupMetric already finished"); - } - - this.endDate = clock.instant(); - setStatus(); - } - - public void setStatus() { - if (failedShellDescriptorsFetchCount == 0) { - this.registryLookupStatus = RegistryLookupStatus.SUCCESSFUL; - - return; - } - - if (failedShellDescriptorsFetchCount > 0 && successShellDescriptorsFetchCount == 0) { - this.registryLookupStatus = RegistryLookupStatus.ERROR; - - return; - } - - if (failedShellDescriptorsFetchCount > 0 && successShellDescriptorsFetchCount > 0) { - this.registryLookupStatus = RegistryLookupStatus.PARTIALLY_SUCCESS; - - return; - } - - this.registryLookupStatus = RegistryLookupStatus.SUCCESSFUL; - } - - public RegistryLookupMetricEntity toEntity() { - return RegistryLookupMetricEntity.builder() - .startDate(startDate) - .status(registryLookupStatus) - .successShellDescriptorsFetchCount(successShellDescriptorsFetchCount) - .failedShellDescriptorsFetchCount(failedShellDescriptorsFetchCount) - .endDate(endDate) - .build(); - } - - public void firstElementDelta() { - this.shellDescriptorsFetchDelta = successShellDescriptorsFetchCount; - } - - public void addDelta(RegistryLookupMetric previousMetric) { - this.shellDescriptorsFetchDelta = previousMetric.successShellDescriptorsFetchCount; - } - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupStatus.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupStatus.java deleted file mode 100644 index eb31d3d3b7..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/metrics/RegistryLookupStatus.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics; - -public enum RegistryLookupStatus { - SUCCESSFUL, PARTIALLY_SUCCESS, ERROR -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorLookupMetricRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorLookupMetricRepository.java deleted file mode 100644 index 68485ecc53..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorLookupMetricRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.domain.repository; - -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupMetric; -import org.springframework.data.domain.Pageable; - -public interface ShellDescriptorLookupMetricRepository { - void save(RegistryLookupMetric registryLookupMetric); - - PageResult getMetrics(Pageable pageable); -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/JpaRegistryLookupMetricRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/JpaRegistryLookupMetricRepository.java deleted file mode 100644 index e8fb4443fc..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/JpaRegistryLookupMetricRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface JpaRegistryLookupMetricRepository extends JpaRepository { -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/RegistryLookupMetricEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/RegistryLookupMetricEntity.java deleted file mode 100644 index 75d3052826..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/registrylookup/RegistryLookupMetricEntity.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupMetric; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupStatus; - -import java.time.Instant; - -@Entity -@Table(name = "registry_lookup_metrics") -@Setter -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class RegistryLookupMetricEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - private Instant startDate; - - private RegistryLookupStatus status; - - private Long successShellDescriptorsFetchCount; - - private Long failedShellDescriptorsFetchCount; - - private Instant endDate; - - public static RegistryLookupMetric toDomain(final RegistryLookupMetricEntity entity) { - return new RegistryLookupMetric( - entity.getStartDate(), - entity.getStatus(), - entity.getSuccessShellDescriptorsFetchCount(), - entity.getFailedShellDescriptorsFetchCount(), - entity.getEndDate() - ); - } -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index 190005f39d..cb7672dcef 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -21,7 +21,6 @@ package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry; -import com.fasterxml.jackson.databind.ObjectMapper; import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; @@ -52,8 +51,7 @@ public class RegistryService { private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; - public RegistryService(ObjectMapper objectMapper, - @Value("${traceability.bpn}") String applicationBPN, + public RegistryService(@Value("${traceability.bpn}") String applicationBPN, @Value("${traceability.registry.manufacturerIdKey}") String manufacturerIdKey, Clock clock, DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { @@ -73,9 +71,7 @@ public List findOwnShellDescriptors() throws RegistryServiceExc Collection registryKeys = null; try { registryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers(applicationBPN); - registryKeys.forEach(digitalTwinRegistryKey -> { - log.info("DTR Key" + digitalTwinRegistryKey); - }); + registryKeys.forEach(digitalTwinRegistryKey -> log.info("DTR Key" + digitalTwinRegistryKey)); } catch (Exception e) { log.error("Fetching shell ownShellsRegistryResponse failed", e); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java index fc5768ed8e..70b1d9a067 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java @@ -36,9 +36,7 @@ public SpecificAssetId(String key, String value) { public static List fromList(List keyValuePair) { List specificAssetIds = new ArrayList<>(); - keyValuePair.forEach(keyValuePair1 -> { - specificAssetIds.add(new SpecificAssetId(keyValuePair1.getName(), keyValuePair1.getValue())); - }); + keyValuePair.forEach(keyValuePair1 -> specificAssetIds.add(new SpecificAssetId(keyValuePair1.getName(), keyValuePair1.getValue()))); return specificAssetIds; } diff --git a/tx-backend/src/main/resources/db/migration/V29__drop_registry_lookup_metrics.sql b/tx-backend/src/main/resources/db/migration/V29__drop_registry_lookup_metrics.sql new file mode 100644 index 0000000000..10f249ebef --- /dev/null +++ b/tx-backend/src/main/resources/db/migration/V29__drop_registry_lookup_metrics.sql @@ -0,0 +1 @@ +DROP TABLE registry_lookup_metrics; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryLookupMetricsControllerTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryLookupMetricsControllerTest.java deleted file mode 100644 index 588649fd81..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryLookupMetricsControllerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.assets.application.rest; - -import org.eclipse.tractusx.traceability.common.request.OwnPageable; -import org.eclipse.tractusx.traceability.shelldescriptor.application.RegistryLookupMetricsController; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorLookupMetricRepository; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class RegistryLookupMetricsControllerTest { - - @Mock - private ShellDescriptorLookupMetricRepository registryLookupMeterRegistry; - - @InjectMocks - private RegistryLookupMetricsController controller; - - @Test - void givenRequest_whenMetrics_thenCallRegistry() { - // given - OwnPageable ownPageable = new OwnPageable(0, 1, "createDate,desc"); - - // when - controller.metrics(ownPageable); - - // then - verify(registryLookupMeterRegistry, times(1)).getMetrics(OwnPageable.toPageable(ownPageable)); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/domain/metrics/RegistryLookupMetricTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/domain/metrics/RegistryLookupMetricTest.java deleted file mode 100644 index c7758e7988..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/domain/metrics/RegistryLookupMetricTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 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 - ********************************************************************************/ -package org.eclipse.tractusx.traceability.assets.domain.metrics; - -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupMetric; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.metrics.RegistryLookupStatus; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.registrylookup.RegistryLookupMetricEntity; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -class RegistryLookupMetricTest { - - private Clock clock; - - @BeforeEach - void setUp() { - clock = Clock.systemUTC(); - } - - - @Test - void testEnd() { - // Test case 1: End date is null, should set the end date and update status - Instant startDate = Instant.now(); - RegistryLookupMetric metric = new RegistryLookupMetric(startDate); - Clock clock = Clock.fixed(startDate.plusSeconds(10), ZoneId.systemDefault()); - metric.end(clock); - assertEquals(startDate.plusSeconds(10), metric.getEndDate()); - assertNotNull(metric.getRegistryLookupStatus()); - } - - @Test - void testToEntity() { - Instant startDate = Instant.parse("2023-05-24T10:00:00Z"); - RegistryLookupMetric metric = new RegistryLookupMetric(startDate, - RegistryLookupStatus.SUCCESSFUL, - 10L, - 5L, - Instant.parse("2023-05-24T11:00:00Z")); - - RegistryLookupMetricEntity entity = metric.toEntity(); - - assertEquals(startDate, entity.getStartDate()); - assertEquals(RegistryLookupStatus.SUCCESSFUL, entity.getStatus()); - assertEquals(10L, entity.getSuccessShellDescriptorsFetchCount()); - assertEquals(5L, entity.getFailedShellDescriptorsFetchCount()); - assertEquals(Instant.parse("2023-05-24T11:00:00Z"), entity.getEndDate()); - } - - @Test - void testSetStatus() { - // Test case 1: All counts are zero - RegistryLookupMetric metric1 = new RegistryLookupMetric(null); - metric1.setStatus(); - assertEquals(RegistryLookupStatus.SUCCESSFUL, metric1.getRegistryLookupStatus()); - - // Test case 2: Only success count is zero - RegistryLookupMetric metric2 = new RegistryLookupMetric(null); - metric2.incrementFailedShellDescriptorsFetchCount(); - metric2.setStatus(); - assertEquals(RegistryLookupStatus.ERROR, metric2.getRegistryLookupStatus()); - - // Test case 3: Both success and failure counts are non-zero - RegistryLookupMetric metric3 = new RegistryLookupMetric(null); - metric3.incrementSuccessShellDescriptorsFetchCount(); - metric3.incrementFailedShellDescriptorsFetchCount(); - metric3.setStatus(); - assertEquals(RegistryLookupStatus.PARTIALLY_SUCCESS, metric3.getRegistryLookupStatus()); - - // Test case 4: Only failure count is zero - RegistryLookupMetric metric4 = new RegistryLookupMetric(null); - metric4.incrementSuccessShellDescriptorsFetchCount(); - metric4.setStatus(); - assertEquals(RegistryLookupStatus.SUCCESSFUL, metric4.getRegistryLookupStatus()); - } - - @Test - void testStart() { - RegistryLookupMetric metric = RegistryLookupMetric.start(clock); - assertNotNull(metric.getStartDate()); - assertNull(metric.getRegistryLookupStatus()); - assertEquals(0L, metric.getSuccessShellDescriptorsFetchCount()); - assertEquals(0L, metric.getFailedShellDescriptorsFetchCount()); - assertNull(metric.getEndDate()); - } - - @Test - void testIncrementSuccessShellDescriptorsFetchCount() { - Instant startDate = Instant.now(); - RegistryLookupMetric metric = new RegistryLookupMetric(startDate); - - metric.incrementSuccessShellDescriptorsFetchCount(); - assertEquals(1L, metric.getSuccessShellDescriptorsFetchCount()); - - metric.incrementSuccessShellDescriptorsFetchCount(); - assertEquals(2L, metric.getSuccessShellDescriptorsFetchCount()); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index 1741e6e091..b6c7defbb2 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -63,11 +63,10 @@ class RegistryServiceTest { @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); - ObjectMapper objectMapper = new ObjectMapper(); String bpn = "test-bpn"; String manufacturerIdKey = "test-manufacturer-id-key"; - registryService = new RegistryService(objectMapper, bpn, manufacturerIdKey, Clock.systemUTC(), decentralDigitalTwinRegistryService); + registryService = new RegistryService(bpn, manufacturerIdKey, Clock.systemUTC(), decentralDigitalTwinRegistryService); } From 101f885346d34853c59ec3e2ddd5c799df91cbe3 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 08:41:30 +0200 Subject: [PATCH 16/33] chore: TRACEFOSS-2404 removing metric. --- .../tractusx/traceability/common/support/DatabaseSupport.groovy | 1 - .../traceability/integration/common/support/DatabaseSupport.java | 1 - 2 files changed, 2 deletions(-) diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/DatabaseSupport.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/DatabaseSupport.groovy index 05156da1e5..b6f97a3ace 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/DatabaseSupport.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/DatabaseSupport.groovy @@ -44,7 +44,6 @@ trait DatabaseSupport implements DatabaseProvider { "bpn_storage", "investigation_notification", "investigation", - "registry_lookup_metrics", "bpn_edc_mappings" ] diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/DatabaseSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/DatabaseSupport.java index 6d5b774547..9c86ce60bf 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/DatabaseSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/DatabaseSupport.java @@ -46,7 +46,6 @@ public class DatabaseSupport { "bpn_storage", "investigation_notification", "investigation", - "registry_lookup_metrics", "bpn_edc_mappings" }); From 8cb317a470657aa66dc3580a007c01308c7bb0b0 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 09:13:51 +0200 Subject: [PATCH 17/33] chore: TRACEFOSS-2404 added test --- .../domain/RegistryFacadeTest.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java new file mode 100644 index 0000000000..a2c41d36e2 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.domain; + +import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; +import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsService; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.scheduling.annotation.AsyncResult; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; + +import static org.mockito.Mockito.*; +@ExtendWith(MockitoExtension.class) +class RegistryFacadeTest { + + @Mock + private ShellDescriptorsService shellDescriptorsService; + + @Mock + private RegistryService registryService; + + @Mock + private AssetServiceImpl assetService; + + @InjectMocks + private RegistryFacade registryFacade; + + + @Test + void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { + List shellDescriptors = new ArrayList<>(); + ShellDescriptor shellDescritor = ShellDescriptor.builder().shellDescriptorId("1").build(); + ShellDescriptor shellDescritor2 = ShellDescriptor.builder().shellDescriptorId("2").build(); + shellDescriptors.add(shellDescritor); + shellDescriptors.add(shellDescritor2); + + when(registryService.findOwnShellDescriptors()).thenReturn(shellDescriptors); + when(shellDescriptorsService.update(shellDescriptors)).thenReturn(shellDescriptors); + + + + registryFacade.updateShellDescriptorAndSynchronizeAssets(); + + verify(registryService, times(1)).findOwnShellDescriptors(); + verify(shellDescriptorsService, times(1)).update(shellDescriptors); + } +} From 38e6050bad02dcb85bcd28e1fab6416c73758a69 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 09:20:48 +0200 Subject: [PATCH 18/33] chore: TRACEFOSS-2404 removed clock from init unused --- .../repository/rest/registry/RegistryService.java | 2 -- .../repository/rest/registry/RegistryServiceTest.java | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index cb7672dcef..fb0aa95cfb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -35,7 +35,6 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.time.Clock; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -53,7 +52,6 @@ public class RegistryService { public RegistryService(@Value("${traceability.bpn}") String applicationBPN, @Value("${traceability.registry.manufacturerIdKey}") String manufacturerIdKey, - Clock clock, DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { this.applicationBPN = applicationBPN; this.manufacturerIdKey = manufacturerIdKey; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index b6c7defbb2..5324a5e51e 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -21,7 +21,6 @@ package org.eclipse.tractusx.traceability.assets.infrastructure.repository.rest.registry; -import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey; @@ -39,7 +38,6 @@ import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Clock; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -66,7 +64,7 @@ void setUp() { String bpn = "test-bpn"; String manufacturerIdKey = "test-manufacturer-id-key"; - registryService = new RegistryService(bpn, manufacturerIdKey, Clock.systemUTC(), decentralDigitalTwinRegistryService); + registryService = new RegistryService(bpn, manufacturerIdKey, decentralDigitalTwinRegistryService); } From 4871ad31240ca2e85a226a68d348708c0de36266 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 09:45:50 +0200 Subject: [PATCH 19/33] chore: TRACEFOSS-2404 moved classes --- .../traceability/IntegrationSpecification.groovy | 2 +- .../common/support/ShellDescriptorStoreProvider.groovy | 2 +- .../shelldescriptor/domain/RegistryFacade.java | 4 ++-- ...rsService.java => ShellDescriptorsServiceImpl.java} | 6 +++--- .../shelldescriptor => model}/GlobalAssetId.java | 2 +- .../RegistryShellDescriptor.java | 10 +++++----- .../RegistryShellDescriptorResponse.java | 2 +- .../ShellDescriptorEntity.java | 2 +- .../shelldescriptor => model}/SpecificAssetId.java | 2 +- .../JpaShellDescriptorRepository.java | 3 ++- .../PersistentShellDescriptorsRepository.java | 4 ++-- .../repository/jpa}/ShellDescriptorRepository.java | 2 +- .../repository/rest/registry/RegistryService.java | 4 ++-- .../jpa/shelldescriptor/ShellDescriptorEntityTest.java | 2 +- .../repository/rest/registry/RegistryServiceTest.java | 4 ++-- .../shelldescriptor/domain/RegistryFacadeTest.java | 8 ++------ .../RegistryShellDescriptorResponseTest.java | 4 ++-- .../shelldescriptor/RegistryShellDescriptorTest.java | 4 +++- 18 files changed, 33 insertions(+), 34 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/{ShellDescriptorsService.java => ShellDescriptorsServiceImpl.java} (92%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{repository/rest/registry/shelldescriptor => model}/GlobalAssetId.java (97%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{repository/rest/registry/shelldescriptor => model}/RegistryShellDescriptor.java (88%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{repository/rest/registry/shelldescriptor => model}/RegistryShellDescriptorResponse.java (98%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{repository/jpa/shelldescriptor => model}/ShellDescriptorEntity.java (98%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{repository/rest/registry/shelldescriptor => model}/SpecificAssetId.java (97%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/{shelldescriptor => }/JpaShellDescriptorRepository.java (92%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/{shelldescriptor => }/PersistentShellDescriptorsRepository.java (94%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/{domain/repository => infrastructure/repository/jpa}/ShellDescriptorRepository.java (94%) diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy index 5a0fbc110c..0462738307 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy @@ -36,7 +36,7 @@ import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.aler import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.alert.repository.JpaAlertRepository import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.investigation.repository.JpaInvestigationNotificationRepository import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.investigation.repository.JpaInvestigationRepository -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.jdbc.core.JdbcTemplate diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy index e47bd3f9ed..ced42f386a 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy @@ -22,7 +22,7 @@ package org.eclipse.tractusx.traceability.common.support -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository interface ShellDescriptorStoreProvider { ShellDescriptorRepository shellDescriptorRepository() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java index c44cb8f8e7..f811cac168 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java @@ -26,7 +26,7 @@ import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsService; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -36,7 +36,7 @@ @RequiredArgsConstructor @Component public class RegistryFacade { - private final ShellDescriptorsService shellDescriptorsService; + private final ShellDescriptorsServiceImpl shellDescriptorsService; private final RegistryService registryService; private final AssetServiceImpl assetService; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java similarity index 92% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsService.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java index bbffb1a90d..d14fcee6cb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java @@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -36,11 +36,11 @@ @Slf4j @Component -public class ShellDescriptorsService { +public class ShellDescriptorsServiceImpl { private final ShellDescriptorRepository shellDescriptorRepository; - public ShellDescriptorsService(ShellDescriptorRepository shellDescriptorRepository) { + public ShellDescriptorsServiceImpl(ShellDescriptorRepository shellDescriptorRepository) { this.shellDescriptorRepository = shellDescriptorRepository; } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/GlobalAssetId.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java similarity index 97% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/GlobalAssetId.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java index 3f18e96694..34f1dd001d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/GlobalAssetId.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; import java.util.List; import java.util.Objects; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java similarity index 88% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java index 16fa4f609f..3f699c58fd 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; @@ -27,10 +27,10 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.BATCH_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.MANUFACTURER_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.MANUFACTURER_PART_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor.AssetIdType.PART_INSTANCE_ID; +import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.BATCH_ID; +import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.MANUFACTURER_ID; +import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.MANUFACTURER_PART_ID; +import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.PART_INSTANCE_ID; @Slf4j public record RegistryShellDescriptor( diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponse.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java similarity index 98% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponse.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java index 710f2d0a1a..db72eb5d7c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponse.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java @@ -19,7 +19,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; import lombok.Builder; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java similarity index 98% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntity.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java index 1683bb53ba..6cc5c157f4 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java @@ -19,7 +19,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java similarity index 97% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java index 70b1d9a067..06bc631cf6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/SpecificAssetId.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/JpaShellDescriptorRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java similarity index 92% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/JpaShellDescriptorRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java index 3770c736d8..4fbc1ff9d2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/JpaShellDescriptorRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java @@ -19,8 +19,9 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.ShellDescriptorEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/PersistentShellDescriptorsRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java similarity index 94% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/PersistentShellDescriptorsRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java index 869b36f913..c8e0151d84 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/shelldescriptor/PersistentShellDescriptorsRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java @@ -19,11 +19,11 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.shelldescriptor; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa; import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.ShellDescriptorEntity; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java similarity index 94% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java index a90ddb2cfe..2df87d6af1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java @@ -19,7 +19,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.domain.repository; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index fb0aa95cfb..e791bc9ad0 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -28,8 +28,8 @@ import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptorResponse; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java index fc61dd6f02..c61695f0c0 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java @@ -20,7 +20,7 @@ package org.eclipse.tractusx.traceability.assets.infrastructure.repository.jpa.shelldescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.shelldescriptor.ShellDescriptorEntity; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.ShellDescriptorEntity; import org.junit.jupiter.api.Test; import java.time.ZonedDateTime; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index 5324a5e51e..8b2080d283 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -28,8 +28,8 @@ import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor.RegistryShellDescriptorResponse; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java index a2c41d36e2..d54ee5cd72 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java @@ -21,27 +21,23 @@ import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsService; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.scheduling.annotation.AsyncResult; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Future; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class RegistryFacadeTest { @Mock - private ShellDescriptorsService shellDescriptorsService; + private ShellDescriptorsServiceImpl shellDescriptorsService; @Mock private RegistryService registryService; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java index 597866a6bb..9e71a55f69 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java @@ -25,13 +25,13 @@ import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; import org.junit.jupiter.api.Test; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; class RegistryShellDescriptorResponseTest { diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java index 26e02f53c4..81feacfa9d 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java @@ -2,8 +2,10 @@ import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.GlobalAssetId; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.SpecificAssetId; import org.junit.jupiter.api.Test; import java.util.List; From 850741d67a45f9ec085fbd541de40ee1b58a95d5 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 10:07:32 +0200 Subject: [PATCH 20/33] chore: TRACEFOSS-2404 moved classes --- .../tractusx/traceability/IntegrationSpecification.groovy | 2 +- .../common/support/ShellDescriptorStoreProvider.groovy | 2 +- .../jpa => domain/repository}/ShellDescriptorRepository.java | 2 +- .../domain/service/ShellDescriptorsServiceImpl.java | 2 +- ...ptorsRepository.java => ShellDescriptorRepositoryImpl.java} | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/{infrastructure/repository/jpa => domain/repository}/ShellDescriptorRepository.java (94%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/{PersistentShellDescriptorsRepository.java => ShellDescriptorRepositoryImpl.java} (93%) diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy index 0462738307..5a0fbc110c 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/IntegrationSpecification.groovy @@ -36,7 +36,7 @@ import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.aler import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.alert.repository.JpaAlertRepository import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.investigation.repository.JpaInvestigationNotificationRepository import org.eclipse.tractusx.traceability.qualitynotification.infrastructure.investigation.repository.JpaInvestigationRepository -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.jdbc.core.JdbcTemplate diff --git a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy index ced42f386a..e47bd3f9ed 100644 --- a/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy +++ b/tx-backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/ShellDescriptorStoreProvider.groovy @@ -22,7 +22,7 @@ package org.eclipse.tractusx.traceability.common.support -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository interface ShellDescriptorStoreProvider { ShellDescriptorRepository shellDescriptorRepository() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java similarity index 94% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java index 2df87d6af1..a90ddb2cfe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/ShellDescriptorRepository.java @@ -19,7 +19,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa; +package org.eclipse.tractusx.traceability.shelldescriptor.domain.repository; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java index d14fcee6cb..59026cb3f6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java @@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa.ShellDescriptorRepository; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java similarity index 93% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java index c8e0151d84..07bd82a70c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/PersistentShellDescriptorsRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java @@ -23,6 +23,7 @@ import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.ShellDescriptorEntity; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -33,7 +34,7 @@ @Component @RequiredArgsConstructor -public class PersistentShellDescriptorsRepository implements ShellDescriptorRepository { +public class ShellDescriptorRepositoryImpl implements ShellDescriptorRepository { private final JpaShellDescriptorRepository repository; From bd377c7e0d1e78c915ee9805e509544cc89cfc80 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 11:11:33 +0200 Subject: [PATCH 21/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../assets/domain/model/SemanticModel.java | 9 ----- .../application/ShellDescriptorService.java | 27 +++++++++++++ .../domain/RegistryFacade.java | 8 ++-- .../domain/model/ShellDescriptor.java | 8 +--- .../service/ShellDescriptorsServiceImpl.java | 9 ++--- .../model/RegistryShellDescriptor.java | 39 ------------------- .../model/ShellDescriptorEntity.java | 19 +-------- .../jpa/JpaShellDescriptorRepository.java | 2 +- .../jpa/ShellDescriptorRepositoryImpl.java | 2 +- .../rest/registry/RegistryService.java | 9 +---- tx-backend/src/main/resources/application.yml | 1 - .../V30__drop_and_reset_shell_descriptors.sql | 9 +++++ .../rest/registry/RegistryServiceTest.java | 4 +- 13 files changed, 50 insertions(+), 96 deletions(-) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java create mode 100644 tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/model/SemanticModel.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/model/SemanticModel.java index f63fff9e94..7a641c153d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/model/SemanticModel.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/model/SemanticModel.java @@ -59,15 +59,6 @@ public static SemanticModel from(AssetAsBuiltEntity assetAsBuiltEntity) { .build(); } - public static SemanticModel from(ShellDescriptor shellDescriptor) { - return SemanticModel.builder() - .manufacturerPartId(shellDescriptor.getManufacturerPartId()) - .nameAtManufacturer(shellDescriptor.getIdShort()) - .nameAtCustomer(shellDescriptor.getIdShort()) - .manufacturingCountry("--") - .manufacturerPartId(defaultValue(shellDescriptor.getManufacturerPartId())) - .build(); - } public static SemanticModel from(PartTypeInformation partTypeInformation, ManufacturingInformation manufacturingInformation) { return SemanticModel.builder() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java new file mode 100644 index 0000000000..47d9c97d62 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java @@ -0,0 +1,27 @@ +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.application; + +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; + +import java.util.List; + +public interface ShellDescriptorService { + List update(List ownShellDescriptors); +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java index f811cac168..a215f4434d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java @@ -23,10 +23,10 @@ import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; -import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; +import org.eclipse.tractusx.traceability.assets.application.rest.service.AssetService; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; +import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorService; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -36,9 +36,9 @@ @RequiredArgsConstructor @Component public class RegistryFacade { - private final ShellDescriptorsServiceImpl shellDescriptorsService; + private final ShellDescriptorService shellDescriptorsService; private final RegistryService registryService; - private final AssetServiceImpl assetService; + private final AssetService assetService; @Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR) public void updateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java index 8fb3be19b2..116d963ade 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java @@ -28,12 +28,6 @@ @Data @Builder public class ShellDescriptor { - private String shellDescriptorId; + private Long id; private String globalAssetId; - private String idShort; - private String partInstanceId; - private String manufacturerPartId; - private String manufacturerId; - private String batchId; - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java index 59026cb3f6..98f5fc6ac7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java @@ -21,7 +21,9 @@ package org.eclipse.tractusx.traceability.shelldescriptor.domain.service; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorService; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; import org.springframework.stereotype.Component; @@ -36,14 +38,11 @@ @Slf4j @Component -public class ShellDescriptorsServiceImpl { +@RequiredArgsConstructor +public class ShellDescriptorsServiceImpl implements ShellDescriptorService { private final ShellDescriptorRepository shellDescriptorRepository; - public ShellDescriptorsServiceImpl(ShellDescriptorRepository shellDescriptorRepository) { - this.shellDescriptorRepository = shellDescriptorRepository; - } - @Transactional public List update(List ownShellDescriptors) { log.info("Starting update of {} shell ownShellDescriptors.", ownShellDescriptors.size()); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java index 3f699c58fd..7c7b480802 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java @@ -24,13 +24,6 @@ import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.BATCH_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.MANUFACTURER_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.MANUFACTURER_PART_ID; -import static org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor.AssetIdType.PART_INSTANCE_ID; @Slf4j public record RegistryShellDescriptor( @@ -40,49 +33,17 @@ public record RegistryShellDescriptor( List specificAssetIds ) { public ShellDescriptor toShellDescriptor() { - String shellDescriptorId = identification(); String globalAssetId = globalAssetId().value().stream() .findFirst() .orElse(null); log.info("toShellDescriptor: {}", specificAssetIds); - Map assetIdsMap = specificAssetIds().stream() - .distinct() - .collect(Collectors.toMap(entry -> entry.key().toLowerCase(), SpecificAssetId::value)); - - String manufacturerPartId = assetIdsMap.get(MANUFACTURER_PART_ID.asKey()); - String partInstanceId = assetIdsMap.get(PART_INSTANCE_ID.asKey()); - String manufacturerId = assetIdsMap.get(MANUFACTURER_ID.asKey()); - String batchId = assetIdsMap.get(BATCH_ID.asKey()); return ShellDescriptor.builder() - .shellDescriptorId(shellDescriptorId) .globalAssetId(globalAssetId) - .idShort(idShort()) - .partInstanceId(partInstanceId) - .manufacturerPartId(manufacturerPartId) - .manufacturerId(manufacturerId) - .batchId(batchId) .build(); } public static RegistryShellDescriptor from(AssetAdministrationShellDescriptor assetAdministrationShellDescriptor) { return new RegistryShellDescriptor(GlobalAssetId.from(List.of(assetAdministrationShellDescriptor.getGlobalAssetId())), assetAdministrationShellDescriptor.getId(), assetAdministrationShellDescriptor.getIdShort(), SpecificAssetId.fromList(assetAdministrationShellDescriptor.getSpecificAssetIds())); } - - enum AssetIdType { - MANUFACTURER_PART_ID("manufacturerPartId"), - PART_INSTANCE_ID("partInstanceId"), - MANUFACTURER_ID("manufacturerId"), - BATCH_ID("batchId"); - - private final String value; - - AssetIdType(String value) { - this.value = value; - } - - public String asKey() { - return this.value.toLowerCase(); - } - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java index 6cc5c157f4..01fe6db8e7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/ShellDescriptorEntity.java @@ -46,13 +46,7 @@ public class ShellDescriptorEntity { private Long id; private ZonedDateTime created; private ZonedDateTime updated; - private String shellDescriptorId; private String globalAssetId; - private String idShort; - private String partInstanceId; - private String manufacturerPartId; - private String batchId; - private String manufacturerId; public static ShellDescriptorEntity newEntityFrom(final ShellDescriptor descriptor) { ZonedDateTime now = ZonedDateTime.now(); @@ -60,25 +54,14 @@ public static ShellDescriptorEntity newEntityFrom(final ShellDescriptor descript .id(null) .created(now) .updated(now) - .shellDescriptorId(descriptor.getShellDescriptorId()) .globalAssetId(descriptor.getGlobalAssetId()) - .idShort(descriptor.getIdShort()) - .partInstanceId(descriptor.getPartInstanceId()) - .manufacturerPartId(descriptor.getManufacturerPartId()) - .batchId(descriptor.getBatchId()) - .manufacturerId(descriptor.getManufacturerId()) .build(); } public ShellDescriptor toShellDescriptor() { return ShellDescriptor.builder() - .shellDescriptorId(shellDescriptorId) + .id(id) .globalAssetId(globalAssetId) - .idShort(idShort) - .manufacturerId(manufacturerId) - .manufacturerPartId(manufacturerPartId) - .batchId(batchId) - .partInstanceId(partInstanceId) .build(); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java index 4fbc1ff9d2..022743a0be 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/JpaShellDescriptorRepository.java @@ -30,6 +30,6 @@ @Repository public interface JpaShellDescriptorRepository extends JpaRepository { - Optional findByShellDescriptorId(String shellDescriptorId); + void deleteAllByUpdatedBefore(ZonedDateTime dateTime); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java index 07bd82a70c..66a6d15a3e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImpl.java @@ -48,7 +48,7 @@ public List findAll() { @Override @Transactional public void update(ShellDescriptor shellDescriptor) { - repository.findByShellDescriptorId(shellDescriptor.getShellDescriptorId()).ifPresent(entity -> { + repository.findById(shellDescriptor.getId()).ifPresent(entity -> { entity.setUpdated(ZonedDateTime.now()); repository.save(entity); }); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java index e791bc9ad0..eb73232fbc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java @@ -45,16 +45,12 @@ @Component public class RegistryService { private final String applicationBPN; - private final String manufacturerIdKey; - private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; public RegistryService(@Value("${traceability.bpn}") String applicationBPN, - @Value("${traceability.registry.manufacturerIdKey}") String manufacturerIdKey, DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { this.applicationBPN = applicationBPN; - this.manufacturerIdKey = manufacturerIdKey; this.decentralDigitalTwinRegistryService = decentralDigitalTwinRegistryService; } @@ -62,10 +58,6 @@ public List findOwnShellDescriptors() throws RegistryServiceExc log.info("Fetching all shell descriptor IDs for BPN {}.", applicationBPN); - Map ownManufacturerIdBPNMap = new HashMap<>(); - - ownManufacturerIdBPNMap.put("assetIds", getFilterValue(manufacturerIdKey, applicationBPN)); - Collection registryKeys = null; try { registryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers(applicationBPN); @@ -111,4 +103,5 @@ public List findOwnShellDescriptors() throws RegistryServiceExc private String getFilterValue(String key, String value) { return URLEncoder.encode(String.format("{\"key\":\"%s\",\"value\":\"%s\"}", key, value), StandardCharsets.UTF_8); } + } diff --git a/tx-backend/src/main/resources/application.yml b/tx-backend/src/main/resources/application.yml index 4e14f4386e..3f2b162ae9 100644 --- a/tx-backend/src/main/resources/application.yml +++ b/tx-backend/src/main/resources/application.yml @@ -22,7 +22,6 @@ traceability: bpn: ${TRACEABILITY_BPN} url: ${TRACEABILITY_URL} - registry.manufacturerIdKey: manufacturerId edc: ids: diff --git a/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql b/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql new file mode 100644 index 0000000000..c4de5ccf86 --- /dev/null +++ b/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql @@ -0,0 +1,9 @@ +DROP TABLE shell_descriptor; + +CREATE TABLE shell_descriptor +( + id SERIAL PRIMARY KEY, + created TIMESTAMPTZ NOT NULL, + updated TIMESTAMPTZ NOT NULL, + global_asset_id TEXT NOT NULL UNIQUE, +); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java index 8b2080d283..fc02fee785 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java @@ -62,9 +62,7 @@ class RegistryServiceTest { void setUp() { MockitoAnnotations.openMocks(this); String bpn = "test-bpn"; - String manufacturerIdKey = "test-manufacturer-id-key"; - - registryService = new RegistryService(bpn, manufacturerIdKey, decentralDigitalTwinRegistryService); + registryService = new RegistryService(bpn, decentralDigitalTwinRegistryService); } From a78b88b5bd1f84621ac42da8cc72a7950f50ef6b Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 11:21:44 +0200 Subject: [PATCH 22/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../ShellDescriptorEntityTest.java | 29 ++----------------- .../domain/RegistryFacadeTest.java | 4 +-- .../RegistryShellDescriptorTest.java | 2 +- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java index c61695f0c0..fb27a05529 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/jpa/shelldescriptor/ShellDescriptorEntityTest.java @@ -37,13 +37,7 @@ void givenEntity_whenToShellDescriptor_themConvertCorrectly() { .id(1L) .created(now) .updated(now) - .shellDescriptorId("shellDescriptorId") .globalAssetId("globalAssetId") - .idShort("idShort") - .partInstanceId("partInstanceId") - .manufacturerPartId("manufacturerPartId") - .batchId("batchId") - .manufacturerId("manufacturerId") .build(); // when @@ -51,26 +45,14 @@ void givenEntity_whenToShellDescriptor_themConvertCorrectly() { // then assertThat(result) - .hasFieldOrPropertyWithValue("shellDescriptorId", entity.getShellDescriptorId()) - .hasFieldOrPropertyWithValue("globalAssetId", entity.getGlobalAssetId()) - .hasFieldOrPropertyWithValue("idShort", entity.getIdShort()) - .hasFieldOrPropertyWithValue("partInstanceId", entity.getPartInstanceId()) - .hasFieldOrPropertyWithValue("manufacturerPartId", entity.getManufacturerPartId()) - .hasFieldOrPropertyWithValue("manufacturerId", entity.getManufacturerId()) - .hasFieldOrPropertyWithValue("batchId", entity.getBatchId()); + .hasFieldOrPropertyWithValue("globalAssetId", entity.getGlobalAssetId()); } @Test void givenDescriptor_whenNewEntityFrom_thenCreateNewEntity() { // given ShellDescriptor descriptor = ShellDescriptor.builder() - .shellDescriptorId("shellDescriptorId") .globalAssetId("globalAssetId") - .idShort("idShort") - .partInstanceId("partInstanceId") - .manufacturerPartId("manufacturerPartId") - .manufacturerId("manufacturerId") - .batchId("batchId") .build(); // when @@ -78,14 +60,7 @@ void givenDescriptor_whenNewEntityFrom_thenCreateNewEntity() { // then assertThat(result).usingRecursiveComparison() - .comparingOnlyFields( - "shellDescriptorId", - "globalAssetId", - "idShort", - "partInstanceId", - "manufacturerPartId", - "manufacturerId", - "batchId"); + .comparingOnlyFields("globalAssetId"); assertThat(result).hasNoNullFieldsOrPropertiesExcept("id"); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java index d54ee5cd72..b7ba14a2a7 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java @@ -52,8 +52,8 @@ class RegistryFacadeTest { @Test void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { List shellDescriptors = new ArrayList<>(); - ShellDescriptor shellDescritor = ShellDescriptor.builder().shellDescriptorId("1").build(); - ShellDescriptor shellDescritor2 = ShellDescriptor.builder().shellDescriptorId("2").build(); + ShellDescriptor shellDescritor = ShellDescriptor.builder().globalAssetId("1").build(); + ShellDescriptor shellDescritor2 = ShellDescriptor.builder().globalAssetId("2").build(); shellDescriptors.add(shellDescritor); shellDescriptors.add(shellDescritor2); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java index 81feacfa9d..0dd82efcf3 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java @@ -26,7 +26,7 @@ void test_ToShellDescriptor() { ShellDescriptor shellDescriptor = registryShellDescriptor.toShellDescriptor(); //THEN - assertEquals("manufacturerPartId", shellDescriptor.getManufacturerPartId()); + assertEquals("assetId1", shellDescriptor.getGlobalAssetId()); } @Test From c25b998c04e696fbbf5ba6e40a38000ea1ea552b Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 11:38:56 +0200 Subject: [PATCH 23/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../domain/RegistryFacade.java | 23 +++- .../domain/model/ShellDescriptor.java | 13 +++ .../rest/registry/RegistryService.java | 107 ------------------ .../rest/registry/RegistryServiceTest.java | 97 ---------------- .../domain/RegistryFacadeTest.java | 6 +- 5 files changed, 33 insertions(+), 213 deletions(-) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java index a215f4434d..c8f401a76a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java @@ -22,27 +22,32 @@ package org.eclipse.tractusx.traceability.shelldescriptor.domain; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.assets.application.rest.service.AssetService; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; +import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorService; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import java.util.Collections; import java.util.List; @RequiredArgsConstructor +@Slf4j @Component public class RegistryFacade { private final ShellDescriptorService shellDescriptorsService; - private final RegistryService registryService; private final AssetService assetService; + private final TraceabilityProperties traceabilityProperties; + private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; @Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR) - public void updateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { - List shellDescriptorList = registryService.findOwnShellDescriptors(); + public void updateShellDescriptorAndSynchronizeAssets() { + List shellDescriptorList = retrieveShellDescriptorsByBpn(traceabilityProperties.getBpn().toString()); List updatedShellDescriptorList = shellDescriptorsService.update(shellDescriptorList); synchronizeAssetsByDescriptors(updatedShellDescriptorList); } @@ -52,4 +57,14 @@ private void synchronizeAssetsByDescriptors(List descriptors) { .map(ShellDescriptor::getGlobalAssetId) .forEach(assetService::synchronizeAssetsAsync); } + + private List retrieveShellDescriptorsByBpn(String bpn) { + try { + return ShellDescriptor.fromGlobalAssetIds(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(bpn)); + } catch (RegistryServiceException exception) { + log.warn("Could not retrieve globalAssetIds by bpn {}", bpn); + return Collections.emptyList(); + } + } } + diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java index 116d963ade..618dbfaa9d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java @@ -24,10 +24,23 @@ import lombok.Builder; import lombok.Data; +import java.util.Collection; +import java.util.List; + @Data @Builder public class ShellDescriptor { private Long id; private String globalAssetId; + + public static ShellDescriptor fromGlobalAssetId(String globalAssetId) { + return ShellDescriptor.builder() + .globalAssetId(globalAssetId) + .build(); + } + + public static List fromGlobalAssetIds(Collection globalAssetIds) { + return globalAssetIds.stream().map(ShellDescriptor::fromGlobalAssetId).toList(); + } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java deleted file mode 100644 index eb73232fbc..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/RegistryService.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry; - -import feign.FeignException; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; -import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; -import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -@Slf4j -@Component -public class RegistryService { - private final String applicationBPN; - private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; - - - public RegistryService(@Value("${traceability.bpn}") String applicationBPN, - DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService) { - this.applicationBPN = applicationBPN; - this.decentralDigitalTwinRegistryService = decentralDigitalTwinRegistryService; - } - - public List findOwnShellDescriptors() throws RegistryServiceException { - - log.info("Fetching all shell descriptor IDs for BPN {}.", applicationBPN); - - Collection registryKeys = null; - try { - registryKeys = decentralDigitalTwinRegistryService.lookupShellIdentifiers(applicationBPN); - registryKeys.forEach(digitalTwinRegistryKey -> log.info("DTR Key" + digitalTwinRegistryKey)); - } catch (Exception e) { - - log.error("Fetching shell ownShellsRegistryResponse failed", e); - } - - log.info("Fetching shell ownShellsRegistryResponse."); - - final RegistryShellDescriptorResponse ownShellsRegistryResponse; - try { - Collection assetAdministrationShellDescriptors = decentralDigitalTwinRegistryService.fetchShells(registryKeys); - assetAdministrationShellDescriptors.forEach(assetAdministrationShellDescriptor -> { - log.info("Asset Administration Shell Descriptor " + assetAdministrationShellDescriptor); - log.info("Asset Administration Global Asset Id " + assetAdministrationShellDescriptor.getGlobalAssetId()); - }); - - ownShellsRegistryResponse = RegistryShellDescriptorResponse.fromCollection(assetAdministrationShellDescriptors); - - } catch (FeignException e) { - - log.error("Fetching shell ownShellsRegistryResponse failed", e); - - throw e; - } - - log.info("Received {} shell ownShellsRegistryResponse for {} IDs.", - ownShellsRegistryResponse.items().size(), - registryKeys == null ? 0 : registryKeys.size()); - - List ownShellDescriptors = ownShellsRegistryResponse.items().stream() - .filter(it -> Objects.nonNull(it.globalAssetId())) - .map(RegistryShellDescriptor::toShellDescriptor) - .toList(); - - log.info("Found {} shell ownShellsRegistryResponse containing a global asset ID.", ownShellDescriptors.size()); - - return ownShellDescriptors; - } - - private String getFilterValue(String key, String value) { - return URLEncoder.encode(String.format("{\"key\":\"%s\",\"value\":\"%s\"}", key, value), StandardCharsets.UTF_8); - } - -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java deleted file mode 100644 index fc02fee785..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/repository/rest/registry/RegistryServiceTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.assets.infrastructure.repository.rest.registry; - -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; -import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; -import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class RegistryServiceTest { - - @InjectMocks - private RegistryService registryService; - - @Mock - private RegistryShellDescriptorResponse registryShellDescriptorResponse; - - @Mock - private RegistryShellDescriptor registryShellDescriptor; - - @Mock - private DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; - - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - String bpn = "test-bpn"; - registryService = new RegistryService(bpn, decentralDigitalTwinRegistryService); - - } - - @Test - void testFindAssets() throws RegistryServiceException { - // Given - List registryKeys = List.of( - new DigitalTwinRegistryKey("assetId", "test-bpn") - ); - when(decentralDigitalTwinRegistryService.lookupShellIdentifiers("test-bpn")).thenReturn(registryKeys); - final String globalAssetId = "GLOBAL_ASSET_ID"; - final String idShort = "ID_SHORT"; - final String identification = "IDENTIFICATION"; - final String keyIdentifier = "KEY_IDENTIFIER"; - final String valueIdentifier = "VALUE_IDENTIFIER"; - IdentifierKeyValuePair identifierKeyValuePair = IdentifierKeyValuePair.builder().name(keyIdentifier).value(valueIdentifier).build(); - final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor = AssetAdministrationShellDescriptor.builder() - .globalAssetId(globalAssetId) - .idShort(idShort) - .id(identification) - .specificAssetIds(List.of(identifierKeyValuePair)) - .build(); - List administrationShellDescriptors = List.of(assetAdministrationShellDescriptor); - when(decentralDigitalTwinRegistryService.fetchShells(registryKeys)).thenReturn(administrationShellDescriptors); - - // When - List shellDescriptors = registryService.findOwnShellDescriptors(); - - // Then - assertThat(shellDescriptors).hasSize(1); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java index b7ba14a2a7..6a7645151a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java @@ -22,7 +22,6 @@ import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.RegistryService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -39,8 +38,6 @@ class RegistryFacadeTest { @Mock private ShellDescriptorsServiceImpl shellDescriptorsService; - @Mock - private RegistryService registryService; @Mock private AssetServiceImpl assetService; @@ -57,14 +54,13 @@ void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceExcep shellDescriptors.add(shellDescritor); shellDescriptors.add(shellDescritor2); - when(registryService.findOwnShellDescriptors()).thenReturn(shellDescriptors); + when(shellDescriptorsService.update(shellDescriptors)).thenReturn(shellDescriptors); registryFacade.updateShellDescriptorAndSynchronizeAssets(); - verify(registryService, times(1)).findOwnShellDescriptors(); verify(shellDescriptorsService, times(1)).update(shellDescriptors); } } From 9a642d082cc151bdd241de17db003cfbc6c47709 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 13:05:10 +0200 Subject: [PATCH 24/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../domain/RegistryFacadeTest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java index 6a7645151a..217a5b523a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java @@ -18,8 +18,11 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.shelldescriptor.domain; +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; +import org.eclipse.tractusx.traceability.common.model.BPN; +import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.junit.jupiter.api.Test; @@ -31,14 +34,21 @@ import java.util.ArrayList; import java.util.List; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + @ExtendWith(MockitoExtension.class) class RegistryFacadeTest { @Mock private ShellDescriptorsServiceImpl shellDescriptorsService; + @Mock + private DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; + @Mock + private TraceabilityProperties traceabilityProperties; @Mock private AssetServiceImpl assetService; @@ -48,19 +58,20 @@ class RegistryFacadeTest { @Test void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceException { + // Given List shellDescriptors = new ArrayList<>(); ShellDescriptor shellDescritor = ShellDescriptor.builder().globalAssetId("1").build(); ShellDescriptor shellDescritor2 = ShellDescriptor.builder().globalAssetId("2").build(); shellDescriptors.add(shellDescritor); shellDescriptors.add(shellDescritor2); + when(traceabilityProperties.getBpn()).thenReturn(BPN.of("test")); + List globalAssetIds = List.of("1", "2"); + when(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(BPN.of("test").toString())).thenReturn(globalAssetIds); - - when(shellDescriptorsService.update(shellDescriptors)).thenReturn(shellDescriptors); - - - + // When registryFacade.updateShellDescriptorAndSynchronizeAssets(); + // Then verify(shellDescriptorsService, times(1)).update(shellDescriptors); } } From dafa85e586a5f3099d610d15b43792da9730ddab Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 13:53:49 +0200 Subject: [PATCH 25/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../application/DecentralRegistryService.java | 23 ++++++ .../application/RegistryController.java | 8 +- .../ShellDescriptorRefreshJob.java | 30 ++++--- .../application/ShellDescriptorService.java | 2 +- .../domain/model/ShellDescriptor.java | 1 - .../DecentralRegistryRepository.java} | 41 ++-------- .../DecentralRegistryServiceImpl.java} | 29 +++---- .../service/ShellDescriptorsServiceImpl.java | 2 +- .../RegistryShellDescriptorResponse.java | 78 ------------------- .../infrastructure/model/SpecificAssetId.java | 72 ----------------- .../DecentralRegistryRepositoryImpl.java} | 42 +++++----- .../rest/RegistryControllerTest.java | 4 +- .../ShellDescriptorRefreshJobTest.java | 6 +- ...tralDecentralRegistryServiceImplTest.java} | 7 +- .../RegistryShellDescriptorResponseTest.java | 66 ---------------- .../RegistryShellDescriptorTest.java | 61 --------------- .../shelldescriptor/ShellDescriptorTest.java | 34 ++++++++ 17 files changed, 120 insertions(+), 386 deletions(-) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/{infrastructure/scheduler => application}/ShellDescriptorRefreshJob.java (67%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/{infrastructure/model/GlobalAssetId.java => domain/repository/DecentralRegistryRepository.java} (50%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/{RegistryFacade.java => service/DecentralRegistryServiceImpl.java} (67%) delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java delete mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/{model/RegistryShellDescriptor.java => rest/DecentralRegistryRepositoryImpl.java} (51%) rename tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/{RegistryFacadeTest.java => DecentralDecentralRegistryServiceImplTest.java} (90%) delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java delete mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/ShellDescriptorTest.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java new file mode 100644 index 0000000000..2c2b06e42b --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/DecentralRegistryService.java @@ -0,0 +1,23 @@ +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.application; + +public interface DecentralRegistryService { + void updateShellDescriptorAndSynchronizeAssets(); +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryController.java index 0652cc8941..539e874c4e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/RegistryController.java @@ -29,9 +29,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.common.response.ErrorResponse; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.RegistryFacade; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -42,7 +40,7 @@ @RequiredArgsConstructor public class RegistryController { - private final RegistryFacade registryFacade; + private final DecentralRegistryService decentralRegistryService; @Operation(operationId = "reload", summary = "Triggers reload of shell descriptors", @@ -82,7 +80,7 @@ public class RegistryController { mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class)))}) @GetMapping("/reload") - public void reload() throws RegistryServiceException { - registryFacade.updateShellDescriptorAndSynchronizeAssets(); + public void reload() { + decentralRegistryService.updateShellDescriptorAndSynchronizeAssets(); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/scheduler/ShellDescriptorRefreshJob.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorRefreshJob.java similarity index 67% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/scheduler/ShellDescriptorRefreshJob.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorRefreshJob.java index 4d154fc555..17c3849177 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/scheduler/ShellDescriptorRefreshJob.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorRefreshJob.java @@ -19,33 +19,29 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.scheduler; +package org.eclipse.tractusx.traceability.shelldescriptor.application; +import lombok.RequiredArgsConstructor; import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; -import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.common.config.ApplicationProfiles; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.RegistryFacade; import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component @Profile(ApplicationProfiles.NOT_TESTS) +@RequiredArgsConstructor public class ShellDescriptorRefreshJob { - private final RegistryFacade registryFacade; + private final DecentralRegistryService decentralRegistryService; - public ShellDescriptorRefreshJob(RegistryFacade registryFacade) { - this.registryFacade = registryFacade; - } - - @Scheduled(cron = "0 0 */2 * * ?", zone = "Europe/Berlin") - @SchedulerLock( - name = "data-sync-lock", - lockAtLeastFor = "PT5M", - lockAtMostFor = "PT15M" - ) - public void refresh() throws RegistryServiceException { - registryFacade.updateShellDescriptorAndSynchronizeAssets(); - } + @Scheduled(cron = "0 0 */2 * * ?", zone = "Europe/Berlin") + @SchedulerLock( + name = "data-sync-lock", + lockAtLeastFor = "PT5M", + lockAtMostFor = "PT15M" + ) + public void refresh() { + decentralRegistryService.updateShellDescriptorAndSynchronizeAssets(); + } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java index 47d9c97d62..0bbe2ce413 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/application/ShellDescriptorService.java @@ -23,5 +23,5 @@ import java.util.List; public interface ShellDescriptorService { - List update(List ownShellDescriptors); + List determineExistingShellDescriptorsAndUpdate(List ownShellDescriptors); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java index 618dbfaa9d..88fe3840c4 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/model/ShellDescriptor.java @@ -27,7 +27,6 @@ import java.util.Collection; import java.util.List; - @Data @Builder public class ShellDescriptor { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/DecentralRegistryRepository.java similarity index 50% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/DecentralRegistryRepository.java index 34f1dd001d..3b86e2a8f9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/GlobalAssetId.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/repository/DecentralRegistryRepository.java @@ -17,43 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; +package org.eclipse.tractusx.traceability.shelldescriptor.domain.repository; -import java.util.List; -import java.util.Objects; - -public final class GlobalAssetId { - private final List value; - - public GlobalAssetId(List value) { - this.value = value; - } - - public static GlobalAssetId from(List ids) { - return new GlobalAssetId(ids); - } +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; - public List value() { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (GlobalAssetId) obj; - return Objects.equals(this.value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(value); - } - - @Override - public String toString() { - return "GlobalAssetId[" + - "value=" + value + ']'; - } +import java.util.List; +public interface DecentralRegistryRepository { + List retrieveShellDescriptorsByBpn(String bpn); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/DecentralRegistryServiceImpl.java similarity index 67% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/DecentralRegistryServiceImpl.java index c8f401a76a..78492d4320 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/DecentralRegistryServiceImpl.java @@ -19,52 +19,41 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.domain; +package org.eclipse.tractusx.traceability.shelldescriptor.domain.service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; -import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.assets.application.rest.service.AssetService; import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; +import org.eclipse.tractusx.traceability.shelldescriptor.application.DecentralRegistryService; import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorService; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.DecentralRegistryRepository; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import java.util.Collections; import java.util.List; @RequiredArgsConstructor @Slf4j @Component -public class RegistryFacade { +public class DecentralRegistryServiceImpl implements DecentralRegistryService { + private final ShellDescriptorService shellDescriptorsService; private final AssetService assetService; private final TraceabilityProperties traceabilityProperties; - private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; + private final DecentralRegistryRepository decentralRegistryRepository; @Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR) public void updateShellDescriptorAndSynchronizeAssets() { - List shellDescriptorList = retrieveShellDescriptorsByBpn(traceabilityProperties.getBpn().toString()); - List updatedShellDescriptorList = shellDescriptorsService.update(shellDescriptorList); - synchronizeAssetsByDescriptors(updatedShellDescriptorList); - } + List shellDescriptorList = decentralRegistryRepository.retrieveShellDescriptorsByBpn(traceabilityProperties.getBpn().toString()); - private void synchronizeAssetsByDescriptors(List descriptors) { - descriptors.stream() + List updatedShellDescriptorList = shellDescriptorsService.determineExistingShellDescriptorsAndUpdate(shellDescriptorList); + updatedShellDescriptorList.stream() .map(ShellDescriptor::getGlobalAssetId) .forEach(assetService::synchronizeAssetsAsync); } - private List retrieveShellDescriptorsByBpn(String bpn) { - try { - return ShellDescriptor.fromGlobalAssetIds(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(bpn)); - } catch (RegistryServiceException exception) { - log.warn("Could not retrieve globalAssetIds by bpn {}", bpn); - return Collections.emptyList(); - } - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java index 98f5fc6ac7..ba63925f1c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImpl.java @@ -44,7 +44,7 @@ public class ShellDescriptorsServiceImpl implements ShellDescriptorService { private final ShellDescriptorRepository shellDescriptorRepository; @Transactional - public List update(List ownShellDescriptors) { + public List determineExistingShellDescriptorsAndUpdate(List ownShellDescriptors) { log.info("Starting update of {} shell ownShellDescriptors.", ownShellDescriptors.size()); Map existingDescriptors = shellDescriptorRepository.findAll().stream() .collect(Collectors.toMap(ShellDescriptor::getGlobalAssetId, Function.identity())); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java deleted file mode 100644 index db72eb5d7c..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptorResponse.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * Copyright (c) 2022, 2023 ZF Friedrichshafen AG - * Copyright (c) 2022, 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; - -import lombok.Builder; -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; - -@Builder -public class RegistryShellDescriptorResponse { - private final List items; - - public RegistryShellDescriptorResponse( - List items - ) { - this.items = items; - } - - public static RegistryShellDescriptorResponse fromCollection(Collection assetAdministrationShellDescriptors) { - List registryShellDescriptors = new ArrayList<>(); - assetAdministrationShellDescriptors.forEach(assetAdministrationShellDescriptor -> { - RegistryShellDescriptor registryShellDescriptor = RegistryShellDescriptor.from(assetAdministrationShellDescriptor); - registryShellDescriptors.add(registryShellDescriptor); - }); - - return RegistryShellDescriptorResponse.builder() - .items(registryShellDescriptors) - .build(); - } - - public List items() { - return items; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (RegistryShellDescriptorResponse) obj; - return Objects.equals(this.items, that.items); - } - - @Override - public int hashCode() { - return Objects.hash(items); - } - - @Override - public String toString() { - return "RegistryShellDescriptorResponse[" + - "items=" + items + ']'; - } - -} - diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java deleted file mode 100644 index 06bc631cf6..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/SpecificAssetId.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; - -import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class SpecificAssetId { - private final String key; - private final String value; - - public SpecificAssetId(String key, String value) { - this.key = key; - this.value = value; - } - - public static List fromList(List keyValuePair) { - List specificAssetIds = new ArrayList<>(); - keyValuePair.forEach(keyValuePair1 -> specificAssetIds.add(new SpecificAssetId(keyValuePair1.getName(), keyValuePair1.getValue()))); - return specificAssetIds; - } - - public String key() { - return key; - } - - public String value() { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (SpecificAssetId) obj; - return Objects.equals(this.key, that.key) && - Objects.equals(this.value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(key, value); - } - - @Override - public String toString() { - return "SpecificAssetId[" + - "key=" + key + ", " + - "value=" + value + ']'; - } - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImpl.java similarity index 51% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImpl.java index 7c7b480802..57f91c0991 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/model/RegistryShellDescriptor.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImpl.java @@ -17,33 +17,35 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model; +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.rest; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; +import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.DecentralRegistryRepository; +import org.springframework.stereotype.Component; +import java.util.Collections; import java.util.List; @Slf4j -public record RegistryShellDescriptor( - GlobalAssetId globalAssetId, - String identification, - String idShort, - List specificAssetIds -) { - public ShellDescriptor toShellDescriptor() { - String globalAssetId = globalAssetId().value().stream() - .findFirst() - .orElse(null); - log.info("toShellDescriptor: {}", specificAssetIds); - - return ShellDescriptor.builder() - .globalAssetId(globalAssetId) - .build(); - } +@Component +@RequiredArgsConstructor +public class DecentralRegistryRepositoryImpl implements DecentralRegistryRepository { + + private final DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; - public static RegistryShellDescriptor from(AssetAdministrationShellDescriptor assetAdministrationShellDescriptor) { - return new RegistryShellDescriptor(GlobalAssetId.from(List.of(assetAdministrationShellDescriptor.getGlobalAssetId())), assetAdministrationShellDescriptor.getId(), assetAdministrationShellDescriptor.getIdShort(), SpecificAssetId.fromList(assetAdministrationShellDescriptor.getSpecificAssetIds())); + @Override + public List retrieveShellDescriptorsByBpn(String bpn) { + try { + return ShellDescriptor.fromGlobalAssetIds(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(bpn)); + } catch (RegistryServiceException exception) { + log.warn("Could not retrieve globalAssetIds by bpn {}", bpn); + return Collections.emptyList(); + } } + + } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryControllerTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryControllerTest.java index 70074182d0..2d308dc1ca 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryControllerTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/application/rest/RegistryControllerTest.java @@ -21,7 +21,7 @@ import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.shelldescriptor.application.RegistryController; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.RegistryFacade; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.DecentralRegistryServiceImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -35,7 +35,7 @@ class RegistryControllerTest { @Mock - private RegistryFacade registryFacade; + private DecentralRegistryServiceImpl registryFacade; @InjectMocks private RegistryController registryController; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/scheduler/ShellDescriptorRefreshJobTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/scheduler/ShellDescriptorRefreshJobTest.java index 3813f59faa..e3ffd8a3be 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/scheduler/ShellDescriptorRefreshJobTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/scheduler/ShellDescriptorRefreshJobTest.java @@ -23,8 +23,8 @@ import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.RegistryFacade; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.scheduler.ShellDescriptorRefreshJob; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.DecentralRegistryServiceImpl; +import org.eclipse.tractusx.traceability.shelldescriptor.application.ShellDescriptorRefreshJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -39,7 +39,7 @@ class ShellDescriptorRefreshJobTest { @Mock - private RegistryFacade registryFacade; + private DecentralRegistryServiceImpl registryFacade; @Test void refresh_shouldCallLoadShellDescriptors() throws RegistryServiceException { diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java similarity index 90% rename from tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java rename to tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java index 217a5b523a..aba37297ff 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/RegistryFacadeTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java @@ -24,6 +24,7 @@ import org.eclipse.tractusx.traceability.common.model.BPN; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.DecentralRegistryServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -39,7 +40,7 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -class RegistryFacadeTest { +class DecentralDecentralRegistryServiceImplTest { @Mock private ShellDescriptorsServiceImpl shellDescriptorsService; @@ -53,7 +54,7 @@ class RegistryFacadeTest { private AssetServiceImpl assetService; @InjectMocks - private RegistryFacade registryFacade; + private DecentralRegistryServiceImpl registryFacade; @Test @@ -72,6 +73,6 @@ void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceExcep registryFacade.updateShellDescriptorAndSynchronizeAssets(); // Then - verify(shellDescriptorsService, times(1)).update(shellDescriptors); + verify(shellDescriptorsService, times(1)).determineExistingShellDescriptorsAndUpdate(shellDescriptors); } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java deleted file mode 100644 index 9e71a55f69..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorResponseTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2021,2022,2023 - * 2022: ZF Friedrichshafen AG - * 2022: ISTOS GmbH - * 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * 2022,2023: BOSCH AG - * Copyright (c) 2021,2022,2023 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 - ********************************************************************************/ - -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; - -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; -import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptorResponse; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -class RegistryShellDescriptorResponseTest { - - @Test - void givenRegistryShellDescriptorResponse_whenFromCollection_thenCorrectMapping() { - // given - final String globalAssetId = "GLOBAL_ASSET_ID"; - final String idShort = "ID_SHORT"; - final String identification = "IDENTIFICATION"; - final String keyIdentifier = "KEY_IDENTIFIER"; - final String valueIdentifier = "VALUE_IDENTIFIER"; - IdentifierKeyValuePair identifierKeyValuePair = IdentifierKeyValuePair.builder().name(keyIdentifier).value(valueIdentifier).build(); - final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor = AssetAdministrationShellDescriptor.builder() - .globalAssetId(globalAssetId) - .idShort(idShort) - .id(identification) - .specificAssetIds(List.of(identifierKeyValuePair)) - .build(); - final RegistryShellDescriptor expectedDescriptor = RegistryShellDescriptor.from(assetAdministrationShellDescriptor); - - // when - final RegistryShellDescriptorResponse result = RegistryShellDescriptorResponse.fromCollection(List.of(assetAdministrationShellDescriptor)); - - // then - assertThat(result.items()) - .hasSize(1) - .containsExactly(expectedDescriptor); - assertThat(result).isEqualTo(RegistryShellDescriptorResponse.builder().items(List.of(expectedDescriptor)).build()); - assertThat(result.toString()).hasToString("RegistryShellDescriptorResponse[" + - "items=" + List.of(expectedDescriptor) + ']'); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java deleted file mode 100644 index 0dd82efcf3..0000000000 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/RegistryShellDescriptorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; - -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; -import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.GlobalAssetId; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.RegistryShellDescriptor; -import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.SpecificAssetId; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - -class RegistryShellDescriptorTest { - - @Test - void test_ToShellDescriptor() { - //GIVEN - GlobalAssetId globalAssetId = new GlobalAssetId(List.of("assetId1", "assetId2")); - List specificAssetIds = List.of(new SpecificAssetId("manufacturerPartId", "manufacturerPartId")); - RegistryShellDescriptor registryShellDescriptor = new RegistryShellDescriptor(globalAssetId, "", "", specificAssetIds); - - //WHEN - ShellDescriptor shellDescriptor = registryShellDescriptor.toShellDescriptor(); - - //THEN - assertEquals("assetId1", shellDescriptor.getGlobalAssetId()); - } - - @Test - void givenAssetAdministrationShellDescriptor_whenFrom_thenConvertProperly() { - // given - final String globalAssetId = "GLOBAL_ASSET_ID"; - final String idShort = "ID_SHORT"; - final String identification = "IDENTIFICATION"; - final String keyIdentifier = "KEY_IDENTIFIER"; - final String valueIdentifier = "VALUE_IDENTIFIER"; - IdentifierKeyValuePair identifierKeyValuePair = IdentifierKeyValuePair.builder().name(keyIdentifier).value(valueIdentifier).build(); - final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor = AssetAdministrationShellDescriptor.builder() - .globalAssetId(globalAssetId) - .idShort(idShort) - .id(identification) - .specificAssetIds(List.of(identifierKeyValuePair)) - .build(); - - // when - final RegistryShellDescriptor result = RegistryShellDescriptor.from(assetAdministrationShellDescriptor); - - // then - assertThat(result.globalAssetId().value()) - .containsExactly(globalAssetId); - assertThat(result.identification()).isEqualTo(identification); - assertThat(result.idShort()).isEqualTo(idShort); - assertThat(result.specificAssetIds()) - .hasSize(1) - .first().hasFieldOrPropertyWithValue("key", keyIdentifier) - .hasFieldOrPropertyWithValue("value", valueIdentifier); - } -} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/ShellDescriptorTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/ShellDescriptorTest.java new file mode 100644 index 0000000000..9d2a62f434 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/rest/registry/shelldescriptor/ShellDescriptorTest.java @@ -0,0 +1,34 @@ +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.rest.registry.shelldescriptor; + +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class ShellDescriptorTest { + + @Test + void testFromGlobalAssetId() { + String globalAssetId = "ABC123"; + ShellDescriptor descriptor = ShellDescriptor.fromGlobalAssetId(globalAssetId); + + assertThat(descriptor).isNotNull(); + assertThat(descriptor.getGlobalAssetId()).isEqualTo(globalAssetId); + } + + @Test + void testFromGlobalAssetIds() { + List globalAssetIds = Arrays.asList("ABC123", "DEF456", "GHI789"); + List descriptors = ShellDescriptor.fromGlobalAssetIds(globalAssetIds); + + assertThat(descriptors).isNotNull().hasSize(globalAssetIds.size()); + + for (int i = 0; i < globalAssetIds.size(); i++) { + assertThat(descriptors.get(i)).isNotNull(); + assertThat(descriptors.get(i).getGlobalAssetId()).isEqualTo(globalAssetIds.get(i)); + } + } +} From 14fd55e32456cebfe67ffdce67edf7fcc62e0f52 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 14:01:36 +0200 Subject: [PATCH 26/33] chore: TRACEFOSS-2404 refactored shelldescriptor table --- .../domain/DecentralDecentralRegistryServiceImplTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java index aba37297ff..2cc17a7d5d 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/DecentralDecentralRegistryServiceImplTest.java @@ -18,12 +18,12 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.shelldescriptor.domain; -import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.traceability.assets.domain.service.AssetServiceImpl; import org.eclipse.tractusx.traceability.common.model.BPN; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.DecentralRegistryRepository; import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.DecentralRegistryServiceImpl; import org.eclipse.tractusx.traceability.shelldescriptor.domain.service.ShellDescriptorsServiceImpl; import org.junit.jupiter.api.Test; @@ -46,7 +46,7 @@ class DecentralDecentralRegistryServiceImplTest { private ShellDescriptorsServiceImpl shellDescriptorsService; @Mock - private DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; + private DecentralRegistryRepository decentralRegistryRepository; @Mock private TraceabilityProperties traceabilityProperties; @@ -66,8 +66,7 @@ void testUpdateShellDescriptorAndSynchronizeAssets() throws RegistryServiceExcep shellDescriptors.add(shellDescritor); shellDescriptors.add(shellDescritor2); when(traceabilityProperties.getBpn()).thenReturn(BPN.of("test")); - List globalAssetIds = List.of("1", "2"); - when(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(BPN.of("test").toString())).thenReturn(globalAssetIds); + when(decentralRegistryRepository.retrieveShellDescriptorsByBpn(BPN.of("test").toString())).thenReturn(shellDescriptors); // When registryFacade.updateShellDescriptorAndSynchronizeAssets(); From 97b854a67cc4d9ff14f039ce8cf1a00035a9e43b Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 14:39:54 +0200 Subject: [PATCH 27/33] chore: TRACEFOSS-2404 added some unit tests. --- .../ShellDescriptorsServiceImplTest.java | 68 ++++++++++ .../ShellDescriptorRepositoryImplTest.java | 116 ++++++++++++++++++ .../DecentralRegistryRepositoryImplTest.java | 77 ++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImplTest.java create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImplTest.java create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImplTest.java diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImplTest.java new file mode 100644 index 0000000000..336b8693f8 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/domain/service/ShellDescriptorsServiceImplTest.java @@ -0,0 +1,68 @@ + +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.domain.service; + +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.repository.ShellDescriptorRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ShellDescriptorsServiceImplTest { + + @Mock + private ShellDescriptorRepository shellDescriptorRepository; + + @InjectMocks + private ShellDescriptorsServiceImpl shellDescriptorsService; + + @Test + void testDetermineExistingShellDescriptorsAndUpdate() { + // Given + List ownShellDescriptors = new ArrayList<>(); + ShellDescriptor existingDescriptor = ShellDescriptor.builder().globalAssetId("existing-id").build(); + ownShellDescriptors.add(existingDescriptor); + ShellDescriptor newDescriptor = ShellDescriptor.builder().globalAssetId("new-id").build(); + ownShellDescriptors.add(newDescriptor); + + when(shellDescriptorRepository.findAll()).thenReturn(List.of(existingDescriptor)); + + + // When + shellDescriptorsService.determineExistingShellDescriptorsAndUpdate(ownShellDescriptors); + + // Then + verify(shellDescriptorRepository, times(1)).saveAll(List.of(newDescriptor)); + verify(shellDescriptorRepository, times(1)).removeDescriptorsByUpdatedBefore(any(ZonedDateTime.class)); + verify(shellDescriptorRepository, times(1)).update(existingDescriptor); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImplTest.java new file mode 100644 index 0000000000..c509aa087c --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/repository/jpa/ShellDescriptorRepositoryImplTest.java @@ -0,0 +1,116 @@ +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.repository.jpa; + +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.model.ShellDescriptorEntity; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ShellDescriptorRepositoryImplTest { + + @Mock + private JpaShellDescriptorRepository repository; + + @InjectMocks + private ShellDescriptorRepositoryImpl shellDescriptorRepository; + + + @Test + void testFindAll() { + // Given + List entities = new ArrayList<>(); + entities.add(new ShellDescriptorEntity(/* create entity */)); + entities.add(new ShellDescriptorEntity(/* create entity */)); + + when(repository.findAll()).thenReturn(entities); + + shellDescriptorRepository = new ShellDescriptorRepositoryImpl(repository); + + // Act + List descriptors = shellDescriptorRepository.findAll(); + + // Then + verify(repository, times(1)).findAll(); + + } + + @Test + void testUpdate() { + // Given + ShellDescriptor descriptor = ShellDescriptor.builder().id(1L).build(); + ShellDescriptorEntity entity = new ShellDescriptorEntity(/* create entity */); + + when(repository.findById(descriptor.getId())).thenReturn(Optional.of(entity)); + when(repository.save(entity)).thenReturn(entity); + + shellDescriptorRepository = new ShellDescriptorRepositoryImpl(repository); + + // When + shellDescriptorRepository.update(descriptor); + + // Then + verify(repository, times(1)).findById(descriptor.getId()); + verify(repository, times(1)).save(entity); + } + + @Test + void testSaveAll() { + // Given + List descriptors = new ArrayList<>(); + descriptors.add(ShellDescriptor.builder().build()); + descriptors.add(ShellDescriptor.builder().build()); + + shellDescriptorRepository = new ShellDescriptorRepositoryImpl(repository); + + // When + shellDescriptorRepository.saveAll(descriptors); + + // Then + verify(repository, times(1)).saveAll(anyList()); + } + + @Test + void testRemoveDescriptorsByUpdatedBefore() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + shellDescriptorRepository = new ShellDescriptorRepositoryImpl(repository); + + // When + shellDescriptorRepository.removeDescriptorsByUpdatedBefore(now); + + // Then + verify(repository, times(1)).deleteAllByUpdatedBefore(now); + } +} diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImplTest.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImplTest.java new file mode 100644 index 0000000000..f3297ed2bf --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/shelldescriptor/infrastructure/rest/DecentralRegistryRepositoryImplTest.java @@ -0,0 +1,77 @@ +/******************************************************************************** + * Copyright (c) 2023 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 + ********************************************************************************/ +package org.eclipse.tractusx.traceability.shelldescriptor.infrastructure.rest; + +import org.eclipse.tractusx.irs.registryclient.decentral.DecentralDigitalTwinRegistryService; +import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; +import org.eclipse.tractusx.traceability.shelldescriptor.domain.model.ShellDescriptor; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class DecentralRegistryRepositoryImplTest { + @Mock + private DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService; + + @InjectMocks + private DecentralRegistryRepositoryImpl decentralRegistryRepository; + + @Test + void testRetrieveShellDescriptorsByBpnSuccess() throws RegistryServiceException { + // Given + String bpn = "12345"; + List globalAssetIds = Arrays.asList("asset1", "asset2"); + List expectedDescriptors = ShellDescriptor.fromGlobalAssetIds(globalAssetIds); + + when(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(bpn)).thenReturn(globalAssetIds); + + decentralRegistryRepository = new DecentralRegistryRepositoryImpl(decentralDigitalTwinRegistryService); + + // When + List actualDescriptors = decentralRegistryRepository.retrieveShellDescriptorsByBpn(bpn); + + // Then + assertThat(actualDescriptors).isEqualTo(expectedDescriptors); + } + + @Test + void testRetrieveShellDescriptorsByBpnRegistryServiceException() throws RegistryServiceException { + // Given + String bpn = "12345"; + + when(decentralDigitalTwinRegistryService.lookupGlobalAssetIds(bpn)).thenThrow(new RegistryServiceException("Error")); + + decentralRegistryRepository = new DecentralRegistryRepositoryImpl(decentralDigitalTwinRegistryService); + + // When + List actualDescriptors = decentralRegistryRepository.retrieveShellDescriptorsByBpn(bpn); + + // Then + assertThat(actualDescriptors).isEmpty(); + } +} From 56332e3a391b0735ff9c5e2d04f51822b29fe8f7 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 14:43:08 +0200 Subject: [PATCH 28/33] chore: TRACEFOSS-2404 added changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be9fa6e1bb..a6f7e874dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Changed digitalTwinRegistryRestTemplate to use token in requests - Update asBuild test data to 1.5.3 and asPlanned to 1.5.1 - Changed transfer notification logic not to break iteration loop when sending notifications to bpn with more than 1 connector endpoints - +- Decentral flow only using bpn for resolving globalAssetIds +- ### Removed ## [6.0.0 - 2023-07-21] From 4394a5c73e0c14e2c7790fe25bcd4713d599aff7 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 15 Aug 2023 16:03:54 +0200 Subject: [PATCH 29/33] chore: TRACEFOSS-XXX added todo --- .../traceability/assets/infrastructure/base/irs/IrsService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/IrsService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/IrsService.java index d338693d0f..a97ced4ce9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/IrsService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/IrsService.java @@ -75,6 +75,7 @@ public List findAssets(String globalAssetId, Direction direction, List Date: Wed, 16 Aug 2023 07:58:15 +0200 Subject: [PATCH 30/33] feature: TRACEFOSS-2320 Changed styling of fonts --- .../request-notification.base.html | 2 +- .../start-investigation.component.html | 4 ++-- frontend/src/theme/base.scss | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/modules/shared/components/request-notification/request-notification.base.html b/frontend/src/app/modules/shared/components/request-notification/request-notification.base.html index 6f466c6e64..0f834850ed 100644 --- a/frontend/src/app/modules/shared/components/request-notification/request-notification.base.html +++ b/frontend/src/app/modules/shared/components/request-notification/request-notification.base.html @@ -19,7 +19,7 @@ SPDX-License-Identifier: Apache-2.0 --> -

{{ this.context + '.headline' | i18n }}

+

{{ this.context + '.headline' | i18n }}

{{ 'requestNotification.partDescription' | i18n }}

diff --git a/frontend/src/app/modules/shared/modules/part-details/presentation/start-investigation/start-investigation.component.html b/frontend/src/app/modules/shared/modules/part-details/presentation/start-investigation/start-investigation.component.html index daad9be059..ca7e516dad 100644 --- a/frontend/src/app/modules/shared/modules/part-details/presentation/start-investigation/start-investigation.component.html +++ b/frontend/src/app/modules/shared/modules/part-details/presentation/start-investigation/start-investigation.component.html @@ -19,7 +19,7 @@ SPDX-License-Identifier: Apache-2.0 --> -

{{ 'partDetail.investigation.headline' | i18n }}

+

{{ 'partDetail.investigation.headline' | i18n }}

@@ -36,7 +36,7 @@

{{ 'partDetail.investigation.head
no_sim -

{{ 'partDetail.investigation.noSelection.header' | i18n }}

+

{{ 'partDetail.investigation.noSelection.header' | i18n }}

{{ 'partDetail.investigation.noSelection.text' | i18n }}

diff --git a/frontend/src/theme/base.scss b/frontend/src/theme/base.scss index 2f024ef3a6..e4238fce53 100644 --- a/frontend/src/theme/base.scss +++ b/frontend/src/theme/base.scss @@ -35,15 +35,34 @@ font-size: 56px; } + h1, + normal-case { + @apply font-medium text-dark; + font-size: 56px; + text-transform: none; + } + h2 { @apply font-medium uppercase text-dark; font-size: 36px; } + h2, + normal-case{ + @apply font-medium uppercase text-dark; + font-size: 36px; + text-transform: none; + } + h3 { @apply font-semiBold sm:text-xl text-dark; font-size: 24px; } + h3, + upper-case{ + @apply uppercase font-semiBold sm:text-xl text-dark; + font-size: 24px; + } h4 { @apply font-semiBold sm:text-lg text-dark; From 0c6dbb3403bd9e1bb90974164fe6990514153879 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 16 Aug 2023 09:14:18 +0200 Subject: [PATCH 31/33] feature: TRACEFOSS-2473 Added sonar action for cron --- .github/workflows/sonar-scan-backend.yml | 2 ++ .github/workflows/sonar-scan-frontend.yml | 41 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .github/workflows/sonar-scan-frontend.yml diff --git a/.github/workflows/sonar-scan-backend.yml b/.github/workflows/sonar-scan-backend.yml index f86bf51c9e..54391e83cc 100644 --- a/.github/workflows/sonar-scan-backend.yml +++ b/.github/workflows/sonar-scan-backend.yml @@ -6,6 +6,8 @@ on: - 'tx-backend/**' branches: - main + schedule: + - cron: "0 0 * * *" env: JAVA_VERSION: 17 diff --git a/.github/workflows/sonar-scan-frontend.yml b/.github/workflows/sonar-scan-frontend.yml new file mode 100644 index 0000000000..54683f2768 --- /dev/null +++ b/.github/workflows/sonar-scan-frontend.yml @@ -0,0 +1,41 @@ +name: Sonar Frontend + +on: + push: + branches: [ main ] + workflow_dispatch: + schedule: + - cron: "0 0 * * *" + +jobs: + build: + + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Install chrome + uses: browser-actions/setup-chrome@latest + - name: Install yarn + run: npm install yarn -g + - name: Install packages + run: yarn install + - name: Run yarn test:ci + run: CHROMIUM_BIN=$(which chrome) yarn test:ci # will run `test:ci` command + - name: Run SonarCloud check + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }} + with: + projectBaseDir: frontend + args: > + -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} + -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_FRONTEND }} From d34dc58dc361b27b631f8e3fba2f9aa43a676f59 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 16 Aug 2023 09:28:46 +0200 Subject: [PATCH 32/33] feature: TRACEFOSS-2473 configured that tests work again. --- .../shared/assembler/notificationMenuActions.assembler.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts b/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts index d2d26ef8f0..deff82eabe 100644 --- a/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts +++ b/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts @@ -31,7 +31,7 @@ import { Severity } from '@shared/model/severity.model'; import { CloseNotificationModalComponent } from '@shared/modules/notification/modal/close/close-notification-modal.component'; import { KeycloakService } from 'keycloak-angular'; -fdescribe('NotificationMenuActionsAssembler', () => { +describe('NotificationMenuActionsAssembler', () => { let helperService: AlertHelperService | InvestigationHelperService; let notificationCommonModalComponent: NotificationCommonModalComponent; From df620f05659659dabb05648555c5106cfcf51d85 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 16 Aug 2023 10:37:22 +0200 Subject: [PATCH 33/33] feature: TRACEFOSS-XXX fix flyway issue. --- .../db/migration/V30__drop_and_reset_shell_descriptors.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql b/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql index c4de5ccf86..2aeb24a449 100644 --- a/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql +++ b/tx-backend/src/main/resources/db/migration/V30__drop_and_reset_shell_descriptors.sql @@ -5,5 +5,5 @@ CREATE TABLE shell_descriptor id SERIAL PRIMARY KEY, created TIMESTAMPTZ NOT NULL, updated TIMESTAMPTZ NOT NULL, - global_asset_id TEXT NOT NULL UNIQUE, + global_asset_id TEXT NOT NULL UNIQUE );