com.networknt.codegen.handler.CodegenMultipleHandler Maven / Gradle / Ivy
package com.networknt.codegen.handler;
import com.fasterxml.jackson.databind.JsonNode;
import com.networknt.codegen.CodegenWebConfig;
import com.networknt.codegen.FrameworkRegistry;
import com.networknt.codegen.Generator;
import com.networknt.codegen.Utils;
import com.networknt.codegen.graphql.GraphqlGenerator;
import com.networknt.config.Config;
import com.networknt.config.JsonMapper;
import com.networknt.rpc.Handler;
import com.networknt.rpc.router.JsonHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.utility.HashUtil;
import com.networknt.utility.NioUtils;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import static java.io.File.separator;
/**
* This is the handler that does the code generation for consumer request with multiple projects. It is used to generate a folder with
* more than one project. For example, generate query side and command side projects for CQRS.
*
* @author Steve Hu
*/
@ServiceHandler(id="lightapi.net/codegen/multiple/0.0.1")
public class CodegenMultipleHandler implements Handler {
static private final String CONFIG_NAME = "codegen-web";
static private final String STATUS_INVALID_FRAMEWORK = "ERR11100";
static private final String STATUS_MISSING_GENERATOR_ITEM = "ERR11101";
static private final String STATUS_INVALID_MODEL_URL = "ERR11103";
static private final String STATUS_INVALID_CONFIG_JSON = "ERR11104";
static private final String STATUS_INVALID_CONFIG_URL_EXTENSION = "ERR11105";
static private final String STATUS_GENERATOR_EXCEPTION = "ERR11106";
static private final String STATUS_COMPRESSION_EXCEPTION = "ERR11107";
static private final Logger logger = LoggerFactory.getLogger(CodegenMultipleHandler.class);
static private CodegenWebConfig codegenWebConfig = (CodegenWebConfig) Config.getInstance().getJsonObjectConfig(CONFIG_NAME, CodegenWebConfig.class);
@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
// generate a destination folder name.
String output = HashUtil.generateUUID();
String zipFile = output + ".zip";
String projectFolder = codegenWebConfig.getTmpFolder() + separator + output;
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy