diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java index e5a2610e3e..b5f0473948 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java @@ -17,49 +17,56 @@ package org.apache.streampark.console.base.domain; +import javax.validation.constraints.NotNull; + import java.util.HashMap; public class RestResponse extends HashMap { public static final String STATUS_SUCCESS = "success"; public static final String STATUS_FAIL = "error"; + public static final String STATUS_KEY = "status"; + public static final String CODE_KEY = "code"; + public static final String MESSAGE_KEY = "message"; + public static final String DATA_KEY = "data"; private static final long serialVersionUID = 1L; public static RestResponse success(Object data) { RestResponse resp = new RestResponse(); - resp.put("status", STATUS_SUCCESS); - resp.put("code", ResponseCode.CODE_SUCCESS); - resp.put("data", data); + resp.put(STATUS_KEY, STATUS_SUCCESS); + resp.put(CODE_KEY, ResponseCode.CODE_SUCCESS); + resp.put(DATA_KEY, data); return resp; } public static RestResponse success() { RestResponse resp = new RestResponse(); - resp.put("status", STATUS_SUCCESS); - resp.put("code", ResponseCode.CODE_SUCCESS); + resp.put(STATUS_KEY, STATUS_SUCCESS); + resp.put(CODE_KEY, ResponseCode.CODE_SUCCESS); return resp; } public static RestResponse fail(String message, Long code) { RestResponse resp = new RestResponse(); - resp.put("status", STATUS_FAIL); - resp.put("message", message); - resp.put("code", code); - resp.put("data", null); + resp.put(STATUS_KEY, STATUS_FAIL); + resp.put(MESSAGE_KEY, message); + resp.put(CODE_KEY, code); + resp.put(DATA_KEY, null); return resp; } public RestResponse message(String message) { - this.put("message", message); + this.put(MESSAGE_KEY, message); return this; } public RestResponse data(Object data) { - this.put("data", data); + this.put(DATA_KEY, data); return this; } + @NotNull @Override public RestResponse put(String key, Object value) { super.put(key, value); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java index 92558aefc0..2850f3a393 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/PassportController.java @@ -80,7 +80,7 @@ public RestResponse signin( throws Exception { if (StringUtils.isEmpty(username)) { - return RestResponse.success().put("code", 0); + return RestResponse.success().put(RestResponse.CODE_KEY, 0); } User user = authenticator.authenticate(username, password, loginType); return userService.getLoginUserInfo(user); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/AccessTokenServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/AccessTokenServiceImpl.java index 19fa3a1d56..fb20100e1f 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/AccessTokenServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/AccessTokenServiceImpl.java @@ -59,7 +59,7 @@ public class AccessTokenServiceImpl extends ServiceImpl data = (Map) - userService.updateUser(user).getOrDefault("data", Collections.emptyMap()); + userService + .updateUser(user) + .getOrDefault(RestResponse.DATA_KEY, Collections.emptyMap()); Assertions.assertNotEquals(true, data.get("needTransferResource")); // unlock user user.setStatus(User.STATUS_VALID); Map data1 = (Map) - userService.updateUser(user).getOrDefault("data", Collections.emptyMap()); + userService + .updateUser(user) + .getOrDefault(RestResponse.DATA_KEY, Collections.emptyMap()); Assertions.assertNotEquals(true, data1.get("needTransferResource")); Resource resource = new Resource(); @@ -74,7 +79,9 @@ void testLockUser() throws Exception { user.setStatus(User.STATUS_LOCK); Map data2 = (Map) - userService.updateUser(user).getOrDefault("data", Collections.emptyMap()); + userService + .updateUser(user) + .getOrDefault(RestResponse.DATA_KEY, Collections.emptyMap()); Assertions.assertEquals(true, data2.get("needTransferResource")); }