// Path: liberty-starter-application/src/main/java/com/ibm/liberty/starter/ProjectConstructionInputData.java
// public class ProjectConstructionInputData {
//     public final Services services;
//     public final ServiceConnector serviceConnector;
//     public final String appName;
//     public final ProjectConstructor.DeployType deployType;
//     public final ProjectConstructor.BuildType buildType;
//     public final String workspaceDirectory;
//     public final String[] techOptions;
//     public final String artifactId;
//     public final String groupId;
//     public final String generationId;
//     public final boolean beta;
// 
//     public ProjectConstructionInputData(Services services, ServiceConnector serviceConnector, String appName, ProjectConstructor.DeployType deployType, ProjectConstructor.BuildType buildType, String workspaceDirectory, String[] techOptions, String artifactId, String groupId, String generationId, boolean beta) {
//         this.services = services;
//         this.serviceConnector = serviceConnector;
//         this.appName = appName;
//         this.deployType = deployType;
//         this.buildType = buildType;
//         this.workspaceDirectory = workspaceDirectory;
//         this.techOptions = techOptions;
//         this.artifactId = artifactId;
//         this.groupId = groupId;
//         this.generationId = generationId;
//         this.beta = beta;
//     }
//     
//     public String toBxJSON() {
//         List<Service> serviceList = services.getServices();
//         Stream<Service> stream = serviceList.stream();
//         StringBuffer technologies = new StringBuffer("\"");
//         stream.forEach((service) -> {
//             technologies.append(service.getId() + ",");
//         });
//         String stringresult = technologies.length() == 1 ? "" : technologies.substring(0, technologies.length() - 1) + "\"";
//         String json = "{\"technologies\":" + stringresult + ","
//                 + "\"appName\":\"" + appName + "\","
//                 + "\"buildType\":\"" + buildType.toString().toLowerCase() + "\","
//                 + "\"createType\":\"picnmix\"";
//         if (deployType.equals(DeployType.BLUEMIX)) {
//             json += ",\"platforms\":\"bluemix\"";
//         } else {
//             json += ",\"platforms\":\"\"";
//         }
//         if (artifactId != null) {
//             json += ",\"artifactId\":\"" + artifactId + "\"";
//         }
//         if (groupId != null) {
//             json += ",\"groupId\":\"" + groupId + "\"";
//         }
//         if (beta) {
//             json += ",\"libertybeta\":\"true\"";
//         }
//         json += "}";
//         return json;
//     }
//     
//     public String toRequestQueryString(String id) {
//         List<Service> serviceList = services.getServices();
//         Stream<Service> stream = serviceList.stream();
//         StringBuffer technologies = new StringBuffer("");
//         stream.forEach((service) -> {
//             technologies.append("&tech=" + service.getId());
//         });
//         String techOptionsString = "";
//         for(String options : techOptions) {
//             techOptionsString += "&techoptions=" + options;
//         }
//         String[] workspaceArray = workspaceDirectory.split("/");
//         String workspaceId = workspaceArray[workspaceArray.length -1];
//         String genId = (id == null ? generationId : id);
//         return "name=" + appName + technologies + "&deploy=" + deployType.toString().toLowerCase() + "&build=" + buildType.toString() + "&workspace=" + workspaceId + techOptionsString + "&artifactId=" + artifactId + "&groupId=" + groupId + "&generationId=" + genId + "&beta=" + beta;
//     }
// }
// 
// Path: liberty-starter-application/src/main/java/com/ibm/liberty/starter/exception/ProjectGenerationException.java
// public class ProjectGenerationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public ProjectGenerationException() {
//     }
// 
//     public ProjectGenerationException(String message) {
//         super(message);
//     }
// 
//     public ProjectGenerationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ProjectGenerationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ProjectGenerationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.ibm.liberty.starter.ProjectConstructionInputData;
import com.ibm.liberty.starter.exception.ProjectGenerationException;
            }
            retries++;
        }
        String status = checkStatus(id);
        if(!("FINISHED").equals(status)) {
            if ("FAILED".equals(status)) {
                throw new ProjectGenerationException("Code generation failed for job with id: " + id + ". Try again later.");
            }
            if ("RUNNING".equals(status)) {
                throw new ProjectGenerationException("Code generation for job with id " + id + " timed out. Try again later");
            }
            throw new ProjectGenerationException("Did not receive FINISHED from Bx codegen for job with id: " + id + ". Status received:" + status);
        }
    }
    
    protected String checkStatus(String id) {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(URL + "api/generator/" + id + "/status");
        Invocation.Builder invoBuild = target.request();
        Response response = invoBuild.accept(MediaType.APPLICATION_JSON_TYPE).get();
        JsonObject responseObject = response.readEntity(JsonObject.class);
        String responseStatus = responseObject.getString("status");
        System.out.println("Received response status : " + responseStatus);
        return responseStatus;
    }
    
    protected Map<String, byte[]> getProjectMap(String id) {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(URL + "api/generator/" + id);
        Invocation.Builder invoBuild = target.request();
// Path: liberty-starter-application/src/main/java/com/ibm/liberty/starter/ProjectConstructionInputData.java
// public class ProjectConstructionInputData {
//     public final Services services;
//     public final ServiceConnector serviceConnector;
//     public final String appName;
//     public final ProjectConstructor.DeployType deployType;
//     public final ProjectConstructor.BuildType buildType;
//     public final String workspaceDirectory;
//     public final String[] techOptions;
//     public final String artifactId;
//     public final String groupId;
//     public final String generationId;
//     public final boolean beta;
// 
//     public ProjectConstructionInputData(Services services, ServiceConnector serviceConnector, String appName, ProjectConstructor.DeployType deployType, ProjectConstructor.BuildType buildType, String workspaceDirectory, String[] techOptions, String artifactId, String groupId, String generationId, boolean beta) {
//         this.services = services;
//         this.serviceConnector = serviceConnector;
//         this.appName = appName;
//         this.deployType = deployType;
//         this.buildType = buildType;
//         this.workspaceDirectory = workspaceDirectory;
//         this.techOptions = techOptions;
//         this.artifactId = artifactId;
//         this.groupId = groupId;
//         this.generationId = generationId;
//         this.beta = beta;
//     }
//     
//     public String toBxJSON() {
//         List<Service> serviceList = services.getServices();
//         Stream<Service> stream = serviceList.stream();
//         StringBuffer technologies = new StringBuffer("\"");
//         stream.forEach((service) -> {
//             technologies.append(service.getId() + ",");
//         });
//         String stringresult = technologies.length() == 1 ? "" : technologies.substring(0, technologies.length() - 1) + "\"";
//         String json = "{\"technologies\":" + stringresult + ","
//                 + "\"appName\":\"" + appName + "\","
//                 + "\"buildType\":\"" + buildType.toString().toLowerCase() + "\","
//                 + "\"createType\":\"picnmix\"";
//         if (deployType.equals(DeployType.BLUEMIX)) {
//             json += ",\"platforms\":\"bluemix\"";
//         } else {
//             json += ",\"platforms\":\"\"";
//         }
//         if (artifactId != null) {
//             json += ",\"artifactId\":\"" + artifactId + "\"";
//         }
//         if (groupId != null) {
//             json += ",\"groupId\":\"" + groupId + "\"";
//         }
//         if (beta) {
//             json += ",\"libertybeta\":\"true\"";
//         }
//         json += "}";
//         return json;
//     }
//     
//     public String toRequestQueryString(String id) {
//         List<Service> serviceList = services.getServices();
//         Stream<Service> stream = serviceList.stream();
//         StringBuffer technologies = new StringBuffer("");
//         stream.forEach((service) -> {
//             technologies.append("&tech=" + service.getId());
//         });
//         String techOptionsString = "";
//         for(String options : techOptions) {
//             techOptionsString += "&techoptions=" + options;
//         }
//         String[] workspaceArray = workspaceDirectory.split("/");
//         String workspaceId = workspaceArray[workspaceArray.length -1];
//         String genId = (id == null ? generationId : id);
//         return "name=" + appName + technologies + "&deploy=" + deployType.toString().toLowerCase() + "&build=" + buildType.toString() + "&workspace=" + workspaceId + techOptionsString + "&artifactId=" + artifactId + "&groupId=" + groupId + "&generationId=" + genId + "&beta=" + beta;
//     }
// }
// 
// Path: liberty-starter-application/src/main/java/com/ibm/liberty/starter/exception/ProjectGenerationException.java
// public class ProjectGenerationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public ProjectGenerationException() {
//     }
// 
//     public ProjectGenerationException(String message) {
//         super(message);
//     }
// 
//     public ProjectGenerationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ProjectGenerationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ProjectGenerationException(String message, Throwable cause, boolean enableSuppression,
//             boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


// Path: liberty-starter-application/src/main/java/com/ibm/liberty/starter/client/BxCodegenClient.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.ibm.liberty.starter.ProjectConstructionInputData;
import com.ibm.liberty.starter.exception.ProjectGenerationException;

            }
            retries++;
        }
        String status = checkStatus(id);
        if(!("FINISHED").equals(status)) {
            if ("FAILED".equals(status)) {
                throw new ProjectGenerationException("Code generation failed for job with id: " + id + ". Try again later.");
            }
            if ("RUNNING".equals(status)) {
                throw new ProjectGenerationException("Code generation for job with id " + id + " timed out. Try again later");
            }
            throw new ProjectGenerationException("Did not receive FINISHED from Bx codegen for job with id: " + id + ". Status received:" + status);
        }
    }
    
    protected String checkStatus(String id) {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(URL + "api/generator/" + id + "/status");
        Invocation.Builder invoBuild = target.request();
        Response response = invoBuild.accept(MediaType.APPLICATION_JSON_TYPE).get();
        JsonObject responseObject = response.readEntity(JsonObject.class);
        String responseStatus = responseObject.getString("status");
        System.out.println("Received response status : " + responseStatus);
        return responseStatus;
    }
    
    protected Map<String, byte[]> getProjectMap(String id) {
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(URL + "api/generator/" + id);
        Invocation.Builder invoBuild = target.request();
        Response response = invoBuild.accept("application/zip").get();