use of com.usthe.common.entity.dto.Message in project hertzbeat by dromara.
the class AlertsController method getAlertsSummary.
@GetMapping(path = "/summary")
@ApiOperation(value = "Get alarm statistics", notes = "获取告警统计信息")
public ResponseEntity<Message<AlertSummary>> getAlertsSummary() {
AlertSummary alertSummary = alertService.getAlertsSummary();
Message<AlertSummary> message = new Message<>(alertSummary);
return ResponseEntity.ok(message);
}
use of com.usthe.common.entity.dto.Message in project hertzbeat by dromara.
the class GlobalExceptionHandler method handleInputValidException.
/**
* handler the exception thrown for data input verify
* valid注解校验框架校验异常统一处理
* @param e data input verify exception
* @return response
*/
@ExceptionHandler({ MethodArgumentNotValidException.class, BindException.class })
@ResponseBody
ResponseEntity<Message<Void>> handleInputValidException(Exception e) {
StringBuffer errorMessage = new StringBuffer();
if (e instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException exception = (MethodArgumentNotValidException) e;
exception.getBindingResult().getAllErrors().forEach(error -> {
try {
String field = (String) fieldErrorField.get(error);
errorMessage.append(field).append(":").append(error.getDefaultMessage()).append(CONNECT_STR);
} catch (Exception e1) {
errorMessage.append(error.getDefaultMessage()).append(CONNECT_STR);
}
});
} else if (e instanceof BindException) {
BindException exception = (BindException) e;
exception.getAllErrors().forEach(error -> errorMessage.append(error.getDefaultMessage()).append(CONNECT_STR));
}
String errorMsg = errorMessage.toString();
if (errorMsg.endsWith(CONNECT_STR)) {
errorMsg = errorMsg.substring(0, errorMsg.length() - 2);
}
if (log.isDebugEnabled()) {
log.debug("[input argument not valid happen]-{}", errorMsg, e);
}
Message<Void> message = Message.<Void>builder().msg(errorMsg).code(PARAM_INVALID_CODE).build();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(message);
}
use of com.usthe.common.entity.dto.Message in project hertzbeat by dromara.
the class MonitorController method getMonitor.
@GetMapping(path = "/{id}")
@ApiOperation(value = "Obtain monitoring information based on monitoring ID", notes = "根据监控ID获取监控信息")
public ResponseEntity<Message<MonitorDto>> getMonitor(@ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) {
// Get monitoring information
// 获取监控信息
MonitorDto monitorDto = monitorService.getMonitorDto(id);
Message.MessageBuilder<MonitorDto> messageBuilder = Message.builder();
if (monitorDto == null) {
messageBuilder.code(MONITOR_NOT_EXIST_CODE).msg("Monitor not exist.");
} else {
messageBuilder.data(monitorDto);
}
return ResponseEntity.ok(messageBuilder.build());
}
use of com.usthe.common.entity.dto.Message in project hertzbeat by dromara.
the class SummaryController method appMonitors.
@GetMapping
@ApiOperation(value = "Query all application category monitoring statistics", notes = "查询所有应用类别监控统计信息")
public ResponseEntity<Message<Dashboard>> appMonitors() {
List<AppCount> appsCount = monitorService.getAllAppMonitorsCount();
Message<Dashboard> message = new Message<>(new Dashboard(appsCount));
return ResponseEntity.ok(message);
}
use of com.usthe.common.entity.dto.Message in project hertzbeat by dromara.
the class TagController method getTags.
@GetMapping()
@ApiOperation(value = "Get tags information", notes = "根据条件获取标签信息")
public ResponseEntity<Message<Page<Tag>>> getTags(@ApiParam(value = "Tag content search | 标签内容模糊查询", example = "status") @RequestParam(required = false) String search, @ApiParam(value = "Tag type | 标签类型", example = "0") @RequestParam(required = false) Byte type, @ApiParam(value = "List current page | 列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, @ApiParam(value = "Number of list pagination | 列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) {
// Get tag information
Specification<Tag> specification = (root, query, criteriaBuilder) -> {
List<Predicate> andList = new ArrayList<>();
if (type != null) {
Predicate predicateApp = criteriaBuilder.equal(root.get("type"), type);
andList.add(predicateApp);
}
Predicate[] andPredicates = new Predicate[andList.size()];
Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates));
List<Predicate> orList = new ArrayList<>();
if (search != null && !"".equals(search)) {
Predicate predicateName = criteriaBuilder.like(root.get("name"), "%" + search + "%");
orList.add(predicateName);
Predicate predicateValue = criteriaBuilder.like(root.get("value"), "%" + search + "%");
orList.add(predicateValue);
}
Predicate[] orPredicates = new Predicate[orList.size()];
Predicate orPredicate = criteriaBuilder.or(orList.toArray(orPredicates));
if (andPredicate.getExpressions().isEmpty() && orPredicate.getExpressions().isEmpty()) {
return query.where().getRestriction();
} else if (andPredicate.getExpressions().isEmpty()) {
return query.where(orPredicate).getRestriction();
} else if (orPredicate.getExpressions().isEmpty()) {
return query.where(andPredicate).getRestriction();
} else {
return query.where(andPredicate, orPredicate).getRestriction();
}
};
PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
Page<Tag> alertPage = tagService.getTags(specification, pageRequest);
Message<Page<Tag>> message = new Message<>(alertPage);
return ResponseEntity.ok(message);
}
Aggregations