Skip to content

Commit

Permalink
refactor: move constants to :dsp-core (#3027)
Browse files Browse the repository at this point in the history
* refactor: move constants to :dsp-core

* refactor(dsp): remove error constant from controllers

* fix(dsp): change wrong properties and imports in catalog modules

* chore(dsp-catalog-api): add missing test dependency

* chore(dsp): rename :dsp-core to :dsp-spi
  • Loading branch information
juliapampus authored May 17, 2023
1 parent b3e37dd commit 6ef51ac
Show file tree
Hide file tree
Showing 68 changed files with 700 additions and 730 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ plugins {

dependencies {
api(project(":data-protocols:dsp:dsp-api-configuration"))
api(project(":data-protocols:dsp:dsp-catalog:dsp-catalog-transform"))
api(project(":data-protocols:dsp:dsp-core"))
api(project(":data-protocols:dsp:dsp-spi"))
api(project(":data-protocols:dsp:dsp-http-spi"))
api(project(":data-protocols:dsp:dsp-transform"))

api(project(":spi:common:core-spi"))
Expand All @@ -30,5 +30,6 @@ dependencies {
implementation(libs.jakarta.rsApi)

testImplementation(project(":core:common:junit"))
testImplementation(project(":data-protocols:dsp:dsp-catalog:dsp-catalog-transform"))
testImplementation(libs.restAssured)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.edc.catalog.spi.CatalogRequestMessage;
import org.eclipse.edc.connector.spi.catalog.CatalogProtocolService;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.jsonld.spi.Namespaces;
import org.eclipse.edc.protocol.dsp.DspError;
import org.eclipse.edc.spi.iam.IdentityService;
import org.eclipse.edc.spi.iam.TokenRepresentation;
Expand All @@ -41,8 +40,9 @@
import static org.eclipse.edc.protocol.dsp.DspErrorDetails.UNAUTHORIZED;
import static org.eclipse.edc.protocol.dsp.catalog.api.CatalogApiPaths.BASE_PATH;
import static org.eclipse.edc.protocol.dsp.catalog.api.CatalogApiPaths.CATALOG_REQUEST;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_ERROR;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;

/**
* Provides the HTTP endpoint for receiving catalog requests.
Expand All @@ -52,8 +52,6 @@
@Path(BASE_PATH)
public class DspCatalogApiController {

private static final String DSPACE_CATALOG_ERROR = Namespaces.DSPACE_SCHEMA + "CatalogError"; // TODO move to :dsp-core https://github.com/eclipse-edc/Connector/issues/3014

private final Monitor monitor;
private final IdentityService identityService;
private final TypeTransformerRegistry transformerRegistry;
Expand Down Expand Up @@ -94,7 +92,7 @@ public Response getCatalog(JsonObject jsonObject, @HeaderParam(AUTHORIZATION) St
}

var expandedJson = expanded.getContent();
if (!isOfExpectedType(expandedJson, DSPACE_CATALOG_REQUEST_TYPE)) {
if (!isOfExpectedType(expandedJson, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE)) {
monitor.debug(String.format("%s, %s", BAD_REQUEST, verificationResult.getFailureMessages()));
return errorResponse(Response.Status.BAD_REQUEST, BAD_REQUEST);
}
Expand Down Expand Up @@ -138,7 +136,7 @@ public Response getCatalog(JsonObject jsonObject, @HeaderParam(AUTHORIZATION) St
private Response errorResponse(Response.Status code, String message) {
return Response.status(code).type(MediaType.APPLICATION_JSON)
.entity(DspError.Builder.newInstance()
.type(DSPACE_CATALOG_ERROR)
.type(DSPACE_TYPE_CATALOG_ERROR)
.code(Integer.toString(code.getStatusCode()))
.messages(List.of(message))
.build().toJson())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.edc.catalog.spi.DataServiceRegistry;
import org.eclipse.edc.connector.spi.catalog.CatalogProtocolService;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.jsonld.spi.Namespaces;
import org.eclipse.edc.junit.annotations.ApiTest;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.service.spi.result.ServiceResult;
Expand All @@ -47,7 +46,8 @@
import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort;
import static org.eclipse.edc.protocol.dsp.catalog.api.CatalogApiPaths.BASE_PATH;
import static org.eclipse.edc.protocol.dsp.catalog.api.CatalogApiPaths.CATALOG_REQUEST;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_ERROR;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CODE;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_REASON;
import static org.hamcrest.CoreMatchers.is;
Expand All @@ -60,8 +60,6 @@
@ExtendWith(EdcExtension.class)
class DspCatalogApiControllerIntegrationTest {

private static final String DSPACE_CATALOG_ERROR = Namespaces.DSPACE_SCHEMA + "CatalogError";

private final int dspApiPort = getFreePort();
private final String dspApiPath = "/api/v1/dsp";
private final String callbackAddress = "http://callback";
Expand Down Expand Up @@ -90,7 +88,7 @@ void setUp(EdcExtension extension) {
.add(CONTEXT, Json.createObjectBuilder()
.add(DSPACE_PREFIX, DSPACE_SCHEMA)
.build())
.add(TYPE, DSPACE_CATALOG_REQUEST_TYPE)
.add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE)
.build();
}

Expand Down Expand Up @@ -121,7 +119,7 @@ void catalogRequest_authenticationFailed_returnUnauthorized() {
.statusCode(401)
.extract().as(Map.class);

assertThat(result.get(JsonLdKeywords.TYPE)).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(result.get(JsonLdKeywords.TYPE)).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(result.get(DSPACE_PROPERTY_CODE)).isEqualTo("401");
assertThat(result.get(DSPACE_PROPERTY_REASON)).isNotNull();
}
Expand All @@ -146,7 +144,7 @@ void catalogRequest_requestTransformationFailed_returnBadRequest() {
.statusCode(400)
.extract().as(Map.class);

assertThat(result.get(JsonLdKeywords.TYPE)).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(result.get(JsonLdKeywords.TYPE)).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(result.get(DSPACE_PROPERTY_CODE)).isEqualTo("400");
assertThat(result.get(DSPACE_PROPERTY_REASON)).isNotNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.jsonld.spi.Namespaces;
import org.eclipse.edc.service.spi.result.ServiceResult;
import org.eclipse.edc.spi.iam.ClaimToken;
import org.eclipse.edc.spi.iam.IdentityService;
Expand All @@ -43,8 +42,9 @@
import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA;
import static org.eclipse.edc.jsonld.spi.Namespaces.ODRL_PREFIX;
import static org.eclipse.edc.jsonld.spi.Namespaces.ODRL_SCHEMA;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_ERROR;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_CODE;
import static org.eclipse.edc.protocol.dsp.type.DspPropertyAndTypeNames.DSPACE_PROPERTY_REASON;
import static org.eclipse.edc.service.spi.result.ServiceResult.badRequest;
Expand All @@ -57,8 +57,6 @@

class DspCatalogApiControllerTest {

private static final String DSPACE_CATALOG_ERROR = Namespaces.DSPACE_SCHEMA + "CatalogError";

private final Monitor monitor = mock(Monitor.class);
private final IdentityService identityService = mock(IdentityService.class);
private final TypeTransformerRegistry transformerRegistry = mock(TypeTransformerRegistry.class);
Expand All @@ -83,7 +81,7 @@ void setUp() {
controller = new DspCatalogApiController(monitor, identityService, transformerRegistry, callbackAddress, service, jsonLdService);

request = Json.createObjectBuilder()
.add(TYPE, DSPACE_CATALOG_REQUEST_TYPE)
.add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE)
.build();
requestMessage = CatalogRequestMessage.Builder.newInstance().protocol("protocol").build();
}
Expand Down Expand Up @@ -124,7 +122,7 @@ void getCatalog_invalidTypeInRequest_throwException() {

var errorObject = (JsonObject) response.getEntity();

assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(DSPACE_PROPERTY_CODE).getString()).isEqualTo("400");
assertThat(errorObject.get(DSPACE_PROPERTY_REASON)).isNotNull();

Expand All @@ -143,7 +141,7 @@ void getCatalog_transformingRequestFails_throwException() {

var errorObject = (JsonObject) response.getEntity();

assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(DSPACE_PROPERTY_CODE).getString()).isEqualTo("400");
assertThat(errorObject.get(DSPACE_PROPERTY_REASON)).isNotNull();
}
Expand All @@ -159,7 +157,7 @@ void getCatalog_authenticationFails_throwException() {

var errorObject = (JsonObject) response.getEntity();

assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(DSPACE_PROPERTY_CODE).getString()).isEqualTo("401");
assertThat(errorObject.get(DSPACE_PROPERTY_REASON)).isNotNull();
}
Expand All @@ -178,7 +176,7 @@ void getCatalog_shouldThrowException_whenServiceCallFails() {

var errorObject = (JsonObject) response.getEntity();

assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CATALOG_ERROR);
assertThat(errorObject.getJsonString(DSPACE_PROPERTY_CODE).getString()).isNotNull();
assertThat(errorObject.get(DSPACE_PROPERTY_REASON)).isNotNull();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ dependencies {
api(project(":spi:common:catalog-spi"))
api(project(":spi:common:json-ld-spi"))
api(project(":extensions:common:json-ld"))
api(project(":data-protocols:dsp:dsp-spi"))
api(project(":data-protocols:dsp:dsp-http-spi"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_FILTER_PROPERTY;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;

/**
* Transforms a {@link CatalogRequestMessage} to a {@link JsonObject} in JSON-LD expanded form.
Expand All @@ -41,10 +41,10 @@ public JsonObjectFromCatalogRequestMessageTransformer(JsonBuilderFactory jsonFac
@Override
public @Nullable JsonObject transform(@NotNull CatalogRequestMessage message, @NotNull TransformerContext context) {
var builder = jsonFactory.createObjectBuilder();
builder.add(TYPE, DSPACE_CATALOG_REQUEST_TYPE);
builder.add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE);

if (message.getQuerySpec() != null) {
builder.add(DSPACE_FILTER_PROPERTY, context.transform(message.getQuerySpec(), JsonObject.class));
builder.add(DSPACE_PROPERTY_FILTER, context.transform(message.getQuerySpec(), JsonObject.class));
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_FILTER_PROPERTY;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER;

/**
* Transforms a {@link JsonObject} in JSON-LD expanded form to a {@link CatalogRequestMessage}.
Expand Down Expand Up @@ -51,7 +51,7 @@ public JsonObjectToCatalogRequestMessageTransformer(ObjectMapper mapper) {

@Nullable
private QuerySpec transformQuerySpec(JsonObject object, TransformerContext context) {
var value = object.get(DSPACE_FILTER_PROPERTY);
var value = object.get(DSPACE_PROPERTY_FILTER);
if (value == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_FILTER_PROPERTY;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -61,8 +61,8 @@ void transform_returnJsonObject() {
var result = transformer.transform(message, context);

assertThat(result).isNotNull();
assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CATALOG_REQUEST_TYPE);
assertThat(result.get(DSPACE_FILTER_PROPERTY)).isEqualTo(querySpecJson);
assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_TYPE_CATALOG_REQUEST_MESSAGE);
assertThat(result.get(DSPACE_PROPERTY_FILTER)).isEqualTo(querySpecJson);
verify(context, never()).reportProblem(anyString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_CATALOG_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.catalog.transform.DspCatalogPropertyAndTypeNames.DSPACE_FILTER_PROPERTY;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_PROPERTY_FILTER;
import static org.eclipse.edc.protocol.dsp.type.DspCatalogPropertyAndTypeNames.DSPACE_TYPE_CATALOG_REQUEST_MESSAGE;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand All @@ -54,8 +54,8 @@ void transform_returnCatalogRequestMessage() {
when(context.transform(querySpecJson, QuerySpec.class)).thenReturn(querySpec);

var message = jsonFactory.createObjectBuilder()
.add(TYPE, DSPACE_CATALOG_REQUEST_TYPE)
.add(DSPACE_FILTER_PROPERTY, querySpecJson)
.add(TYPE, DSPACE_TYPE_CATALOG_REQUEST_MESSAGE)
.add(DSPACE_PROPERTY_FILTER, querySpecJson)
.build();

var result = transformer.transform(message, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ plugins {

dependencies {
api(project(":data-protocols:dsp:dsp-api-configuration"))
api(project(":data-protocols:dsp:dsp-core"))
api(project(":data-protocols:dsp:dsp-http-core"))

// TODO remove this dependency by moving type constants to another module https://github.com/eclipse-edc/Connector/issues/3014
api(project(":data-protocols:dsp:dsp-negotiation:dsp-negotiation-transform"))
api(project(":data-protocols:dsp:dsp-spi"))
api(project(":data-protocols:dsp:dsp-http-spi"))

api(project(":spi:common:core-spi"))
api(project(":spi:control-plane:control-plane-spi"))
Expand Down
Loading

0 comments on commit 6ef51ac

Please sign in to comment.