annotations.io.fabric8.openshift.api.model.template.TemplateBuilder Maven / Gradle / Ivy
package io.fabric8.openshift.api.model.template;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.ValidationException;
import java.util.Set;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.OAuthClient;
import io.fabric8.kubernetes.api.model.ReplicationController;
import io.fabric8.openshift.api.model.DeploymentConfig;
import java.util.Map;
import io.fabric8.openshift.api.model.ImageStream;
import java.util.List;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.Service;
import java.util.HashMap;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.openshift.api.model.OAuthAccessToken;
import io.fabric8.openshift.api.model.OAuthClientAuthorization;
import io.fabric8.openshift.api.model.Route;
import java.util.ArrayList;
import io.fabric8.common.Builder;
public class TemplateBuilder extends TemplateFluent implements Builder{
TemplateFluent> fluent;
public TemplateBuilder(){
this(new Template());
}
public TemplateBuilder( TemplateFluent> fluent ){
this(fluent, new Template());
}
public TemplateBuilder( TemplateFluent> fluent , Template instance ){
this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); fluent.withLabels(instance.getLabels()); fluent.withMetadata(instance.getMetadata()); fluent.withObjects(instance.getObjects()); fluent.withParameters(instance.getParameters()); fluent.withServices(instance.getServices()); fluent.withReplicationControllers(instance.getReplicationControllers()); fluent.withPods(instance.getPods()); fluent.withBuildConfigs(instance.getBuildConfigs()); fluent.withDeploymentConfigs(instance.getDeploymentConfigs()); fluent.withImageStreams(instance.getImageStreams()); fluent.withRoutes(instance.getRoutes()); fluent.withTemplates(instance.getTemplates()); fluent.withOAuthClients(instance.getOAuthClients()); fluent.withOAuthClientAuthorizations(instance.getOAuthClientAuthorizations()); fluent.withOAuthAccessTokens(instance.getOAuthAccessTokens()); fluent.withNamespaces(instance.getNamespaces()); fluent.withSecrets(instance.getSecrets());
}
public TemplateBuilder( Template instance ){
this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); this.withLabels(instance.getLabels()); this.withMetadata(instance.getMetadata()); this.withObjects(instance.getObjects()); this.withParameters(instance.getParameters()); this.withServices(instance.getServices()); this.withReplicationControllers(instance.getReplicationControllers()); this.withPods(instance.getPods()); this.withBuildConfigs(instance.getBuildConfigs()); this.withDeploymentConfigs(instance.getDeploymentConfigs()); this.withImageStreams(instance.getImageStreams()); this.withRoutes(instance.getRoutes()); this.withTemplates(instance.getTemplates()); this.withOAuthClients(instance.getOAuthClients()); this.withOAuthClientAuthorizations(instance.getOAuthClientAuthorizations()); this.withOAuthAccessTokens(instance.getOAuthAccessTokens()); this.withNamespaces(instance.getNamespaces()); this.withSecrets(instance.getSecrets());
}
public Template build(){
Template buildable = new Template(fluent.getApiVersion(),fluent.getKind(),fluent.getLabels(),fluent.getMetadata(),fluent.getObjects(),fluent.getParameters(),fluent.getServices(),fluent.getReplicationControllers(),fluent.getPods(),fluent.getBuildConfigs(),fluent.getDeploymentConfigs(),fluent.getImageStreams(),fluent.getRoutes(),fluent.getTemplates(),fluent.getOAuthClients(),fluent.getOAuthClientAuthorizations(),fluent.getOAuthAccessTokens(),fluent.getNamespaces(),fluent.getSecrets());
validate(buildable);
return buildable;
}
private void validate(T item) {
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set> violations = validator.validate(item);
if (!violations.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Constraint Violations:\n");
for (ConstraintViolation violation : violations) {
sb.append("\t").append(violation.getRootBeanClass().getSimpleName()).append(" ").append(violation.getPropertyPath()).append(":").append(violation.getMessage()).append("\n");
}
throw new IllegalStateException(sb.toString());
}
} catch(ValidationException e) {
//ignore
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy