Skip to content

Commit

Permalink
Merge pull request #153 from catenax-ng/release_dt_access_api_support_1
Browse files Browse the repository at this point in the history
feat | Release dt access api support 1
  • Loading branch information
almadigabor authored May 9, 2024
2 parents 8644b9a + 596d600 commit 37f08fe
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +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
- Support EDC 7
- 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
@@ -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;
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 @@ public class DigitalTwinsFacilitator {

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 @@ public ShellDescriptorResponse createShellDescriptor(ShellDescriptorRequest requ
}
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 @@ public void updateShellDetails(String shellId, ShellDescriptorRequest aasDescrip

if (shellDescriptorResponse != null) {

shellDescriptorResponse.getSubmodelDescriptors().forEach(e ->
shellDescriptorResponse.getSubmodelDescriptors()
.stream()
.filter(ele -> createSubModelRequest == null || (createSubModelRequest != null
&& !ele.getIdShort().equals(createSubModelRequest.getIdShort())))
.forEach(e ->
aasDescriptorRequest.getSubmodelDescriptors().add(CreateSubModelRequest.builder()
.id(e.getId())
.idShort(e.getIdShort())
Expand All @@ -178,10 +204,15 @@ public void updateShellDetails(String shellId, ShellDescriptorRequest aasDescrip
.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
@@ -0,0 +1,54 @@
/********************************************************************************
* 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
********************************************************************************/
package org.eclipse.tractusx.sde.digitaltwins.gateways.external;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

import com.fasterxml.jackson.databind.JsonNode;

@FeignClient(value = "IAccessRuleManagementApi", url = "${digital-twins.hostname:default}", configuration = DigitalTwinsFeignClientConfiguration.class)
public interface IAccessRuleManagementApi {

@GetMapping(path = "${digital-twins.registry.uri:/api/v3}/access-controls/rules")
public JsonNode getAccessControlsRules(@RequestHeader("Edc-Bpn") String edcBpn);

@PostMapping(path = "${digital-twins.registry.uri:/api/v3}/access-controls/rules")
public JsonNode createAccessControlsRule(@RequestHeader("Edc-Bpn") String edcBpn, @RequestBody JsonNode request);

@GetMapping(path = "${digital-twins.registry.uri:/api/v3}/access-controls/rules/{ruleId}")
public JsonNode getAccessControlsRuleById(@PathVariable("ruleId") String ruleId,
@RequestHeader("Edc-Bpn") String edcBpn);

@PutMapping(path = "${digital-twins.registry.uri:/api/v3}/access-controls/rules/{ruleId}")
public JsonNode updateAccessControlsRule(@PathVariable("ruleId") String ruleId,
@RequestHeader("Edc-Bpn") String edcBpn, @RequestBody JsonNode request);

@DeleteMapping(path = "${digital-twins.registry.uri:/api/v3}/access-controls/rules/{ruleId}")
public void deleteAccessControlsRule(@PathVariable("ruleId") String ruleId,
@RequestHeader("Edc-Bpn") String edcBpn);

}

0 comments on commit 37f08fe

Please sign in to comment.