Search in sources :

Example 1 with AddServiceResponse

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

the class AddService method exec.

public AddServiceResponse exec(AddServiceRequest request) throws UnsupportedEncodingException {
    AddServiceResponse response = new AddServiceResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getService_name() == null || request.getService_name().equals("") || request.getService_name().equals("RESERVED") || request.getService_level() == null || request.getService_level().equals("") || request.getService_level().equals("")) {
        response.setMessage("The name/level of service to be added should NOT be empty or RESERVED.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_name().contains(".")) {
        response.setMessage("The name of service to be added should NOT contains \".\".");
        response.setStatus(100);
        return response;
    }
    if (request.getService_name().getBytes("UTF-8").length >= 64) {
        response.setMessage("The length of the name of service to be added should NOT be larger than 64 bytes.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_level().equals("second_level") && (request.getService_parent() == null || request.getService_parent().equals(""))) {
        response.setMessage("The first level service name should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    String sql;
    List<Object> params = new ArrayList<Object>();
    if (request.getService_level().equals("first_level")) {
        sql = "insert into t_first_level_service( first_level_service_name, type) values(?, 'standard')";
        params.add(request.getService_name());
    } else {
        sql = "insert into t_second_level_service(second_level_service_name, first_level_service_name, status) values(?,?,'OK')";
        params.add(request.getService_name());
        params.add(request.getService_parent());
    }
    try {
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum >= 0) {
            response.setAddNum(addNum);
            response.setMessage("success");
            response.setStatus(0);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("add record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
    return response;
}
Also used : AddServiceResponse(beans.response.AddServiceResponse) DBUtil(msec.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Example 2 with AddServiceResponse

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

the class AddOddService method exec.

public AddServiceResponse exec(AddServiceRequest request) {
    AddServiceResponse response = new AddServiceResponse();
    response.setMessage("unkown error.");
    response.setStatus(100);
    String result = checkIdentity();
    if (!result.equals("success")) {
        response.setStatus(99);
        response.setMessage(result);
        return response;
    }
    if (request.getService_name() == null || request.getService_name().equals("") || request.getService_level() == null || request.getService_level().equals("")) {
        response.setMessage("The name/level of service to be added should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    if (request.getService_level().equals("second_level") && (request.getService_parent() == null || request.getService_parent().equals(""))) {
        response.setMessage("The first level service name  should NOT be empty.");
        response.setStatus(100);
        return response;
    }
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        response.setMessage("DB connect failed.");
        response.setStatus(100);
        return response;
    }
    String sql;
    List<Object> params = new ArrayList<Object>();
    if (request.getService_level().equals("first_level")) {
        sql = "insert into t_first_level_service( first_level_service_name, type) values(?, 'odd')";
        params.add(request.getService_name());
    } else {
        sql = "insert into t_second_level_service(second_level_service_name, first_level_service_name, type) values(?,?, 'odd')";
        params.add(request.getService_name());
        params.add(request.getService_parent());
    }
    try {
        int addNum = util.updateByPreparedStatement(sql, params);
        if (addNum >= 0) {
            response.setAddNum(addNum);
            response.setMessage("success");
            response.setStatus(0);
            return response;
        }
    } catch (SQLException e) {
        response.setMessage("add record failed:" + e.toString());
        response.setStatus(100);
        e.printStackTrace();
        return response;
    } finally {
        util.releaseConn();
    }
    return response;
}
Also used : AddServiceResponse(beans.response.AddServiceResponse) DBUtil(ngse.org.DBUtil) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Aggregations

AddServiceResponse (beans.response.AddServiceResponse)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 DBUtil (msec.org.DBUtil)1 DBUtil (ngse.org.DBUtil)1