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

Chore/upstream contribution #1383

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions cfx-frontend/src/environments/environment.authTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/********************************************************************************
* 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
********************************************************************************/

import { _environment } from './_environment.base';

export const environment = {
..._environment,
mockService: false,
authDisabled: false,
apiUrl: 'https://traceability-test.dev.demo.catena-x.net/api',
keycloakUrl: 'https://centralidp.dev.demo.catena-x.net/auth',
clientId: 'Cl17-CX-Part',
api: '',
};
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ SPDX-License-Identifier: Apache-2.0
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
<maven-site-plugin.version>4.0.0-M11</maven-site-plugin.version>
<!-- versions for 3rd party dependecies -->
<commons.fileupload>1.5</commons.fileupload>
<logback.version>1.5.6</logback.version>
<eclipse-dash-ip.version>1.1.0</eclipse-dash-ip.version>
<nimbus-jose-jwt.version>9.40</nimbus-jose-jwt.version>
Expand Down Expand Up @@ -89,7 +90,7 @@ SPDX-License-Identifier: Apache-2.0
<junit-bom.version>5.10.3</junit-bom.version>
<awaitility.version>4.2.1</awaitility.version>
<!-- TODO https://github.com/eclipse-tractusx/traceability-foss/issues/978 update to the cx release version of irs lib IMPORTANT NO SNAPSHOT-->
<irs-client-lib.version>2.1.9</irs-client-lib.version>
<irs-client-lib.version>2.1.16</irs-client-lib.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please recheck if this exists open source

<json-schema-validator.version>5.4.0</json-schema-validator.version>
<!-- Sonar related properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public ResponseEntity<ImportResponse> importJson(@RequestPart("file") MultipartF
}


Map<AssetBase, Boolean> resultMap = null;
Map<AssetBase, Boolean> resultMap;
try {
resultMap = importService.importAssets(file, importJob);
} catch (ImportException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AssetBase {
private String manufacturerName;
private String nameAtManufacturer;
private String manufacturerPartId;
private String digitalTwinType;
private Owner owner;
@Singular
private List<Descriptions> childRelations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.assets.domain.importpoc.model;

public record AssetMetaInfoRequest(String catenaXId) {
public record AssetMetaInfoRequest(String catenaXId, String digitalTwinType) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.eclipse.tractusx.traceability.assets.domain.importpoc.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
Expand All @@ -34,8 +36,8 @@
import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase;
import org.eclipse.tractusx.traceability.assets.domain.importpoc.repository.SubmodelPayloadRepository;
import org.eclipse.tractusx.traceability.common.properties.EdcProperties;
import org.eclipse.tractusx.traceability.common.properties.RegistryProperties;
import org.eclipse.tractusx.traceability.submodel.domain.repository.SubmodelServerRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Arrays;
Expand All @@ -45,6 +47,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.semanticdatamodel.LocalIdKey.DIGITAL_TWIN_TYPE;
import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.semanticdatamodel.LocalIdKey.MANUFACTURER_ID;
import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.semanticdatamodel.LocalIdKey.MANUFACTURER_PART_ID;

@Slf4j
@Service
@RequiredArgsConstructor
Expand All @@ -56,44 +62,55 @@ public class DtrService {
private final SubmodelPayloadRepository submodelPayloadRepository;
private final SubmodelServerRepository submodelServerRepository;
private final EdcProperties edcProperties;

@Value("${registry.allowedBpns}")
String allowedBpns;
private final RegistryProperties registryProperties;
private final ObjectMapper objectMapper;

public String createShellInDtr(final AssetBase assetBase, String submodelServerAssetId) throws CreateDtrShellException {
Map<String, String> payloadByAspectType = submodelPayloadRepository.getAspectTypesAndPayloadsByAssetId(assetBase.getId());
Map<String, UUID> createdSubmodelIdByAspectType = payloadByAspectType.entrySet().stream()
Map<String, String> createdSubmodelIdByAspectType = payloadByAspectType.entrySet().stream()
.map(this::createSubmodel)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(existingValue, newValue) -> {
log.warn("Duplicate key detected. Using the new value: {}.",
newValue);
return newValue;
}
));

List<SubmodelDescriptor> descriptors = toSubmodelDescriptors(createdSubmodelIdByAspectType, submodelServerAssetId);
AssetAdministrationShellDescriptor assetAdministrationShellDescriptor = aasFrom(assetBase, descriptors);
try {
String requestBody = objectMapper.writeValueAsString(assetAdministrationShellDescriptor);
log.info("Creating DTR asset with request body {}", requestBody);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
dtrCreateShellService.createShell(assetAdministrationShellDescriptor);
return assetBase.getId();
}

private List<SubmodelDescriptor> toSubmodelDescriptors(Map<String, UUID> createdSubmodelIdByAspectType, String submodelServerAssetId) {
private List<SubmodelDescriptor> toSubmodelDescriptors(Map<String, String> createdSubmodelIdByAspectType, String submodelServerAssetId) {
return createdSubmodelIdByAspectType.entrySet()
.stream().map(entry ->
toSubmodelDescriptor(entry.getKey(), entry.getValue(), submodelServerAssetId)

).toList();
toSubmodelDescriptor(entry.getKey(), entry.getValue(), submodelServerAssetId))
.toList();
}

private SubmodelDescriptor toSubmodelDescriptor(String aspectType, UUID submodelServerIdReference, String submodelServerAssetId) {
private SubmodelDescriptor toSubmodelDescriptor(String aspectType, String submodelServerIdReference, String submodelServerAssetId) {
return SubmodelDescriptor.builder()
.description(List.of())
.idShort(aspectTypeToSimpleSubmodelName(aspectType))
.id(submodelServerIdReference.toString())
.id(submodelServerIdReference)
.semanticId(
Reference.builder()
.type(EXTERNAL_REFERENCE)
.keys(
List.of(SemanticId.builder()
.type(GLOBAL_REFERENCE)
.value(aspectType).build())
).build()
)
.value(aspectType).build()))
.build())
.endpoints(
List.of(
Endpoint.builder()
Expand All @@ -107,11 +124,10 @@ private SubmodelDescriptor toSubmodelDescriptor(String aspectType, UUID submodel
.subprotocolBodyEncoding("plain")
.subprotocolBody(getSubProtocol(submodelServerAssetId))
.securityAttributes(
List.of(SecurityAttribute.none())
).build()
).build()
)
).build();
List.of(SecurityAttribute.none()))
.build())
.build()))
.build();
}

