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

DigitalTwinRegistryCreateShellService irs-registry-client #437

Merged
merged 15 commits into from
Feb 21, 2024
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 @@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- DigitalTwinRegistryCreateShellService in irs-registry-client for creating shells in DTR directly


## [4.6.0] - 2024-02-20
Expand All @@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Moved Docker notice to separate file #425


## [4.5.0] - 2024-02-07
### Added
- Added helper script for building documentation locally.
Expand Down
24 changes: 21 additions & 3 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ components:
lexicalValue: piece
quantityNumber: 1.0
shells:
- contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b
- contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
payload:
description:
- language: en
Expand Down Expand Up @@ -1131,6 +1131,7 @@ components:
type: ModelReference
submodels:
- aspectType: supply_chain_impacted
contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff
payload:
supplyChainImpacted: "YES"
Expand Down Expand Up @@ -1199,7 +1200,7 @@ components:
lexicalValue: piece
quantityNumber: 1.0
shells:
- contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b
- contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
payload:
description:
- language: en
Expand Down Expand Up @@ -1253,6 +1254,7 @@ components:
type: ModelReference
submodels:
- aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0
contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff
payload:
catenaXId: urn:uuid:d9bec1c6-e47c-4d18-ba41-0a5fe8b7f447
Expand Down Expand Up @@ -1390,7 +1392,7 @@ components:
lexicalValue: piece
quantityNumber: 1.0
shells:
- contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b
- contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
payload:
description:
- language: en
Expand Down Expand Up @@ -1442,6 +1444,7 @@ components:
value: urn:bamm:com.catenax.vehicle:0.1.1#PartDetails
submodels:
- aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0
contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462
identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff
payload:
catenaXId: urn:uuid:d9bec1c6-e47c-4d18-ba41-0a5fe8b7f447
Expand Down Expand Up @@ -2326,6 +2329,11 @@ components:
type: string
subprotocolBodyEncoding:
type: string
securityAttributes:
type: array
items:
$ref: '#/components/schemas/SecurityAttribute'
maxItems: 2147483647
Quantity:
type: object
additionalProperties: false
Expand Down Expand Up @@ -2622,6 +2630,16 @@ components:
value:
type: string
example: Submodel
SecurityAttribute:
type: object
additionalProperties: false
properties:
type:
type: string
key:
type: string
value:
type: string
Shell:
type: object
additionalProperties: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ private Example createCompleteEssJobResult() {

private Submodel createEssSubmodel() {
return Submodel.builder()
.contractAgreementId(EXAMPLE_ID)
.aspectType(SUPPLY_CHAIN_IMPACTED_ASPECT_TYPE)
.identification(SUBMODEL_IDENTIFICATION)
.payload(Map.of(SUPPLY_CHAIN_IMPACTED_KEY, SUPPLY_CHAIN_IMPACTER_RESULT))
Expand Down Expand Up @@ -343,6 +344,7 @@ private Example createCanceledJobResponse() {

private Submodel createSubmodel() {
return Submodel.builder()
.contractAgreementId(EXAMPLE_ID)
.aspectType("urn:bamm:io.catenax.single_level_bom_as_built:1.0.0")
.identification(SUBMODEL_IDENTIFICATION)
.payload(createAssemblyPartRelationshipPayloadMap())
Expand Down Expand Up @@ -373,7 +375,7 @@ private Tombstone createTombstone() {
}

private Shell createShell() {
return new Shell("a787aa13-2bd7-488f-9e25-40682003901b",
return new Shell(EXAMPLE_ID,
AssetAdministrationShellDescriptor.builder()
.description(List.of(LangString.builder()
.language("en")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ public class ProtocolInformation {
* subprotocolBodyEncoding
*/
private String subprotocolBodyEncoding;
/**
* securityAttributes
*/
@ArraySchema(arraySchema = @Schema(implementation = SecurityAttribute.class), maxItems = Integer.MAX_VALUE)
private List<SecurityAttribute> securityAttributes;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,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.irs.component.assetadministrationshell;

import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

/**
* SecurityAttribute
*/
@Data
@Builder
@Jacksonized
public class SecurityAttribute {

/**
* type
*/
private String type;
/**
* key
*/
private String key;
/**
* value
*/
private String value;

public static SecurityAttribute none() {
return SecurityAttribute.builder().type("NONE").key("NONE").value("NONE").build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,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.irs.registryclient.decentral;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.registryclient.decentral.exception.CreateDtrShellException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

/**
* implementation of DigitalTwinRegistryService used to create shells in DTR
*/
@Slf4j
@RequiredArgsConstructor
public class DigitalTwinRegistryCreateShellService {

private final RestTemplate restTemplate;
private final String createShellUrl;

public AssetAdministrationShellDescriptor createShell(
final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor)
throws CreateDtrShellException {
final ResponseEntity<AssetAdministrationShellDescriptor> createdShellResponse;
try {
createdShellResponse = restTemplate.postForEntity(createShellUrl,
new HttpEntity<>(assetAdministrationShellDescriptor, headers()),
AssetAdministrationShellDescriptor.class);
final HttpStatusCode responseCode = createdShellResponse.getStatusCode();

if (responseCode.value() == HttpStatus.CREATED.value()) {
return createdShellResponse.getBody();
}
} catch (RestClientException e) {
throw new CreateDtrShellException(e);
}
throw new CreateDtrShellException(
"Failed to create shell %s".formatted(assetAdministrationShellDescriptor.getGlobalAssetId()));
}

private HttpHeaders headers() {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,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.irs.registryclient.decentral.exception;

/**
* CreateDtrShellException used for create asset failure
*/
public class CreateDtrShellException extends Exception {
public CreateDtrShellException(final String message) {
super(message);
}

public CreateDtrShellException(final Throwable cause) {
super(cause);
}
}
Loading
Loading