Browse Source

管理员可为资源点分配可查看的模版

sunyj 8 years ago
parent
commit
cf7daf8555

+ 5 - 1
kanban-auth/src/main/java/com/uas/kanban/filter/SecurityInterceptor.java

@@ -56,8 +56,12 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter {
 					contextPath + "/login?returnUrl=" + URLEncoder.encode(request.getRequestURL().toString(), "UTF-8"));
 			return false;
 		}
+
+		// 只允许管理员访问
 		if (url.startsWith("/user/save") || url.startsWith("/user/update") || url.startsWith("/user/delete")
-				|| url.startsWith("/user/get")) {
+				|| url.startsWith("/user/get") || url.startsWith("/resourcePoint/save")
+				|| url.startsWith("/resourcePoint/update") || url.startsWith("/resourcePoint/delete")
+				|| url.startsWith("/resourcePoint/get")) {
 			if (user.getRole() != Role.Admin) {
 				throw new OperationException("没有权限");
 			}

+ 19 - 3
kanban-auth/src/main/java/com/uas/kanban/model/ResourcePoint.java

@@ -1,5 +1,6 @@
 package com.uas.kanban.model;
 
+import java.util.List;
 import java.util.Objects;
 
 import org.mongodb.morphia.annotations.Entity;
@@ -24,6 +25,12 @@ public class ResourcePoint extends BaseEntity {
 	@FieldProperty(nullable = false)
 	private String name;
 
+	/**
+	 * 模版的 code
+	 */
+	@FieldProperty(nullable = false)
+	private List<String> templateCodes;
+
 	public String getName() {
 		return name;
 	}
@@ -32,10 +39,18 @@ public class ResourcePoint extends BaseEntity {
 		this.name = name;
 	}
 
+	public List<String> getTemplateCodes() {
+		return templateCodes;
+	}
+
+	public void setTemplateCodes(List<String> templateCodes) {
+		this.templateCodes = templateCodes;
+	}
+
 	@Override
 	public String toString() {
-		return "ResourcePoint [name=" + name + ", id=" + id + ", createTime=" + createTime + ", lastModified="
-				+ lastModified + ", version=" + version + ", code=" + code + "]";
+		return "ResourcePoint [name=" + name + ", templateCodes=" + templateCodes + ", id=" + id + ", createTime="
+				+ createTime + ", lastModified=" + lastModified + ", version=" + version + ", code=" + code + "]";
 	}
 
 	@Override
@@ -47,6 +62,7 @@ public class ResourcePoint extends BaseEntity {
 			return false;
 		}
 		ResourcePoint other = (ResourcePoint) obj;
-		return Objects.equals(code, other.getCode()) && Objects.equals(name, other.getName());
+		return Objects.equals(code, other.getCode()) && Objects.equals(name, other.getName())
+				&& Objects.equals(templateCodes, other.getTemplateCodes());
 	}
 }

+ 18 - 0
kanban-auth/src/main/java/com/uas/kanban/model/Template.java

@@ -0,0 +1,18 @@
+package com.uas.kanban.model;
+
+import org.mongodb.morphia.annotations.Entity;
+
+import com.uas.kanban.base.BaseEntity;
+
+/**
+ * 模版(这里仅仅声明这个类,之后在 kanban-console 会覆盖该类)
+ * 
+ * @author sunyj
+ * @since 2017年8月29日 上午10:06:55
+ */
+@Entity
+public class Template extends BaseEntity {
+
+	private static final long serialVersionUID = 1L;
+
+}

+ 15 - 0
kanban-auth/src/main/java/com/uas/kanban/model/User.java

@@ -1,6 +1,7 @@
 package com.uas.kanban.model;
 
 import java.util.List;
+import java.util.Objects;
 
 import org.mongodb.morphia.annotations.Entity;
 
@@ -80,6 +81,20 @@ public class User extends BaseEntity {
 				+ ", version=" + version + ", code=" + code + "]";
 	}
 
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj) {
+			return true;
+		}
+		if (obj == null || getClass() != obj.getClass() || !(obj instanceof User)) {
+			return false;
+		}
+		User other = (User) obj;
+		return Objects.equals(code, other.getCode()) && Objects.equals(name, other.getName())
+				&& Objects.equals(password, other.getPassword()) && Objects.equals(role, other.getRole())
+				&& Objects.equals(resourcePointCodes, other.getResourcePointCodes());
+	}
+
 	/**
 	 * 角色
 	 * 

+ 32 - 0
kanban-auth/src/main/java/com/uas/kanban/service/impl/ResourcePointServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.kanban.service.impl;
 
+import java.util.List;
 import java.util.Objects;
 
 import org.mongodb.morphia.query.Query;
@@ -7,10 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.uas.kanban.annotation.NotEmpty;
+import com.uas.kanban.base.BaseDao;
 import com.uas.kanban.base.BaseService;
 import com.uas.kanban.dao.ResourcePointDao;
 import com.uas.kanban.exception.OperationException;
 import com.uas.kanban.model.ResourcePoint;
+import com.uas.kanban.model.Template;
+import com.uas.kanban.util.CollectionUtils;
 
 /**
  * 资源点
@@ -24,12 +28,16 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
 	@Autowired
 	private ResourcePointDao resourcePointDao;
 
+	@Autowired
+	private BaseDao<Template> templateDao;
+
 	@Override
 	public ResourcePoint save(@NotEmpty("json") String json) {
 		ResourcePoint resourcePoint = resourcePointDao.parse(json);
 		if (exist(resourcePoint.getName())) {
 			throw new IllegalStateException("资源点已存在");
 		}
+		checkTemplates(resourcePoint.getTemplateCodes());
 		return resourcePointDao.save(resourcePoint);
 	}
 
@@ -53,6 +61,7 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
 		if (!Objects.equals(name, rPoint.getName()) && exist(name)) {
 			throw new IllegalStateException("资源点已存在");
 		}
+		checkTemplates(resourcePoint.getTemplateCodes());
 		return resourcePointDao.update(resourcePoint);
 	}
 
@@ -61,6 +70,29 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
 		return update(json);
 	}
 
+	/**
+	 * 检查模版是否存在
+	 * 
+	 * @param templateCodes
+	 *            模版的 code
+	 * @throws IllegalArgumentException
+	 *             模版不存在
+	 */
+	private void checkTemplates(List<String> templateCodes) throws IllegalArgumentException {
+		if (CollectionUtils.isEmpty(templateCodes)) {
+			return;
+		}
+		for (String templateCode : templateCodes) {
+			if (templateCodes.indexOf(templateCode) != templateCodes.lastIndexOf(templateCode)) {
+				throw new IllegalArgumentException("模版重复:" + templateCode);
+			}
+			Template template = templateDao.findOne(templateCode);
+			if (template == null) {
+				throw new IllegalArgumentException("模版不存在:" + templateCode);
+			}
+		}
+	}
+
 	/**
 	 * 资源点是否已存在
 	 * 

+ 1 - 1
kanban-console/src/main/java/com/uas/kanban/model/Kanban.java

@@ -34,7 +34,7 @@ public class Kanban extends BaseEntity {
 	private String name;
 
 	/**
-	 * 模版的 code(不可重复,因此采用 Set)
+	 * 模版的 code
 	 */
 	@FieldProperty(nullable = false)
 	private List<String> templateCodes;

+ 1 - 1
kanban-console/src/main/java/com/uas/kanban/model/Template.java

@@ -9,7 +9,7 @@ import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
 
 /**
- * 数据源
+ * 模版
  * 
  * @author sunyj
  * @since 2017年8月29日 上午10:06:55

+ 4 - 4
kanban-console/src/main/webapp/WEB-INF/views/console.html

@@ -10,9 +10,9 @@
 		<ol>
 			<strong><li class="title">用户</li></strong>
 			<ol>
-				<li><a target="_blank">user/save?json={"name": "name","password": "password"}</a></li>
+				<li><a target="_blank">user/save?json={"name": "name","password": "password","resourcePointCodes":["4EC2735D343"]}</a></li>
 				<li><a target="_blank">user/savePart?json={"name": "name","password": "password"}</a></li>
-				<li><a target="_blank">user/update?json={"code":"4EC2735D343","name": "name","password": "password"}</a></li>
+				<li><a target="_blank">user/update?json={"code":"4EC2735D343","name": "name","password": "password","resourcePointCodes":["4EC2735D343"]}</a></li>
 				<li><a target="_blank">user/updatePart?json={"code":"4EC2735D343","name": "name","password": "password"}</a></li>
 				<li><a target="_blank">user/delete/4EC2735D343</a></li>
 				<li><a target="_blank">user/get/all</a></li>
@@ -25,9 +25,9 @@
 			</ol>
 			<strong><li class="title">资源点</li></strong>
 			<ol>
-				<li><a target="_blank">resourcePoint/save?json={"name": "name"}</a></li>
+				<li><a target="_blank">resourcePoint/save?json={"name": "name","templateCodes":["4EC2735D343"]}</a></li>
 				<li><a target="_blank">resourcePoint/savePart?json={"name": "name"}</a></li>
-				<li><a target="_blank">resourcePoint/update?json={"code":"4EC2735D343","name": "name"}</a></li>
+				<li><a target="_blank">resourcePoint/update?json={"code":"4EC2735D343","name": "name","templateCodes":["4EC2735D343"]}</a></li>
 				<li><a target="_blank">resourcePoint/updatePart?json={"code":"4EC2735D343","name": "name"}</a></li>
 				<li><a target="_blank">resourcePoint/delete/4EC2735D343</a></li>
 				<li><a target="_blank">resourcePoint/get/all</a></li>