Browse Source

validatorUtils工具类修改

dev_shibei_match
= 5 years ago
parent
commit
3ee2822a41
  1. 5
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java
  2. 3
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java
  3. 1
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java
  4. 4
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java
  5. 3
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java
  6. 4
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java
  7. 4
      epmet-openapi/epmet-openapi-scan/src/main/resources/readme

5
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/ValidatorUtils.java

@ -50,7 +50,10 @@ public class ValidatorUtils {
List<Class<?>> customerShowGroups = new ArrayList<>(); List<Class<?>> customerShowGroups = new ArrayList<>();
List<Class<?>> internalGroups = new ArrayList<>(); List<Class<?>> internalGroups = new ArrayList<>();
if (groups == null || groups.length ==0){
validate(EpmetErrorCode.CUSTOMER_VALIDATE_ERROR ,object,groups);
return;
}
Arrays.asList(groups).forEach(g -> { Arrays.asList(groups).forEach(g -> {
if (CustomerClientShowGroup.class.isAssignableFrom(g)) { if (CustomerClientShowGroup.class.isAssignableFrom(g)) {
//如果派生自客户端显示分组,那么会优先校验,并且将错误提示给客户端,返回客户端可见的错误码 //如果派生自客户端显示分组,那么会优先校验,并且将错误提示给客户端,返回客户端可见的错误码

3
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java

@ -1,6 +1,7 @@
package com.epmet.openapi.scan.controller; package com.epmet.openapi.scan.controller;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.openapi.scan.service.impl.ScanService; import com.epmet.openapi.scan.service.impl.ScanService;
import com.epmet.openapi.scan.support.param.ImgScanParam; import com.epmet.openapi.scan.support.param.ImgScanParam;
import com.epmet.openapi.scan.support.param.TextScanParam; import com.epmet.openapi.scan.support.param.TextScanParam;
@ -32,6 +33,7 @@ public class ScanController {
*/ */
@RequestMapping("imgSyncScan") @RequestMapping("imgSyncScan")
public Result<SyncScanResult> ImgSyncScan(@RequestBody ImgScanParam param) { public Result<SyncScanResult> ImgSyncScan(@RequestBody ImgScanParam param) {
ValidatorUtils.validateEntity(param);
Result<SyncScanResult> scanResultResult = scanService.sendSyncImgScan(param); Result<SyncScanResult> scanResultResult = scanService.sendSyncImgScan(param);
return scanResultResult; return scanResultResult;
} }
@ -44,6 +46,7 @@ public class ScanController {
*/ */
@RequestMapping("textSyncScan") @RequestMapping("textSyncScan")
public Result<SyncScanResult> textSyncScan(@RequestBody TextScanParam param) { public Result<SyncScanResult> textSyncScan(@RequestBody TextScanParam param) {
ValidatorUtils.validateEntity(param);
Result<SyncScanResult> scanResultResult = scanService.sendTextScan(param); Result<SyncScanResult> scanResultResult = scanService.sendTextScan(param);
return scanResultResult; return scanResultResult;
} }

1
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java

@ -12,6 +12,7 @@ import com.aliyuncs.green.model.v20180509.TextScanRequest;
import com.aliyuncs.http.FormatType; import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse; import com.aliyuncs.http.HttpResponse;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.openapi.scan.common.constant.SysConstant; import com.epmet.openapi.scan.common.constant.SysConstant;
import com.epmet.openapi.scan.common.enu.ImgSceneEnum; import com.epmet.openapi.scan.common.enu.ImgSceneEnum;
import com.epmet.openapi.scan.common.enu.SuggestionEnum; import com.epmet.openapi.scan.common.enu.SuggestionEnum;

4
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgScanParam.java

@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param;
import lombok.Data; import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -30,6 +32,8 @@ public class ImgScanParam implements Serializable {
* 要检测的内容列表必填 * 要检测的内容列表必填
* remark一组任务列表中的taskId不能相同 * remark一组任务列表中的taskId不能相同
*/ */
@Valid
@NotEmpty(message = "任务列表不能为空")
private List<ImgTask> tasks; private List<ImgTask> tasks;
/** /**

3
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/ImgTask.java

@ -2,6 +2,7 @@ package com.epmet.openapi.scan.support.param;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -19,10 +20,12 @@ public class ImgTask implements Serializable {
* 要检测的数据id 非必填 * 要检测的数据id 非必填
* *
* */ * */
@NotNull(message = "dataId不能为空")
private String dataId; private String dataId;
/** /**
* 图片url 必填 * 图片url 必填
*/ */
@NotNull(message = "图片URL不能为空")
private String url; private String url;
} }

4
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/TextScanParam.java

@ -2,6 +2,8 @@ package com.epmet.openapi.scan.support.param;
import lombok.Data; import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -24,6 +26,8 @@ public class TextScanParam implements Serializable {
* *
* @see com.epmet.openapi.scan.common.enu.ImgSceneEnum; * @see com.epmet.openapi.scan.common.enu.ImgSceneEnum;
*/ */
@Valid
@NotEmpty(message = "任务列表不能为空")
private List<String> scenes; private List<String> scenes;
/** /**

4
epmet-openapi/epmet-openapi-scan/src/main/resources/readme

@ -1,2 +1,4 @@
#添加白名单 #访问openApi 需要向redis中 添加白名单
sadd epmet:openapi:scan:whitelist "客户端ip地址" sadd epmet:openapi:scan:whitelist "客户端ip地址"
#eg:
sadd epmet:openapi:scan:whitelist "\"192.168.1.1\""
Loading…
Cancel
Save