added common lib and added service uri's to properties file
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package ch.unisg.common.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class ErrorResponse {
|
||||
private final HttpStatus httpStatus;
|
||||
private final String message;
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package ch.unisg.common.exception;
|
||||
|
||||
public class InvalidExecutorURIException extends Exception {
|
||||
public InvalidExecutorURIException() {
|
||||
super("URI is invalid");
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package ch.unisg.common.validation;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class SelfValidating<T> {
|
||||
|
||||
private Validator validator;
|
||||
|
||||
protected SelfValidating() {
|
||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
||||
validator = factory.getValidator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates all Bean Validations on the attributes of this
|
||||
* instance.
|
||||
*/
|
||||
protected void validateSelf() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<ConstraintViolation<T>> violations = validator.validate((T) this);
|
||||
if (!violations.isEmpty()) {
|
||||
throw new ConstraintViolationException(violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package ch.unisg.common.valueobject;
|
||||
|
||||
import ch.unisg.common.exception.InvalidExecutorURIException;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class ExecutorURI {
|
||||
private String value;
|
||||
|
||||
public ExecutorURI(String uri) throws InvalidExecutorURIException {
|
||||
if (uri.equalsIgnoreCase("localhost") ||
|
||||
uri.matches("^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)(\\.(?!$)|$)){4}$")) {
|
||||
this.value = uri;
|
||||
} else {
|
||||
throw new InvalidExecutorURIException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user