All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.openshift.api.model.DockerImageBuilder Maven / Gradle / Ivy

package io.fabric8.openshift.api.model;

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 java.util.HashMap;
import java.util.Map;
import io.fabric8.common.Builder;

public class DockerImageBuilder extends DockerImageFluent implements Builder{

private final DockerImageFluent fluent;

public DockerImageBuilder(){
    this(new DockerImage());
}
public DockerImageBuilder( DockerImageFluent fluent ){
    this(fluent, new DockerImage());
}
public DockerImageBuilder( DockerImageFluent fluent , DockerImage instance ){
    this.fluent = fluent; fluent.withArchitecture(instance.getArchitecture()); fluent.withAuthor(instance.getAuthor()); fluent.withComment(instance.getComment()); fluent.withConfig(instance.getConfig()); fluent.withContainer(instance.getContainer()); fluent.withContainerConfig(instance.getContainerConfig()); fluent.withCreated(instance.getCreated()); fluent.withDockerVersion(instance.getDockerVersion()); fluent.withId(instance.getId()); fluent.withParent(instance.getParent()); fluent.withSize(instance.getSize()); fluent.withApiVersion(instance.getApiVersion()); fluent.withKind(instance.getKind()); 
}
public DockerImageBuilder( DockerImage instance ){
    this.fluent = this; this.withArchitecture(instance.getArchitecture()); this.withAuthor(instance.getAuthor()); this.withComment(instance.getComment()); this.withConfig(instance.getConfig()); this.withContainer(instance.getContainer()); this.withContainerConfig(instance.getContainerConfig()); this.withCreated(instance.getCreated()); this.withDockerVersion(instance.getDockerVersion()); this.withId(instance.getId()); this.withParent(instance.getParent()); this.withSize(instance.getSize()); this.withApiVersion(instance.getApiVersion()); this.withKind(instance.getKind()); 
}

public DockerImage build(){
    DockerImage buildable = new DockerImage(fluent.getArchitecture(),fluent.getAuthor(),fluent.getComment(),fluent.getConfig(),fluent.getContainer(),fluent.getContainerConfig(),fluent.getCreated(),fluent.getDockerVersion(),fluent.getId(),fluent.getParent(),fluent.getSize(),fluent.getApiVersion(),fluent.getKind());
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 - 2025 Weber Informatics LLC | Privacy Policy