diff --git a/client/src/main/java/dev/fitko/fitconnect/client/cli/CommandExecutor.java b/client/src/main/java/dev/fitko/fitconnect/client/cli/CommandExecutor.java index b9805e8c9b1cc90fd788a555261c6f34791bcd74..1affe52792e5b316bd29d6e3f9a81b63446c0a2c 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/cli/CommandExecutor.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/cli/CommandExecutor.java @@ -113,6 +113,7 @@ class CommandExecutor { .withJsonData(getDataAsString(sendSubmissionCommand.data)) .withDestination(sendSubmissionCommand.destinationId) .withServiceType(sendSubmissionCommand.serviceName, sendSubmissionCommand.leikaKey) + .withSchemaUri(sendSubmissionCommand.schemaUri) .build(); return senderClient.submit(submissionPayload); @@ -125,6 +126,7 @@ class CommandExecutor { .withXmlData(getDataAsString(sendSubmissionCommand.data)) .withDestination(sendSubmissionCommand.destinationId) .withServiceType(sendSubmissionCommand.serviceName, sendSubmissionCommand.leikaKey) + .withSchemaUri(sendSubmissionCommand.schemaUri) .build(); return senderClient.submit(submissionPayload); diff --git a/client/src/main/java/dev/fitko/fitconnect/client/cli/commands/SendSubmissionCommand.java b/client/src/main/java/dev/fitko/fitconnect/client/cli/commands/SendSubmissionCommand.java index bebfccf03cc11cc7e1bafbf5c79e43c60f64c586..2a1dd604e43106c083394b43e5fbc99f04de05af 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/cli/commands/SendSubmissionCommand.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/cli/commands/SendSubmissionCommand.java @@ -7,6 +7,7 @@ import dev.fitko.fitconnect.client.cli.util.UUIDConverter; import dev.fitko.fitconnect.client.cli.util.UUIDValidator; import lombok.Data; +import java.net.URI; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -46,5 +47,8 @@ public class SendSubmissionCommand { public List<String> attachments = Collections.emptyList(); + @Parameter(names = "--schemaUri", description = "Schema URI to be used on subscriber side", variableArity = true) + public + URI schemaUri; } diff --git a/client/src/main/java/dev/fitko/fitconnect/client/sender/SubmissionBuilder.java b/client/src/main/java/dev/fitko/fitconnect/client/sender/SubmissionBuilder.java index 9c55d0ffe3e6babc90367271ee301eedb1ef0d49..9f013904678213a4621d3ae4eda83faa9aa7ac45 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/sender/SubmissionBuilder.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/sender/SubmissionBuilder.java @@ -3,16 +3,13 @@ package dev.fitko.fitconnect.client.sender; import dev.fitko.fitconnect.api.domain.model.metadata.data.MimeType; import dev.fitko.fitconnect.api.domain.model.submission.ServiceType; import dev.fitko.fitconnect.client.sender.model.SubmissionPayload; -import dev.fitko.fitconnect.client.sender.steps.BuildStep; -import dev.fitko.fitconnect.client.sender.steps.BuilderStartStep; -import dev.fitko.fitconnect.client.sender.steps.DataStep; -import dev.fitko.fitconnect.client.sender.steps.DestinationStep; -import dev.fitko.fitconnect.client.sender.steps.ServiceTypeStep; +import dev.fitko.fitconnect.client.sender.steps.*; import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.net.URI; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -25,6 +22,7 @@ public final class SubmissionBuilder implements BuilderStartStep, DataStep, DestinationStep, ServiceTypeStep, + SchemaUriStep, BuildStep { private static final Logger LOGGER = LoggerFactory.getLogger(SubmissionBuilder.class); @@ -34,6 +32,7 @@ public final class SubmissionBuilder implements BuilderStartStep, private String data; private MimeType dataMimeType; private ServiceType serviceType; + private URI schemaUri; private SubmissionBuilder() { } @@ -76,7 +75,7 @@ public final class SubmissionBuilder implements BuilderStartStep, } @Override - public BuildStep withServiceType(final String serviceTypeName, final String leikaKey) { + public SchemaUriStep withServiceType(final String serviceTypeName, final String leikaKey) { serviceType = ServiceType.builder() .identifier(leikaKey) .name(serviceTypeName) @@ -85,7 +84,7 @@ public final class SubmissionBuilder implements BuilderStartStep, } @Override - public BuildStep withServiceType(final String serviceTypeName, final String description, final String leikaKey) { + public SchemaUriStep withServiceType(final String serviceTypeName, final String description, final String leikaKey) { serviceType = ServiceType.builder() .identifier(leikaKey) .description(description) @@ -94,6 +93,12 @@ public final class SubmissionBuilder implements BuilderStartStep, return this; } + @Override + public BuildStep withSchemaUri(URI schemaUri) { + this.schemaUri = schemaUri; + return this; + } + @Override public SubmissionPayload build() { return new SubmissionPayload(this); diff --git a/client/src/main/java/dev/fitko/fitconnect/client/sender/model/SubmissionPayload.java b/client/src/main/java/dev/fitko/fitconnect/client/sender/model/SubmissionPayload.java index 9a82309d4abba17d356d9c2e9a3f243ad8efc186..fc7956049bd99f805db90ea84834cf161cf16337 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/sender/model/SubmissionPayload.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/sender/model/SubmissionPayload.java @@ -6,6 +6,7 @@ import dev.fitko.fitconnect.client.sender.SubmissionBuilder; import lombok.Getter; import java.io.File; +import java.net.URI; import java.util.List; import java.util.UUID; @@ -17,6 +18,7 @@ public class SubmissionPayload { private final MimeType dataMimeType; private final List<File> attachments; private final ServiceType serviceType; + private final URI schemaUri; public SubmissionPayload(final SubmissionBuilder builder) { destinationId = builder.getDestinationId(); @@ -24,5 +26,6 @@ public class SubmissionPayload { dataMimeType = builder.getDataMimeType(); attachments = builder.getAttachments(); serviceType = builder.getServiceType(); + schemaUri = builder.getSchemaUri(); } } diff --git a/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/SchemaUriStep.java b/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/SchemaUriStep.java new file mode 100644 index 0000000000000000000000000000000000000000..91adf134326a013d84040ec36a24b0812febe430 --- /dev/null +++ b/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/SchemaUriStep.java @@ -0,0 +1,14 @@ +package dev.fitko.fitconnect.client.sender.steps; + +import java.net.URI; + +public interface SchemaUriStep { + + /** + * Sets a {@link URI}, which determines the schema that is supposed to be used when parsing the submission on subscriber side + * + * @param schemaUri URI of the schema to be used + * @return next step to finish the build + */ + BuildStep withSchemaUri(URI schemaUri); +} diff --git a/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/ServiceTypeStep.java b/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/ServiceTypeStep.java index ee172efd8689b46fcd14b5c240ffdadcc8236fd6..16ab83f413b4577186bc94fdc63cbbdac223d8fe 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/ServiceTypeStep.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/sender/steps/ServiceTypeStep.java @@ -9,10 +9,10 @@ public interface ServiceTypeStep { * * @param name a name of the service * @param leikaKey unique identifier of the service in the form <b>urn:de:fim:leika:leistung:</b> - * @return next step to add attachments + * @return next step to ad a schema URI * @see <a href="https://fimportal.de/">Search For Service Types</a> */ - BuildStep withServiceType(String name, String leikaKey); + SchemaUriStep withServiceType(String name, String leikaKey); /** * Sets a {@link ServiceType} for a submission @@ -20,8 +20,8 @@ public interface ServiceTypeStep { * @param name a name of the service * @param description description of the service * @param leikaKey unique identifier of the service in the form <b>urn:de:fim:leika:leistung:</b> - * @return next step to add attachments + * @return next step to ad a schema URI * @see <a href="https://fimportal.de/">Search For Service Types</a> */ - BuildStep withServiceType(String name, String description, String leikaKey); + SchemaUriStep withServiceType(String name, String description, String leikaKey); } diff --git a/client/src/main/java/dev/fitko/fitconnect/client/sender/strategies/SendNewSubmissionStrategy.java b/client/src/main/java/dev/fitko/fitconnect/client/sender/strategies/SendNewSubmissionStrategy.java index 162fef4271a78cb7cd522aa03fb5a26b655a245d..664109153eb409b19e28c53657b6bb46f6cad3e0 100644 --- a/client/src/main/java/dev/fitko/fitconnect/client/sender/strategies/SendNewSubmissionStrategy.java +++ b/client/src/main/java/dev/fitko/fitconnect/client/sender/strategies/SendNewSubmissionStrategy.java @@ -126,8 +126,7 @@ public class SendNewSubmissionStrategy { final String hashedData = sender.createHash(submissionPayload.getData().getBytes(StandardCharsets.UTF_8)); final MimeType dataMimeType = submissionPayload.getDataMimeType(); - final URI schemaUri = getSubmissionSchemaFromDestination(destination, dataMimeType); - final Data data = createData(dataMimeType, hashedData, schemaUri); + final Data data = createData(dataMimeType, hashedData, submissionPayload.getSchemaUri()); final PublicServiceType publicServiceType = buildPublicServiceType(submissionPayload.getServiceType()); final List<Attachment> attachmentMetadata = encryptedAttachments.stream().map(this::toHashedAttachment).collect(Collectors.toList()); @@ -184,16 +183,6 @@ public class SendNewSubmissionStrategy { return attachment; } - private URI getSubmissionSchemaFromDestination(final Destination destination, final MimeType mimeType) { - return destination.getServices().stream() - .map(DestinationService::getSubmissionSchemas) - .flatMap(Collection::stream) - .filter(schema -> schema.getMimeType().equals(mimeType)) - .map(SubmissionSchema::getSchemaUri) - .findFirst() - .orElseThrow(() -> new SchemaNotFoundException("Destination does not support data with mime-type " + mimeType)); - } - private void uploadAttachments(final List<AttachmentPayload> attachmentPayloads, final UUID submissionId) { if (attachmentPayloads.isEmpty()) { LOGGER.info("No attachments to upload"); diff --git a/client/src/test/java/dev/fitko/fitconnect/client/ClientIntegrationTest.java b/client/src/test/java/dev/fitko/fitconnect/client/ClientIntegrationTest.java index 04999c16ed5f8c0c83afa575d58e280276b0d019..a16f18bcab45f190f46685bb109e116b5f12577f 100644 --- a/client/src/test/java/dev/fitko/fitconnect/client/ClientIntegrationTest.java +++ b/client/src/test/java/dev/fitko/fitconnect/client/ClientIntegrationTest.java @@ -98,6 +98,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -219,6 +220,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -248,12 +250,14 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten 1\" }") .withDestination(destinationId) .withServiceType(serviceName, leikaKey) + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var submissionTwo = SubmissionBuilder.Builder() .withJsonData("{ \"data\": \"Beispiel Fachdaten 2\" }") .withDestination(destinationId) .withServiceType(serviceName, leikaKey) + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmissionOne = senderClient.submit(submissionOne); @@ -292,6 +296,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -322,6 +327,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -351,6 +357,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -382,6 +389,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); @@ -420,6 +428,7 @@ class ClientIntegrationTest { .withJsonData("{ \"data\": \"Beispiel Fachdaten\" }") .withDestination(UUID.fromString(System.getenv("TEST_DESTINATION_ID"))) .withServiceType("Test Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = ClientFactory.senderClient(config).submit(submission); diff --git a/client/src/test/java/dev/fitko/fitconnect/client/SenderClientTest.java b/client/src/test/java/dev/fitko/fitconnect/client/SenderClientTest.java index d9a9c1c70788fe5c52f2ef292282faea1b68fd55..ea35dd69f4919d6642a20016ea5e1d15d39582a8 100644 --- a/client/src/test/java/dev/fitko/fitconnect/client/SenderClientTest.java +++ b/client/src/test/java/dev/fitko/fitconnect/client/SenderClientTest.java @@ -86,6 +86,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -127,6 +128,7 @@ public class SenderClientTest { .withXmlData("<xml><test>data</test></xml>") .withDestination(destinationId) .withServiceType("Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -151,6 +153,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -189,6 +192,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("Service", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -210,6 +214,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -231,6 +236,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -252,6 +258,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -273,6 +280,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -294,6 +302,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -316,6 +325,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -337,6 +347,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); @@ -398,6 +409,7 @@ public class SenderClientTest { .withJsonData("{}") .withDestination(destinationId) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); final var sentSubmission = senderClient.submit(submission); diff --git a/client/src/test/java/dev/fitko/fitconnect/client/util/ValidDataGuardTest.java b/client/src/test/java/dev/fitko/fitconnect/client/util/ValidDataGuardTest.java index 86b0e2777d61f8d528da4e38f0d3369c0b26b36c..2afef9c7b343adc8d6e519aed3b7a1de32d060e9 100644 --- a/client/src/test/java/dev/fitko/fitconnect/client/util/ValidDataGuardTest.java +++ b/client/src/test/java/dev/fitko/fitconnect/client/util/ValidDataGuardTest.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import java.net.URI; import java.util.Set; import java.util.UUID; @@ -54,6 +55,7 @@ class ValidDataGuardTest { .withJsonData("\"test\": \"json\"") .withDestination(UUID.randomUUID()) .withServiceType("Test", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // Then valid if no exception is thrown @@ -68,6 +70,7 @@ class ValidDataGuardTest { .withJsonData(null) .withDestination(UUID.randomUUID()) .withServiceType("Test", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When @@ -85,6 +88,7 @@ class ValidDataGuardTest { .withXmlData(null) .withDestination(UUID.randomUUID()) .withServiceType("Test", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When @@ -104,6 +108,7 @@ class ValidDataGuardTest { .withJsonData("{}") .withDestination(null) .withServiceType("name", "urn:de:fim:leika:leistung:99400048079000") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When @@ -123,6 +128,7 @@ class ValidDataGuardTest { .withJsonData("{\"test\" . \"data\"}") .withDestination(UUID.randomUUID()) .withServiceType("name", "illegal:test:identifier") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> underTest.ensureValidDataPayload(submissionPayload)); @@ -141,6 +147,7 @@ class ValidDataGuardTest { .withJsonData("{\"test\" . \"data\"}") .withDestination(UUID.randomUUID()) .withServiceType("name", null) + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> underTest.ensureValidDataPayload(submissionPayload)); @@ -166,6 +173,7 @@ class ValidDataGuardTest { .withJsonData("\"test\": \"json\"") .withDestination(UUID.randomUUID()) .withServiceType("Test", "urn:de:fim:leika:leistung:123456789101114") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build(); // When final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> underTest.ensureValidDataPayload(submissionPayload)); @@ -344,6 +352,7 @@ class ValidDataGuardTest { .withJsonData("{}") .withDestination(UUID.fromString(invalidUUID)) .withServiceType("name", "test:key") + .withSchemaUri(URI.create("https://schema.fitko.de/fim/s00000000009_1.0.0.schema.json")) .build()); // Then