Search in sources :

Example 1 with IdsId

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);
    }
}
Also used : IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) DescriptionRequestMessage(de.fraunhofer.iais.eis.DescriptionRequestMessage) IdsType(org.eclipse.dataspaceconnector.ids.spi.IdsType)

Example 2 with IdsId

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();
}
Also used : IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) DescriptionResponseMessageUtil.createDescriptionResponseMessage(org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.DescriptionResponseMessageUtil.createDescriptionResponseMessage) DescriptionResponseMessage(de.fraunhofer.iais.eis.DescriptionResponseMessage) URI(java.net.URI)

Example 3 with IdsId

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;
}
Also used : IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 4 with IdsId

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));
}
Also used : IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) HashMap(java.util.HashMap) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 5 with IdsId

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));
}
Also used : IdsId(org.eclipse.dataspaceconnector.ids.spi.IdsId) HashMap(java.util.HashMap) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) Representation(de.fraunhofer.iais.eis.Representation) ArtifactBuilder(de.fraunhofer.iais.eis.ArtifactBuilder) URI(java.net.URI) Artifact(de.fraunhofer.iais.eis.Artifact) Test(org.junit.jupiter.api.Test)

Aggregations

IdsId (org.eclipse.dataspaceconnector.ids.spi.IdsId)25 URI (java.net.URI)15 Nullable (org.jetbrains.annotations.Nullable)10 Artifact (de.fraunhofer.iais.eis.Artifact)6 Test (org.junit.jupiter.api.Test)6 Representation (de.fraunhofer.iais.eis.Representation)4 ArtifactBuilder (de.fraunhofer.iais.eis.ArtifactBuilder)3 ConstraintViolationException (de.fraunhofer.iais.eis.util.ConstraintViolationException)3 MultiplicityConstraint (org.eclipse.dataspaceconnector.policy.model.MultiplicityConstraint)3 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)3 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)3 AbstractConstraint (de.fraunhofer.iais.eis.AbstractConstraint)2 DescriptionRequestMessage (de.fraunhofer.iais.eis.DescriptionRequestMessage)2 DescriptionResponseMessage (de.fraunhofer.iais.eis.DescriptionResponseMessage)2 RepresentationBuilder (de.fraunhofer.iais.eis.RepresentationBuilder)2 ResourceBuilder (de.fraunhofer.iais.eis.ResourceBuilder)2 HashMap (java.util.HashMap)2 DescriptionResponseMessageUtil.createDescriptionResponseMessage (org.eclipse.dataspaceconnector.ids.api.multipart.handler.description.DescriptionResponseMessageUtil.createDescriptionResponseMessage)2 Action (de.fraunhofer.iais.eis.Action)1 ArtifactRequestMessage (de.fraunhofer.iais.eis.ArtifactRequestMessage)1