use of org.apache.velocity.VelocityContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.
private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Map<String, JavaMethodHost> freeSqlPojoHosts = ctx.get_freeSqlPojoHosts();
for (final JavaMethodHost host : freeSqlPojoHosts.values()) {
if (host.isSampleType())
continue;
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getPojoClassName() + "] Pojo");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
Queue<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
for (final FreeSqlHost host : freeSqlHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Dap, Test");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/dao/freesql/FreeSqlDAO.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/test/FreeSqlDaoUnitTest.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of org.apache.velocity.VelocityContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfSpProcessor method generateSpDao.
private List<Callable<ExecuteResult>> generateSpDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
List<Callable<ExecuteResult>> results = new ArrayList<Callable<ExecuteResult>>();
for (final SpDbHost host : _spHostMaps.values()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate SP[" + host.getDbSetName() + "] Dao, Pojo, Test");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sSpDao.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/DAOBySp.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sSpDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/test/DAOBySpUnitTest.java.tpl");
for (SpHost sp : host.getSpHosts()) {
sp.setDbSetName(host.getDbSetName());
context.put("host", sp);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), sp.getPojoClassName()), "templates/java/Pojo.java.tpl");
}
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of org.apache.velocity.VelocityContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfTableProcessor method generateTableDao.
private List<Callable<ExecuteResult>> generateTableDao(CodeGenContext context, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
final Progress progress = ctx.getProgress();
Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
List<Callable<ExecuteResult>> results = new ArrayList<>();
for (final JavaTableHost host : tableHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate Table[" + host.getDbSetName() + "." + host.getTableName() + "] Dao, Pojo, Test");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/dao/standard/DAO.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/test/DaoUnitTests.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of org.apache.velocity.VelocityContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfViewProcessor method generateViewDao.
private List<Callable<ExecuteResult>> generateViewDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
Queue<ViewHost> _viewHosts = ctx.getViewHosts();
List<Callable<ExecuteResult>> results = new ArrayList<>();
for (final ViewHost host : _viewHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate View[" + host.getDbSetName() + "." + host.getViewName() + "] Dao");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/ViewDAO.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/test/DAOByViewUnitTest.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of org.apache.velocity.VelocityContext in project dal by ctripcorp.
the class GenTaskResource method approveTask.
@POST
@Path("approveTask")
@Produces(MediaType.APPLICATION_JSON)
public Status approveTask(@Context HttpServletRequest request, @FormParam("taskId") String taskId, @FormParam("taskType") String taskType, @FormParam("userId") int userId) throws Exception {
try {
Status status = Status.ERROR();
LoginUser approver = BeanGetter.getDaoOfLoginUser().getUserById(userId);
if (approver == null) {
return status;
}
int len = request.getRequestURI().length();
String host = request.getRequestURL().toString();
host = host.substring(0, len);
String approveUrl = host + "rest/task/taskApproveOperationForEmail?";
String myApprovelTaskUrl = host + "eventmanage.jsp";
String[] taskIds = taskId.split(",");
String[] taskTypes = taskType.split(",");
List<GenTaskByTableViewSp> tableViewSpTasks = new ArrayList<>();
List<GenTaskBySqlBuilder> autoTasks = new ArrayList<>();
List<GenTaskByFreeSql> sqlTasks = new ArrayList<>();
String userNo = RequestUtil.getUserNo(request);
LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
ApproveTask at = new ApproveTask();
at.setApprove_user_id(approver.getId());
at.setCreate_user_id(user.getId());
at.setCreate_time(new Timestamp(System.currentTimeMillis()));
for (int i = 0; i < taskIds.length; i++) {
int id = Integer.parseInt(taskIds[i]);
String type = taskTypes[i].trim();
if ("table_view_sp".equalsIgnoreCase(type)) {
GenTaskByTableViewSp task = BeanGetter.getDaoByTableViewSp().getTasksByTaskId(id);
tableViewSpTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("table_view_sp");
BeanGetter.getApproveTaskDao().insertApproveTask(at);
} else if ("auto".equalsIgnoreCase(type)) {
GenTaskBySqlBuilder task = BeanGetter.getDaoBySqlBuilder().getTasksByTaskId(id);
autoTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("auto");
BeanGetter.getApproveTaskDao().insertApproveTask(at);
} else if ("sql".equalsIgnoreCase(type)) {
GenTaskByFreeSql task = BeanGetter.getDaoByFreeSql().getTasksByTaskId(id);
sqlTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("sql");
BeanGetter.getApproveTaskDao().insertApproveTask(at);
}
}
java.util.Collections.sort(tableViewSpTasks);
java.util.Collections.sort(autoTasks);
java.util.Collections.sort(sqlTasks);
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("standardDao", tableViewSpTasks);
context.put("autoDao", autoTasks);
context.put("sqlDao", sqlTasks);
context.put("approveUrl", approveUrl);
context.put("myApprovelTaskUrl", myApprovelTaskUrl);
context.put("approveUser", approver.getUserName());
String msg = GenUtils.mergeVelocityContext(context, "templates/approval/approveDao.tpl");
HtmlEmail email = new HtmlEmail();
email.setHostName(Configuration.get("email_host_name"));
email.setAuthentication(Configuration.get("email_user_name"), Configuration.get("email_password"));
try {
email.addTo(approver.getUserEmail());
email.setFrom(user.getUserEmail(), user.getUserName());
email.setSubject("Codegen DAO 审批");
email.setHtmlMsg(msg);
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
return Status.OK();
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
Status status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
}
Aggregations