Skip to content

Commit

Permalink
Merge pull request #460 from catenax-ng/feature/536-extend-aas-shell-…
Browse files Browse the repository at this point in the history
…with-external-subject-id

feature(irs-edc-client): #536 adjustments for subsequential flow
  • Loading branch information
ds-mmaul authored Mar 4, 2024
2 parents f959006 + 2456182 commit e9aeb60
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- EDC client handles multiple Digital Twin Registries and Digital Twins now #395
- Change logo of irs
- EdcPolicyDefinitionService, EdcContractDefinitionService and EdcAssetService return existing resource if when it exists in EDC
- Added AssetAdministrationShellDescriptor specificAssetIds support for externalSubjectId required for data provisioning
- Added 'businessPartnerNumber' field to Tombstone model. This will be filled only when UsagePolicyValidation tombstone is being created. #404

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,8 @@ components:
$ref: '#/components/schemas/Reference'
subjectId:
$ref: '#/components/schemas/Reference'
externalSubjectId:
$ref: '#/components/schemas/Reference'
value:
type: string
example: "12309481209312"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ public String createNotificationAsset(final String baseUrl, final String assetNa
return sendRequest(request);
}

public String createDtrAsset(final String baseUrl, final String assetName) throws CreateEdcAssetException {
final Asset request = createDtrAssetRequest(assetName, baseUrl);
public String createDtrAsset(final String baseUrl, final String assetId) throws CreateEdcAssetException {
final Asset request = createDtrAssetRequest(assetId, baseUrl);
return sendRequest(request);
}

public String createSubmodelAsset(final String baseUrl, final String assetId) throws CreateEdcAssetException {
final Asset request = createSubmodelAssetRequest(assetId, baseUrl);
return sendRequest(request);
}

Expand Down Expand Up @@ -146,9 +151,8 @@ private Asset createNotificationAssetRequest(final String assetName, final Strin
.build();
}

private Asset createDtrAssetRequest(final String assetName, final String baseUrl) {
final String assetId = UUID.randomUUID().toString();
final Map<String, Object> properties = Map.of(ASSET_CREATION_PROPERTY_DESCRIPTION, assetName, ASSET_CREATION_PROPERTY_TYPE,
private Asset createDtrAssetRequest(final String assetId, final String baseUrl) {
final Map<String, Object> properties = Map.of(ASSET_CREATION_PROPERTY_DESCRIPTION, "Digital Twin Registry Asset", ASSET_CREATION_PROPERTY_TYPE,
"data.core.digitalTwinRegistry");

final DataAddress dataAddress = DataAddress.Builder.newInstance()
Expand All @@ -163,7 +167,31 @@ private Asset createDtrAssetRequest(final String assetName, final String baseUrl
Boolean.TRUE.toString())
.property(ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS,
Boolean.TRUE.toString())
.property(ASSET_CREATION_DATA_ADDRESS_METHOD, DEFAULT_METHOD)
.build();

return Asset.Builder.newInstance()
.id(assetId)
.contentType("Asset")
.properties(properties)
.dataAddress(dataAddress)
.build();
}

private Asset createSubmodelAssetRequest(final String assetId, final String baseUrl) {
final Map<String, Object> properties = Map.of(ASSET_CREATION_PROPERTY_DESCRIPTION, "Submodel Server Asset");

final DataAddress dataAddress = DataAddress.Builder.newInstance()
.type("DataAddress")
.property(EDC_DATA_ADDRESS_TYPE_PROPERTY, HTTP_DATA)
.property(ASSET_CREATION_DATA_ADDRESS_BASE_URL, baseUrl)
.property(ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD,
Boolean.FALSE.toString())
.property(ASSET_CREATION_DATA_ADDRESS_PROXY_BODY,
Boolean.FALSE.toString())
.property(ASSET_CREATION_DATA_ADDRESS_PROXY_PATH,
Boolean.TRUE.toString())
.property(ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS,
Boolean.FALSE.toString())
.build();

return Asset.Builder.newInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public String createContractDefinition(final String assetId, final String policy
final HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode();

if (responseCode.value() == HttpStatus.CONFLICT.value()) {
log.info("{} asset contract definition already exists in the EDC", assetId);
log.info("{} contract definition already exists in the EDC", policyId);

throw new CreateEdcContractDefinitionException("Asset contract definition already exists in the EDC");
return policyId;
}

if (responseCode.value() == HttpStatus.OK.value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,23 @@ public class EdcPolicyDefinitionService {

public String createAccessPolicy(final String policyName) throws CreateEdcPolicyDefinitionException {
final String accessPolicyId = UUID.randomUUID().toString();
final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId);

return createAccessPolicy(policyName, accessPolicyId);
}

public String createAccessPolicy(final String policyName, final String policyId)
throws CreateEdcPolicyDefinitionException {
final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, policyId);

return createAccessPolicy(request);
}

public String createAccessPolicy(final EdcCreatePolicyDefinitionRequest policyRequest)
throws CreateEdcPolicyDefinitionException {
final ResponseEntity<String> createPolicyDefinitionResponse;
try {
createPolicyDefinitionResponse = restTemplate.postForEntity(
config.getControlplane().getEndpoint().getPolicyDefinition(), request, String.class);
config.getControlplane().getEndpoint().getPolicyDefinition(), policyRequest, String.class);
} catch (RestClientException e) {
log.error("Failed to create EDC notification asset policy. Reason: ", e);

Expand All @@ -80,11 +91,11 @@ public String createAccessPolicy(final String policyName) throws CreateEdcPolicy
if (responseCode.value() == HttpStatus.CONFLICT.value()) {
log.info("Notification asset policy definition already exists in the EDC");

throw new CreateEdcPolicyDefinitionException("Asset policy definition already exists in the EDC");
return policyRequest.getPolicyDefinitionId();
}

if (responseCode.value() == HttpStatus.OK.value()) {
return request.getPolicyDefinitionId();
return policyRequest.getPolicyDefinitionId();
}

throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset");
Expand Down Expand Up @@ -131,8 +142,7 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String poli
.build();
}

public void deleteAccessPolicy(final String accessPolicyId)
throws DeleteEdcPolicyDefinitionException {
public void deleteAccessPolicy(final String accessPolicyId) throws DeleteEdcPolicyDefinitionException {
final String deleteUri = UriComponentsBuilder.fromPath(
config.getControlplane().getEndpoint().getPolicyDefinition())
.pathSegment("{accessPolicyId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAsset
assertThat(assetId).isNotBlank();
}

@Test
void givenCreateSubmodelAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAssetException {
// given
when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig);
when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig);
when(endpointConfig.getAsset()).thenReturn("/management/v2/assets");
String baseUrl = "http://test.test";
String assetName = "asset1";
when(restTemplate.postForEntity(any(String.class), any(String.class), any())).thenReturn(
ResponseEntity.ok("test"));

// when
String assetId = service.createSubmodelAsset(baseUrl, assetName);

// then
assertThat(assetId).isNotBlank();
}

@Test
void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() throws DeleteEdcAssetException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ void givenCreateContractDefinition_whenOK_thenReturnPolicyId() throws CreateEdcC
}

@Test
void givenCreateContractDefinition_whenConflict_thenThrowException() {
void givenCreateContractDefinition_whenConflict_thenThrowException() throws CreateEdcContractDefinitionException {
// given
when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig);
when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig);
when(endpointConfig.getContractDefinition()).thenReturn("/management/v2/contractdefinitions");
String assetId = "Asset1";
String policyId = "Policy1";
final String assetId = "Asset1";
final String policyId = "Policy1";
when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class),
any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build());

assertThrows(CreateEdcContractDefinitionException.class,
() -> service.createContractDefinition(assetId, policyId));
// when
final String result = service.createContractDefinition(assetId, policyId);

// then
assertThat(result).isEqualTo(policyId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,20 @@ void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() throws CreateEdcPolicyDef
}

@Test
void givenCreatePolicy_whenConflict_thenThrowException() {
void givenCreatePolicy_whenConflict_thenReturnExstingPolicyId() throws CreateEdcPolicyDefinitionException {
// given
when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig);
when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig);
when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions");
String policyName = "policyName";
final String policyName = "policyName";
when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class),
any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build());

assertThrows(CreateEdcPolicyDefinitionException.class, () -> service.createAccessPolicy(policyName));
// when
final String result = service.createAccessPolicy(policyName);

// then
assertThat(result).isNotBlank();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class IdentifierKeyValuePair {
* subjectId
*/
private Reference subjectId;
/**
* externalSubjectId
*/
private Reference externalSubjectId;
/**
* value
*/
Expand All @@ -54,5 +58,4 @@ public class IdentifierKeyValuePair {
* semanticId
*/
private Reference semanticId;

}

0 comments on commit e9aeb60

Please sign in to comment.