Skip to content

Commit

Permalink
Merge pull request #77 from catenax-ng/hotfix_3.2_with_pcf_part_3
Browse files Browse the repository at this point in the history
[feat] : SDE backend : Refactor DT registry use through EDC connector : rel-2.3.0
  • Loading branch information
almadigabor authored Nov 29, 2023
2 parents 9cd4417 + 5929fe2 commit fd82a8c
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
sarif_file: "trivy-results.sarif"
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [2.2.2] - 2023-11-28
## [2.3.0] - 2023-11-29
### Added
- DT use refactor for look up twin.

## [2.2.2] - non-released
### Added
- Added oauth security for sde public api.
- BPN url add API path.
Expand All @@ -13,7 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Trivy workflow update.

## [2.2.1] - non-released
### Fix
### Fixed
- Update PCF schema fields for SDE.

## [2.2.0] - 2023-09-20
Expand Down Expand Up @@ -238,8 +242,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Compliance with Catena-X Guidelines
- Integration with Digital Twin registry service.

[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.2.2...main
[2.2.2]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.2.0...v2.2.2
[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.0...main
[2.3.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.1.1...v2.2.0
[2.1.1]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.0.11...v2.1.0
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ COPY --from=build modules/sde-core/target/*.jar ./app.jar
EXPOSE 8080
# set the startup command to run your binary

CMD ["java", "-jar", "./app.jar","--spring.config.location=file:/app/configuration.properties"]
CMD ["java", "-jar", "./app.jar","--spring.config.location=file:/app/configuration.properties"]
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.tractusx.sde.edc.entities.request.policies.Operator;
import org.eclipse.tractusx.sde.edc.entities.request.policies.PolicyConstraintBuilderService;
import org.eclipse.tractusx.sde.edc.facilitator.ContractNegotiateManagementHelper;
import org.eclipse.tractusx.sde.edc.facilitator.EDRRequestHelper;
import org.eclipse.tractusx.sde.edc.gateways.database.ContractNegotiationInfoRepository;
import org.eclipse.tractusx.sde.edc.model.contractoffers.ContractOfferRequestFactory;
import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest;
Expand Down Expand Up @@ -89,6 +90,9 @@ class ConsumerControlPanelServiceTest {

@MockBean
private ContractOfferRequestFactory contractOfferRequestFactory;

@MockBean
private EDRRequestHelper eDRRequestHelper;

@Test
void testQueryOnDataOfferEmpty() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

package org.eclipse.tractusx.sde.digitaltwins.facilitator;

import java.net.URI;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.tractusx.sde.common.exception.ServiceException;
import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest;
import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest;
Expand All @@ -39,6 +37,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -50,38 +49,30 @@ public class DigitalTwinsFacilitator {

private final DigitalTwinsFeignClient digitalTwinsFeignClient;

@Value(value = "${digital-twins.hostname:default}")
private String digitalTwinsHost;

@Value(value = "${digital-twins.api:/api/v3.0}")
private String dtApiUri;

@Value(value = "${manufacturerId}")
public String manufacturerId;

public List<String> shellLookup(ShellLookupRequest request) throws ServiceException {
return shellLookupFromDDTR(request, null, manufacturerId);
}

@SneakyThrows
public List<String> shellLookupFromDDTR(ShellLookupRequest request, String ddtrUrl, String edcBpn)
throws ServiceException {

URI dtURL = StringUtils.isAllEmpty(ddtrUrl) ? getDtURL(digitalTwinsHost) : getDtURL(ddtrUrl);
public List<String> shellLookup(ShellLookupRequest request) throws ServiceException {

List<String> shellIds = List.of();

try {
ResponseEntity<ShellLookupResponse> response = digitalTwinsFeignClient.shellLookup(dtURL,
request.toJsonString(), edcBpn);
ResponseEntity<ShellLookupResponse> response = digitalTwinsFeignClient.shellLookup(request.toJsonString(),
manufacturerId);

ShellLookupResponse body = response.getBody();
if (response.getStatusCode() == HttpStatus.OK && body != null) {
shellIds = body.getResult();
}

} catch (FeignException e) {
log.error("FeignException RequestBody : " + e.request());
String errorMsg = "Error in DT twin lookup " + e.request().url() + ", because: " + request.toJsonString()
+ "," + e.contentUTF8();
log.error("FeignException : " + errorMsg);
throw new ServiceException(errorMsg);
} catch (Exception e) {
String error = "Error in lookup DT lookup:" + dtURL + ", " + request.toJsonString() + ", " + e.getMessage();
String error = "Error in DT twin lookup " + request.toJsonString() + ", " + e.getMessage();
log.error(error);
throw new ServiceException(error);
}
Expand All @@ -92,44 +83,46 @@ public List<String> shellLookupFromDDTR(ShellLookupRequest request, String ddtrU
public String deleteShell(String shellId) {
String deleteResponse = "";
try {
ResponseEntity<Void> response = digitalTwinsFeignClient.deleteShell(getDtURL(digitalTwinsHost),
encodeShellIdBase64Utf8(shellId));
ResponseEntity<Void> response = digitalTwinsFeignClient.deleteShell(encodeShellIdBase64Utf8(shellId));

if (response.getStatusCode() == HttpStatus.NO_CONTENT) {
deleteResponse = "Asset identifier" + shellId + "deleted successfully";
}
} catch (FeignException e) {
log.error("FeignException RequestBody : " + e.request());
String errorMsg = "Error in deleteShell " + e.request().url() + ", because: " + e.contentUTF8();
log.error("FeignException : " + errorMsg);
throw new ServiceException(errorMsg);
} catch (Exception e) {
String error = "Error in deleteShell :" + digitalTwinsHost + ", " + shellId + "," + e.getMessage();
String error = "Error in deleteShell : " + shellId + "," + e.getMessage();
log.error(error);
throw new ServiceException(error);
}
return deleteResponse;
}

@SneakyThrows
public List<ShellDescriptorResponse> getShellDescriptorsWithSubmodelDetails(List<String> shellIds, String ddtrUrl) {
public List<ShellDescriptorResponse> getShellDescriptorsWithSubmodelDetails(List<String> shellIds) {

List<ShellDescriptorResponse> items = new ArrayList<>();
for (String shellId : shellIds) {
items.add(getShellDetailsById(shellId, ddtrUrl, manufacturerId));
items.add(getShellDetailsById(shellId));
}
return items;
}

public ShellDescriptorResponse getShellDetailsById(String shellId, String ddtrUrl, String edcBpn) {

URI dtURL = StringUtils.isAllEmpty(ddtrUrl) ? getDtURL(digitalTwinsHost) : getDtURL(ddtrUrl);
public ShellDescriptorResponse getShellDetailsById(String shellId) {

ResponseEntity<ShellDescriptorResponse> shellDescriptorResponse = digitalTwinsFeignClient
.getShellDescriptorByShellId(dtURL, encodeShellIdBase64Utf8(shellId), edcBpn);
.getShellDescriptorByShellId(encodeShellIdBase64Utf8(shellId), manufacturerId);
return shellDescriptorResponse.getBody();
}

@SneakyThrows
public void deleteSubmodelfromShellById(String shellId, String subModelId) {
try {
digitalTwinsFeignClient.deleteSubmodelfromShellById(getDtURL(digitalTwinsHost),
encodeShellIdBase64Utf8(shellId), encodeShellIdBase64Utf8(subModelId));
digitalTwinsFeignClient.deleteSubmodelfromShellById(encodeShellIdBase64Utf8(shellId),
encodeShellIdBase64Utf8(subModelId));
} catch (Exception e) {
parseExceptionMessage(e);
}
Expand All @@ -138,7 +131,7 @@ public void deleteSubmodelfromShellById(String shellId, String subModelId) {
public ShellDescriptorResponse createShellDescriptor(ShellDescriptorRequest request) {
ShellDescriptorResponse responseBody;
ResponseEntity<ShellDescriptorResponse> registerSubmodel = digitalTwinsFeignClient
.createShellDescriptor(getDtURL(digitalTwinsHost), request);
.createShellDescriptor(request);
if (registerSubmodel.getStatusCode() != HttpStatus.CREATED) {
responseBody = null;
} else {
Expand All @@ -149,11 +142,10 @@ public ShellDescriptorResponse createShellDescriptor(ShellDescriptorRequest requ

public void updateShellSpecificAssetIdentifiers(String shellId, List<Object> specificAssetIds) {

digitalTwinsFeignClient.deleteShellSpecificAttributes(getDtURL(digitalTwinsHost),
encodeShellIdBase64Utf8(shellId), manufacturerId);
digitalTwinsFeignClient.deleteShellSpecificAttributes(encodeShellIdBase64Utf8(shellId), manufacturerId);

ResponseEntity<List<Object>> registerSubmodel = digitalTwinsFeignClient.createShellSpecificAttributes(
getDtURL(digitalTwinsHost), encodeShellIdBase64Utf8(shellId), manufacturerId, specificAssetIds);
ResponseEntity<List<Object>> registerSubmodel = digitalTwinsFeignClient
.createShellSpecificAttributes(encodeShellIdBase64Utf8(shellId), manufacturerId, specificAssetIds);
if (registerSubmodel.getStatusCode() != HttpStatus.CREATED) {
log.error("Error in shell SpecificAssetIdentifiers deletion: " + registerSubmodel.toString());
}
Expand All @@ -163,8 +155,8 @@ public void createSubModel(String shellId, CreateSubModelRequest request) {

request.setDescription(List.of());

ResponseEntity<String> response = digitalTwinsFeignClient.createSubModel(getDtURL(digitalTwinsHost),
encodeShellIdBase64Utf8(shellId), request);
ResponseEntity<String> response = digitalTwinsFeignClient.createSubModel(encodeShellIdBase64Utf8(shellId),
request);
if (response.getStatusCode() != HttpStatus.CREATED) {
log.error("Unable to create submodel descriptor");
}
Expand All @@ -173,8 +165,8 @@ public void createSubModel(String shellId, CreateSubModelRequest request) {

public SubModelListResponse getSubModels(String shellId) {

ResponseEntity<SubModelListResponse> response = digitalTwinsFeignClient.getSubModels(getDtURL(digitalTwinsHost),
encodeShellIdBase64Utf8(shellId));
ResponseEntity<SubModelListResponse> response = digitalTwinsFeignClient
.getSubModels(encodeShellIdBase64Utf8(shellId));
SubModelListResponse responseBody = null;
if (response.getStatusCode() == HttpStatus.OK) {
responseBody = response.getBody();
Expand All @@ -192,9 +184,4 @@ public void parseExceptionMessage(Exception e) throws ServiceException {
throw new ServiceException("Exception in Digital delete request process: " + e.getMessage());
}
}

@SneakyThrows
private URI getDtURL(String dtURL) {
return new URI(dtURL.concat(dtApiUri));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public class DigitalTwinsUtility {
private static final String PUBLIC_READABLE = "PUBLIC_READABLE";

@Value(value = "${manufacturerId}")
public String manufacturerId;
private String manufacturerId;

@Value(value = "${edc.hostname}${edc.dsp.endpointpath:/api/v1/dsp}")
public String digitalTwinEdcDspEndpoint;
private String digitalTwinEdcDspEndpoint;

@Value(value = "${edc.hostname}${edc.dataplane.endpointpath:/api/public}")
public String digitalTwinEdcDataplaneEndpoint;
private String digitalTwinEdcDataplaneEndpoint;

ObjectMapper mapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,43 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "DigitalTwinsFeignClient", url = "placeholder", configuration = DigitalTwinsFeignClientConfiguration.class)
@FeignClient(value = "DigitalTwinsFeignClient", url = "${digital-twins.hostname:default}${digital-twins.api:/api/v3.0}", configuration = DigitalTwinsFeignClientConfiguration.class)
public interface DigitalTwinsFeignClient {

@PostMapping
KeycloakJWTTokenResponse readAuthToken(URI url, @RequestBody MultiValueMap<String, Object> body);

@PostMapping(path = "/shell-descriptors")
ResponseEntity<ShellDescriptorResponse> createShellDescriptor(URI url, @RequestBody ShellDescriptorRequest request);
ResponseEntity<ShellDescriptorResponse> createShellDescriptor(@RequestBody ShellDescriptorRequest request);


@GetMapping(path = "/shell-descriptors/{aasIdentifier}")
ResponseEntity<ShellDescriptorResponse> getShellDescriptorByShellId(URI url,
@PathVariable("aasIdentifier") String shellId, @RequestHeader("Edc-Bpn") String edcBpn);
ResponseEntity<ShellDescriptorResponse> getShellDescriptorByShellId(@PathVariable("aasIdentifier") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn);

@DeleteMapping(path = "/shell-descriptors/{aasIdentifier}")
ResponseEntity<Void> deleteShell(URI url, @PathVariable("assetIds") String shellId);
ResponseEntity<Void> deleteShell(@PathVariable("assetIds") String shellId);

@PostMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors")
ResponseEntity<String> createSubModel(URI url, @PathVariable("aasIdentifier") String shellId,
ResponseEntity<String> createSubModel(@PathVariable("aasIdentifier") String shellId,
@RequestBody CreateSubModelRequest request);

@GetMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors")
ResponseEntity<SubModelListResponse> getSubModels(URI digitalTwinsHost,
@PathVariable("aasIdentifier") String shellId);
ResponseEntity<SubModelListResponse> getSubModels(@PathVariable("aasIdentifier") String shellId);

@DeleteMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")
ResponseEntity<Object> deleteSubmodelfromShellById(URI url, @PathVariable("aasIdentifier") String shellId,
ResponseEntity<Object> deleteSubmodelfromShellById(@PathVariable("aasIdentifier") String shellId,
@PathVariable("submodelIdentifier") String submodelIdentifier);

@GetMapping(path = "/lookup/shells")
ResponseEntity<ShellLookupResponse> shellLookup(URI url, @RequestParam String assetIds,
ResponseEntity<ShellLookupResponse> shellLookup(@RequestParam String assetIds,
@RequestHeader("Edc-Bpn") String edcBpn);

@PostMapping(path = "/lookup/shells/{assetIds}")
ResponseEntity<List<Object>> createShellSpecificAttributes(URI url, @PathVariable("assetIds") String shellId,
ResponseEntity<List<Object>> createShellSpecificAttributes(@PathVariable("assetIds") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn, @RequestBody List<Object> specificAssetIds);

@DeleteMapping(path = "/lookup/shells/{assetIds}")
ResponseEntity<Void> deleteShellSpecificAttributes(URI url, @PathVariable("assetIds") String shellId,
ResponseEntity<Void> deleteShellSpecificAttributes(@PathVariable("assetIds") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/********************************************************************************
* Copyright (c) 2023 T-Systems International GmbH
* 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.sde.digitaltwins.gateways.external;

import java.net.URI;
import java.util.Map;

import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse;
import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "EDCDigitalTwinProxyForLookUp", url = "placeholder")
public interface EDCDigitalTwinProxyForLookUp {

@GetMapping(path = "/shell-descriptors/{aasIdentifier}")
ResponseEntity<ShellDescriptorResponse> getShellDescriptorByShellId(URI url,
@PathVariable("aasIdentifier") String shellId, @RequestHeader Map<String, String> header);

@GetMapping(path = "/lookup/shells")
ResponseEntity<ShellLookupResponse> shellLookup(URI url, @RequestParam String assetIds,
@RequestHeader Map<String, String> header);

}
Loading

0 comments on commit fd82a8c

Please sign in to comment.