Search in sources :

Example 6 with Message

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);
}
Also used : Message(com.usthe.common.entity.dto.Message) AlertSummary(com.usthe.alert.dto.AlertSummary) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with 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);
}
Also used : DataAccessException(org.springframework.dao.DataAccessException) CommonConstants(com.usthe.common.util.CommonConstants) FieldError(org.springframework.validation.FieldError) MonitorDatabaseException(com.usthe.manager.support.exception.MonitorDatabaseException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Field(java.lang.reflect.Field) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) RestControllerAdvice(org.springframework.web.bind.annotation.RestControllerAdvice) AlertNoticeException(com.usthe.manager.support.exception.AlertNoticeException) Message(com.usthe.common.entity.dto.Message) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntity(org.springframework.http.ResponseEntity) BindException(org.springframework.validation.BindException) MonitorDetectException(com.usthe.manager.support.exception.MonitorDetectException) BindException(org.springframework.validation.BindException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) DataAccessException(org.springframework.dao.DataAccessException) MonitorDatabaseException(com.usthe.manager.support.exception.MonitorDatabaseException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) AlertNoticeException(com.usthe.manager.support.exception.AlertNoticeException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException) BindException(org.springframework.validation.BindException) MonitorDetectException(com.usthe.manager.support.exception.MonitorDetectException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with 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());
}
Also used : MonitorDto(com.usthe.manager.pojo.dto.MonitorDto) Message(com.usthe.common.entity.dto.Message) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with Message

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);
}
Also used : Message(com.usthe.common.entity.dto.Message) AppCount(com.usthe.manager.pojo.dto.AppCount) Dashboard(com.usthe.manager.pojo.dto.Dashboard) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with 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);
}
Also used : ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) HashSet(java.util.HashSet) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) Message(com.usthe.common.entity.dto.Message) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate) TagService(com.usthe.manager.service.TagService) Tag(com.usthe.common.entity.manager.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) Api(io.swagger.annotations.Api) PageRequest(org.springframework.data.domain.PageRequest) Message(com.usthe.common.entity.dto.Message) ArrayList(java.util.ArrayList) List(java.util.List) Page(org.springframework.data.domain.Page) Tag(com.usthe.common.entity.manager.Tag) Predicate(javax.persistence.criteria.Predicate) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Message (com.usthe.common.entity.dto.Message)10 ApiOperation (io.swagger.annotations.ApiOperation)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 ResponseEntity (org.springframework.http.ResponseEntity)5 Api (io.swagger.annotations.Api)4 ApiParam (io.swagger.annotations.ApiParam)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Predicate (javax.persistence.criteria.Predicate)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Page (org.springframework.data.domain.Page)4 PageRequest (org.springframework.data.domain.PageRequest)4 Specification (org.springframework.data.jpa.domain.Specification)4 APPLICATION_JSON_VALUE (org.springframework.http.MediaType.APPLICATION_JSON_VALUE)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Sort (org.springframework.data.domain.Sort)3 AlertSummary (com.usthe.alert.dto.AlertSummary)2 AlertDefine (com.usthe.common.entity.alerter.AlertDefine)2 Valid (javax.validation.Valid)2