summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangwei <[email protected]>2023-04-04 21:06:41 +0800
committerwangwei <[email protected]>2023-04-04 21:12:01 +0800
commit655f36f12ef8505638bd374ba8ca35f3c45fc22a (patch)
treef68acd3f269b957f88f3b1ffff38e9bbc1c6eedc
parent4be115454b41912392e18001ab2b5658f6743944 (diff)
fix(update schema): 加强更新shcema限制,提交字段TTL>表TTL时给予报错提示,储存配额更新schema时涉及ttl=null 默认不做修改
-rw-r--r--src/main/java/com/mesalab/qgw/constant/QGWMessageConst.java1
-rw-r--r--src/main/java/com/mesalab/qgw/controller/MetadataController.java9
-rw-r--r--src/main/java/com/mesalab/qgw/service/impl/SystemServiceImpl.java4
3 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/com/mesalab/qgw/constant/QGWMessageConst.java b/src/main/java/com/mesalab/qgw/constant/QGWMessageConst.java
index 06bd6744..e7bf7593 100644
--- a/src/main/java/com/mesalab/qgw/constant/QGWMessageConst.java
+++ b/src/main/java/com/mesalab/qgw/constant/QGWMessageConst.java
@@ -10,6 +10,7 @@ package com.mesalab.qgw.constant;
public class QGWMessageConst {
public static final String SCHEMA_ERROR_TTL_VALUE = "Schema error, invalid TTL value.";
+ public static final String SCHEMA_ERROR_TTL_SIZE = "Not allowed, schema fields TTL cannot be greater than table TTL";
public static final String SCHEMA_ERROR_VISIBILITY_VALUE = "Schema error, invalid visibility value.";
diff --git a/src/main/java/com/mesalab/qgw/controller/MetadataController.java b/src/main/java/com/mesalab/qgw/controller/MetadataController.java
index 4d56dad0..530ddafe 100644
--- a/src/main/java/com/mesalab/qgw/controller/MetadataController.java
+++ b/src/main/java/com/mesalab/qgw/controller/MetadataController.java
@@ -1,5 +1,6 @@
package com.mesalab.qgw.controller;
+import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import com.jayway.jsonpath.JsonPath;
import com.mesalab.common.entity.BaseResult;
@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
@Slf4j
@RestController
@@ -55,7 +57,7 @@ public class MetadataController {
private void validationParam(String name, Map<String, Object> obj) {
if (!metadataService.getAllTable().contains(name)) {
throw new QGWBusinessException(ResultStatusEnum.BAD_REQUEST.getCode(), ResultCodeEnum.PARAMETER_ERROR.getCode(),
- String.format(ResultCodeEnum.PARAMETER_ERROR.getMessage(),name + QGWMessageConst.NOT_SUPPORT_SETTING_TTL));
+ String.format(ResultCodeEnum.PARAMETER_ERROR.getMessage(), name + QGWMessageConst.NOT_SUPPORT_SETTING_TTL));
}
String param = JsonMapper.toJsonString(obj);
if (!VISIBILITY.containsAll(JsonPath.read(param, "$.fields[?(@.doc.visibility != null)].doc.visibility"))) {
@@ -73,5 +75,10 @@ public class MetadataController {
throw new QGWBusinessException(ResultStatusEnum.BAD_REQUEST.getCode(), ResultCodeEnum.PARAMETER_ERROR.getCode(),
String.format(ResultCodeEnum.PARAMETER_ERROR.getMessage(), QGWMessageConst.SCHEMA_ERROR_TTL_VALUE));
}
+ if (schemaDocTTL.size() > 0 && fieldDocTTL.size() > 0
+ && CollectionUtil.max(schemaDocTTL.stream().map(o -> Long.parseLong(o.toString())).collect(Collectors.toList())) < CollectionUtil.max(fieldDocTTL.stream().map(o -> Long.parseLong(o.toString())).collect(Collectors.toList()))) {
+ throw new QGWBusinessException(ResultStatusEnum.BAD_REQUEST.getCode(), ResultCodeEnum.PARAMETER_ERROR.getCode(),
+ String.format(ResultCodeEnum.PARAMETER_ERROR.getMessage(), QGWMessageConst.SCHEMA_ERROR_TTL_SIZE));
+ }
}
}
diff --git a/src/main/java/com/mesalab/qgw/service/impl/SystemServiceImpl.java b/src/main/java/com/mesalab/qgw/service/impl/SystemServiceImpl.java
index dec9fc38..11809408 100644
--- a/src/main/java/com/mesalab/qgw/service/impl/SystemServiceImpl.java
+++ b/src/main/java/com/mesalab/qgw/service/impl/SystemServiceImpl.java
@@ -511,7 +511,7 @@ public class SystemServiceImpl implements SystemService, EnvironmentAware {
if (StringUtil.isNotEmpty(schemaDoc)) {
map = (Map<String, Object>) schemaDoc;
}
- if (StringUtil.isEmpty(map.get("ttl")) || ttl < Long.parseLong(map.get("ttl").toString())) {
+ if (StringUtil.isNotEmpty(map.get("ttl")) && ttl < Long.parseLong(map.get("ttl").toString())) {
map.put("ttl", ttl);
schemaMap.put("doc", map);
}
@@ -528,7 +528,7 @@ public class SystemServiceImpl implements SystemService, EnvironmentAware {
field.put("doc", fieldDoc);
continue;
}
- if (StringUtil.isEmpty(fieldDoc.get("ttl")) || ttl < Long.parseLong(fieldDoc.get("ttl").toString())) {
+ if (StringUtil.isNotEmpty(fieldDoc.get("ttl")) && ttl < Long.parseLong(fieldDoc.get("ttl").toString())) {
fieldDoc.put("ttl", ttl);
field.put("doc", fieldDoc);
}