Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean up ids-api-multipart-endpoint-v1 #1715

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0ef385c
chore: remove IdsResponseMessageFactory
ronjaquensel Jul 8, 2022
d815e25
chore: remove unused exceptions
ronjaquensel Jul 8, 2022
1ab2fc5
chore: merge response and rejection util classes
ronjaquensel Jul 8, 2022
034dc73
chore: remove class IdsClientCredentialsScope
ronjaquensel Jul 11, 2022
42b1156
chore: do not use description sub-handlers
ronjaquensel Jul 11, 2022
6cfd5d7
chore: remove sub-handler classes
ronjaquensel Jul 12, 2022
5f32658
chore: remove DescriptionRequestHandler interface
ronjaquensel Jul 12, 2022
be3c483
chore: remove DescriptionResponseMessageUtil
ronjaquensel Jul 12, 2022
d90f447
chore: move util classes to util package
ronjaquensel Jul 12, 2022
7582399
chore: add token to all response headers
ronjaquensel Jul 12, 2022
fc11082
chore: add Javadoc to MultipartController
ronjaquensel Jul 12, 2022
1896f7b
chore: move method for building description response to util
ronjaquensel Jul 12, 2022
84f70e5
chore: return RequestInProcessMessage for artifact requests
ronjaquensel Jul 12, 2022
20df603
chore: make response depend on status result from state machine
ronjaquensel Jul 12, 2022
eb07868
chore: do not build message in ArtifactRequestHandler
ronjaquensel Jul 12, 2022
7a05a51
chore: rename DescriptionRequestHandler
ronjaquensel Jul 13, 2022
761f359
chore: align parameter order in ResponseMessageUtil
ronjaquensel Jul 13, 2022
4786e6b
docs: add Javadoc for ResponseMessageUtil
ronjaquensel Jul 13, 2022
5d6651c
chore: remove unused method
ronjaquensel Jul 13, 2022
1344b2d
docs: add Javadoc for MultipartResponseUtil
ronjaquensel Jul 13, 2022
4db8bf7
refactor: remove duplicated methods from handlers
ronjaquensel Jul 18, 2022
83f5e59
refactor: remove MultipartResponseUtil
ronjaquensel Jul 18, 2022
0dad8e2
refactor: process status result in contract handlers
ronjaquensel Jul 18, 2022
62b30c8
refactor: remove notification sub-handlers
ronjaquensel Jul 18, 2022
39fb36c
chore: remove check for connector payload in MultipartController
ronjaquensel Jul 18, 2022
755e5d7
refactor: remove superfluous claim token parameter
ronjaquensel Jul 18, 2022
a61cdf9
refactor: remove internal handle method from DescriptionRequestHandler
ronjaquensel Jul 18, 2022
dea5fcf
docs: add comments and Javadoc
ronjaquensel Jul 19, 2022
199ff97
refactor: make handleRequest in Handler @NotNull
ronjaquensel Jul 19, 2022
0a0b08f
chore: change rejection reason in EDR handler
ronjaquensel Jul 19, 2022
39a9d1d
chore: add required fields to test messages
ronjaquensel Jul 19, 2022
24b2045
test: update handler tests
ronjaquensel Jul 19, 2022
96697d2
test: replace tests for DescriptionRequestHandler
ronjaquensel Jul 19, 2022
2dbcbea
refactor: rename RequestUtil
ronjaquensel Jul 20, 2022
fd28727
chore: only store secret if TP initialized successfully
ronjaquensel Jul 20, 2022
118d3f0
docs: update CHANGELOG.md
ronjaquensel Jul 20, 2022
833f521
test: update ResponseUtilTest
ronjaquensel Jul 20, 2022
189ede4
chore: fix import order
ronjaquensel Jul 20, 2022
ec60ced
chore: fix import order
ronjaquensel Jul 20, 2022
818269e
refactor: return FormDataMultiPart from MultipartController
ronjaquensel Jul 20, 2022
cb3fe43
refactor: return token from method in MultipartController
ronjaquensel Jul 20, 2022
48103c3
chore: remove unused contract offer handler
ronjaquensel Jul 20, 2022
95f3634
chore: remove superfluous requireNonNull checks
ronjaquensel Jul 20, 2022
7f4dfa7
refactor: inject monitor into IdsMultipartApiServiceExtension
ronjaquensel Jul 22, 2022
d7cbdd5
chore: add TODOs for after project structure review
ronjaquensel Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ in the detailed section referring to by linking pull requests or issues.
* Log correct type in contract-definition API (#1584)
* Replace unmaintained test dependency `java-faker` with `datafaker` (#1709)
* Change CredentialsVerifier contract (#1702)
* Return `RequestInProcessMessage` for IDS artifact requests (#1610)

#### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@

package org.eclipse.dataspaceconnector.ids.api.multipart;

import de.fraunhofer.iais.eis.ParticipantUpdateMessage;
import org.eclipse.dataspaceconnector.ids.api.configuration.IdsApiConfiguration;
import org.eclipse.dataspaceconnector.ids.api.multipart.controller.MultipartController;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.ArtifactRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.ContractAgreementHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.ContractOfferHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.ContractRejectionHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.ContractRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.DescriptionHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.DescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.EndpointDataReferenceHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.Handler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.NotificationMessageHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.NotificationMessageHandlerRegistry;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.ArtifactDescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.ConnectorDescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.DataCatalogDescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.RepresentationDescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.ResourceDescriptionRequestHandler;
import org.eclipse.dataspaceconnector.ids.api.multipart.message.ids.IdsResponseMessageFactory;
import org.eclipse.dataspaceconnector.ids.core.serialization.ObjectMapperFactory;
import org.eclipse.dataspaceconnector.ids.spi.IdsId;
import org.eclipse.dataspaceconnector.ids.spi.IdsIdParser;
import org.eclipse.dataspaceconnector.ids.spi.IdsType;
import org.eclipse.dataspaceconnector.ids.spi.service.CatalogService;
Expand All @@ -64,7 +53,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.LinkedList;
import java.util.Objects;

/**
* ServiceExtension providing IDS multipart related API controllers
Expand All @@ -75,6 +63,7 @@ public final class IdsMultipartApiServiceExtension implements ServiceExtension {
public static final String EDC_IDS_ID = "edc.ids.id";
public static final String DEFAULT_EDC_IDS_ID = "urn:connector:edc";

@Inject
private Monitor monitor;
@Inject
private WebService webService;
Expand Down Expand Up @@ -118,82 +107,41 @@ public String name() {


@Override
public void initialize(ServiceExtensionContext serviceExtensionContext) {
monitor = serviceExtensionContext.getMonitor();

registerControllers(serviceExtensionContext);
public void initialize(ServiceExtensionContext context) {
registerControllers(context);
}

private void registerControllers(ServiceExtensionContext serviceExtensionContext) {

var connectorId = resolveConnectorId(serviceExtensionContext);

// create description request handlers
var artifactDescriptionRequestHandler = new ArtifactDescriptionRequestHandler(monitor, connectorId, assetIndex, transformerRegistry);
var dataCatalogDescriptionRequestHandler = new DataCatalogDescriptionRequestHandler(monitor, connectorId, dataCatalogService, transformerRegistry);
var representationDescriptionRequestHandler = new RepresentationDescriptionRequestHandler(monitor, connectorId, assetIndex, transformerRegistry);
var resourceDescriptionRequestHandler = new ResourceDescriptionRequestHandler(monitor, connectorId, assetIndex, contractOfferService, transformerRegistry);
var connectorDescriptionRequestHandler = new ConnectorDescriptionRequestHandler(monitor, connectorId, connectorService, transformerRegistry);

// create & register controller
private void registerControllers(ServiceExtensionContext context) {
var connectorId = resolveConnectorId(context);

// TODO ObjectMapper needs to be replaced by one capable to write proper IDS JSON-LD
// once https://github.com/eclipse-dataspaceconnector/DataSpaceConnector/issues/236 is done
var objectMapper = objectMapperFactory.getObjectMapper();

// create request handler
var descriptionHandler = new DescriptionHandler(
monitor,
connectorId,
transformerRegistry,
artifactDescriptionRequestHandler,
dataCatalogDescriptionRequestHandler,
representationDescriptionRequestHandler,
resourceDescriptionRequestHandler,
connectorDescriptionRequestHandler);

// create request handlers
var handlers = new LinkedList<Handler>();
handlers.add(descriptionHandler);

var artifactRequestHandler = new ArtifactRequestHandler(monitor, connectorId, objectMapper, contractNegotiationStore, contractValidationService, transferProcessManager, vault);
handlers.add(artifactRequestHandler);

// create contract message handlers
var responseMessageFactory = new IdsResponseMessageFactory(connectorId, identityService);
handlers.add(new ContractRequestHandler(monitor, connectorId, objectMapper, providerNegotiationManager, responseMessageFactory, transformerRegistry, assetIndex));
handlers.add(new DescriptionRequestHandler(monitor, connectorId, transformerRegistry, assetIndex, dataCatalogService, contractOfferService, connectorService));
handlers.add(new ArtifactRequestHandler(monitor, connectorId, objectMapper, contractNegotiationStore, contractValidationService, transferProcessManager, vault));
handlers.add(new EndpointDataReferenceHandler(monitor, connectorId, endpointDataReferenceReceiverRegistry, endpointDataReferenceTransformerRegistry, context.getTypeManager()));
handlers.add(new ContractRequestHandler(monitor, connectorId, objectMapper, providerNegotiationManager, transformerRegistry, assetIndex));
handlers.add(new ContractAgreementHandler(monitor, connectorId, objectMapper, consumerNegotiationManager, transformerRegistry));
handlers.add(new ContractOfferHandler(monitor, connectorId, objectMapper, providerNegotiationManager, consumerNegotiationManager, responseMessageFactory));
handlers.add(new ContractRejectionHandler(monitor, connectorId, providerNegotiationManager, consumerNegotiationManager));

// add notification handler and sub-handlers
var notificationHandlersRegistry = new NotificationMessageHandlerRegistry();
var endpointDataReferenceHandler = new EndpointDataReferenceHandler(monitor, connectorId, endpointDataReferenceReceiverRegistry, endpointDataReferenceTransformerRegistry, serviceExtensionContext.getTypeManager());
notificationHandlersRegistry.addHandler(ParticipantUpdateMessage.class, endpointDataReferenceHandler);
handlers.add(new NotificationMessageHandler(connectorId, notificationHandlersRegistry));

// create & register controller
var multipartController = new MultipartController(monitor, connectorId, objectMapper, identityService, handlers, idsApiConfiguration.getIdsWebhookAddress());
webService.registerResource(idsApiConfiguration.getContextAlias(), multipartController);
}

private String resolveConnectorId(@NotNull ServiceExtensionContext context) {
Objects.requireNonNull(context);

String value = context.getSetting(EDC_IDS_ID, null);

if (value == null) {
String message = "IDS Settings: No setting found for key '%s'. Using default value '%s'";
monitor.warning(String.format(message, EDC_IDS_ID, DEFAULT_EDC_IDS_ID));
value = DEFAULT_EDC_IDS_ID;
}

var value = context.getSetting(EDC_IDS_ID, DEFAULT_EDC_IDS_ID);
try {
// Hint: use stringified uri to keep uri path and query
IdsId idsId = IdsIdParser.parse(value);
var idsId = IdsIdParser.parse(value);
if (idsId != null && idsId.getType() == IdsType.CONNECTOR) {
return idsId.getValue();
}
} catch (IllegalArgumentException e) {
String message = "IDS Settings: Expected valid URN for setting '%s', but was %s'. Expected format: 'urn:connector:[id]'";
var message = "IDS Settings: Expected valid URN for setting '%s', but was %s'. Expected format: 'urn:connector:[id]'";
throw new EdcException(String.format(message, EDC_IDS_ID, DEFAULT_EDC_IDS_ID));
}

Expand Down
Loading