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

Cleanup EDC logic and replace with irs-edc-library #704

Merged
merged 20 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
04c3b20
chore(tx-backend): #412 test lib notification asset creation
ds-ext-sceronik Feb 22, 2024
bb2d8db
chore(tx-backend): #412 change asset creation path API from v2 to v3
ds-ext-sceronik Feb 23, 2024
4a8734c
chore(tx-backend): #412 remove some tests temp
ds-ext-sceronik Feb 23, 2024
4b26566
chore(tx-backend): #412 adjust management endpoints
ds-ext-sceronik Feb 23, 2024
576d183
chore(tx-backend): #412 publish docker image regardles of sonar
ds-ext-sceronik Feb 23, 2024
5309a7d
chore(tx-backend): #412 publish docker image regardles of sonar
ds-ext-sceronik Feb 23, 2024
556f7a5
chore(tx-backend): #412 test template headers
ds-ext-sceronik Feb 23, 2024
c729343
chore(tx-backend): #412 adjust to new build on lib
ds-ext-sceronik Feb 23, 2024
d48aeaf
chore(tx-backend): #412 adjust to new build on lib
ds-ext-sceronik Feb 23, 2024
62b8644
chore(tx-backend): #412 fix test
ds-ext-sceronik Feb 23, 2024
71205fb
chore(tx-backend): #412 fix test
ds-ext-sceronik Feb 23, 2024
5ee0a2f
Merge branch 'main' into feat/412-cleanup-edc-logic
ds-ext-sceronik Feb 23, 2024
58a47a9
chore(tx-backend): #412 new rest template for notification asset crea…
ds-ext-sceronik Feb 23, 2024
c6c0c5e
chore(tx-backend): #412 remove unused classes
ds-ext-sceronik Feb 25, 2024
aaadd3b
chore(tx-backend): #412 fix tests
ds-ext-sceronik Feb 25, 2024
420d7d5
chore(tx-backend): #412 dedicated exception thrown
ds-ext-sceronik Feb 25, 2024
9bff1b9
chore(tx-backend): #412 formatting
ds-ext-sceronik Feb 26, 2024
eb1826b
chore(tx-backend): #412 bump spring core from 6.0.16 to 6.0.17
ds-ext-sceronik Feb 26, 2024
8d3bae5
chore(tx-backend): #412 bump spring core from 6.0.16 to 6.0.17
ds-ext-sceronik Feb 26, 2024
e50a8f1
Merge pull request #1012 from catenax-ng/feat/412-cleanup-edc-logic
ds-ext-sceronik Feb 26, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

### Changed
- sring-core bumped from 6.0.16 to 6.0.17

### Removed
- removed EDC notification asset classes and replaced with IRS lib implementation

## [10.5.0 - 22.02.2024]

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SPDX-License-Identifier: Apache-2.0

<properties>
<springboot.version>3.1.8</springboot.version>
<spring-core.version>6.0.16</spring-core.version>
<spring-core.version>6.0.17</spring-core.version>
<spring-security-config.version>6.1.3</spring-security-config.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.edc.client.EdcConfiguration;
import org.eclipse.tractusx.irs.edc.client.asset.EdcAssetService;
import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractDefinitionService;
import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPoliciesProvider;
import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy;
import org.eclipse.tractusx.irs.edc.client.policy.Constraint;
Expand All @@ -41,6 +44,8 @@
import org.eclipse.tractusx.irs.edc.client.policy.Permission;
import org.eclipse.tractusx.irs.edc.client.policy.Policy;
import org.eclipse.tractusx.irs.edc.client.policy.PolicyType;
import org.eclipse.tractusx.irs.edc.client.policy.service.EdcPolicyDefinitionService;
import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.IrsService;
import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.PolicyResponse;
import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties;
Expand All @@ -58,6 +63,7 @@
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.thymeleaf.spring6.SpringTemplateEngine;
Expand Down Expand Up @@ -209,4 +215,19 @@ public void onEntryRemovedEvent(EntryRemovedEvent<Retry> entryRemoveEvent) {
}
};
}

@Bean
public EdcAssetService edcNotificationAssetService(EdcConfiguration edcConfiguration, EdcTransformer edcTransformer, RestTemplate edcNotificationAssetRestTemplate) {
return new EdcAssetService(edcTransformer, edcConfiguration, edcNotificationAssetRestTemplate);
}

@Bean
public EdcPolicyDefinitionService edcPolicyDefinitionService(EdcConfiguration edcConfiguration, RestTemplate edcNotificationAssetRestTemplate) {
return new EdcPolicyDefinitionService(edcConfiguration, edcNotificationAssetRestTemplate);
}

