Search in sources :

Example 1 with DalGroupDBDao

use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.

the class DatabaseResource method addNewAllInOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("addNewAllInOneDB")
public Status addNewAllInOneDB(@Context HttpServletRequest request, @FormParam("dbtype") String dbtype, @FormParam("allinonename") String allinonename, @FormParam("dbaddress") String dbaddress, @FormParam("dbport") String dbport, @FormParam("dbuser") String dbuser, @FormParam("dbpassword") String dbpassword, @FormParam("dbcatalog") String dbcatalog, @FormParam("addtogroup") boolean addToGroup, @FormParam("dalgroup") String groupId, @FormParam("gen_default_dbset") boolean isGenDefault) {
    Status status = Status.OK;
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    if (allDbDao.getGroupDBByDbName(allinonename) != null) {
        status = Status.ERROR;
        status.setInfo(allinonename + "已经存在!");
        return status;
    } else {
        DalGroupDB groupDb = new DalGroupDB();
        groupDb.setDbname(allinonename);
        groupDb.setDb_address(dbaddress);
        groupDb.setDb_port(dbport);
        groupDb.setDb_user(dbuser);
        groupDb.setDb_password(dbpassword);
        groupDb.setDb_catalog(dbcatalog);
        groupDb.setDb_providerName(DatabaseType.valueOf(dbtype).getValue());
        groupDb.setDal_group_id(-1);
        // add to current user's group
        if (addToGroup) {
            int gid = -1;
            if (groupId != null && !groupId.isEmpty()) {
                gid = Integer.parseInt(groupId);
                groupDb.setDal_group_id(gid);
            } else {
                LoginUser user = RequestUtil.getUserInfo(request);
                if (user != null) {
                    int userId = user.getId();
                    List<UserGroup> list = SpringBeanGetter.getDalUserGroupDao().getUserGroupByUserId(userId);
                    if (list != null && list.size() > 0) {
                        gid = list.get(0).getGroup_id();
                        groupDb.setDal_group_id(gid);
                    }
                }
            }
            // generate default databaseset
            if (isGenDefault) {
                status = DalGroupDbResource.genDefaultDbset(gid, allinonename);
            }
        }
        allDbDao.insertDalGroupDB(groupDb);
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Example 2 with DalGroupDBDao

use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.

the class DatabaseResource method mergeDB.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("merge")
public Status mergeDB(@Context HttpServletRequest request) {
    String userNo = RequestUtil.getUserNo(request);
    Status status = Status.OK;
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    List<UserGroup> urGroups = SpringBeanGetter.getDalUserGroupDao().getUserGroupByUserId(user.getId());
    boolean havePersimion = false;
    if (urGroups != null && urGroups.size() > 0) {
        for (UserGroup ug : urGroups) {
            if (ug.getGroup_id() == DalGroupResource.SUPER_GROUP_ID) {
                havePersimion = true;
                break;
            }
        }
    }
    if (!havePersimion) {
        status = Status.ERROR;
        status.setInfo("You have no permision, only DAL Admin Team can do this.");
        return status;
    }
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    Map<String, DalGroupDB> allDbs = new AllInOneConfigParser(Configuration.get("all_in_one")).getDBAllInOneConfig();
    Set<String> keys = allDbs.keySet();
    for (String key : keys) {
        DalGroupDB db = allDbDao.getGroupDBByDbName(key);
        if (db == null) {
            allDbDao.insertDalGroupDB(allDbs.get(key));
        } else {
            DalGroupDB fileDB = allDbs.get(key);
            allDbDao.updateGroupDB(db.getId(), key, fileDB.getDb_address(), fileDB.getDb_port(), fileDB.getDb_user(), fileDB.getDb_password(), fileDB.getDb_catalog(), fileDB.getDb_providerName());
        }
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Example 3 with DalGroupDBDao

use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.

the class DatabaseResource method getOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("getOneDB")
public Status getOneDB(@Context HttpServletRequest request, @FormParam("allinonename") String allinonename) {
    String userNo = RequestUtil.getUserNo(request);
    Status status = Status.OK;
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    DalGroupDB groupDb = allDbDao.getGroupDBByDbName(allinonename);
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    if (!validatePermision(user.getId(), groupDb.getDal_group_id())) {
        status = Status.ERROR;
        status.setInfo("你没有当前DataBase的操作权限.");
        return status;
    }
    try {
        if (DatabaseType.MySQL.getValue().equals(groupDb.getDb_providerName())) {
            groupDb.setDb_providerName(DatabaseType.MySQL.toString());
        } else if (DatabaseType.SQLServer.getValue().equals(groupDb.getDb_providerName())) {
            groupDb.setDb_providerName(DatabaseType.SQLServer.toString());
        } else {
            groupDb.setDb_providerName("no");
        }
        status.setInfo(mapper.writeValueAsString(groupDb));
    } catch (JsonProcessingException e) {
        status = Status.ERROR;
        status.setInfo(e.getMessage());
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with DalGroupDBDao

use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.

the class DatabaseResource method deleteAllInOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("deleteAllInOneDB")
public Status deleteAllInOneDB(@Context HttpServletRequest request, @FormParam("allinonename") String allinonename) {
    String userNo = RequestUtil.getUserNo(request);
    Status status = Status.OK;
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    DalGroupDB groupDb = allDbDao.getGroupDBByDbName(allinonename);
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    if (!validatePermision(user.getId(), groupDb.getDal_group_id())) {
        status = Status.ERROR;
        status.setInfo("你没有当前DataBase的操作权限.");
    } else {
        allDbDao.deleteDalGroupDB(groupDb.getId());
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Example 5 with DalGroupDBDao

use of com.ctrip.platform.dal.daogen.dao.DalGroupDBDao in project dal by ctripcorp.

the class DatabaseResource method updateDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("updateDB")
public Status updateDB(@Context HttpServletRequest request, @FormParam("id") int id, @FormParam("dbtype") String dbtype, @FormParam("allinonename") String allinonename, @FormParam("dbaddress") String dbaddress, @FormParam("dbport") String dbport, @FormParam("dbuser") String dbuser, @FormParam("dbpassword") String dbpassword, @FormParam("dbcatalog") String dbcatalog) {
    Status status = Status.OK;
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    DalGroupDB db = allDbDao.getGroupDBByDbName(allinonename);
    if (db != null && db.getId() != id) {
        status = Status.ERROR;
        status.setInfo(allinonename + "已经存在!");
        return status;
    }
    String userNo = RequestUtil.getUserNo(request);
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    DalGroupDB groupDb = allDbDao.getGroupDBByDbId(id);
    if (!validatePermision(user.getId(), groupDb.getDal_group_id())) {
        status = Status.ERROR;
        status.setInfo("你没有当前DataBase的操作权限.");
        return status;
    }
    allDbDao.updateGroupDB(id, allinonename, dbaddress, dbport, dbuser, dbpassword, dbcatalog, DatabaseType.valueOf(dbtype).getValue());
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Aggregations

DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)6 Status (com.ctrip.platform.dal.daogen.domain.Status)5 DalGroupDB (com.ctrip.platform.dal.daogen.entity.DalGroupDB)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1