From 89f7fd8d3c3df038a19c667ce3c894636f241a50 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 20 Feb 2012 14:42:07 -0300 Subject: [PATCH] Add REST service /service/maps. --- .../wisemapping/rest/MindmapController.java | 16 ++++-- .../wisemapping/rest/model/RestMindmap.java | 5 +- .../rest/model/RestMindmapList.java | 52 +++++++++++++++++ .../webapp/WEB-INF/classes/log4j.properties | 4 +- .../main/webapp/WEB-INF/jsp-rest/mapView.jsp | 56 +++++++++++++------ .../main/webapp/WEB-INF/jsp-rest/mapsView.jsp | 51 +++++++++++++++++ .../main/webapp/WEB-INF/wisemapping-rest.xml | 3 +- .../webapp/WEB-INF/wisemapping-security.xml | 20 +------ 8 files changed, 163 insertions(+), 44 deletions(-) create mode 100644 wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapList.java create mode 100644 wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapsView.jsp diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index ea78ae2a..3c92ac5b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -5,6 +5,7 @@ import com.wisemapping.model.MindMap; import com.wisemapping.model.MindmapUser; import com.wisemapping.model.User; import com.wisemapping.rest.model.RestMindmap; +import com.wisemapping.rest.model.RestMindmapList; import com.wisemapping.service.MindmapService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import java.io.IOException; +import java.util.ArrayList; import java.util.List; @Controller @@ -30,13 +32,17 @@ public class MindmapController { return new ModelAndView("mapView", "map", map); } - @RequestMapping(method = RequestMethod.GET, value = "/maps") + @RequestMapping(method = RequestMethod.GET, value = "/maps", produces = {"text/xml", "application/json", "text/html"}) public ModelAndView getMindmaps() throws IOException { final User user = com.wisemapping.security.Utils.getUser(); - final List list = mindmapService.getMindmapUserByUser(user); -// final RestMindMap map = new RestMindmap(mindMap); -// return new ModelAndView("mapView", "map", map); - return null; + final List mapsByUser = mindmapService.getMindmapUserByUser(user); + final List mindmaps = new ArrayList(); + for (MindmapUser mindmapUser : mapsByUser) { + mindmaps.add(mindmapUser.getMindMap()); + } + + final RestMindmapList restMindmapList = new RestMindmapList(mindmaps); + return new ModelAndView("mapsView", "list", restMindmapList); } } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java index 8c4cf46e..2680d089 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java @@ -3,6 +3,7 @@ package com.wisemapping.rest.model; import com.wisemapping.model.MindMap; import com.wisemapping.model.User; +import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.jetbrains.annotations.NotNull; @@ -10,16 +11,16 @@ import org.jetbrains.annotations.NotNull; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import java.io.IOException; import java.util.Calendar; import java.util.Date; @XmlRootElement(name = "map") @XmlAccessorType(XmlAccessType.PROPERTY) +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, + getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY) public class RestMindmap { - @JsonIgnore private MindMap mindmap; public RestMindmap() { diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapList.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapList.java new file mode 100644 index 00000000..96022155 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapList.java @@ -0,0 +1,52 @@ +package com.wisemapping.rest.model; + + +import com.wisemapping.model.MindMap; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnore; +import org.jetbrains.annotations.NotNull; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; + +import java.util.List; + +@XmlRootElement(name = "maps") +@XmlAccessorType(XmlAccessType.PROPERTY) +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, + getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY) +public class RestMindmapList { + + private List mindmaps; + + public RestMindmapList() { + this(null); + } + + public RestMindmapList(@NotNull List mindmaps) { + this.mindmaps = new ArrayList(); + for (MindMap mindMap : mindmaps) { + this.mindmaps.add(new RestMindmap(mindMap)); + } + } + + public int getCount() { + return this.mindmaps.size(); + } + + public void setCount(int count) { + + } + + @XmlElement(name = "map") + public List getMindmaps() { + return mindmaps; + } + + public void setMindmaps(List mindmaps) { + this.mindmaps = mindmaps; + } +} diff --git a/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties b/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties index 3bed50c9..70ee6799 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/classes/log4j.properties @@ -1,8 +1,8 @@ log4j.rootLogger=WARN, stdout, R log4j.logger.net.sf=FATAL,stdout, R log4j.logger.com.wisemapping=WARN,stdout,R -log4j.logger.org.wisemapping.ws= WARN,stdout, R -log4j.logger.org.acegisecurity.event.authentication= FATAL,stdout, R +log4j.logger.org.springframework=WARN,stdout,R + # Stdout logger � log4j.appender.stdout=org.apache.log4j.ConsoleAppender diff --git a/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapView.jsp b/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapView.jsp index 862b9a73..95e23838 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapView.jsp +++ b/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapView.jsp @@ -1,24 +1,48 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - Employees + + Mindmap Detail - - - - - - - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> - <%----%> +

Details for map with id '${map.id}'

+
IDNameEmail
${employee.id}${employee.name}${employee.email}
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id:${map.id}
Title:${map.title}
Description:${map.description}
Owner:${map.owner}
Xml:
Last Modified:${map.lastModifierUser}
Creator:${map.creator}
Public:${map.public}
\ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapsView.jsp b/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapsView.jsp new file mode 100644 index 00000000..2a40ceb2 --- /dev/null +++ b/wise-webapp/src/main/webapp/WEB-INF/jsp-rest/mapsView.jsp @@ -0,0 +1,51 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Mindmaps List + + +

Mindmaps List

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id:${map.id}
Title:${map.title}
Description:${map.description}
Owner:${map.owner}
Xml:
Last Modified:${map.lastModifierUser}
Creator:${map.creator}
Public:${map.public}
+
+
+ + \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml index 1e0b28b4..8395ad92 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-rest.xml @@ -19,6 +19,7 @@ com.wisemapping.rest.model.RestMindmap + com.wisemapping.rest.model.RestMindmapList @@ -29,7 +30,7 @@ - + diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml index 0c3bde00..ae03bcad 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml @@ -29,14 +29,11 @@ - - - + + - @@ -61,17 +58,4 @@ - - - - - - - - - - - - \ No newline at end of file