Merge remote-tracking branch 'origin/master'

This commit is contained in:
Saturneric 2020-02-22 21:41:27 +08:00
commit f2369e4cfe
4 changed files with 16 additions and 33 deletions

View File

@ -79,6 +79,11 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>

View File

@ -11,7 +11,7 @@ import java.util.Set;
@Component
public class ActivityFormConfigure {
private static final Set<String> stdActivityForm = new HashSet(){{
private final HashSet<String> stdActivityForm = new HashSet<String>(){{
add("title");
add("creator");
add("type");
@ -29,11 +29,8 @@ public class ActivityFormConfigure {
add("assist-manager");
add("attendance");
}};
public final static Map<String, HashSet<String>> stdActivityMap;
static {
stdActivityMap = new HashMap() {{
put("activity", stdActivityForm);
}};
public HashSet<String> getStdActivityForm() {
return stdActivityForm;
}
}

View File

@ -31,11 +31,12 @@ public class ActivityController {
ASESpringUtil aseSpringUtil = new ASESpringUtil();
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
HashMap<String, Boolean> checkResult = webFormValidator.check(activityFormConfigure.stdActivityMap, parameterMap);
if(checkResult.get("activity").equals(false)){
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)){
throw new InvalidFormFormatException("Invalid activity form.");
}
return "act_created";
}
}

View File

@ -8,32 +8,12 @@ import java.util.*;
@Component
public class WebFormValidator {
/**
* 传入标准表单所具有的属性set以及网页表单的属性set确保map中的key和value一一对应
* 检查的时候会将标准表单和网页表单两个map中key相同的value进行完全匹配比较
* 返回一个map不同表单有不同的合法情况
* 支持一次处理多个表单请务必保持对应表单的标准和网页map中的key一样
* @return 封装在一个map里的不同表单对应的合法情况
*/
public HashMap<String, Boolean> check(Map<String, HashSet<String>> stdFormMap, Map<String, String[]> webFormMap){
public boolean check(Collection<String> stdForm, Map<String, String[]> webFormMap){
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
Set<String> stdKey = stdFormMap.keySet();
Set<String> webKey = webFormMap.keySet();
for(String key : webKey){
if(stdKey.contains(key)){
Set<String> stdSet = stdFormMap.get(key);
String[] webForm = webFormMap.get(key);
List<String> webList = new ArrayList<>();
Collections.addAll(webList, webForm);
if(stdSet.containsAll(webList)){
result.put(key,true);
Collection<String> webForm = webFormMap.keySet();
if(stdForm.containsAll(webForm)){
return true;
}
else result.put(key,false);
}
}
return result;
return false;
}
}