Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to eclipse #155

Merged
merged 24 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7300c45
feat(data-integrity): Add module to enrich testdata with data integri…
ds-jhartmann Jul 31, 2023
2c1e6f6
fix(testdata): fix local shell upload
ds-jhartmann Jul 31, 2023
7a5f4a2
feat(data-integrity): Add readme and testdatafile with integrity aspect
ds-jhartmann Jul 31, 2023
6f0391e
feat(data-integrity): Fix pom
ds-jhartmann Jul 31, 2023
61fce7b
feat(data-integrity): Fix signature creation and add irs- prefix
ds-jhartmann Aug 1, 2023
c58e355
feat(data-integrity): Fix Tests and PMD issues
ds-jhartmann Aug 3, 2023
2e8dd9d
feat(data-integrity): Fix docker build
ds-jhartmann Aug 3, 2023
21953f4
feat(data-integrity): Update cx ids
ds-jhartmann Aug 3, 2023
76fc6f6
feat(data-integrity): Exclude irs-testdata-upload from coverage
ds-jhartmann Aug 3, 2023
c0d6ee5
feat(data-integrity): Exclude spotbugs finding
ds-jhartmann Aug 3, 2023
2464de4
feat(data-integrity): Add DataIntegrity JSON-Schema
ds-jhartmann Aug 3, 2023
ff3538b
feat(data-integrity): Add Testcases for error paths
ds-jhartmann Aug 4, 2023
49891aa
feat(data-integrity): Fix spotbugs path
ds-jhartmann Aug 7, 2023
7af31e5
feat(data-integrity): Remove invalid javadoc
ds-jhartmann Aug 7, 2023
5412c9a
chore(dependencies): Update DEPENDENCIES
ds-jhartmann Aug 8, 2023
94f8c3d
Merge branch 'main' into feature/TRI-1291-data-integrity-testdata
ds-ext-abugajewski Aug 14, 2023
6e8c653
feat(data-integrity): [TRI-1291] [DATA_INTEGRITY_LAYER] Extend/Provid…
ds-ext-abugajewski Aug 14, 2023
5db5bf5
feat(impl):[CXRM-1835] include foss files in jar, remove from docker …
ds-ext-kmassalski Aug 21, 2023
8bdc933
Merge pull request #484 from catenax-ng/feature/CXRM-1835-include-fos…
mkanal Aug 21, 2023
d382f93
Merge pull request #466 from catenax-ng/feature/TRI-1291-data-integri…
mkanal Aug 21, 2023
d9fb4b5
feat(impl):[TRI-1835] add notice license to documentation
ds-ext-kmassalski Aug 21, 2023
2199b07
Merge pull request #486 from catenax-ng/feature/CXRM-1835-add-notice-…
ds-ext-kmassalski Aug 21, 2023
7059383
feat(impl):[TRI-1469] delete doc file
ds-ext-kmassalski Aug 22, 2023
fd4cfe7
Merge pull request #487 from catenax-ng/feature/TRI-1469-delete-doc-file
mkanal Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .config/spotbugs-excludes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@
<Class name="org.eclipse.tractusx.irs.semanticshub.SemanticsHubClientImpl"/>
<Bug pattern="PATH_TRAVERSAL_IN,WEAK_FILENAMEUTILS"/>
</Match>
<Match>
<!-- The application is intended to access all files -->
<Class name="org.eclipse.tractusx.irs.testing.dataintegrity.TestdataTransformer"/>
<Bug pattern="PATH_TRAVERSAL_IN"/>
</Match>
</FindBugsFilter>
3 changes: 3 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved,
maven/mavencentral/org.aspectj/aspectjweaver/1.9.19, EPL-1.0, approved, tools.aspectj
maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161
maven/mavencentral/org.bouncycastle/bcpkix-jdk18on/1.75, MIT, approved, #9166
maven/mavencentral/org.bouncycastle/bcpkix-jdk18on/1.76, MIT, approved, #9825
maven/mavencentral/org.bouncycastle/bcprov-jdk18on/1.75, MIT AND CC0-1.0, approved, #9167
maven/mavencentral/org.bouncycastle/bcprov-jdk18on/1.76, MIT AND CC0-1.0, approved, #9827
maven/mavencentral/org.bouncycastle/bcutil-jdk18on/1.75, MIT, approved, #9170
maven/mavencentral/org.bouncycastle/bcutil-jdk18on/1.76, MIT, approved, #9828
maven/mavencentral/org.checkerframework/checker-qual/3.33.0, MIT, approved, clearlydefined
maven/mavencentral/org.eclipse.edc/aggregate-service-spi/0.1.3, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/asset-spi/0.1.3, Apache-2.0, approved, technology.edc
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ COPY irs-report-aggregate irs-report-aggregate
COPY irs-cucumber-tests irs-cucumber-tests
COPY docs docs
COPY irs-load-tests irs-load-tests
COPY irs-testdata-upload irs-testdata-upload

# the --mount option requires BuildKit.
RUN --mount=type=cache,target=/root/.m2 mvn -B clean package -pl :$BUILD_TARGET -am -DskipTests
Expand All @@ -60,10 +61,6 @@ WORKDIR /app

