Skip to content
Snippets Groups Projects
Commit 118e750e authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Refactor domain model classes

parent afb6939d
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
package de.fitko.fitconnect.api.domain.model.event;
package de.fitko.fitconnect.api.domain.model.events;
public class SecurityEventToken {
}
......@@ -6,7 +6,7 @@ import lombok.Value;
import java.util.UUID;
@Value
public class CreatedSubmission {
public class SubmissionForPickup {
@JsonProperty("destinationId")
private final UUID destinationId;
......
......@@ -14,7 +14,7 @@ import java.util.UUID;
@Setter
@Value
@Builder
public class SubmissionRequest {
public class SubmissionSubmit {
@JsonProperty("destinationId")
UUID destinationId;
......
package de.fitko.fitconnect.api.domain.model.submission;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Value;
import java.util.Collections;
import java.util.List;
@Value
public class AvailableSubmissions {
@Builder
public class SubmissionsForPickup{
@JsonProperty("count")
int count;
......@@ -18,5 +21,5 @@ public class AvailableSubmissions {
int totalCount;
@JsonProperty("submissions")
List<CreatedSubmission> submissions;
}
List<SubmissionForPickup> submissions = Collections.emptyList();
}
\ No newline at end of file
package de.fitko.fitconnect.api.domain.validation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Wrapper for validations including errors that occurred
*/
public class ValidationResult {
private final boolean isValid;
private final List<Exception> errors;
private Exception error;
private ValidationResult(final boolean isValid) {
this.isValid = isValid;
this.errors = Collections.emptyList();
}
private ValidationResult(final boolean isValid, Exception... exceptions) {
private ValidationResult(final boolean isValid, Exception exception) {
this.isValid = isValid;
this.errors = Arrays.asList(exceptions);
this.error = exception;
}
public static ValidationResult ok() {
return new ValidationResult(true);
}
public static ValidationResult error(Exception... exceptions) {
return new ValidationResult(false, exceptions);
public static ValidationResult error(Exception exception) {
return new ValidationResult(false, exception);
}
public boolean isValid() {
return this.isValid;
}
public boolean hasErrors() {
return !isValid || !errors.isEmpty();
public boolean hasError() {
return !isValid || error != null;
}
public List<Exception> getErrors() {
return this.errors;
public Exception getError() {
return this.error;
}
}
......@@ -8,10 +8,10 @@ import de.fitko.fitconnect.api.domain.model.metadata.attachment.Attachment;
import de.fitko.fitconnect.api.domain.model.metadata.attachment.signature.Hash__1;
import de.fitko.fitconnect.api.domain.model.metadata.attachment.signature.Type;
import de.fitko.fitconnect.api.domain.model.metadata.data.Data;
import de.fitko.fitconnect.api.domain.model.submission.SubmissionRequest;
import de.fitko.fitconnect.api.domain.model.submission.CreatedSubmission;
import de.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup;
import de.fitko.fitconnect.api.domain.model.submission.SubmissionSubmit;
import de.fitko.fitconnect.api.domain.validation.ValidationResult;
import de.fitko.fitconnect.api.exceptions.internal.AuthenticationException;
import de.fitko.fitconnect.api.exceptions.AttachmentCreationException;
import de.fitko.fitconnect.api.services.Sender;
import de.fitko.fitconnect.api.services.auth.OAuthService;
import de.fitko.fitconnect.api.services.crypto.CryptoService;
......@@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public class SubmissionSender implements Sender {
......@@ -35,8 +34,7 @@ public class SubmissionSender implements Sender {
private final CertificateValidator certificateValidator;
private final CryptoService cryptoService;
private final MetadataService metadataService;
private HashUtil hashUtil = new HashUtil();
private final HashUtil hashUtil = new HashUtil();
@Inject
public SubmissionSender(final OAuthService authService,
......@@ -51,77 +49,72 @@ public class SubmissionSender implements Sender {
@Override
public ValidationResult validatePublicKey(RSAKey publicKey) {
public ValidationResult validatePublicKey(final RSAKey publicKey) {
return certificateValidator.validatePublicKey(publicKey);
}
@Override
public Optional<Data> encryptSubmissionData(RSAKey publicKey, Data data) {
public Data encryptSubmissionData(final RSAKey publicKey, final Data data) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<Attachment> encryptAttachment(RSAKey publicKey, Attachment attachment) {
public Attachment encryptAttachment(final RSAKey publicKey, final Attachment attachment) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<OAuthToken> retrieveOAuthToken(String clientId, String clientSecret, String... scope) {
try {
final OAuthToken token = authService.authenticate(clientId, clientSecret, scope);
logger.debug("successfully retrieved token {}", token.getAccessToken());
return Optional.of(token);
} catch (AuthenticationException e) {
logger.error("client could not be authenticated", e.getMessage());
return Optional.empty();
}
public OAuthToken retrieveOAuthToken(final String clientId, final String clientSecret, final String... scope) {
final OAuthToken token = authService.authenticate(clientId, clientSecret, scope);
logger.debug("Successfully retrieved OAuth token: {}", token.getAccessToken());
return token;
}
@Override
public Optional<Metadata> createMetadata(Data data, List<Attachment> attachments) {
public Metadata createMetadata(final Data data, final List<Attachment> attachments) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<Metadata> createMetadata(List<Attachment> attachments) {
public Metadata createMetadata(final List<Attachment> attachments) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<CreatedSubmission> createSubmission(SubmissionRequest submission) {
public SubmissionForPickup createSubmission(final SubmissionSubmit submission) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<CreatedSubmission> sendSubmission(UUID submissionId, Metadata encryptedMetadata) {
public SubmissionForPickup sendSubmission(final UUID submissionId, final Metadata encryptedMetadata) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public void uploadAttachments(UUID submissionId, List<Attachment> encryptedAttachments) {
public void uploadAttachments(final UUID submissionId, final List<Attachment> encryptedAttachments) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public Optional<Attachment> createAttachment(File file) {
public Attachment createAttachment(final File file) {
try {
String hashedFileContent = hashUtil.createHashFromFile(file);
Hash__1 hash = new Hash__1();
final String hashedFileContent = hashUtil.createHashFromFile(file);
final Hash__1 hash = new Hash__1();
hash.setType(Type.SHA_512);
hash.setContent(hashedFileContent);
return Optional.ofNullable(Attachment.builder()
return Attachment.builder()
.attachmentId(UUID.randomUUID())
.filename(file.getName())
.hash(hash)
.build());
} catch (IOException e) {
.build();
} catch (final IOException e) {
logger.error("Attachment could not be read", e);
return Optional.empty();
throw new AttachmentCreationException(e.getMessage(), e);
}
}
@Override
public RSAKey getEncryptionKeyForDestination(UUID destinationId) {
public RSAKey getEncryptionKeyForDestination(final UUID destinationId) {
throw new UnsupportedOperationException("not yet implemented");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment