Merge with 555a094e2000059e5ff39303baae941c87dac3cd
authorymh <ymh.work@gmail.com>
Fri, 15 Mar 2013 14:37:21 +0100
changeset 85 1e9a22f04c39
parent 82 ff79f9f4321a (current diff)
parent 84 b4b83e9b808d (diff)
child 86 0fe9045d25b7
Merge with 555a094e2000059e5ff39303baae941c87dac3cd
--- a/server/src/main/java/org/iri_research/renkan/controller/RenkanController.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/controller/RenkanController.java	Fri Mar 15 14:37:21 2013 +0100
@@ -97,6 +97,9 @@
 		}
 		
 		Project project = this.projectsRepository.findOne(project_id);
+		if(project == null) {
+			throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Project " + project_id + " not found.");
+		}
 
 		this.checkCowebkey(cowebkey, project, EditMode.READ_ONLY);
 		
@@ -106,11 +109,20 @@
 		return "renkanProjectPublish";
 	}
 	
-	/*@RequestMapping("/test")
-	public ModelAndView projectPrompt() {
-		String message = "Hello world, Spring";
+	@RequestMapping(value="/copy", method = RequestMethod.POST, params="project_id={project_id}", produces={"application/json;charset=UTF-8"})
+	public Project copyProject(@RequestParam(value="project_id") String projectId ) {
+				
+		if(projectId == null || projectId.length() == 0) {
+			throw new IllegalArgumentException("RenkanContoller.renkanProject: Project id is null or empty.");
+		}
+		Project project = this.projectsRepository.findOne(projectId);
+		if(project == null) {
+			throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Project " + projectId + " not found.");
+		}
+
+		Project newProject = this.projectsRepository.copy(project, project.getTitle() + " (copy)");
 		
-		return new ModelAndView("projectPrompt", "message", message);
-	}*/
+		return newProject;
+	}
 	
 }
--- a/server/src/main/java/org/iri_research/renkan/models/AbstractRenkanModel.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/models/AbstractRenkanModel.java	Fri Mar 15 14:37:21 2013 +0100
@@ -57,5 +57,5 @@
 		}
 		this.id = id;
 	}
-
+		
 }
--- a/server/src/main/java/org/iri_research/renkan/models/Edge.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/models/Edge.java	Fri Mar 15 14:37:21 2013 +0100
@@ -1,5 +1,8 @@
 package org.iri_research.renkan.models;
 
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 import org.springframework.data.mongodb.core.mapping.Field;
@@ -23,8 +26,20 @@
 	@Field("created_by")
 	@JsonProperty("created_by")
 	private String createdBy;
+		
+	@SuppressWarnings("unused")
+	private Edge() {		
+	}
 	
+	public Edge(Edge edge, Node from, Node to, String projectId) {
+		this(UUID.randomUUID().toString(), edge.title, edge.description, edge.uri, edge.color, edge.from, edge.to, edge.createdBy, projectId);
+	}	
 
+	public Edge(Edge edge) {
+		this(edge, edge.from, edge.to, edge.projectId);
+	}	
+
+	@Autowired(required=true)
 	public Edge(String id, String title, String description, String uri, String color, Node from, Node to, String createdBy, String projectId) {
 		super(id,title, description, uri, color);
 		this.from = from;
@@ -61,5 +76,5 @@
 			return null;
 		}
 	}
-
+	
 }
--- a/server/src/main/java/org/iri_research/renkan/models/Node.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/models/Node.java	Fri Mar 15 14:37:21 2013 +0100
@@ -1,5 +1,8 @@
 package org.iri_research.renkan.models;
 
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.geo.Point;
 import org.springframework.data.mongodb.core.mapping.Document;
 import org.springframework.data.mongodb.core.mapping.Field;
@@ -9,7 +12,19 @@
 @Document(collection="nodes")
 public class Node extends AbstractRenkanModel<String> {
 
+	public Node(Node node, String projectId) {
+		this(UUID.randomUUID().toString(), node.title, node.description, node.uri, node.color, node.createdBy, node.position, node.image, node.size, projectId);
+	}
+	
+	public Node(Node node) {
+		this(node, node.projectId);
+	}
+	
+	@SuppressWarnings("unused")
+	private Node() {		
+	}
 
+	@Autowired(required=true)
 	public Node(String id, String title, String description, String uri, String color, String createdBy, Point position, String image, Integer size, String projectId) {
 		super(id, title, description, uri, color);
 		
@@ -56,5 +71,4 @@
 		return size;
 	}
 	
-
 }
