use of io.jpom.permission.Feature in project Jpom by dromara.
the class MonitorListController method deleteMonitor.
/**
* 删除列表
*
* @param id id
* @return json
*/
@RequestMapping(value = "deleteMonitor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteMonitor(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "删除失败") String id) throws SQLException {
//
HttpServletRequest request = getRequest();
int delByKey = monitorService.delByKey(id, request);
if (delByKey > 0) {
// 删除日志
dbMonitorNotifyLogService.delByWorkspace(request, entity -> entity.set("monitorId", id));
}
return JsonMessage.getString(200, "删除成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class MonitorListController method updateMonitor.
/**
* 增加或修改监控
*
* @param id id
* @param name name
* @param notifyUser user
* @return json
*/
@RequestMapping(value = "updateMonitor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String updateMonitor(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "监控名称不能为空") String name, @ValidatorItem(msg = "请配置监控周期") String execCron, String notifyUser, String webhook) {
String status = getParameter("status");
String autoRestart = getParameter("autoRestart");
JSONArray jsonArray = JSONArray.parseArray(notifyUser);
// List<String> notifyUsers = jsonArray.toJavaList(String.class);
List<String> notifyUserList = jsonArray.toJavaList(String.class);
if (CollUtil.isNotEmpty(notifyUserList)) {
for (String userId : notifyUserList) {
Assert.state(userService.exists(new UserModel(userId)), "没有对应的用户:" + userId);
}
}
String projects = getParameter("projects");
JSONArray projectsArray = JSONArray.parseArray(projects);
List<MonitorModel.NodeProject> nodeProjects = projectsArray.toJavaList(MonitorModel.NodeProject.class);
Assert.notEmpty(nodeProjects, "请至少选择一个节点");
for (MonitorModel.NodeProject nodeProject : nodeProjects) {
Assert.notEmpty(nodeProject.getProjects(), "请至少选择一个项目");
for (String project : nodeProject.getProjects()) {
boolean exists = projectInfoCacheService.exists(nodeProject.getNode(), project);
Assert.state(exists, "没有对应的项目:" + project);
}
}
// 设置参数
if (StrUtil.isNotEmpty(webhook)) {
Validator.validateMatchRegex(RegexPool.URL_HTTP, webhook, "WebHooks 地址不合法");
}
Assert.state(CollUtil.isNotEmpty(notifyUserList) || StrUtil.isNotEmpty(webhook), "请选择一位报警联系人或者填写webhook");
boolean start = "on".equalsIgnoreCase(status);
MonitorModel monitorModel = monitorService.getByKey(id);
if (monitorModel == null) {
monitorModel = new MonitorModel();
}
monitorModel.setAutoRestart("on".equalsIgnoreCase(autoRestart));
monitorModel.setExecCron(this.checkCron(execCron));
monitorModel.projects(nodeProjects);
monitorModel.setStatus(start);
monitorModel.setWebhook(webhook);
monitorModel.notifyUser(notifyUserList);
monitorModel.setName(name);
if (StrUtil.isEmpty(id)) {
// 添加监控
monitorService.insert(monitorModel);
return JsonMessage.getString(200, "添加成功");
}
HttpServletRequest request = getRequest();
monitorService.updateById(monitorModel, request);
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class MonitorUserOptListController method changeStatus.
/**
* 开启或关闭监控
*
* @param id id
* @param status 状态
* @return json
*/
@RequestMapping(value = "changeStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String changeStatus(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id不能为空") String id, String status) {
MonitorUserOptModel monitorModel = monitorUserOptService.getByKey(id);
Assert.notNull(monitorModel, "不存在监控项啦");
boolean bStatus = Convert.toBool(status, false);
monitorModel.setStatus(bStatus);
monitorUserOptService.update(monitorModel);
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class NodeEditController method del.
/**
* 删除节点
*
* @param id 节点id
* @return json
*/
@PostMapping(value = "del.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id) {
HttpServletRequest request = getRequest();
this.checkDataBind(id, request);
//
{
ProjectInfoCacheModel projectInfoCacheModel = new ProjectInfoCacheModel();
projectInfoCacheModel.setNodeId(id);
projectInfoCacheModel.setWorkspaceId(projectInfoCacheService.getCheckUserWorkspace(request));
boolean exists = projectInfoCacheService.exists(projectInfoCacheModel);
Assert.state(!exists, "该节点下还存在项目,不能删除");
}
//
{
ScriptCacheModel scriptCacheModel = new ScriptCacheModel();
scriptCacheModel.setNodeId(id);
scriptCacheModel.setWorkspaceId(nodeScriptServer.getCheckUserWorkspace(request));
boolean exists = nodeScriptServer.exists(scriptCacheModel);
Assert.state(!exists, "该节点下还存在脚本模版,不能删除");
}
//
this.delNodeData(id, request);
return JsonMessage.getString(200, "操作成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class NodeEditController method unbind.
/**
* 解绑
*
* @param id 分发id
* @return json
*/
@GetMapping(value = "unbind.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String unbind(String id) {
HttpServletRequest request = getRequest();
this.checkDataBind(id, request);
//
projectInfoCacheService.delCache(id, request);
nodeScriptServer.delCache(id, request);
this.delNodeData(id, request);
return JsonMessage.getString(200, "操作成功");
}
Aggregations