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

feat | Release dt access api support 1 #153

Merged
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Refactored/Updated SingleLevelUsageAsBuilt maven module to support multi version.
- Refactored/Updated PCF maven module to support multi version.
- Added new flyway files.
- Supporting new submodel Singlelevelbomasplanned
- Supporting new submodel Singlelevelbomasplanned.
- Support EDC 7.
- Added new files for digital twin access rule support.

### Fixed
- Remove garbage character from 'edc_request_template' path. Fixed [#147](https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/issues/147).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void requestToProviderForPCFValue(String productId, StringBuilder sb, Str
pcfpushEnpoint = new URI(edrToken.getEndpoint());

Map<String, String> header = new HashMap<>();
header.put(edrToken.getAuthKey(), edrToken.getAuthCode());
header.put("authorization", edrToken.getAuthorization());

// Send request to data provider for PCF value push
pcfExchangeProxy.getPcfByProduct(pcfpushEnpoint, header, manufacturerId,
Expand Down Expand Up @@ -136,7 +136,7 @@ private void sendNotification(JsonObject calculatedPCFValue, String productId, S
edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId);

Map<String, String> header = new HashMap<>();
header.put(edrToken.getAuthKey(), edrToken.getAuthCode());
header.put("authorization", edrToken.getAuthorization());

pcfExchangeProxy.uploadPcfSubmodel(pcfpushEnpoint, header, bpnNumber, requestId, message,
jsonObjectMapper.gsonObjectToJsonNode(calculatedPCFValue));
Expand All @@ -161,4 +161,4 @@ private void sendNotification(JsonObject calculatedPCFValue, String productId, S



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private String lookUpChildTwin(Integer rowIndex, ShellLookupRequest shellLookupR
try {

Map<String, String> header = new HashMap<>();
header.put(edrToken.getAuthKey(), edrToken.getAuthCode());
header.put("authorization", edrToken.getAuthorization());
header.put("Edc-Bpn", bpnForRemoteRegistry);

ShellLookupResponse shellLookup = eDCDigitalTwinProxyForLookUp.shellLookup(new URI(endpoint),
Expand Down Expand Up @@ -197,4 +197,4 @@ private String encodeShellIdBase64Utf8(String shellId) {
return Base64.getUrlEncoder().encodeToString(shellId.getBytes());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ public JsonObject mapJsonbjectToFormatedResponse(JsonObject jsonObject) {
removeNullAndEmptyElementsFromJson(removeNullAndEmptyElementsFromJson(valueReplacer)));
}

@SuppressWarnings("deprecation")
public static String removeNullAndEmptyElementsFromJson(String jsonString) {
if (jsonString == null) {
return jsonString;
}
try {
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(jsonString);
JsonElement element = JsonParser.parseString(jsonString);
cleanByTree(element);
jsonString = new GsonBuilder().disableHtmlEscaping().create().toJson(element);
return jsonString;
Expand All @@ -78,8 +76,8 @@ public static String removeNullAndEmptyElementsFromJson(String jsonString) {
}

private static void cleanByTree(JsonElement e1) {
if (e1 == null || e1.isJsonNull()) {
} else if (e1.isJsonArray()) {
if (e1 == null || e1.isJsonNull()) {}
else if (e1.isJsonArray()) {
for (Iterator<JsonElement> it = e1.getAsJsonArray().iterator(); it.hasNext();) {
extracted(it);
}
Expand Down Expand Up @@ -126,4 +124,4 @@ private static void extracted(Iterator<JsonElement> it) {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 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
********************************************************************************/

DO $$
BEGIN
IF EXISTS (select 1 as foundtable from pg_tables WHERE tablename = 'pcf_aspect')
THEN
DELETE FROM pcf_aspect WHERE id IN (SELECT id FROM (SELECT id, ROW_NUMBER() OVER( PARTITION BY productid ORDER BY id ) AS row_num FROM pcf_aspect ) t WHERE t.row_num > 1);
END IF;
END $$;

ALTER TABLE IF EXISTS pcf_aspect DROP CONSTRAINT IF EXISTS "pcf_aspect_un";

ALTER TABLE IF EXISTS pcf_aspect ADD CONSTRAINT pcf_aspect_un UNIQUE (productid);
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/********************************************************************************
* Copyright (c) 2024 T-Systems International GmbH
* Copyright (c) 2024 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
********************************************************************************/

ALTER TABLE IF EXISTS aspect ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS aspect_relationship ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS batch ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS batch_v_300 ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS part_as_planned ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS part_site_information_as_planned ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS parttypeinformation_v_100 ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS pcf_aspect ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS serialpart_v_300 ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS single_level_bom_as_planned ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS single_level_bom_as_planned_v_300 ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS single_level_bom_asbuilt_v_300 ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS single_level_usage_as_built ADD IF NOT EXISTS shell_access_rule_ids text NULL;

ALTER TABLE IF EXISTS single_level_usage_as_built_v_300 ADD IF NOT EXISTS shell_access_rule_ids text NULL;
Binary file removed modules/sde-external-services/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2023, 2024 T-Systems International GmbH
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2023,2024 T-Systems International GmbH
* Copyright (c) 2023,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -40,6 +40,7 @@
import com.google.gson.JsonObject;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

@Service
@RequiredArgsConstructor
Expand All @@ -64,19 +65,9 @@ public void run(Map<String, String> input) throws ServiceException {
}
}

@SneakyThrows
@Override
public JsonNode run(Integer rowIndex, ObjectNode jsonObject, String processId, PolicyModel policy) {
// TODO Auto-generated method stub
return null;
}

@Override
public void delete(Integer rowIndex, JsonObject jsonObject, String delProcessId, String refProcessId) {
// TODO Auto-generated method stub

}

public void run(JsonNode jsonObject) throws ServiceException {
if (StringUtils.isBlank(
JsonObjectUtility.getValueFromJsonObjectAsString(jsonObject, SubmoduleCommonColumnsConstant.UPDATED))) {
try {
Expand All @@ -94,8 +85,15 @@ public void run(JsonNode jsonObject) throws ServiceException {
throw new ServiceException("Exception in BPN Discovery creation : " + e.getMessage());
}
}
return jsonObject;
}

@Override
public void delete(Integer rowIndex, JsonObject jsonObject, String delProcessId, String refProcessId) {
// Nothing to do with bpn discovery for delete
}


private Map<String, String> generateBPNDiscoveryIdentifiersIds(JsonNode jsonObject) {
return getBPNDiscoverySpecsOfModel().entrySet().stream().map(entry -> {
String value = JsonObjectUtility.getValueFromJsonObjectAsString(jsonObject, entry.getValue().getAsString());
Expand All @@ -107,4 +105,4 @@ private Map<String, String> generateBPNDiscoveryIdentifiersIds(JsonNode jsonObje
}


}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2022,2024 T-Systems International GmbH
* Copyright (c) 2022,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Optional;

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 @@ -32,11 +33,14 @@
import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse;
import org.eclipse.tractusx.sde.digitaltwins.entities.response.SubModelListResponse;
import org.eclipse.tractusx.sde.digitaltwins.gateways.external.DigitalTwinsFeignClient;
import org.eclipse.tractusx.sde.digitaltwins.gateways.external.IAccessRuleManagementApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.JsonNode;

import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -48,7 +52,7 @@
public class DigitalTwinsFacilitator {

private final DigitalTwinsFeignClient digitalTwinsFeignClient;

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

Expand All @@ -57,6 +61,8 @@

private final DigitalTwinsUtility digitalTwinsUtility;

private final IAccessRuleManagementApi iAccessRuleManagementApi;


@SneakyThrows
public List<String> shellLookup(ShellLookupRequest request) throws ServiceException {
Expand Down Expand Up @@ -148,6 +154,22 @@
}
return responseBody;
}

public JsonNode createAccessControlsRule(String edcBpn, JsonNode request) {
return iAccessRuleManagementApi.createAccessControlsRule(edcBpn, request);
}

public void updateAccessControlsRule(String ruleId, String edcBpn, JsonNode request) {
iAccessRuleManagementApi.updateAccessControlsRule(ruleId, edcBpn, request);
}

public JsonNode getAccessControlsRule(String ruleId, String edcBpn) {
return iAccessRuleManagementApi.getAccessControlsRuleById(ruleId, edcBpn);
}

public void deleteAccessControlsRule(String ruleId, String edcBpn) {
iAccessRuleManagementApi.deleteAccessControlsRule(ruleId, edcBpn);
}

public void updateShellDetails(String shellId, ShellDescriptorRequest aasDescriptorRequest,
CreateSubModelRequest createSubModelRequest) {
Expand All @@ -169,7 +191,11 @@

if (shellDescriptorResponse != null) {

shellDescriptorResponse.getSubmodelDescriptors().forEach(e ->
shellDescriptorResponse.getSubmodelDescriptors()
.stream()
.filter(ele -> createSubModelRequest == null || (createSubModelRequest != null

Check warning

Code scanning / CodeQL

Useless null check Warning

This check is useless.
createSubModelRequest
cannot be null at this check, since it is guarded by
... == ...
.
&& !ele.getIdShort().equals(createSubModelRequest.getIdShort())))
.forEach(e ->
aasDescriptorRequest.getSubmodelDescriptors().add(CreateSubModelRequest.builder()
.id(e.getId())
.idShort(e.getIdShort())
Expand All @@ -178,10 +204,15 @@
.description(e.getDescription())
.build())
);

}

if (StringUtils.isBlank(aasDescriptorRequest.getIdShort()) && (shellDescriptorResponse != null
&& StringUtils.isNotBlank(shellDescriptorResponse.getIdShort()))) {
aasDescriptorRequest.setIdShort(shellDescriptorResponse.getIdShort());
}

aasDescriptorRequest.setId(shellId);
log.debug(aasDescriptorRequest.toJsonString());

ResponseEntity<Void> updateShellDescriptorByShellId = digitalTwinsFeignClient
.updateShellDescriptorByShellId(digitalTwinsUtility.encodeValueAsBase64Utf8(shellId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/********************************************************************************
* Copyright (c) 2022, 2024 T-Systems International GmbH
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2022,2024 T-Systems International GmbH
* Copyright (c) 2022,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -47,47 +47,47 @@ public interface DigitalTwinsFeignClient {
@PostMapping
KeycloakJWTTokenResponse readAuthToken(URI url, @RequestBody MultiValueMap<String, Object> body);

@PostMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors")
@PostMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors")
ResponseEntity<ShellDescriptorResponse> createShellDescriptor(@RequestBody ShellDescriptorRequest request);

@GetMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}")
@GetMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}")
ResponseEntity<ShellDescriptorResponse> getShellDescriptorByShellId(@PathVariable("aasIdentifier") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn);

@PutMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}")
@PutMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}")
ResponseEntity<Void> updateShellDescriptorByShellId(@PathVariable("aasIdentifier") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn, @RequestBody ShellDescriptorRequest request);

@DeleteMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}")
@DeleteMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}")
ResponseEntity<Void> deleteShell(@PathVariable("assetIds") String shellId);

@PostMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}/submodel-descriptors")
@PostMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}/submodel-descriptors")
ResponseEntity<String> createSubModel(@PathVariable("aasIdentifier") String shellId,
@RequestBody CreateSubModelRequest request, @RequestHeader("Edc-Bpn") String edcBpn);

@PutMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")
@PutMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")
ResponseEntity<String> updateSubModel(@PathVariable("aasIdentifier") String shellId,
@PathVariable("submodelIdentifier") String submodelIdentifier, @RequestBody CreateSubModelRequest request,
@RequestHeader("Edc-Bpn") String edcBpn);

@GetMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}/submodel-descriptors")
@GetMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}/submodel-descriptors")
ResponseEntity<SubModelListResponse> getSubModels(@PathVariable("aasIdentifier") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn);

@DeleteMapping(path = "${digital-twins.registry.uri:/api/v3.0}/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")
@DeleteMapping(path = "${digital-twins.registry.uri:/api/v3}/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}")
ResponseEntity<Object> deleteSubmodelfromShellById(@PathVariable("aasIdentifier") String shellId,
@PathVariable("submodelIdentifier") String submodelIdentifier);

@GetMapping(path = "${digital-twins.registry.lookup.uri:/api/v3.0}/lookup/shells")
@GetMapping(path = "${digital-twins.registry.lookup.uri:/api/v3}/lookup/shells")
ResponseEntity<ShellLookupResponse> shellLookup(@RequestParam("assetIds") List<String> assetIds,
@RequestHeader("Edc-Bpn") String edcBpn);

@PostMapping(path = "${digital-twins.registry.lookup.uri:/api/v3.0}/lookup/shells/{shellId}")
@PostMapping(path = "${digital-twins.registry.lookup.uri:/api/v3}/lookup/shells/{shellId}")
ResponseEntity<List<Object>> createShellSpecificAttributes(@PathVariable("shellId") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn, @RequestBody List<Object> specificAssetIds);

@DeleteMapping(path = "${digital-twins.registry.lookup.uri:/api/v3.0}/lookup/shells/{shellId}")
@DeleteMapping(path = "${digital-twins.registry.lookup.uri:/api/v3}/lookup/shells/{shellId}")
ResponseEntity<Object> deleteShellSpecificAttributes(@PathVariable("assetIds") String shellId,
@RequestHeader("Edc-Bpn") String edcBpn);

}
}
Loading
Loading