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

feat: split Dtos in InputDto and OutputDto for Asset and ContractDefinition #1797

Merged
merged 7 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import org.eclipse.dataspaceconnector.spi.EdcException;
import org.eclipse.dataspaceconnector.spi.result.Result;
import org.eclipse.dataspaceconnector.spi.transformer.TransformerContext;
import org.eclipse.dataspaceconnector.spi.transformer.TransformerContextImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

Expand All @@ -44,7 +43,7 @@ public void register(IdsTypeTransformer<?, ?> transformer) {
public <INPUT, OUTPUT> Result<OUTPUT> transform(@NotNull INPUT object, @NotNull Class<OUTPUT> outputType) {
var context = new TransformerContextImpl(this);
var output = transform(object, outputType, context);
return context.hasProblems() ? Result.failure(context.problems) : Result.success(output);
return context.hasProblems() ? Result.failure(context.getProblems()) : Result.success(output);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
Expand Down Expand Up @@ -117,32 +116,4 @@ public String toString() {
}
}

private static class TransformerContextImpl implements TransformerContext {
private final List<String> problems = new ArrayList<>();
private final IdsTransformerRegistryImpl registry;

TransformerContextImpl(IdsTransformerRegistryImpl registry) {
this.registry = registry;
}

@Override
public boolean hasProblems() {
return !problems.isEmpty();
}

@Override
public List<String> getProblems() {
return problems;
}

@Override
public void reportProblem(String problem) {
problems.add(problem);
}

@Override
public <INPUT, OUTPUT> @Nullable OUTPUT transform(INPUT object, Class<OUTPUT> outputType) {
return registry.transform(object, outputType, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.math.BigInteger;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -95,7 +94,7 @@ void testSuccessfulSimple() {

@Test
void testSuccessfulMap() {
var properties = new HashMap<>(Map.of(TransformKeys.KEY_ASSET_FILE_NAME, ASSET_FILENAME, TransformKeys.KEY_ASSET_BYTE_SIZE, ASSET_BYTESIZE));
var properties = Map.<String, Object>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();

var result = transformer.transform(asset, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -87,7 +86,7 @@ void testSuccessfulSimple() {

@Test
void testSuccessfulMap() {
var properties = new HashMap<>(Map.of(TransformKeys.KEY_ASSET_FILE_EXTENSION, ASSET_FILE_EXTENSION));
var properties = Map.<String, Object>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);
Expand Down
Loading