@Bean
public EdcContractDefinitionService edcContractDefinitionService(EdcConfiguration edcConfiguration, RestTemplate edcNotificationAssetRestTemplate) {
return new EdcContractDefinitionService(edcConfiguration, edcNotificationAssetRestTemplate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public RestTemplate edcRestTemplate(@Autowired EdcProperties edcProperties) {
.build();
}

@Bean
public RestTemplate edcNotificationAssetRestTemplate(@Autowired EdcProperties edcProperties) {
return new RestTemplateBuilder()
.rootUri(edcProperties.getProviderEdcUrl())
.defaultHeader("Accept", MediaType.APPLICATION_JSON_VALUE)
.defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey())
.setConnectTimeout(Duration.ofSeconds(10L))
.setReadTimeout(Duration.ofSeconds(25L))
.build();
}

/* RestTemplate used by trace x for the notification transfer to the edc controlplane including edc api key*/
@Bean
public RestTemplate edcNotificationTemplate(@Autowired EdcProperties edcProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ private CatalogItem getCatalogItem(final QualityNotificationMessage notification
.build())
.build()
).stream()
.filter(catalogItem -> policyCheckerService.isValid(catalogItem.getPolicy()))
.filter(catalogItem -> {
log.info("-- catalog item check --");
log.info("Item {}: {}", catalogItem.getItemId(), catalogItem);
boolean isValid = policyCheckerService.isValid(catalogItem.getPolicy());
log.info("IsValid : {}", isValid);
return isValid;
})
.findFirst()
.orElseThrow();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,62 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.qualitynotification.domain.contract;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.edc.client.asset.EdcAssetService;
import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType;
import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException;
import org.eclipse.tractusx.irs.edc.client.asset.model.exception.DeleteEdcAssetException;
import org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException;
import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractDefinitionService;
import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException;
import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException;
import org.eclipse.tractusx.irs.edc.client.policy.service.EdcPolicyDefinitionService;
import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties;
import org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.CreateNotificationContractException;
import org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.CreateNotificationContractRequest;
import org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.CreateNotificationContractResponse;
import org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.NotificationMethod;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.asset.model.CreateEdcAssetException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.asset.service.EdcNotificationAssetService;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.contract.model.CreateEdcContractDefinitionException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.contract.service.EdcContractDefinitionService;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.policy.model.CreateEdcPolicyDefinitionException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.contract.policy.service.EdcPolicyDefinitionService;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@AllArgsConstructor
public class EdcNotificationContractService {

private final EdcNotificationAssetService edcNotificationAssetService;
private final EdcAssetService edcNotificationAssetService;
private final EdcPolicyDefinitionService edcPolicyDefinitionService;
private final EdcContractDefinitionService edcContractDefinitionService;
private final TraceabilityProperties traceabilityProperties;

private static final String TRACE_FOSS_QUALITY_NOTIFICATION_INVESTIGATION_URL_TEMPLATE = "/api/qualitynotifications/%s";
private static final String TRACE_FOSS_QUALITY_NOTIFICATION_ALERT_URL_TEMPLATE = "/api/qualityalerts/%s";

public CreateNotificationContractResponse handle(CreateNotificationContractRequest request) {

NotificationMethod notificationMethod = request.notificationMethod();

log.info("Creating EDC asset notification contract for {} method and {} notification type", notificationMethod.getValue(), request.notificationType().getValue());

String notificationAssetId = "";

String notificationAssetId;
try {
notificationAssetId = edcNotificationAssetService.createNotificationAsset(notificationMethod, request.notificationType());
notificationAssetId = edcNotificationAssetService.createNotificationAsset(
createBaseUrl(request.notificationType(), request.notificationMethod()),
request.notificationType().name() + " " + request.notificationMethod().name(),
org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod.valueOf(request.notificationMethod().name()),
NotificationType.valueOf(request.notificationType().name()));
} catch (CreateEdcAssetException e) {
throw new CreateNotificationContractException(e);
} catch (JsonProcessingException e2) {
log.error(e2.toString());
}


String accessPolicyId = "";
try {
accessPolicyId = edcPolicyDefinitionService.createAccessPolicy();
accessPolicyId = edcPolicyDefinitionService.createAccessPolicy(traceabilityProperties.getRightOperand());
} catch (CreateEdcPolicyDefinitionException e) {
revertNotificationAsset(notificationAssetId);
throw new CreateNotificationContractException(e);
} catch (JsonProcessingException e2) {
log.error(e2.toString());
}

String contractDefinitionId = "";
Expand All @@ -78,11 +86,13 @@ public CreateNotificationContractResponse handle(CreateNotificationContractReque
revertNotificationAsset(notificationAssetId);

throw new CreateNotificationContractException(e);
} catch (JsonProcessingException e2) {
log.error(e2.toString());
}

log.info("Created notification contract for {} notification asset id, access policy id {} and contract definition id {}", notificationAssetId, accessPolicyId, contractDefinitionId);
log.info(
"Created notification contract for {} notification asset id, access policy id {} and contract definition id {}",
notificationAssetId,
accessPolicyId,
contractDefinitionId);

return new CreateNotificationContractResponse(
notificationAssetId,
Expand All @@ -94,12 +104,25 @@ public CreateNotificationContractResponse handle(CreateNotificationContractReque
private void revertAccessPolicy(String accessPolicyId) {
log.info("Removing {} access policy", accessPolicyId);

edcPolicyDefinitionService.deleteAccessPolicy(accessPolicyId);
try {
edcPolicyDefinitionService.deleteAccessPolicy(accessPolicyId);
} catch (DeleteEdcPolicyDefinitionException e) {
throw new CreateNotificationContractException(e);
}
}

private void revertNotificationAsset(String notificationAssetId) {
log.info("Removing {} notification asset", notificationAssetId);

edcNotificationAssetService.deleteNotificationAsset(notificationAssetId);
try {
edcNotificationAssetService.deleteAsset(notificationAssetId);
} catch (DeleteEdcAssetException e) {
throw new CreateNotificationContractException(e);
}
}

private String createBaseUrl(org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.NotificationType notificationType, NotificationMethod notificationMethod) {
final String template = notificationType.equals(org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.NotificationType.QUALITY_ALERT) ? TRACE_FOSS_QUALITY_NOTIFICATION_ALERT_URL_TEMPLATE : TRACE_FOSS_QUALITY_NOTIFICATION_INVESTIGATION_URL_TEMPLATE;
return traceabilityProperties.getUrl() + template.formatted(notificationMethod.getValue());
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading