Skip to content

Commit

Permalink
refactor: cleanup 0.3.x deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed May 22, 2024
1 parent 9210a69 commit 4db1e86
Show file tree
Hide file tree
Showing 20 changed files with 13 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,6 @@ public SqlQueryStatement addWhereClause(String clause, Object... parameters) {
return this;
}

/**
* Add where clause. If it contains multiple clauses better wrap it with parenthesis
*
* @param clause the SQL where clause.
* @deprecated please use {@link #addWhereClause(String, Object...)}
*/
@Deprecated(since = "0.3.1")
public void addWhereClause(String clause) {
whereClauses.add(clause);
}

/**
* Add parameter.
*
* @param parameter the parameter.
* @deprecated please use {@link #addWhereClause(String, Object...)}
*/
@Deprecated(since = "0.3.1")
public void addParameter(Object parameter) {
parameters.add(parameter);
}

private void initialize(QuerySpec query) {
query.getFilterExpression().stream()
.map(criterion -> criterionToWhereConditionConverter.convert(criterion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import jakarta.json.JsonObject;
import org.eclipse.edc.api.model.ApiCoreSchema;
import org.eclipse.edc.connector.api.management.configuration.ManagementApiSchema;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.ContractOfferDescription;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.NegotiationState;

import java.util.List;
Expand Down Expand Up @@ -128,17 +127,11 @@ record ContractRequestSchema(
String type,
@Schema(requiredMode = REQUIRED)
String protocol,
@Deprecated(since = "0.3.2")
@Schema(deprecated = true, description = "please use counterPartyAddress instead")
String connectorAddress,
@Schema(requiredMode = REQUIRED)
String counterPartyAddress,
@Deprecated(since = "0.5.1")
@Schema(deprecated = true, description = "please use policy.assigner instead")
String providerId,
@Deprecated(since = "0.3.2")
@Schema(deprecated = true, description = "please use policy instead of offer")
ContractOfferDescriptionSchema offer,
@Schema(requiredMode = REQUIRED)
OfferSchema policy,
List<ManagementApiSchema.CallbackAddressSchema> callbackAddresses) {
Expand Down Expand Up @@ -211,17 +204,6 @@ record NegotiationStateSchema(
""";
}

@Schema(name = "ContractOfferDescription")
record ContractOfferDescriptionSchema(
@Schema(name = TYPE, example = ContractOfferDescription.CONTRACT_OFFER_DESCRIPTION_TYPE)
String type,
String offerId,
String assetId,
ManagementApiSchema.PolicySchema policy
) {

}

@Schema(example = TerminateNegotiationSchema.TERMINATE_NEGOTIATION_EXAMPLE)
record TerminateNegotiationSchema(
@Schema(name = TYPE, example = TERMINATE_NEGOTIATION_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectFromContractNegotiationTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectFromNegotiationStateTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractOfferDescriptionTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractOfferTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractRequestTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToTerminateNegotiationCommandTransformer;
Expand Down Expand Up @@ -73,7 +72,6 @@ public void initialize(ServiceExtensionContext context) {

managementApiTransformerRegistry.register(new JsonObjectToContractRequestTransformer());
managementApiTransformerRegistry.register(new JsonObjectToContractOfferTransformer());
managementApiTransformerRegistry.register(new JsonObjectToContractOfferDescriptionTransformer());
managementApiTransformerRegistry.register(new JsonObjectToTerminateNegotiationCommandTransformer());
managementApiTransformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(factory));
managementApiTransformerRegistry.register(new JsonObjectFromNegotiationStateTransformer(factory));
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform;

import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.ContractOfferDescription;
import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
Expand All @@ -25,9 +24,7 @@
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CALLBACK_ADDRESSES;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.OFFER;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.POLICY;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.PROTOCOL;

Expand All @@ -40,7 +37,7 @@ public JsonObjectToContractRequestTransformer() {
@Override
public @Nullable ContractRequest transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) {
var contractRequestBuilder = ContractRequest.Builder.newInstance()
.counterPartyAddress(counterPartyAddressOrConnectorAddress(jsonObject, context))
.counterPartyAddress(transformString(jsonObject.get(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS), context))
.protocol(transformString(jsonObject.get(PROTOCOL), context));

contractRequestBuilder.contractOffer(contractOffer(jsonObject, context));
Expand All @@ -59,24 +56,7 @@ private ContractOffer contractOffer(@NotNull JsonObject jsonObject, @NotNull Tra
return transformObject(policy, ContractOffer.class, context);
}

var offerJson = jsonObject.get(OFFER);
if (offerJson != null) {
var contractOfferDescription = transformObject(jsonObject.get(OFFER), ContractOfferDescription.class, context);
return ContractOffer.Builder.newInstance()
.id(contractOfferDescription.getOfferId())
.assetId(contractOfferDescription.getAssetId())
.policy(contractOfferDescription.getPolicy())
.build();
}

return null;
}

/**
* This method can be removed once `connectorAddress` is deleted and exists only for legacy reasons
*/
private String counterPartyAddressOrConnectorAddress(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) {
var counterPartyAddress = transformString(jsonObject.get(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS), context);
return counterPartyAddress != null ? counterPartyAddress : transformString(jsonObject.get(CONNECTOR_ADDRESS), context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
package org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.validation;

import jakarta.json.JsonObject;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.ContractOfferDescription;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.validator.jsonobject.JsonLdPath;
import org.eclipse.edc.validator.jsonobject.JsonObjectValidator;
import org.eclipse.edc.validator.jsonobject.validators.LogDeprecatedValue;
import org.eclipse.edc.validator.jsonobject.validators.MandatoryIdNotBlank;
import org.eclipse.edc.validator.jsonobject.validators.MandatoryObject;
import org.eclipse.edc.validator.jsonobject.validators.MandatoryValue;
import org.eclipse.edc.validator.jsonobject.validators.TypeIs;
import org.eclipse.edc.validator.spi.ValidationResult;
import org.eclipse.edc.validator.spi.Validator;

import static org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.ContractOfferDescription.ASSET_ID;
import static org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.ContractOfferDescription.OFFER_ID;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONNECTOR_ADDRESS;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_TYPE;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.OFFER;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.POLICY;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.PROTOCOL;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.PROVIDER_ID;
Expand All @@ -44,11 +37,10 @@ public class ContractRequestValidator {
public static Validator<JsonObject> instance(Monitor monitor) {
return JsonObjectValidator.newValidator()
.verify(PROVIDER_ID, path -> new LogDeprecatedValue(path, CONTRACT_REQUEST_TYPE, ODRL_ASSIGNER_ATTRIBUTE, monitor))
.verify(OFFER, path -> new LogDeprecatedValue(path, CONTRACT_REQUEST_TYPE, POLICY, monitor))
.verify(CONNECTOR_ADDRESS, path -> new LogDeprecatedValue(path, CONTRACT_REQUEST_TYPE, CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, monitor))
.verify(path -> new MandatoryCounterPartyAddressOrConnectorAddress(path, monitor))
.verify(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS, MandatoryValue::new)
.verify(PROTOCOL, MandatoryValue::new)
.verify(path -> new MandatoryOfferOrPolicy(path, monitor))
.verify(POLICY, MandatoryObject::new)
.verifyObject(POLICY, ContractRequestValidator::offerValidator)
.build();
}

Expand All @@ -62,45 +54,4 @@ public static JsonObjectValidator.Builder offerValidator(JsonObjectValidator.Bui
.verifyObject(ODRL_TARGET_ATTRIBUTE, b -> b.verifyId(MandatoryIdNotBlank::new));
}

private record MandatoryOfferOrPolicy(JsonLdPath path, Monitor monitor) implements Validator<JsonObject> {
@Override
public ValidationResult validate(JsonObject input) {
var offerValidity = new MandatoryObject(path.append(OFFER)).validate(input);
if (offerValidity.succeeded()) {
return JsonObjectValidator.newValidator()
.verifyObject(OFFER, v -> v
.verify(OFFER_ID, MandatoryValue::new)
.verify(ASSET_ID, MandatoryValue::new)
.verify(ContractOfferDescription.POLICY, MandatoryObject::new)
).build().validate(input);
}

return JsonObjectValidator.newValidator()
.verify(POLICY, MandatoryObject::new)
.verifyObject(POLICY, ContractRequestValidator::offerValidator)
.build().validate(input);
}

}

/**
* This custom validator can be removed once `connectorAddress` is deleted and exists only for legacy reasons
*/
private record MandatoryCounterPartyAddressOrConnectorAddress(JsonLdPath path, Monitor monitor) implements Validator<JsonObject> {

@Override
public ValidationResult validate(JsonObject input) {
var counterPartyAddress = new MandatoryValue(path.append(CONTRACT_REQUEST_COUNTER_PARTY_ADDRESS));
var validateCounterParty = counterPartyAddress.validate(input);
if (validateCounterParty.succeeded()) {
return ValidationResult.success();
}
var connectorAddress = new MandatoryValue(path.append(CONNECTOR_ADDRESS));
var validateConnectorAddress = connectorAddress.validate(input);
if (validateConnectorAddress.succeeded()) {
return ValidationResult.success();
}
return validateCounterParty;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.JsonObject;
import org.eclipse.edc.api.transformer.JsonObjectToCallbackAddressTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractOfferDescriptionTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractOfferTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToContractRequestTransformer;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.transform.JsonObjectToTerminateNegotiationCommandTransformer;
Expand Down Expand Up @@ -64,7 +63,6 @@ class ContractNegotiationApiTest {
void setUp() {
transformer.register(new JsonObjectToContractRequestTransformer());
transformer.register(new JsonObjectToContractOfferTransformer());
transformer.register(new JsonObjectToContractOfferDescriptionTransformer());
transformer.register(new JsonObjectToCallbackAddressTransformer());
transformer.register(new JsonObjectToTerminateNegotiationCommandTransformer());
ParticipantIdMapper participantIdMapper = mock();
Expand Down
Loading

0 comments on commit 4db1e86

Please sign in to comment.