--- a/server/src/main/java/org/iri_research/renkan/models/Project.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/models/Project.java	Fri Mar 15 14:37:21 2013 +0100
@@ -6,7 +6,10 @@
 import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 
 import org.apache.commons.codec.binary.Hex;
 import org.iri_research.renkan.Constants;
@@ -14,6 +17,7 @@
 import org.iri_research.renkan.RenkanException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 import org.springframework.data.mongodb.core.mapping.Field;
@@ -49,6 +53,24 @@
 	private List<User> users = new ArrayList<User>();
 	
 	
+	public Project(Project project) {
+		this(project.spaceId, UUID.randomUUID().toString(), project.title, project.description, project.uri, new Date());
+		
+		Map<String, Node> nodeCloneMap = new HashMap<String, Node>(project.nodes.size());
+		for (Node node : project.nodes) {
+			Node newNode = new Node(node,this.id);
+			this.nodes.add(newNode);
+			nodeCloneMap.put(node.id, newNode);
+		}
+
+		for (Edge edge : project.edges) {
+			this.edges.add(new Edge(edge, nodeCloneMap.get(edge.getFrom()), nodeCloneMap.get(edge.getTo()), this.id));
+		}
+		for(User user : project.users) {
+			this.users.add(user);
+		}
+	}
+	
 	public Project(String spaceId, String id, String title, String description, String uri, Date created,
 			int revCounter) {
 		super(id,title, description, uri, null);
@@ -60,6 +82,7 @@
 		}
 	}
 
+	@Autowired(required=true)
 	public Project(String spaceId, String id, String title, String description, String uri, Date created) {
 		this(spaceId, id,title, description, uri, created, 1);
 	}
@@ -67,7 +90,7 @@
 	@SuppressWarnings("unused")
 	private Project() {		
 	}
-	
+		
 	public int getRevCounter() {
 		return this.revCounter;
 	}
@@ -170,5 +193,9 @@
 		return new_key.equals(signature);
 	}
 
+	public void setTitle(String title) {		
+		this.title = title;		
+	}
+	
 
 }
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryCustom.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryCustom.java	Fri Mar 15 14:37:21 2013 +0100
@@ -2,10 +2,12 @@
 
 import java.util.Map;
 
+import org.iri_research.renkan.models.Project;
+
 public interface ProjectsRepositoryCustom {
 	
 	public int getRevCounter(String projectId);
-	
 	public Map<String, Integer> getCountBySpace();
+	public Project copy(Project p, String newTitle);
 	
 }
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java	Fri Mar 15 14:37:21 2013 +0100
@@ -17,6 +17,16 @@
 @Component
 public class ProjectsRepositoryImpl implements ProjectsRepositoryCustom {
 	
+	@Autowired
+	private ProjectsRepository projectsRepository;
+
+	@Autowired
+	private NodesRepository nodesRepository;
+
+	@Autowired
+	private EdgesRepository edgesRepository;
+
+	
 	private class GroupResult {
 		public String space_id;
 		public int count;		
@@ -52,4 +62,15 @@
 		
 	}
 
+	@Override
+	public Project copy(Project p, String newTitle) {
+		
+		Project res = new Project(p);
+		res.setTitle(newTitle);
+		this.nodesRepository.save(p.getNodes());
+		this.edgesRepository.save(p.getEdges());
+		this.projectsRepository.save(p);
+		return res;
+	}
+
 }
--- a/server/src/main/webapp/WEB-INF/mongo-config.xml	Fri Mar 15 16:34:56 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/mongo-config.xml	Fri Mar 15 14:37:21 2013 +0100
@@ -5,14 +5,15 @@
     xmlns:mongo="http://www.springframework.org/schema/data/mongo"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:jpa="http://www.springframework.org/schema/data/jpa"
-	xsi:schemaLocation="http://www.springframework.org/schema/beans 
-	   		http://www.springframework.org/schema/beans/spring-beans.xsd
+	xsi:schemaLocation="
+	        http://www.springframework.org/schema/context
+            http://www.springframework.org/schema/context/spring-context.xsd
+	        http://www.springframework.org/schema/beans
+	   		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    			http://www.springframework.org/schema/data/mongo
-    		http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
-    		http://www.springframework.org/schema/context
-            http://www.springframework.org/schema/context/spring-context.xsd
+    		http://www.springframework.org/schema/data/mongo/spring-mongo-1.2.xsd
             http://www.springframework.org/schema/data/jpa
-            http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">	
+            http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd">	
 	<!-- Default bean name is 'mongo' -->
 	<mongo:mongo host="localhost" port="27017"/>