use of org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryFederatedCacheStoreTest method queryCacheAfterInsertingSameAssetTwice_shouldReturnLastInsertedContractOfferOnly.
@Test
void queryCacheAfterInsertingSameAssetTwice_shouldReturnLastInsertedContractOfferOnly() {
String contractOfferId1 = UUID.randomUUID().toString();
String contractOfferId2 = UUID.randomUUID().toString();
String assetId = UUID.randomUUID().toString();
ContractOffer contractOffer1 = createContractOffer(contractOfferId1, createAsset(assetId));
ContractOffer contractOffer2 = createContractOffer(contractOfferId2, createAsset(assetId));
store.save(contractOffer1);
store.save(contractOffer2);
Collection<ContractOffer> result = store.query(Collections.emptyList());
assertThat(result).hasSize(1).allSatisfy(co -> {
assertThat(co.getId()).isEqualTo(contractOfferId2);
assertThat(co.getAsset().getId()).isEqualTo(assetId);
});
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer in project DataSpaceConnector by eclipse-dataspaceconnector.
the class InMemoryFederatedCacheStoreTest method queryCacheContainingTwoDistinctAssets_shouldReturnBothContractOffers.
@Test
void queryCacheContainingTwoDistinctAssets_shouldReturnBothContractOffers() {
String contractOfferId1 = UUID.randomUUID().toString();
String contractOfferId2 = UUID.randomUUID().toString();
String assetId1 = UUID.randomUUID().toString();
String assetId2 = UUID.randomUUID().toString();
ContractOffer contractOffer1 = createContractOffer(contractOfferId1, createAsset(assetId1));
ContractOffer contractOffer2 = createContractOffer(contractOfferId2, createAsset(assetId2));
store.save(contractOffer1);
store.save(contractOffer2);
Collection<ContractOffer> result = store.query(Collections.emptyList());
assertThat(result).hasSize(2).anySatisfy(co -> assertThat(co.getAsset().getId()).isEqualTo(assetId1)).anySatisfy(co -> assertThat(co.getAsset().getId()).isEqualTo(assetId2));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ResourceDescriptionRequestHandler method retrieveObject.
protected OfferedAsset retrieveObject(@NotNull IdsId idsId, @NotNull Result<ClaimToken> verificationResult) {
String assetId = idsId.getValue();
Asset asset = assetIndex.findById(assetId);
if (asset == null) {
return null;
}
ContractOfferQuery contractOfferQuery = ContractOfferQuery.Builder.newInstance().claimToken(verificationResult.getContent()).criterion(new Criterion(Asset.PROPERTY_ID, "=", assetId)).build();
List<ContractOffer> targetingContractOffers = contractOfferService.queryContractOffers(contractOfferQuery).collect(toList());
return new OfferedAsset(asset, targetingContractOffers);
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ConsumerContractNegotiationManagerImplTest method initiate_should_save_a_new_negotiation_in_initial_state.
@Test
void initiate_should_save_a_new_negotiation_in_initial_state() {
var contractOffer = contractOffer();
ContractOfferRequest request = ContractOfferRequest.Builder.newInstance().connectorId("connectorId").connectorAddress("connectorAddress").protocol("protocol").contractOffer(contractOffer).build();
var result = negotiationManager.initiate(request);
assertThat(result.succeeded()).isTrue();
verify(store).save(argThat(negotiation -> negotiation.getState() == INITIAL.code() && negotiation.getCounterPartyId().equals(request.getConnectorId()) && negotiation.getCounterPartyAddress().equals(request.getConnectorAddress()) && negotiation.getProtocol().equals(request.getProtocol()) && negotiation.getCorrelationId() == null && negotiation.getContractOffers().size() == 1 && negotiation.getLastContractOffer().equals(contractOffer)));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractRequestHandler method handleRequest.
@Override
@Nullable
public MultipartResponse handleRequest(@NotNull MultipartRequest multipartRequest, @NotNull ClaimToken claimToken) {
Objects.requireNonNull(multipartRequest);
Objects.requireNonNull(claimToken);
var message = (ContractRequestMessage) multipartRequest.getHeader();
ContractRequest contractRequest;
try {
contractRequest = objectMapper.readValue(multipartRequest.getPayload(), ContractRequest.class);
} catch (IOException e) {
monitor.severe("ContractRequestHandler: Contract Request is invalid", e);
return createBadParametersErrorMultipartResponse(message);
}
var idsWebhookAddress = message.getProperties().get(IDS_WEBHOOK_ADDRESS_PROPERTY);
if (idsWebhookAddress == null || idsWebhookAddress.toString().isBlank()) {
var msg = "Ids webhook address is invalid";
monitor.debug(String.format("ContractRequestHandler: %s", msg));
return createBadParametersErrorMultipartResponse(message, msg);
}
// extract target from contract request
var permission = contractRequest.getPermission().stream().findFirst().orElse(null);
if (permission == null) {
monitor.debug("ContractRequestHandler: Contract Request is invalid");
return createBadParametersErrorMultipartResponse(message);
}
var target = permission.getTarget();
if (target == null || String.valueOf(target).isBlank()) {
monitor.debug("ContractRequestHandler: Contract Request is invalid");
return createBadParametersErrorMultipartResponse(message);
}
// search for matching asset
var assetId = IdsIdParser.parse(String.valueOf(target));
var asset = assetIndex.findById(assetId.getValue());
if (asset == null) {
var msg = "Target id is invalid";
monitor.debug(String.format("ContractRequestHandler: %s", msg));
return createBadParametersErrorMultipartResponse(message, msg);
}
// Create contract offer request
var input = ContractTransformerInput.Builder.newInstance().contract(contractRequest).asset(asset).build();
Result<ContractOffer> result = transformerRegistry.transform(input, ContractOffer.class);
if (result.failed()) {
monitor.debug(String.format("Could not transform contract request: [%s]", String.join(", ", result.getFailureMessages())));
return createBadParametersErrorMultipartResponse(message);
}
var contractOffer = result.getContent();
var requestObj = ContractOfferRequest.Builder.newInstance().protocol(Protocols.IDS_MULTIPART).connectorAddress(idsWebhookAddress.toString()).type(ContractOfferRequest.Type.INITIAL).connectorId(String.valueOf(message.getIssuerConnector())).correlationId(String.valueOf(message.getTransferContract())).contractOffer(contractOffer).build();
Message response;
try {
response = responseMessageFactory.createRequestInProcessMessage(message);
} catch (Exception e) {
if (e instanceof InvalidCorrelationMessageException) {
monitor.debug(String.format("Rejecting invalid IDS contract request message [Msg-ID: %s]", message.getId()), e);
} else {
monitor.severe(String.format("Exception while creating IDS RequestInProcessMessage to answer contract request [Msg-ID: %s]", message.getId()), e);
}
response = responseMessageFactory.createRejectionMessage(message, e);
}
if (response instanceof RequestInProcessMessage) {
// Start negotiation process
negotiationManager.requested(claimToken, requestObj);
}
return MultipartResponse.Builder.newInstance().header(response).build();
}
Aggregations