
annotations.io.fabric8.openshift.api.model.LocalSubjectAccessReviewBuilder Maven / Gradle / Ivy
package io.fabric8.openshift.api.model;
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import java.lang.Boolean;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.ValidationException;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Set;
import java.lang.Object;
public class LocalSubjectAccessReviewBuilder extends LocalSubjectAccessReviewFluentImpl implements VisitableBuilder{
LocalSubjectAccessReviewFluent> fluent;
Boolean validationEnabled;
public LocalSubjectAccessReviewBuilder(){
this(true);
}
public LocalSubjectAccessReviewBuilder(Boolean validationEnabled){
this(new LocalSubjectAccessReview(), validationEnabled);
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReviewFluent> fluent){
this(fluent, true);
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReviewFluent> fluent,Boolean validationEnabled){
this(fluent, new LocalSubjectAccessReview(), validationEnabled);
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReviewFluent> fluent,LocalSubjectAccessReview instance){
this(fluent, instance, true);
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReviewFluent> fluent,LocalSubjectAccessReview instance,Boolean validationEnabled){
this.fluent = fluent;
fluent.withApiVersion(instance.getApiVersion());
fluent.withContent(instance.getContent());
fluent.withGroups(instance.getGroups());
fluent.withKind(instance.getKind());
fluent.withNamespace(instance.getNamespace());
fluent.withResource(instance.getResource());
fluent.withResourceAPIGroup(instance.getResourceAPIGroup());
fluent.withResourceAPIVersion(instance.getResourceAPIVersion());
fluent.withResourceName(instance.getResourceName());
fluent.withScopes(instance.getScopes());
fluent.withUser(instance.getUser());
fluent.withVerb(instance.getVerb());
this.validationEnabled = validationEnabled;
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReview instance){
this(instance,true);
}
public LocalSubjectAccessReviewBuilder(LocalSubjectAccessReview instance,Boolean validationEnabled){
this.fluent = this;
this.withApiVersion(instance.getApiVersion());
this.withContent(instance.getContent());
this.withGroups(instance.getGroups());
this.withKind(instance.getKind());
this.withNamespace(instance.getNamespace());
this.withResource(instance.getResource());
this.withResourceAPIGroup(instance.getResourceAPIGroup());
this.withResourceAPIVersion(instance.getResourceAPIVersion());
this.withResourceName(instance.getResourceName());
this.withScopes(instance.getScopes());
this.withUser(instance.getUser());
this.withVerb(instance.getVerb());
this.validationEnabled = validationEnabled;
}
public LocalSubjectAccessReview build(){
LocalSubjectAccessReview buildable = new LocalSubjectAccessReview(fluent.getApiVersion(),fluent.getContent(),fluent.getGroups(),fluent.getKind(),fluent.getNamespace(),fluent.getResource(),fluent.getResourceAPIGroup(),fluent.getResourceAPIVersion(),fluent.getResourceName(),fluent.getScopes(),fluent.getUser(),fluent.getVerb());
validate(buildable);
return buildable;
}
private void validate(T item){
if (!validationEnabled) { return; }
Validator validator = null;
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
} catch(ValidationException e) {return;}
Set> violations = validator.validate(item);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
LocalSubjectAccessReviewBuilder that = (LocalSubjectAccessReviewBuilder) o;
if (fluent != null &&fluent != this ? !fluent.equals(that.fluent) :that.fluent != null &&fluent != this ) return false;
if (validationEnabled != null ? !validationEnabled.equals(that.validationEnabled) :that.validationEnabled != null) return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy