Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f2369e4cfe
5
pom.xml
5
pom.xml
@ -79,6 +79,11 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-test</artifactId>
|
<artifactId>spring-boot-test</artifactId>
|
||||||
|
@ -11,7 +11,7 @@ import java.util.Set;
|
|||||||
@Component
|
@Component
|
||||||
public class ActivityFormConfigure {
|
public class ActivityFormConfigure {
|
||||||
|
|
||||||
private static final Set<String> stdActivityForm = new HashSet(){{
|
private final HashSet<String> stdActivityForm = new HashSet<String>(){{
|
||||||
add("title");
|
add("title");
|
||||||
add("creator");
|
add("creator");
|
||||||
add("type");
|
add("type");
|
||||||
@ -29,11 +29,8 @@ public class ActivityFormConfigure {
|
|||||||
add("assist-manager");
|
add("assist-manager");
|
||||||
add("attendance");
|
add("attendance");
|
||||||
}};
|
}};
|
||||||
public final static Map<String, HashSet<String>> stdActivityMap;
|
|
||||||
|
|
||||||
static {
|
public HashSet<String> getStdActivityForm() {
|
||||||
stdActivityMap = new HashMap() {{
|
return stdActivityForm;
|
||||||
put("activity", stdActivityForm);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,12 @@ public class ActivityController {
|
|||||||
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
||||||
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
||||||
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||||
HashMap<String, Boolean> checkResult = webFormValidator.check(activityFormConfigure.stdActivityMap, parameterMap);
|
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)){
|
||||||
if(checkResult.get("activity").equals(false)){
|
|
||||||
throw new InvalidFormFormatException("Invalid activity form.");
|
throw new InvalidFormFormatException("Invalid activity form.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "act_created";
|
return "act_created";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,32 +8,12 @@ import java.util.*;
|
|||||||
@Component
|
@Component
|
||||||
public class WebFormValidator {
|
public class WebFormValidator {
|
||||||
|
|
||||||
/**
|
public boolean check(Collection<String> stdForm, Map<String, String[]> webFormMap){
|
||||||
* 传入标准表单所具有的属性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){
|
|
||||||
|
|
||||||
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
|
Collection<String> webForm = webFormMap.keySet();
|
||||||
Set<String> stdKey = stdFormMap.keySet();
|
if(stdForm.containsAll(webForm)){
|
||||||
Set<String> webKey = webFormMap.keySet();
|
return true;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else result.put(key,false);
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user