Skip to content
Snippets Groups Projects

Validierung des Metadaten Schemas

Merged Martin Vogel requested to merge feature/566-check-metadata-schema into main
@@ -45,8 +45,8 @@ public class SenderClient {
private SenderClient() {
}
public static WithDestination build(final Sender sender) {
return new ClientBuilder(sender);
public static WithDestination build(final Sender sender, final String metadataSchema) {
return new ClientBuilder(sender, metadataSchema);
}
public interface WithDestination {
@@ -159,10 +159,12 @@ public class SenderClient {
private DataPayload dataPayload;
private UUID destinationId;
private ServiceType serviceType;
private final String metadataSchema;
private List<File> attachments = new ArrayList<>();
public ClientBuilder(final Sender sender) {
public ClientBuilder(final Sender sender, final String metadataSchema) {
this.sender = sender;
this.metadataSchema = metadataSchema;
}
@Override
@@ -239,9 +241,16 @@ public class SenderClient {
/** Set encrypted metadata with data payload and attachments **/
logger.info("Adding data payload with mime-type {} to submission", this.dataPayload.mimeType);
final DataPayload data = getEncryptedData(this.dataPayload, destination, encryptionKey);
submission.setEncryptedData(data.getEncryptedData());
submission.setEncryptedMetadata(getEncryptedMetadata(encryptionKey, data, hashedAttachments));
final DataPayload dataToSend = getEncryptedData(this.dataPayload, destination, encryptionKey);
final Metadata metadata = createMetadata(hashedAttachments, dataToSend);
final ValidationResult validatedMetadata = sender.validateMetadata(metadata, metadataSchema);
if (validatedMetadata.hasError()) {
logger.error("Metadata does not match schema", validatedMetadata.getError());
sender.rejectSubmission(submissionId, destinationId, announcedSubmission.getCaseId());
return Optional.empty();
}
submission.setEncryptedData(dataToSend.getEncryptedData());
submission.setEncryptedMetadata(sender.encryptObject(encryptionKey, metadata));
/** submit submission **/
sender.sendSubmission(submission);
@@ -277,11 +286,6 @@ public class SenderClient {
.withHashedData(hashedData);
}
private String getEncryptedMetadata(final RSAKey encryptionKey, final DataPayload dataPayload, final List<Attachment> hashedAttachments) {
final Metadata metadata = createMetadata(hashedAttachments, dataPayload);
return sender.encryptObject(encryptionKey, metadata);
}
private List<Attachment> toHashedAttachments(final List<AttachmentPayload> attachmentPayloads) {
return attachmentPayloads.stream()
.map(this::toHashedAttachment)
Loading