use of beans.response.AddIDLTagResponse in project MSEC by Tencent.
the class AddIDLTag method exec.
public AddIDLTagResponse exec(IDL request) {
AddIDLTagResponse response = new AddIDLTagResponse();
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 = IDL.getIDLFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getTag_name());
if (!SaveIDLContent(filename, request.getContent())) {
response.setMessage("save file failed.");
response.setStatus(100);
return response;
}
//在数据库里记录一条
String sql;
List<Object> params = new ArrayList<Object>();
sql = "insert into t_idl_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 (SQLException e) {
response.setMessage("add record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
} finally {
util.releaseConn();
}
}
Aggregations