Skip to content

Commit

Permalink
chore(tx-backend): #412 adjust to new build on lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-sceronik committed Feb 23, 2024
1 parent c729343 commit d48aeaf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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 @@ -43,6 +44,7 @@
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;
Expand Down Expand Up @@ -218,4 +220,14 @@ public void onEntryRemovedEvent(EntryRemovedEvent<Retry> entryRemoveEvent) {
public EdcAssetService edcAssetService(EdcConfiguration edcConfiguration, EdcTransformer edcTransformer, RestTemplate edcRestTemplate) {
return new EdcAssetService(edcTransformer, edcConfiguration, edcRestTemplate);
}

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

@Bean
public EdcContractDefinitionService edcContractDefinitionService(EdcConfiguration edcConfiguration, RestTemplate edcRestTemplate) {
return new EdcContractDefinitionService(edcConfiguration, edcRestTemplate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@
********************************************************************************/
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.DeleteEdcAssetException;
import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractDefinitionService;
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.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;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Component
@AllArgsConstructor
public class EdcNotificationContractService {

private final EdcAssetService edcAssetService; // TODO rename after testing and removing of EdcNotificationAssetService
private final RestTemplate edcRestTemplate; // TODO modify delete asset not to recieve rest template on method ( woooops ;O )
// private final EdcPolicyDefinitionService edcPolicyDefinitionService;
private final EdcPolicyDefinitionService edcPolicyDefinitionService;
private final EdcContractDefinitionService edcContractDefinitionService;
private final TraceabilityProperties traceabilityProperties;
Expand All @@ -61,7 +58,7 @@ public CreateNotificationContractResponse handle(CreateNotificationContractReque

String notificationAssetId;
try {
notificationAssetId = edcAssetService.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()));
notificationAssetId = edcAssetService.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()));
// notificationAssetId = edcNotificationAssetService.createNotificationAsset(notificationMethod, request.notificationType());
// } catch (CreateEdcAssetException e) {
// throw new CreateNotificationContractException(e);
Expand All @@ -72,24 +69,20 @@ public CreateNotificationContractResponse handle(CreateNotificationContractReque

String accessPolicyId = "";
try {
accessPolicyId = edcPolicyDefinitionService.createAccessPolicy();
} catch (CreateEdcPolicyDefinitionException e) {
accessPolicyId = edcPolicyDefinitionService.createAccessPolicy(traceabilityProperties.getRightOperand());
} catch (org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException e) {
revertNotificationAsset(notificationAssetId);
throw new CreateNotificationContractException(e);
} catch (JsonProcessingException e2) {
log.error(e2.toString());
}

String contractDefinitionId = "";
try {
contractDefinitionId = edcContractDefinitionService.createContractDefinition(notificationAssetId, accessPolicyId);
} catch (CreateEdcContractDefinitionException e) {
} catch (org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException e) {
revertAccessPolicy(accessPolicyId);
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);
Expand All @@ -104,7 +97,11 @@ 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 RuntimeException(e);
}
}

private void revertNotificationAsset(String notificationAssetId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.eclipse.tractusx.traceability.common.model.SecurityUtils.sanitizeHtml;

@Slf4j
@Component
//@Component
public class EdcContractDefinitionService {

private static final String ASSET_SELECTOR_ID = "https://w3id.org/edc/v0.0.1/ns/id";
Expand All @@ -53,7 +53,7 @@ public class EdcContractDefinitionService {
private final EdcProperties edcProperties;
private final ObjectMapper objectMapper;

@Autowired
// @Autowired
public EdcContractDefinitionService(RestTemplate edcRestTemplate, EdcProperties edcProperties, ObjectMapper objectMapper) {
this.edcRestTemplate = edcRestTemplate;
this.edcProperties = edcProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import static org.eclipse.tractusx.traceability.common.model.SecurityUtils.sanitizeHtml;

@Slf4j
@Component
//@Component
public class EdcPolicyDefinitionService {

private static final String USE_ACTION = "USE";
Expand All @@ -64,7 +64,7 @@ public class EdcPolicyDefinitionService {
private final EdcProperties edcProperties;
private final TraceabilityProperties traceabilityProperties;

@Autowired
// @Autowired
public EdcPolicyDefinitionService(ObjectMapper objectMapper, RestTemplate edcRestTemplate, EdcProperties edcProperties, TraceabilityProperties traceabilityProperties) {
this.objectMapper = objectMapper;
this.edcRestTemplate = edcRestTemplate;
Expand Down

0 comments on commit d48aeaf

Please sign in to comment.