CustomAssert.java
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.objecteye.utils;
import com.objecteye.exception.CustomXException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
public class CustomAssert extends Assert {
public static void checkHeader(String header) {
if (!header.equals("application/json;charset=UTF-8")) {
throw new CustomXException(CustomInfoCollections.REQUEST_HEADER_CONTENT_ERROR.getMsg(),
CustomInfoCollections.REQUEST_HEADER_CONTENT_ERROR.getCode());
}
}
public static void checkField(Map<String, Object> map, String[] keys) {
for (String key : keys) {
if (map.get(key) == null) {
throw new CustomXException(CustomInfoCollections.REQUEST_BODY_FIELD_INCOMPLETE.getMsg(),
CustomInfoCollections.REQUEST_BODY_FIELD_INCOMPLETE.getCode());
}
}
}
public static void checkSimpleMapParam(Map<String, Object> map, String[] keys) {
for (String key : keys) {
if (StringUtils.isEmpty(map.get(key))) {
throw new CustomXException(CustomInfoCollections.REQUEST_BODY_IS_EMPTY.getMsg(),
CustomInfoCollections.REQUEST_BODY_IS_EMPTY.getCode());
}
}
}
public static void checkFileNull(MultipartFile file) {
if (null == file) {
throw new CustomXException(CustomInfoCollections.IMAGE_PARSE_EXCEPTION.getMsg(),
CustomInfoCollections.IMAGE_PARSE_EXCEPTION.getCode());
}
}
}