use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class DalGroupResource method delete.
@POST
@Path("delete")
public Status delete(@Context HttpServletRequest request, @FormParam("id") String id) {
String userNo = RequestUtil.getUserNo(request);
if (userNo == null || id == null || id.isEmpty()) {
log.error(String.format("Delete dal group failed, caused by illegal parameters " + "[ids=%s]", id));
Status status = Status.ERROR;
status.setInfo("Illegal parameters.");
return status;
}
if (!this.validate(userNo)) {
Status status = Status.ERROR;
status.setInfo("你没有当前DAL Team的操作权限.");
return status;
}
int groupId = -1;
try {
groupId = Integer.parseInt(id);
} catch (NumberFormatException ex) {
log.error("Delete dal group failed", ex);
Status status = Status.ERROR;
status.setInfo("Illegal group id");
return status;
}
List<Project> prjs = SpringBeanGetter.getDaoOfProject().getProjectByGroupId(groupId);
if (prjs != null && prjs.size() > 0) {
Status status = Status.ERROR;
status.setInfo("当前DAL Team中还有Project,请清空Project后再操作!");
return status;
}
List<DalGroupDB> dbs = SpringBeanGetter.getDaoOfDalGroupDB().getGroupDBsByGroup(groupId);
if (dbs != null && dbs.size() > 0) {
Status status = Status.ERROR;
status.setInfo("当前DAL Team中还有DataBase,请清空DataBase后再操作!");
return status;
}
List<DatabaseSet> dbsets = SpringBeanGetter.getDaoOfDatabaseSet().getAllDatabaseSetByGroupId(groupId);
if (dbsets != null && dbsets.size() > 0) {
Status status = Status.ERROR;
status.setInfo("当前DAL Team中还有DataBaseSet,请清空DataBaseSet后再操作!");
return status;
}
List<LoginUser> us = SpringBeanGetter.getDaoOfLoginUser().getUserByGroupId(groupId);
if (us != null && us.size() > 0) {
Status status = Status.ERROR;
status.setInfo("当前DAL Team中还有Member,请清空Member后再操作!");
return status;
}
int ret = SpringBeanGetter.getDaoOfDalGroup().deleteDalGroup(groupId);
if (ret <= 0) {
log.error("Delete dal group failed, caused by db operation failed, pls check the spring log");
Status status = Status.ERROR;
status.setInfo("Delete operation failed.");
return status;
}
return Status.OK;
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class DalUserResource method userSignIn.
@POST
@Path("signin")
public Status userSignIn(@Context HttpServletRequest request, @FormParam("userNo") String userNo, @FormParam("password") String password) {
Status status = Status.ERROR;
if (userNo == null || userNo.isEmpty()) {
status.setInfo(userNumberNullMessage);
return status;
}
if (password == null || password.isEmpty()) {
status.setInfo(passwordNullMessage);
return status;
}
try {
LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
if (user != null) {
String pw = user.getPassword();
if (pw != null && pw.equals(MD5Util.parseStrToMd5L32(password))) {
status = Status.OK;
setSession(request, user);
return status;
}
}
} catch (Exception e) {
log.error(e.getMessage());
status.setInfo(e.getMessage());
}
status.setInfo(loginFailMessage);
return status;
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class GenTaskResource method taskApproveOperation.
@GET
@Path("taskApproveOperation")
@Produces(MediaType.APPLICATION_JSON)
public Status taskApproveOperation(@Context HttpServletRequest request, @QueryParam("taskId") int taskId, @QueryParam("taskType") String taskType, @QueryParam("approveFlag") int approveFlag, @QueryParam("approveMsg") String approveMsg) {
Status status = Status.ERROR;
String userNo = RequestUtil.getUserNo(request);
LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
if (user == null) {
status.setInfo("please login fisrt.");
return status;
}
ApproveTask task = haveApprovePermision(user.getId(), taskId, taskType);
if (task == null) {
status.setInfo("you don't have permision to approve this task.");
return status;
}
List<GenTaskByTableViewSp> tableViewSpTasks = new ArrayList<>();
List<GenTaskBySqlBuilder> autoTasks = new ArrayList<>();
List<GenTaskByFreeSql> sqlTasks = new ArrayList<>();
if ("table_view_sp".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoByTableViewSp().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
tableViewSpTasks.add(SpringBeanGetter.getDaoByTableViewSp().getTasksByTaskId(taskId));
} else if ("auto".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoBySqlBuilder().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
autoTasks.add(SpringBeanGetter.getDaoBySqlBuilder().getTasksByTaskId(taskId));
} else if ("sql".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoByFreeSql().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
sqlTasks.add(SpringBeanGetter.getDaoByFreeSql().getTasksByTaskId(taskId));
}
java.util.Collections.sort(tableViewSpTasks);
java.util.Collections.sort(autoTasks);
java.util.Collections.sort(sqlTasks);
LoginUser noticeUsr = SpringBeanGetter.getDaoOfLoginUser().getUserById(task.getCreate_user_id());
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("standardDao", tableViewSpTasks);
context.put("autoDao", autoTasks);
context.put("sqlDao", sqlTasks);
String msg = "你好," + noticeUsr.getUserName() + ":<br/> 你提交的DAO已审批,审批";
if (approveFlag == 2) {
msg += "通过。";
} else {
msg += "未通过。";
}
if (approveMsg != null) {
msg += "<br/> 审批意见:" + approveMsg;
}
context.put("msg", msg);
String mailMsg = GenUtils.mergeVelocityContext(context, "templates/approval/approveResult.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(noticeUsr.getUserEmail());
email.setFrom(user.getUserEmail(), user.getUserName());
email.setSubject("Codegen DAO 审批结果通知");
email.setHtmlMsg(mailMsg);
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
return Status.OK;
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class GenTaskResource method checkDaoNameConflict.
@POST
@Path("checkDaoNameConflict")
@Produces(MediaType.APPLICATION_JSON)
public Status checkDaoNameConflict(@FormParam("project_id") int project_id, @FormParam("db_set_name") String db_set_name, @FormParam("daoName") String daoName, @FormParam("is_update") String is_update, @FormParam("dao_id") int dao_id, @FormParam("prefix") String prefix, @FormParam("suffix") String suffix) {
Status status = Status.ERROR;
daoName = daoName.replaceAll("_", "");
List<GenTaskByTableViewSp> tableViewSpTasks = SpringBeanGetter.getDaoByTableViewSp().getTasksByProjectId(project_id);
List<GenTaskBySqlBuilder> autoTasks = SpringBeanGetter.getDaoBySqlBuilder().getTasksByProjectId(Integer.valueOf(project_id));
List<GenTaskByFreeSql> sqlTasks = SpringBeanGetter.getDaoByFreeSql().getTasksByProjectId(Integer.valueOf(project_id));
// 在同一个project中,不同数据库下面不能存在相同的表名或者Dao类名
if (tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
for (GenTaskByTableViewSp task : tableViewSpTasks) {
if (// 修改操作,过滤掉修改的当前记录
"1".equalsIgnoreCase(is_update) && task.getId() == dao_id)
continue;
String[] daoClassName = daoName.split(",");
for (String name : daoClassName) {
if (name.indexOf(prefix) == 0)
name = name.replaceFirst(prefix, "");
name = name + suffix;
String[] existTableName = task.getTable_names().replaceAll("_", "").split(",");
for (String tableName : existTableName) {
if (tableName.indexOf(task.getPrefix()) == 0)
tableName = tableName.replaceFirst(task.getPrefix(), "");
String existDaoName = tableName + task.getSuffix();
if (existDaoName.equalsIgnoreCase(name) && !task.getDatabaseSetName().equalsIgnoreCase(db_set_name)) {
status.setInfo("在同一个project中,不同数据库下面不能定义相同的表名或者DAO类名.<br/>" + "逻辑数据库" + task.getDatabaseSetName() + "下已经存在名为" + name + "的DAO.");
return status;
}
}
}
}
}
if (autoTasks != null && autoTasks.size() > 0) {
for (GenTaskBySqlBuilder task : autoTasks) {
if (// 修改操作,过滤掉修改的当前记录
"1".equalsIgnoreCase(is_update) && task.getId() == dao_id)
continue;
String existBuildSqlTableName = task.getTable_name().replaceAll("_", "");
String existBuildSqlDaoName = existBuildSqlTableName;
if (tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
for (GenTaskByTableViewSp tableTask : tableViewSpTasks) {
String[] tableNames = tableTask.getTable_names().replaceAll("_", "").split(",");
for (String tableName : tableNames) {
if (tableName.equalsIgnoreCase(existBuildSqlTableName)) {
if (tableName.indexOf(tableTask.getPrefix()) == 0)
tableName = tableName.replaceFirst(tableTask.getPrefix(), "");
tableName = tableName + tableTask.getSuffix();
existBuildSqlDaoName = tableName;
break;
}
}
}
}
if (existBuildSqlDaoName.equalsIgnoreCase(daoName) && !task.getDatabaseSetName().equalsIgnoreCase(db_set_name)) {
status.setInfo("在同一个project中,不同数据库下面不能定义相同的表名.<br/>" + "逻辑数据库" + task.getDatabaseSetName() + "下已经存在名为" + daoName + "的DAO.");
return status;
}
}
}
if (sqlTasks != null && sqlTasks.size() > 0) {
for (GenTaskByFreeSql task : sqlTasks) {
if (// 修改操作,过滤掉修改的当前记录
"1".equalsIgnoreCase(is_update) && task.getId() == dao_id)
continue;
if (task.getClass_name().equalsIgnoreCase(daoName) && !task.getDatabaseSetName().equalsIgnoreCase(db_set_name)) {
status.setInfo("在同一个project中,不同数据库下面不能定义相同的DAO类名.<br/>" + "逻辑数据库" + task.getDatabaseSetName() + "下已经存在名为" + daoName + "的DAO.");
return status;
}
}
}
return Status.OK;
}
use of com.ctrip.platform.dal.daogen.domain.Status 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) {
Status status = Status.ERROR;
LoginUser approver = SpringBeanGetter.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 = SpringBeanGetter.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 = SpringBeanGetter.getDaoByTableViewSp().getTasksByTaskId(id);
tableViewSpTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("table_view_sp");
SpringBeanGetter.getApproveTaskDao().insertApproveTask(at);
} else if ("auto".equalsIgnoreCase(type)) {
GenTaskBySqlBuilder task = SpringBeanGetter.getDaoBySqlBuilder().getTasksByTaskId(id);
autoTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("auto");
SpringBeanGetter.getApproveTaskDao().insertApproveTask(at);
} else if ("sql".equalsIgnoreCase(type)) {
GenTaskByFreeSql task = SpringBeanGetter.getDaoByFreeSql().getTasksByTaskId(id);
sqlTasks.add(task);
at.setTask_id(task.getId());
at.setTask_type("sql");
SpringBeanGetter.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;
}
Aggregations