Search in sources :

Example 1 with Project

use of com.ctrip.platform.dal.daogen.entity.Project in project dal by ctripcorp.

the class JavaCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    Project project = SpringBeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
    DalConfigHost dalConfigHost = null;
    if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getDal_config_name());
    } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getNamespace());
    } else {
        dalConfigHost = new DalConfigHost("");
    }
    ctx.setDalConfigHost(dalConfigHost);
    ctx.setNamespace(project.getNamespace());
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 2 with Project

use of com.ctrip.platform.dal.daogen.entity.Project in project dal by ctripcorp.

the class CSharpCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    Project project = SpringBeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
    DalConfigHost dalConfigHost = null;
    if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getDal_config_name());
    } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getNamespace());
    } else {
        dalConfigHost = new DalConfigHost("");
    }
    ctx.setDalConfigHost(dalConfigHost);
    ctx.setNamespace(project.getNamespace());
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Example 3 with Project

use of com.ctrip.platform.dal.daogen.entity.Project in project dal by ctripcorp.

the class CSharpDalGenerator method createContext.

@Override
public CodeGenContext createContext(int projectId, boolean regenerate, Progress progress, boolean newPojo, boolean ignoreApproveStatus) throws Exception {
    CSharpCodeGenContext ctx = null;
    try {
        Map<String, Boolean> hints = new HashMap<>();
        hints.put("newPojo", newPojo);
        ctx = new CSharpCodeGenContext(projectId, regenerate, progress, hints);
        ctx.setNewPojo(newPojo);
        Project project = SpringBeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
        DalConfigHost dalConfigHost = null;
        if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getDal_config_name());
        } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getNamespace());
        } else {
            dalConfigHost = new DalConfigHost("");
        }
        ctx.setDalConfigHost(dalConfigHost);
        ctx.setNamespace(project.getNamespace());
    } catch (Exception e) {
        log.warn("exception occur when createContext", e);
        throw e;
    }
    return ctx;
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) HashMap(java.util.HashMap) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Example 4 with Project

use of com.ctrip.platform.dal.daogen.entity.Project in project dal by ctripcorp.

the class JavaDalGenerator method createContext.

@Override
public CodeGenContext createContext(int projectId, boolean regenerate, Progress progress, boolean newPojo, boolean ignoreApproveStatus) throws Exception {
    JavaCodeGenContext ctx = null;
    try {
        ctx = new JavaCodeGenContext(projectId, regenerate, progress);
        Project project = SpringBeanGetter.getDaoOfProject().getProjectByID(projectId);
        DalConfigHost dalConfigHost = null;
        if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getDal_config_name());
        } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
            dalConfigHost = new DalConfigHost(project.getNamespace());
        } else {
            dalConfigHost = new DalConfigHost("");
        }
        ctx.setDalConfigHost(dalConfigHost);
        ctx.setNamespace(project.getNamespace());
    } catch (Exception e) {
        log.warn("exception occur when createContext", e);
        throw e;
    }
    return ctx;
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Example 5 with Project

use of com.ctrip.platform.dal.daogen.entity.Project in project dal by ctripcorp.

the class FileResource method download.

@GET
@Path("download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public String download(@QueryParam("id") String id, @QueryParam("language") String name, @Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception {
    File f = null;
    if (null != name && !name.isEmpty()) {
        f = new File(new File(generatePath, id), name);
    } else {
        f = new File(generatePath, id);
    }
    Project proj = SpringBeanGetter.getDaoOfProject().getProjectByID(Integer.valueOf(id));
    DateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = format1.format(new Date());
    final String zipFileName = proj.getName() + "-" + date + ".zip";
    if (f.isFile()) {
        zipFile(f, zipFileName);
    } else {
        new ZipFolder(f.getAbsolutePath()).zipIt(zipFileName);
    }
    FileInputStream fis = null;
    BufferedInputStream buff = null;
    OutputStream myout = null;
    String path = generatePath + "/" + zipFileName;
    File file = new File(path);
    try {
        if (!file.exists()) {
            response.sendError(404, "File not found!");
            return "";
        } else {
            response.setContentType("application/zip;charset=utf-8");
            response.setContentLength((int) file.length());
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(file.getName().getBytes(Charsets.UTF_8), "UTF-8"));
        }
        // response.reset();
        fis = new FileInputStream(file);
        buff = new BufferedInputStream(fis);
        byte[] b = new byte[1024];
        long k = 0;
        myout = response.getOutputStream();
        while (k < file.length()) {
            int j = buff.read(b, 0, 1024);
            k += j;
            myout.write(b, 0, j);
        }
        myout.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (buff != null)
                buff.close();
            if (myout != null)
                myout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return "";
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipFolder(com.ctrip.platform.dal.daogen.utils.ZipFolder) Date(java.util.Date) Project(com.ctrip.platform.dal.daogen.entity.Project) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Project (com.ctrip.platform.dal.daogen.entity.Project)5 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)4 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 ZipFolder (com.ctrip.platform.dal.daogen.utils.ZipFolder)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1