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());
}
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());
}
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;
}
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;
}
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 "";
}
Aggregations