Search in sources :

Example 56 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class ProjectResource method addProject.

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status addProject(@Context HttpServletRequest request, @FormParam("id") int id, @FormParam("name") String name, @FormParam("namespace") String namespace, @FormParam("dalconfigname") String dalconfigname, @FormParam("action") String action, @FormParam("project_group_id") int project_group_id) throws Exception {
    try {
        Project proj = new Project();
        String userNo = RequestUtil.getUserNo(request);
        LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
        if (user == null) {
            Status status = Status.ERROR();
            status.setInfo("You have not login.");
            return status;
        }
        List<UserGroup> urGroups = BeanGetter.getDalUserGroupDao().getUserGroupByUserId(user.getId());
        if (urGroups == null || urGroups.size() < 1) {
            Status status = Status.ERROR();
            status.setInfo("请先加入某个DAL Team.");
            return status;
        }
        if (action.equals("insert")) {
            List<Project> pjs = BeanGetter.getDaoOfProject().getProjectByConfigname(dalconfigname);
            if (null != pjs && pjs.size() > 0) {
                Status status = Status.ERROR();
                status.setInfo("Dal.config Name --> " + dalconfigname + " 已经存在,请重新命名!");
                return status;
            }
            proj.setName(name);
            proj.setNamespace(namespace);
            proj.setDal_config_name(dalconfigname);
            proj.setDal_group_id(project_group_id);
            proj.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
            proj.setUpdate_time(new Timestamp(System.currentTimeMillis()));
            BeanGetter.getDaoOfProject().insertProject(proj);
            return Status.OK();
        }
        if (!validateProjectUpdatePermision(userNo, id, project_group_id)) {
            Status status = Status.ERROR();
            status.setInfo("你没有当前Project的操作权限.");
            return status;
        }
        if (action.equals("update")) {
            List<Project> pjs = BeanGetter.getDaoOfProject().getProjectByConfigname(dalconfigname);
            if (null != pjs && pjs.size() > 0) {
                for (Project temp : pjs) {
                    if (temp.getId() != id) {
                        Status status = Status.ERROR();
                        status.setInfo("Dal.config Name --> " + dalconfigname + " 已经存在,请重新命名!");
                        return status;
                    }
                }
            }
            proj.setId(id);
            proj.setName(name);
            proj.setNamespace(namespace);
            proj.setDal_config_name(dalconfigname);
            proj.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
            proj.setUpdate_time(new Timestamp(System.currentTimeMillis()));
            BeanGetter.getDaoOfProject().updateProject(proj);
        } else if (action.equals("delete")) {
            proj.setId(Integer.valueOf(id));
            if (BeanGetter.getDaoOfProject().deleteProject(proj) > 0) {
                BeanGetter.getDaoOfUserProject().deleteUserProject(id);
                BeanGetter.getDaoByFreeSql().deleteByProjectId(id);
                BeanGetter.getDaoBySqlBuilder().deleteByProjectId(id);
                BeanGetter.getDaoByTableViewSp().deleteByProjectId(id);
            }
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Timestamp(java.sql.Timestamp)

Example 57 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class ProjectResource method projectPermisionCheck.

@POST
@Path("projectPermisionCheck")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status projectPermisionCheck(@Context HttpServletRequest request, @FormParam("prjId") int prjId) throws Exception {
    try {
        String userNo = RequestUtil.getUserNo(request);
        if (!validateProjectUpdatePermision(userNo, prjId, -1)) {
            Status status = Status.ERROR();
            status.setInfo("你没有当前DAO的操作权限.");
            return status;
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 58 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class ProjectResource method generateProject.

@POST
@Path("generate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status generateProject(@Context HttpServletRequest request, @FormParam("project_id") int id, @FormParam("regenerate") boolean regen, @FormParam("language") String language, @FormParam("newPojo") boolean newPojo, @FormParam("random") String random) {
    Status status = null;
    Progress progress = null;
    try {
        String userNo = RequestUtil.getUserNo(request);
        progress = ProgressResource.getProgress(userNo, id, random);
        status = validatePermision(userNo, id);
        if (status.getCode().equals(Status.ERROR().getCode())) {
            progress.setStatus(ProgressResource.FINISH);
            return status;
        }
        HashSet<String> hashSet = getProjectSqlStyles(id);
        if (hashSet.isEmpty()) {
            progress.setStatus(ProgressResource.FINISH);
            status = Status.ERROR();
            status.setInfo(String.format("Language error for project %s", id));
            return status;
        }
        String code = "";
        if (hashSet.contains(JAVA)) {
            code = JAVA;
            DalGenerator generator = new JavaDalGenerator();
            CodeGenContext context = generator.createContext(id, true, progress, newPojo, false);
            LoggerManager.getInstance().info(String.format("Begin to generate java task for project %s", id));
            generateLanguageProject(generator, context);
            LoggerManager.getInstance().info(String.format("Java task for project %s generated.", id));
        }
        if (hashSet.contains(CS)) {
            // cs
            code = "cs";
            DalGenerator generator = new CSharpDalGenerator();
            CodeGenContext context = generator.createContext(id, true, progress, newPojo, false);
            LoggerManager.getInstance().info(String.format("Begin to generate csharp task for project %s", id));
            generateLanguageProject(generator, context);
            LoggerManager.getInstance().info(String.format("Csharp task for project %s generated.", id));
        }
        status = Status.OK();
        status.setInfo(code);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    } finally {
        progress.setStatus(ProgressResource.FINISH);
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) DalGenerator(com.ctrip.platform.dal.daogen.DalGenerator) CodeGenContext(com.ctrip.platform.dal.daogen.CodeGenContext) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)

Example 59 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class ProjectResource method validatePermision.

private Status validatePermision(String userNo, int project_id) throws SQLException {
    Status status = Status.ERROR();
    LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    List<UserGroup> urGroups = BeanGetter.getDalUserGroupDao().getUserGroupByUserId(user.getId());
    if (urGroups == null) {
        status.setInfo("你没有权限生成代码.请先加入一个 DAL Team.");
        return status;
    }
    if (urGroups.size() == 0) {
        status.setInfo("你没有权限生成代码.请先加入一个 DAL Team.");
        return status;
    }
    int groupId = -1;
    groupId = BeanGetter.getDaoOfProject().getProjectByID(project_id).getDal_group_id();
    String info = "";
    // 验证project的task所需要的databaseSet在组内是否存在
    status = validateDbsetPermision(groupId, project_id);
    if (status.getCode().equals(Status.ERROR().getCode())) {
        info = status.getInfo();
    }
    // 验证project的task所需要的database在组内是否存在
    status = validateDbPermision(groupId, project_id);
    if (status.getCode().equals(Status.ERROR().getCode())) {
        info += "</br>" + status.getInfo();
    }
    if (info.length() > 0) {
        status = Status.ERROR();
        status.setInfo(info);
        return status;
    }
    return Status.OK();
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 60 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class ProjectResource method eraseFiles.

@POST
@Path("eraseFiles")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status eraseFiles(@FormParam("prjId") int prjId) {
    try {
        String path = Configuration.get("gen_code_path");
        File dir = new File(String.format("%s/%s", path, prjId));
        if (dir.exists())
            try {
                FileUtils.forceDelete(dir);
            } catch (IOException e) {
            }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) IOException(java.io.IOException) File(java.io.File)

Aggregations

Status (com.ctrip.platform.dal.daogen.domain.Status)63 Timestamp (java.sql.Timestamp)13 SQLException (java.sql.SQLException)7 LoginUser (com.ctrip.platform.dal.daogen.entity.LoginUser)6 DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ConfigTemplate (com.ctrip.platform.dal.daogen.entity.ConfigTemplate)3 CurrentLanguage (com.ctrip.platform.dal.daogen.enums.CurrentLanguage)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)2 ValidateResult (com.ctrip.platform.dal.daogen.sql.validate.ValidateResult)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 EmailException (org.apache.commons.mail.EmailException)2 HtmlEmail (org.apache.commons.mail.HtmlEmail)2 VelocityContext (org.apache.velocity.VelocityContext)2 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)1 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 TableSpNames (com.ctrip.platform.dal.daogen.domain.TableSpNames)1