private String getSubProtocol(String submodelServerAssetId) {
Expand All @@ -124,9 +140,8 @@ private String aspectTypeToSimpleSubmodelName(String aspectType) {
return split[1];
}

private Map.Entry<String, UUID> createSubmodel(Map.Entry<String, String> payloadByAspectType) {
UUID submodelId = UUID.randomUUID();
submodelServerRepository.saveSubmodel(submodelId.toString(), payloadByAspectType.getValue());
private Map.Entry<String, String> createSubmodel(Map.Entry<String, String> payloadByAspectType) {
String submodelId = submodelServerRepository.saveSubmodel(payloadByAspectType.getValue());
log.info("create submodelId {} for aspectType {} on submodelServer", submodelId, payloadByAspectType.getKey());
return Map.entry(payloadByAspectType.getKey(), submodelId);
}
Expand All @@ -145,7 +160,7 @@ List<IdentifierKeyValuePair> aasIdentifiersFromAsset(AssetBase assetBase) {

List<IdentifierKeyValuePair> identifierKeyValuePairs = List.of(
IdentifierKeyValuePair.builder()
.name("manufacturerId")
.name(MANUFACTURER_ID.getValue())
.value(assetBase.getManufacturerId())
.externalSubjectId(
Reference.builder()
Expand All @@ -154,8 +169,17 @@ List<IdentifierKeyValuePair> aasIdentifiersFromAsset(AssetBase assetBase) {
.build())
.build(),
IdentifierKeyValuePair.builder()
.name("manufacturerPartId")
.name(MANUFACTURER_PART_ID.getValue())
.value(assetBase.getManufacturerPartId())
.externalSubjectId(
Reference.builder()
.type(EXTERNAL_REFERENCE)
.keys(getExternalSubjectIds())
.build())
.build(),
IdentifierKeyValuePair.builder()
.name(DIGITAL_TWIN_TYPE.getValue())
.value(assetBase.getDigitalTwinType())
.externalSubjectId(
Reference.builder()
.type(EXTERNAL_REFERENCE)
Expand All @@ -167,7 +191,6 @@ List<IdentifierKeyValuePair> aasIdentifiersFromAsset(AssetBase assetBase) {
return identifierKeyValuePairs;
}


private List<SemanticId> getExternalSubjectIds() {
List<SemanticId> externalSubjectIds = List.of(SemanticId.builder()
.type(GLOBAL_REFERENCE)
Expand All @@ -178,15 +201,14 @@ private List<SemanticId> getExternalSubjectIds() {
SemanticId.builder()
.type(GLOBAL_REFERENCE)
.value(allowedBpn)
.build()
)
.build())
.toList();

return Stream.concat(externalSubjectIds.stream(), configurationExternalSubjectIds.stream()).toList();
}

// TODO: Issue #740 will handle and decide how to avoid having allowed bpns in config ( should be managed by policy to access data ) needs investigation
public List<String> getAllowedBpns() {
return Arrays.stream(allowedBpns.split(",")).toList();
return Arrays.stream(registryProperties.getAllowedBpns().split(",")).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException;
import org.eclipse.tractusx.irs.edc.client.policy.model.exception.EdcPolicyDefinitionAlreadyExists;
import org.eclipse.tractusx.irs.edc.client.policy.service.EdcPolicyDefinitionService;
import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties;
import org.eclipse.tractusx.traceability.common.properties.RegistryProperties;
import org.eclipse.tractusx.traceability.common.properties.SubmodelProperties;
import org.eclipse.tractusx.traceability.policies.application.service.PolicyService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import policies.response.PolicyResponse;

Expand All @@ -43,65 +43,71 @@
@Service
@RequiredArgsConstructor
public class EdcAssetCreationService {
private static final String REGISTRY_ASSET_ID = "registry-asset";
private final EdcAssetService edcAssetService;
private final EdcPolicyDefinitionService edcPolicyDefinitionService;
private final EdcContractDefinitionService edcContractDefinitionService;
private final TraceabilityProperties traceabilityProperties;
private final RegistryProperties registryProperties;
private final SubmodelProperties submodelProperties;
private final PolicyService policyService;
@Value("${registry.urlWithPath}")
String registryUrlWithPath = null;


public String createEdcContractDefinitionsForDtrAndSubmodel(String policyId) throws CreateEdcPolicyDefinitionException, CreateEdcAssetException, CreateEdcContractDefinitionException {
PolicyResponse policy = policyService.getPolicy(policyId);
String createdPolicyId;
try {
boolean exists = edcPolicyDefinitionService.policyDefinitionExists(policyId);
if (exists) {
log.info("Policy with id " + policyId + " already exists and contains necessary application constraints. Reusing for edc asset contract definition.");
createdPolicyId =policyId;
} else{
log.info("EDC Policy (DTR) already exists with id: {} reusing it", policyId);
createdPolicyId = policyId;
} else {
createdPolicyId = edcPolicyDefinitionService.createAccessPolicy(mapToEdcPolicyRequest(policy));
log.info("DTR Policy Id created :{}", createdPolicyId);
log.info("EDC Policy (DTR) created with id :{}", createdPolicyId);
}
} catch (EdcPolicyDefinitionAlreadyExists e) {
createdPolicyId = policyId;
} catch (Exception exception) {
log.warn("EDC Policy (DTR) could not be created: {}", exception.getMessage());
throw new CreateEdcPolicyDefinitionException(exception);
}

String dtrAssetId;
try {
dtrAssetId = edcAssetService.createDtrAsset(registryUrlWithPath, REGISTRY_ASSET_ID);
log.info("DTR Asset Id created :{}", dtrAssetId);
dtrAssetId = edcAssetService.createDtrAsset(registryProperties.getUrlWithPathInternal(), registryProperties.getEdcAssetId());
log.info("EDC Asset (DTR) created with id :{}", dtrAssetId);
} catch (EdcAssetAlreadyExistsException e) {
dtrAssetId = REGISTRY_ASSET_ID;
log.info("EDC Asset (DTR) already exists with id: {} reusing it", registryProperties.getEdcAssetId());
dtrAssetId = registryProperties.getEdcAssetId();
} catch (Exception exception) {
log.warn("EDC Asset (DTR) could not be created: {}", exception.getMessage());
throw new CreateEdcAssetException(exception);
}

try {
String dtrContractId = edcContractDefinitionService.createContractDefinition(dtrAssetId, createdPolicyId);
log.info("DTR Contract Id created :{}", dtrContractId);
log.info("EDC ContractDefinition (DTR) created with id :{}", dtrContractId);
} catch (Exception e) {
log.warn("EDC ContractDefinition (DTR) could not be created: {}", e.getMessage());
throw new CreateEdcContractDefinitionException(e);
}

String submodelAssetId;
String submodelAssetIdToCreate = "urn:uuid:" + UUID.randomUUID();
try {
submodelAssetId = edcAssetService.createSubmodelAsset(traceabilityProperties.getSubmodelBase(), submodelAssetIdToCreate);
log.info("Submodel Asset Id created :{}", submodelAssetId);
submodelAssetId = edcAssetService.createSubmodelAsset(submodelProperties.getBaseInternal(), submodelAssetIdToCreate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you set the public url for the submodel, this is the case in the open source variant. Please check

log.info("EDC Asset (Submodel) created with id :{}", submodelAssetId);
} catch (EdcAssetAlreadyExistsException e) {
submodelAssetId = submodelAssetIdToCreate;
log.info("EDC Asset (Submodel) already exists with id: {} reusing it", submodelAssetId);
} catch (Exception exception) {
log.warn("EDC Asset (Submodel) could not be created: {}", exception.getMessage());
throw new CreateEdcAssetException(exception);
}

try {
String submodelContractId = edcContractDefinitionService.createContractDefinition(submodelAssetId, createdPolicyId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if the submodel server is returning the id on open source variant.

log.info("Submodel Contract Id created :{}", submodelContractId);
log.info("EDC ContractDefinition (Submodel) created with id :{}", submodelContractId);
} catch (Exception e) {
log.warn("EDC ContractDefinition (Submodel) could not be created: {}", e.getMessage());
throw new CreateEdcContractDefinitionException(e);
}

Expand Down
Loading
Loading