Search in sources :

Example 1 with AddSecondLevelServiceConfigTagResponse

use of beans.response.AddSecondLevelServiceConfigTagResponse in project MSEC by Tencent.

the class AddSecondLevelServiceConfigTag method exec.

public AddSecondLevelServiceConfigTagResponse exec(AddSecondLevelServiceConfigTagRequest request) {
    AddSecondLevelServiceConfigTagResponse response = new AddSecondLevelServiceConfigTagResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getTag_name() == null || request.getTag_name().equals("") || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().length() < 1 || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().length() < 1 || request.getContent() == null || request.getContent().length() < 1) {
        response.setMessage("Some request field is  empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    try {
        //保存文件内容到服务器磁盘
        String filename = SecondLevelServiceConfigTag.getConfigFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getTag_name());
        if (!SaveConfigContent(filename, request.getContent())) {
            response.setMessage("save file failed.");
            response.setStatus(100);
            return response;
        }
        //写入端口配置信息
        int port = getStandardServicePort(util, request.getFirst_level_service_name(), request.getSecond_level_service_name());
        addPortConfig(filename, port);
        //插入数据库
        String sql;
        List<Object> params = new ArrayList<Object>();
        sql = "insert into t_config_tag(tag_name, memo, second_level_service_name,first_level_service_name) values(?,?,?,?)";
        params.add(request.getTag_name());
        if (request.getMemo() == null) {
            params.add("");
        } else {
            params.add(request.getMemo());
        }
        params.add(request.getSecond_level_service_name());
        params.add(request.getFirst_level_service_name());
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum > 0) {
            response.setAddNumber(addNum);
            response.setMessage("success");
            response.setStatus(0);
            return response;
        } else {
            response.setAddNumber(addNum);
            response.setMessage("failed to insert table");
            response.setStatus(100);
            return response;
        }
    } catch (Exception e) {
        response.setMessage("add record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) AddSecondLevelServiceConfigTagResponse(beans.response.AddSecondLevelServiceConfigTagResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Aggregations

AddSecondLevelServiceConfigTagResponse (beans.response.AddSecondLevelServiceConfigTagResponse)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DBUtil (ngse.org.DBUtil)1