dev.fitko.fitconnect.api.domain.validation.ValidationContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
Library that provides client access to the FIT-Connect api-endpoints for sending, subscribing and
routing
The newest version!
package dev.fitko.fitconnect.api.domain.validation;
import dev.fitko.fitconnect.api.domain.model.event.authtags.AuthenticationTags;
import dev.fitko.fitconnect.api.exceptions.internal.ValidationException;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Getter
public class ValidationContext {
private final List validationResults;
private final UUID destinationId;
private final UUID caseId;
private final AuthenticationTags authenticationTags;
private final boolean validateAuthTags;
private ValidationContext(final UUID destinationId, final UUID caseId, final boolean validateAuthTags, final AuthenticationTags authenticationTags) {
this.destinationId = destinationId;
this.caseId = caseId;
this.authenticationTags = authenticationTags;
validationResults = new ArrayList<>();
// flag cannot be derived from set authTags because they can still be null if validation is wanted
this.validateAuthTags = validateAuthTags;
}
public static ValidationContext withAuthTagValidation(final UUID destinationId, final UUID caseId, final AuthenticationTags authenticationTags){
return new ValidationContext(destinationId, caseId,true, authenticationTags);
}
public static ValidationContext withoutAuthTagValidation(final UUID destinationId, final UUID caseId){
return new ValidationContext(destinationId, caseId, false, null);
}
public static ValidationContext withoutAuthTagValidation(final UUID caseId){
return new ValidationContext(null, caseId, false, null);
}
public void addResult(final ValidationResult validationResult) {
if (validationResult.hasError()) {
validationResults.add(validationResult);
}
}
public void addErrorIfTestFailed(final boolean test, final String message) {
if (!test) {
addResult(ValidationResult.error(new ValidationException(message)));
}
}
public void addError(final String message) {
addResult(ValidationResult.error(new ValidationException(message)));
}
public void addError(final Exception exception) {
addResult(ValidationResult.error(new ValidationException(exception.getMessage(), exception)));
}
public UUID getDestinationId() {
return destinationId;
}
public UUID getCaseId() {
return caseId;
}
public AuthenticationTags getAuthenticationTags() {
return authenticationTags;
}
public boolean validateAuthTags() {
return validateAuthTags;
}
}