COPY --chmod=755 --from=maven /build/irs-api/target/irs-api-*-exec.jar app.jar

COPY LICENSE LICENSE
COPY NOTICE.md NOTICE.md
COPY DEPENDENCIES DEPENDENCIES

USER ${UID}:${GID}

ENTRYPOINT ["java", "-Djava.util.logging.config.file=./logging.properties", "-jar", "app.jar"]
Expand Down
12 changes: 12 additions & 0 deletions docs/src/docs/administration/administration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ include::system-overview.adoc[leveloffset=+1]
include::installation.adoc[leveloffset=+1]
include::configuration.adoc[leveloffset=+1]
include::troubleshooting.adoc[leveloffset=+1]

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2021, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
- SPDX-FileCopyrightText: 2022, 2023 BOSCH AG
- SPDX-FileCopyrightText: 2021, 2022 ZF Friedrichshafen AG
- SPDX-FileCopyrightText: 2022 ISTOS GmbH
- SPDX-FileCopyrightText: 2021, 2023 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/item-relationship-service
12 changes: 12 additions & 0 deletions docs/src/docs/arc42/full.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ include::deployment-view/index.adoc[leveloffset=+1]
include::cross-cutting/full.adoc[leveloffset=+1]
include::quality/index.adoc[leveloffset=+1]
include::glossary.adoc[leveloffset=+1]

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2021, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
- SPDX-FileCopyrightText: 2022, 2023 BOSCH AG
- SPDX-FileCopyrightText: 2021, 2022 ZF Friedrichshafen AG
- SPDX-FileCopyrightText: 2022 ISTOS GmbH
- SPDX-FileCopyrightText: 2021, 2023 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/item-relationship-service
14 changes: 13 additions & 1 deletion docs/src/docs/arc42/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@
- xref:deployment-view/index.adoc[Deployment view]
- xref:cross-cutting/index.adoc[Cross-cutting concepts]
- xref:quality/index.adoc[Quality requirements]
- xref:glossary.adoc[Glossary]
- xref:glossary.adoc[Glossary]

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2021, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
- SPDX-FileCopyrightText: 2022, 2023 BOSCH AG
- SPDX-FileCopyrightText: 2021, 2022 ZF Friedrichshafen AG
- SPDX-FileCopyrightText: 2022 ISTOS GmbH
- SPDX-FileCopyrightText: 2021, 2023 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/item-relationship-service
19 changes: 10 additions & 9 deletions docs/src/docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ xref:api-specification/api-specification.adoc[OpenApi specification]
- xref:arc42/index.adoc[Single chapters]
- xref:arc42/full.adoc[Full document]

== License
* SPDX-License-Identifier: CC-BY-4.0
* Licence Path: https://creativecommons.org/licenses/by/4.0/legalcode
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2022 ZF Friedrichshafen AG
* Copyright (c) 2022 ISTOS GmbH
* Copyright (c) 2021,2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2022,2023 BOSCH AG
## NOTICE

* Source URL: https://github.com/eclipse-tractusx/item-relationship-service
This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2021, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
- SPDX-FileCopyrightText: 2022, 2023 BOSCH AG
- SPDX-FileCopyrightText: 2021, 2022 ZF Friedrichshafen AG
- SPDX-FileCopyrightText: 2022 ISTOS GmbH
- SPDX-FileCopyrightText: 2021, 2023 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/item-relationship-service
14 changes: 14 additions & 0 deletions irs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@
</dependencies>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}/..</directory>
<includes>
<include>LICENSE</include>
<include>NOTICE.md</include>
<include>DEPENDENCIES</include>
</includes>
<targetPath>META-INF/</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
87 changes: 87 additions & 0 deletions irs-testdata-upload/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.tractusx.irs</groupId>
<artifactId>irs-parent-spring-boot</artifactId>
<version>${revision}</version>
<relativePath>../irs-parent-spring-boot</relativePath>
</parent>

<artifactId>irs-testdata-upload</artifactId>

<name>IRS Testdata Utilities</name>
<description>Item Relationship Service Testdata Utilities</description>

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.76</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.76</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-assertj</artifactId>
<version>${json-unit-assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.eclipse.tractusx.irs.testing.dataintegrity.TestdataTransformer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/********************************************************************************
* 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.irs.testing.dataintegrity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.util.encoders.Hex;
import org.eclipse.tractusx.irs.testing.dataintegrity.models.IntegrityAspect;
import org.eclipse.tractusx.irs.testing.dataintegrity.models.IntegrityChildPart;
import org.eclipse.tractusx.irs.testing.dataintegrity.models.IntegrityReference;
import org.eclipse.tractusx.irs.testing.dataintegrity.models.SingleLevelBomAsBuiltPayload;
import org.eclipse.tractusx.irs.testing.dataintegrity.models.TestdataContainer;

/**
* Create and add a DataIntegrity AspectModels to a testdata set.
*/
@Slf4j
public class IntegrityAspectCreator {
public static final String SLBAB_IDENTIFIER = "urn:bamm:io.catenax.single_level_bom_as_built:1.0.0#SingleLevelBomAsBuilt";
public static final String DIL_IDENTIFIER = "urn:bamm:io.catenax.data_integrity:1.0.0#DataIntegrity";
public static final String CATENA_X_ID_IDENTIFIER = "catenaXId";
private final ObjectMapper objectMapper;
private final IntegritySigner integritySigner;

public IntegrityAspectCreator(final IntegritySigner integritySigner) {
this.integritySigner = integritySigner;
objectMapper = new ObjectMapper();
}

public String enrichTestdata(final String jsonData) throws IOException {
final TestdataContainer testdataContainer = objectMapper.readValue(jsonData, TestdataContainer.class);
final List<Map<String, Object>> testdata = testdataContainer.getContainer();

for (final Map<String, Object> digitalTwin : testdata) {
log.info("Building Integrity Aspect for '{}'", digitalTwin.get(CATENA_X_ID_IDENTIFIER));
addIntegrityAspect(digitalTwin, testdata);
}
return objectMapper.writeValueAsString(testdataContainer);
}

private String mapToString(final Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new IntegrityAspectException(e);
}
}

private <T> T readValue(final String data, final Class<T> type) {
try {
return objectMapper.readValue(data, type);
} catch (JsonProcessingException e) {
throw new IntegrityAspectException(e);
}
}

private void addIntegrityAspect(final Map<String, Object> digitalTwin, final List<Map<String, Object>> testdata) {
if (digitalTwin.containsKey(DIL_IDENTIFIER)) {
log.info("Integrity Aspect already present");
return;
}

if (digitalTwin.containsKey(SLBAB_IDENTIFIER)) {
final List<SingleLevelBomAsBuiltPayload> payloads = new ArrayList<>();
digitalTwin.entrySet()
.stream()
.filter(stringObjectEntry -> SLBAB_IDENTIFIER.equals(stringObjectEntry.getKey()))
.map(Map.Entry::getValue)
.map(this::mapToString)
.map(o -> readValue(o, SingleLevelBomAsBuiltPayload[].class))
.map(Arrays::asList)
.forEach(payloads::addAll);

if (!payloads.isEmpty()) {
final SingleLevelBomAsBuiltPayload singleLevelBomAsBuiltPayloads = payloads.stream()
.findFirst()
.orElseThrow();
singleLevelBomAsBuiltPayloads.getChildItems()
.stream()
.map(SingleLevelBomAsBuiltPayload.ChildData::getCatenaXId)
.map(id -> findDigitalTwinById(testdata, id))
.forEach(stringObjectMap -> addIntegrityAspect(stringObjectMap, testdata));

final List<IntegrityChildPart> integrityChildParts = new ArrayList<>();
singleLevelBomAsBuiltPayloads.getChildItems()
.stream()
.map(SingleLevelBomAsBuiltPayload.ChildData::getCatenaXId)
.map(id -> findDigitalTwinById(testdata, id))
.forEach(stringObjectMap -> {
final IntegrityChildPart integrityChildPart = createIntegrityChildPart(
stringObjectMap);
integrityChildParts.add(integrityChildPart);
});
final String cxId = (String) digitalTwin.get(CATENA_X_ID_IDENTIFIER);
final IntegrityAspect integrityAspect = new IntegrityAspect(cxId, integrityChildParts);
log.info("Adding integrity Aspect to Twin.");
digitalTwin.put(DIL_IDENTIFIER, List.of(integrityAspect));
}
}
}

private IntegrityChildPart createIntegrityChildPart(final Map<String, Object> childTwin) {
final List<IntegrityReference> references = new ArrayList<>();
final String cxId = (String) childTwin.get(CATENA_X_ID_IDENTIFIER);
log.info("Creating Integrity Part for ID: '{}'", cxId);
childTwin.entrySet()
.stream()
.filter(aspectModel -> !CATENA_X_ID_IDENTIFIER.equals(aspectModel.getKey()) && !"bpnl".equals(
aspectModel.getKey()))
.forEach(aspectModelEntry -> references.add(createIntegrityReference(aspectModelEntry)));
return new IntegrityChildPart(cxId, references);
}

protected IntegrityReference createIntegrityReference(final Map.Entry<String, Object> aspectModelEntry) {
final String aspectModel = mapToString(aspectModelEntry.getValue());
final Object[] strings = readValue(aspectModel, Object[].class);
try {
final byte[] payloadHash = integritySigner.hashString(mapToString(strings[0]));
final String payloadSignature = integritySigner.sign(payloadHash);
return new IntegrityReference(aspectModelEntry.getKey(), Hex.toHexString(payloadHash), payloadSignature);
} catch (CryptoException e) {
throw new IntegrityAspectException(e);
}
}

private Map<String, Object> findDigitalTwinById(final List<Map<String, Object>> testdata, final String catenaXId) {
for (final Map<String, Object> digitalTwin : testdata) {
final String twinCatenaXId = (String) digitalTwin.get(CATENA_X_ID_IDENTIFIER);
if (catenaXId.equals(twinCatenaXId)) {
return digitalTwin;
}
}
return Map.of();
}
}
Loading
Loading