Skip to content

Commit

Permalink
feat(edc-client):[#616] refactoring after review
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jhartmann committed May 17, 2024
1 parent a5fcb50 commit 446ec3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.tractusx.irs.edc.client.EdcConfiguration;
import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext;
import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator;
import org.eclipse.tractusx.irs.edc.client.policy.PolicyType;
import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest;
import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicy;
import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermission;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class EdcPolicyDefinitionService {
private static final String ATOMIC_CONSTRAINT = "AtomicConstraint";
private static final String CONSTRAINT = "Constraint";
private static final String OPERATOR_PREFIX = "odrl:";
private static final String USE_ACTION = "use";
private static final String USE_ACTION = PolicyType.USE.getValue();

private final EdcConfiguration config;
private final RestTemplate restTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,18 @@ void shouldRetrieveEndpointReferenceForAsset2() throws Exception {
}

@Test
void shouldRetrieveEndpointReferenceForRegistryAssetForOldIdentifier() throws Exception {
void shouldRetrieveEndpointReferenceForRegistryAssetUsingFallbackOldIdentifier() throws Exception {
// arrange
when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX);

final String agreementId = "agreementId";
// no catalog item for taxonomy#DigitalTwinRegistry is found,
// so the fallback data.core.digitalTwinRegistry is used
when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY),
any())).thenReturn(Collections.emptyList());
when(catalogFacade.fetchCatalogByFilter(any(), eq(EDC_TYPE), eq(DATA_CORE_DIGITAL_TWIN_REGISTRY),
any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build()));

when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX);

final String agreementId = "agreementId";
when(contractNegotiationService.negotiate(any(), any(),
eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn(
NegotiationResponse.builder().contractAgreementId(agreementId).build());
Expand All @@ -497,11 +500,13 @@ void shouldRetrieveEndpointReferenceForRegistryAssetForOldIdentifier() throws Ex
@Test
void shouldRetrieveEndpointReferenceForRegistryAssetForNewIdentifier() throws Exception {
// arrange
// catalog item for taxonomy#DigitalTwinRegistry is found, so the fallback type is not used
when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY),
any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build()));

when(config.getControlplane().getProviderSuffix()).thenReturn(PROVIDER_SUFFIX);

final String agreementId = "agreementId";
when(catalogFacade.fetchCatalogByFilter(any(), eq(DCT_TYPE_ID), eq(TAXONOMY_DIGITAL_TWIN_REGISTRY),
any())).thenReturn(List.of(CatalogItem.builder().itemId("asset-id").build()));
when(contractNegotiationService.negotiate(any(), any(),
eq(new EndpointDataReferenceStatus(null, TokenStatus.REQUIRED_NEW)), any())).thenReturn(
NegotiationResponse.builder().contractAgreementId(agreementId).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.eclipse.tractusx.irs.data.StringMapper;
import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.edc.client.policy.PolicyType;
import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -141,7 +142,7 @@ private static String getOfferId(final String assetId) {

private static Permission createUsePermission(final Constraint constraint) {
return Permission.Builder.newInstance()
.action(Action.Builder.newInstance().type("use").build())
.action(Action.Builder.newInstance().type(PolicyType.USE.getValue()).build())
.constraint(constraint)
.build();
}
Expand Down

0 comments on commit 446ec3f

Please sign in to comment.