Skip to content

Commit

Permalink
Merge pull request #599 from catenax-ng/feat/358-fix-cid-retrieval
Browse files Browse the repository at this point in the history
feat(impl):[#358] fix cid retrieval
  • Loading branch information
ds-jhartmann authored May 7, 2024
2 parents 7a869f5 + ff052bf commit 16038de
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ _**For better traceability add the corresponding GitHub issue number in each cha

## [Unreleased]

### Fixed

- Fixed issue in EDR Token renewal #358

## Added
### Added

- Cucumber test step definitions for Policy Store API (Happy Path) including some test helper utilities. #518


## [5.1.0] - 2024-05-06

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException;
import org.eclipse.tractusx.irs.edc.client.model.CatalogItem;
import org.eclipse.tractusx.irs.edc.client.model.ContractOffer;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest;
import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse;
import org.eclipse.tractusx.irs.edc.client.model.Response;
Expand Down Expand Up @@ -95,12 +94,7 @@ public NegotiationResponse negotiate(final String providerConnectorUrl, final Ca
contractAgreementId = negotiationResponse.getContractAgreementId();
}
case EXPIRED -> {
final String authCode = resultEndpointDataReferenceStatus.endpointDataReference().getAuthCode();
if (authCode == null) {
throw new IllegalStateException("Missing information about AuthKey.");
}
log.error("AuthCode to be parsed: {}", authCode);
contractAgreementId = EDRAuthCode.fromAuthCodeToken(authCode).getCid();
contractAgreementId = resultEndpointDataReferenceStatus.endpointDataReference().getContractId();
log.info(
"Cached endpoint data reference has expired token. Refreshing token without new contract negotiation for contractAgreementId: {}",
Masker.mask(contractAgreementId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import io.github.resilience4j.retry.RetryRegistry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.irs.edc.client.cache.endpointdatareference.EndpointDataReferenceCacheService;
Expand All @@ -47,14 +46,12 @@
import org.eclipse.tractusx.irs.edc.client.exceptions.TransferProcessException;
import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException;
import org.eclipse.tractusx.irs.edc.client.model.CatalogItem;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.edc.client.model.NegotiationResponse;
import org.eclipse.tractusx.irs.edc.client.model.SubmodelDescriptor;
import org.eclipse.tractusx.irs.edc.client.model.notification.EdcNotification;
import org.eclipse.tractusx.irs.edc.client.model.notification.EdcNotificationResponse;
import org.eclipse.tractusx.irs.edc.client.model.notification.NotificationContent;
import org.eclipse.tractusx.irs.edc.client.util.Masker;
import org.jetbrains.annotations.Nullable;
import org.springframework.util.StopWatch;

/**
Expand Down Expand Up @@ -103,17 +100,12 @@ private Optional<SubmodelDescriptor> retrieveSubmodelData(final String submodelD
stopWatchOnEdcTask(stopWatch);

return Optional.of(
new SubmodelDescriptor(getContractAgreementId(endpointDataReference.getAuthCode()), payload));
new SubmodelDescriptor(endpointDataReference.getContractId(), payload));
}

return Optional.empty();
}

@Nullable
private String getContractAgreementId(final String authCode) {
return StringUtils.isNotBlank(authCode) ? EDRAuthCode.fromAuthCodeToken(authCode).getCid() : null;
}

private Optional<EndpointDataReference> retrieveEndpointReference(final String storageId,
final StopWatch stopWatch) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand All @@ -44,7 +43,6 @@
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.irs.edc.client.EdcConfiguration;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey;
import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryService;
import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService;
Expand Down Expand Up @@ -193,7 +191,7 @@ private List<Shell> fetchShellDescriptorsForKey(final List<DigitalTwinRegistryKe

try {
return keys.stream()
.map(key -> new Shell(contractNegotiationId(endpointDataReference.getAuthCode()),
.map(key -> new Shell(endpointDataReference.getContractId(),
fetchShellDescriptor(endpointDataReference, key)))
.toList();
} finally {
Expand All @@ -219,10 +217,6 @@ private AssetAdministrationShellDescriptor fetchShellDescriptor(final EndpointDa
}
}

private String contractNegotiationId(final String token) {
return Optional.ofNullable(token).map(EDRAuthCode::fromAuthCodeToken).map(EDRAuthCode::getCid).orElse("");
}

/**
* This method takes the provided ID and maps it to the corresponding asset administration shell ID.
* If the ID is already a shellId, the same ID will be returned.
Expand Down

0 comments on commit 16038de

Please sign in to comment.