use of org.eclipse.dataspaceconnector.ids.spi.IdsId in project DataSpaceConnector by eclipse-dataspaceconnector.
the class DescriptionHandler method handleRequestInternal.
public MultipartResponse handleRequestInternal(@NotNull MultipartRequest multipartRequest, @NotNull Result<ClaimToken> verificationResult) {
Objects.requireNonNull(multipartRequest);
Objects.requireNonNull(verificationResult);
var descriptionRequestMessage = (DescriptionRequestMessage) multipartRequest.getHeader();
var payload = multipartRequest.getPayload();
var requestedElement = descriptionRequestMessage.getRequestedElement();
IdsId idsId = null;
if (requestedElement != null) {
var result = transformerRegistry.transform(requestedElement, IdsId.class);
if (result.failed() || (idsId = result.getContent()) == null) {
monitor.warning(String.format("Could not transform URI to IdsId: [%s]", String.join(", ", result.getFailureMessages())));
return createBadParametersErrorMultipartResponse(descriptionRequestMessage);
}
}
IdsType type;
if (idsId == null || (type = idsId.getType()) == IdsType.CONNECTOR) {
return connectorDescriptionRequestHandler.handle(descriptionRequestMessage, verificationResult, payload);
}
switch(type) {
case ARTIFACT:
return artifactDescriptionRequestHandler.handle(descriptionRequestMessage, verificationResult, payload);
case CATALOG:
return dataCatalogDescriptionRequestHandler.handle(descriptionRequestMessage, verificationResult, payload);
case REPRESENTATION:
return representationDescriptionRequestHandler.handle(descriptionRequestMessage, verificationResult, payload);
case RESOURCE:
return resourceDescriptionRequestHandler.handle(descriptionRequestMessage, verificationResult, payload);
default:
return createErrorMultipartResponse(descriptionRequestMessage);
}
}
use of org.eclipse.dataspaceconnector.ids.spi.IdsId in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AbstractDescriptionRequestHandler method handle.
@Override
public final MultipartResponse handle(@NotNull DescriptionRequestMessage descriptionRequestMessage, @NotNull Result<ClaimToken> verificationResult, @Nullable String payload) {
Objects.requireNonNull(descriptionRequestMessage);
URI uri = descriptionRequestMessage.getRequestedElement();
if (uri == null) {
return createBadParametersErrorMultipartResponse(connectorId, descriptionRequestMessage);
}
var result = transformerRegistry.transform(uri, IdsId.class);
if (result.failed()) {
monitor.warning(String.format("Could not transform URI to IdsId: [%s]", String.join(", ", result.getFailureMessages())));
return createBadParametersErrorMultipartResponse(connectorId, descriptionRequestMessage);
}
IdsId idsId = result.getContent();
if (Objects.requireNonNull(idsId).getType() != targetIdsType) {
return createBadParametersErrorMultipartResponse(connectorId, descriptionRequestMessage);
}
T retrievedObject = retrieveObject(idsId, verificationResult);
if (retrievedObject == null) {
return createNotFoundErrorMultipartResponse(connectorId, descriptionRequestMessage);
}
Result<S> transformResult = transformerRegistry.transform(retrievedObject, resultType);
if (transformResult.failed()) {
monitor.warning(String.format("Could not transform %s to %S: [%s]", retrievedObject.getClass().getSimpleName(), resultType.getSimpleName(), String.join(", ", transformResult.getFailureMessages())));
return createBadParametersErrorMultipartResponse(connectorId, descriptionRequestMessage);
}
S handlerResult = transformResult.getContent();
DescriptionResponseMessage descriptionResponseMessage = createDescriptionResponseMessage(connectorId, descriptionRequestMessage);
return MultipartResponse.Builder.newInstance().header(descriptionResponseMessage).payload(handlerResult).build();
}
use of org.eclipse.dataspaceconnector.ids.spi.IdsId in project DataSpaceConnector by eclipse-dataspaceconnector.
the class IdsMultipartDispatcherServiceExtension method resolveConnectorId.
private String resolveConnectorId(@NotNull ServiceExtensionContext context) {
Objects.requireNonNull(context);
String value = getSetting(context, EDC_IDS_ID, DEFAULT_EDC_IDS_ID);
try {
// Hint: use stringified uri to keep uri path and query
IdsId 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]'";
throw new EdcException(String.format(message, EDC_IDS_ID, DEFAULT_EDC_IDS_ID));
}
return value;
}
use of org.eclipse.dataspaceconnector.ids.spi.IdsId in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AssetToIdsArtifactTransformerTest method testSuccessfulMap.
@Test
void testSuccessfulMap() {
var properties = new HashMap<>(Map.of(TransformKeys.KEY_ASSET_FILE_NAME, ASSET_FILENAME, TransformKeys.KEY_ASSET_BYTE_SIZE, ASSET_BYTESIZE));
var asset = Asset.Builder.newInstance().properties(properties).id(ASSET_ID).build();
IdsId id = IdsId.Builder.newInstance().value(ASSET_ID).type(IdsType.ARTIFACT).build();
when(context.transform(eq(id), eq(URI.class))).thenReturn(ASSET_ID_URI);
var result = transformer.transform(asset, context);
assertThat(result).isNotNull();
assertThat(result.getId()).isEqualTo(ASSET_ID_URI);
assertThat(result.getFileName()).isEqualTo(ASSET_FILENAME);
assertThat(result.getByteSize()).isEqualTo(ASSET_BYTESIZE);
verify(context).transform(eq(id), eq(URI.class));
}
use of org.eclipse.dataspaceconnector.ids.spi.IdsId in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AssetToIdsRepresentationTransformerTest method testSuccessfulMap.
@Test
void testSuccessfulMap() {
var properties = new HashMap<>(Map.of(TransformKeys.KEY_ASSET_FILE_EXTENSION, ASSET_FILE_EXTENSION));
var asset = Asset.Builder.newInstance().properties(properties).id(REPRESENTATION_ID).build();
var artifact = new ArtifactBuilder().build();
when(context.transform(any(Asset.class), eq(Artifact.class))).thenReturn(artifact);
IdsId id = IdsId.Builder.newInstance().value(REPRESENTATION_ID).type(IdsType.REPRESENTATION).build();
when(context.transform(eq(id), eq(URI.class))).thenReturn(REPRESENTATION_ID_URI);
Representation result = transformer.transform(asset, context);
Assertions.assertNotNull(result);
Assertions.assertEquals(REPRESENTATION_ID_URI, result.getId());
Assertions.assertEquals(ASSET_FILE_EXTENSION, result.getMediaType().getFilenameExtension());
verify(context).transform(any(Asset.class), eq(Artifact.class));
verify(context).transform(eq(id), eq(URI.class));
}
Aggregations