refactor: fix medium-severity code convention violations

- Add @ToString.Exclude on self-referencing children fields in 6 tree
  BO/VO classes to prevent StackOverflowError on toString()
- Fix TopicController/Service Page<List<TopicVO>> to Page<TopicVO>
- Add @Validated to HmacAuthProperties, OkHttpProperties,
  NotifyCredentialProperties for JSR-303 validation support
- Remove dead Eureka constants from EnvironmentConstant
- Remove deprecated spring.main.allow-bean-definition-overriding from
  3 YAML files (no-op in Spring Boot 3.x)
- Extract hardcoded 'unknown' string to DataConstant.STATUS_UNKNOWN and
  reference it from 5 call sites
This commit is contained in:
pnoker
2026-06-05 23:25:19 +08:00
parent f095948a79
commit 099d37c9b5
21 changed files with 39 additions and 31 deletions
@@ -41,6 +41,7 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = true)
public class MenuTreeBO extends MenuBO {
@ToString.Exclude
private List<MenuTreeBO> children = new ArrayList<>();
public static MenuTreeBO fromBO(MenuBO source) {
@@ -42,6 +42,7 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = true)
public class ResourceTreeBO extends ResourceBO {
@ToString.Exclude
private List<ResourceTreeBO> children = new ArrayList<>();
/**
@@ -43,6 +43,7 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = true)
public class RoleTreeBO extends RoleBO {
@ToString.Exclude
private List<RoleTreeBO> children = new ArrayList<>();
/**
@@ -43,6 +43,7 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class MenuTreeVO extends MenuVO {
@ToString.Exclude
private List<MenuTreeVO> children = new ArrayList<>();
}
@@ -43,6 +43,7 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class ResourceTreeVO extends ResourceVO {
@ToString.Exclude
private List<ResourceTreeVO> children = new ArrayList<>();
}
@@ -43,6 +43,7 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class RoleTreeVO extends RoleVO {
@ToString.Exclude
private List<RoleTreeVO> children = new ArrayList<>();
}
@@ -20,8 +20,8 @@ package io.github.pnoker.common.constant.common;
/**
* Environment variables and configuration variables related constants
* <p>
* Provides constants for environment types, Spring configuration properties, Eureka
* configuration, and driver-related configuration keys.
* Provides constants for environment types, Spring configuration properties,
* and driver-related configuration keys.
* </p>
*
* @author pnoker
@@ -50,17 +50,6 @@ public class EnvironmentConstant {
*/
public static final String ENV_PRO = "pro";
/**
* Eureka TLS enable configuration key: "eureka.client.tls.enabled"
*/
public static final String EUREKA_TLS_ENABLE = "eureka.client.tls.enabled";
/**
* Eureka service registry URL configuration key:
* "eureka.client.service-url.defaultZone"
*/
public static final String EUREKA_SERVICE_URL = "eureka.client.service-url.defaultZone";
/**
* Current environment type configuration key: "spring.env"
*/
@@ -34,6 +34,11 @@ public class DataConstant {
*/
public static final String SERVICE_NAME = "dc3-center-data";
/**
* Fallback status when an entity status cannot be resolved.
*/
public static final String STATUS_UNKNOWN = "unknown";
public static final String POINT_VALUE_URL_PREFIX = "/point_value";
public static final String POINT_COMMAND_URL_PREFIX = "/point_command";
@@ -18,6 +18,7 @@
package io.github.pnoker.common.data.biz.alarm;
import io.github.pnoker.common.constant.driver.RabbitConstant;
import io.github.pnoker.common.constant.service.DataConstant;
import io.github.pnoker.common.entity.dto.NotifyTaskDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -54,7 +55,7 @@ public class NotifyTaskSender {
}
String channelType = Objects.nonNull(task.getChannelTypeFlag())
? task.getChannelTypeFlag().toString()
: "unknown";
: DataConstant.STATUS_UNKNOWN;
String routingKey = (RabbitConstant.ROUTING_NOTIFY_TASK_PREFIX + channelType).toLowerCase(Locale.ROOT);
rabbitTemplate.convertAndSend(alarmExchange.getName(), routingKey, task);
}
@@ -24,6 +24,7 @@ import io.github.pnoker.common.data.entity.model.EntityStateDO;
import io.github.pnoker.common.data.mapper.EntityStateMapper;
import io.github.pnoker.common.entity.dto.DeviceAlarmDTO;
import io.github.pnoker.common.entity.dto.DeviceStateDTO;
import io.github.pnoker.common.constant.service.DataConstant;
import io.github.pnoker.common.enums.EntityStatusEnum;
import io.github.pnoker.common.enums.EntityTypeFlagEnum;
import io.github.pnoker.common.enums.TimeoutSourceFlagEnum;
@@ -102,7 +103,7 @@ public class DeviceStateServiceImpl implements DeviceStateService {
byte lastIndex = stateDO.getLastStateFlag();
if (isFlip(lastIndex, current)) {
String message = String.format("Device status changed: %s -> %s",
EntityStatusEnum.ofIndex(lastIndex) != null ? EntityStatusEnum.ofIndex(lastIndex).getCode() : "unknown",
EntityStatusEnum.ofIndex(lastIndex) != null ? EntityStatusEnum.ofIndex(lastIndex).getCode() : DataConstant.STATUS_UNKNOWN,
current);
DeviceAlarmDTO alarm = DeviceAlarmDTO.builder()
.driverId(entityDTO.getDriverId())
@@ -19,6 +19,7 @@ package io.github.pnoker.common.data.biz.impl;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.github.pnoker.common.constant.driver.RabbitConstant;
import io.github.pnoker.common.constant.service.DataConstant;
import io.github.pnoker.common.data.biz.DriverAlarmService;
import io.github.pnoker.common.data.biz.DriverStateService;
import io.github.pnoker.common.data.entity.model.EntityStateDO;
@@ -111,7 +112,7 @@ public class DriverStateServiceImpl implements DriverStateService {
byte lastIndex = stateDO.getLastStateFlag();
if (isFlip(lastIndex, current)) {
String message = String.format("Driver status changed: %s -> %s",
EntityStatusEnum.ofIndex(lastIndex) != null ? EntityStatusEnum.ofIndex(lastIndex).getCode() : "unknown",
EntityStatusEnum.ofIndex(lastIndex) != null ? EntityStatusEnum.ofIndex(lastIndex).getCode() : DataConstant.STATUS_UNKNOWN,
current);
DriverAlarmDTO alarm = DriverAlarmDTO.builder()
.tenantId(entityDTO.getTenantId())
@@ -19,6 +19,7 @@ package io.github.pnoker.common.data.biz.impl;
import com.rabbitmq.client.Channel;
import io.github.pnoker.common.constant.driver.RabbitConstant;
import io.github.pnoker.common.constant.service.DataConstant;
import io.github.pnoker.common.data.biz.alarm.AlarmRuleTriggerService;
import io.github.pnoker.common.data.dal.EntityAlarmManager;
import io.github.pnoker.common.data.dal.EntityStateManager;
@@ -160,7 +161,7 @@ public class EntityStateExpiryScanner {
private EntityAlarmDO buildOfflineAlarm(EntityStateDO scanned) {
EntityStatusEnum prev = EntityStatusEnum.ofIndex(scanned.getLastStateFlag());
String prevCode = Objects.nonNull(prev) ? prev.getCode() : "unknown";
String prevCode = Objects.nonNull(prev) ? prev.getCode() : DataConstant.STATUS_UNKNOWN;
String message = String.format("Device heartbeat timed out (last=%s); marked OFFLINE", prevCode);
EntityAlarmDO alarm = new EntityAlarmDO();
@@ -185,7 +186,7 @@ public class EntityStateExpiryScanner {
EntityStateDO scanned = ctx.state;
EntityAlarmDO alarm = ctx.alarm;
EntityStatusEnum prev = EntityStatusEnum.ofIndex(scanned.getLastStateFlag());
String prevCode = Objects.nonNull(prev) ? prev.getCode() : "unknown";
String prevCode = Objects.nonNull(prev) ? prev.getCode() : DataConstant.STATUS_UNKNOWN;
// Update lastAlarmId
entityStateManager.lambdaUpdate()
@@ -20,6 +20,7 @@ package io.github.pnoker.common.data.entity.property;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -36,6 +37,7 @@ import java.util.Map;
*/
@Getter
@Setter
@Validated
@ConfigurationProperties(prefix = "dc3.data.notify")
public class NotifyCredentialProperties {
@@ -20,7 +20,6 @@
# the property values configured in application.yml will be the main ones.
spring:
main:
allow-bean-definition-overriding: true
grpc:
client:
channels:
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Objects;
/**
@@ -52,11 +52,11 @@ public class TopicController implements BaseController {
private final TopicService topicService;
@PostMapping("/list")
public Mono<R<Page<List<TopicVO>>>> query(@RequestBody(required = false) TopicQuery topicQuery) {
public Mono<R<Page<TopicVO>>> query(@RequestBody(required = false) TopicQuery topicQuery) {
return getTenantId().flatMap(tenantId -> async(() -> {
TopicQuery query = Objects.isNull(topicQuery) ? new TopicQuery() : topicQuery;
query.setTenantId(tenantId);
Page<List<TopicVO>> topicVOList = topicService.query(query);
Page<TopicVO> topicVOList = topicService.query(query);
return R.ok(topicVOList);
}));
}
@@ -23,7 +23,7 @@ import io.github.pnoker.common.manager.entity.model.DeviceDO;
import io.github.pnoker.common.manager.entity.query.TopicQuery;
import io.github.pnoker.common.manager.entity.vo.TopicVO;
import java.util.List;
/**
* Business service for topic operations.
@@ -35,6 +35,6 @@ import java.util.List;
public interface TopicService extends IService<DeviceDO> {
Page<List<TopicVO>> query(TopicQuery topicQuery);
Page<TopicVO> query(TopicQuery topicQuery);
}
@@ -47,13 +47,13 @@ import java.util.Objects;
public class TopicServiceImpl extends ServiceImpl<DeviceMapper, DeviceDO> implements TopicService {
@Override
public Page<List<TopicVO>> query(TopicQuery topicQuery) {
public Page<TopicVO> query(TopicQuery topicQuery) {
if (Objects.isNull(topicQuery.getPage())) {
topicQuery.setPage(new Pages());
}
int page = (int) topicQuery.getPage().getCurrent();
int size = (int) topicQuery.getPage().getSize();
Page<List<TopicVO>> resultPage = new Page<>(page, size);
Page<TopicVO> resultPage = new Page<>(page, size);
List<TopicVO> topicVOList = new ArrayList<>();
String topic = topicQuery.getTopic();
Long deviceIdL = null;
@@ -93,9 +93,11 @@ public class TopicServiceImpl extends ServiceImpl<DeviceMapper, DeviceDO> implem
int totalItems = topicVOList.size();
int fromIndex = Math.max(0, (page - 1) * size);
int toIndex = Math.min(fromIndex + size, totalItems);
List<List<TopicVO>> paginatedData = new ArrayList<>();
List<TopicVO> paginatedData;
if (fromIndex < toIndex) {
paginatedData.add(topicVOList.subList(fromIndex, toIndex));
paginatedData = topicVOList.subList(fromIndex, toIndex);
} else {
paginatedData = new ArrayList<>();
}
resultPage.setRecords(paginatedData);
resultPage.setTotal(totalItems);
@@ -21,6 +21,7 @@ import io.github.pnoker.common.constant.common.EnvironmentConstant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
/**
* Shared HMAC signing properties.
@@ -31,6 +32,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@Getter
@Setter
@Validated
@ConfigurationProperties(prefix = EnvironmentConstant.AUTH_HMAC_PREFIX)
public class HmacAuthProperties {
@@ -21,6 +21,7 @@ import io.github.pnoker.common.constant.common.EnvironmentConstant;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import java.time.Duration;
@@ -33,6 +34,7 @@ import java.time.Duration;
*/
@Getter
@Setter
@Validated
@ConfigurationProperties(prefix = EnvironmentConstant.HTTP_CLIENT_PREFIX)
public class OkHttpProperties {
@@ -21,7 +21,6 @@
spring:
main:
banner-mode: off
allow-bean-definition-overriding: true
rabbitmq:
publisher-confirm-type: correlated
publisher-returns: true
@@ -24,8 +24,6 @@ spring:
# Enable rollback if a failure occurs during transaction commit.
rollback-on-commit-failure: true
main:
# Allow bean definition overriding when multiple configurations define the same bean.
allow-bean-definition-overriding: true
web:
resources:
# Disable Spring Boot's default static resource mappings.