wisemapping-open-source/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java

49 lines
1.9 KiB
Java
Raw Normal View History

2012-02-13 01:57:11 +01:00
package com.wisemapping.rest;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.MindmapUser;
import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestMindmap;
2012-02-20 18:42:07 +01:00
import com.wisemapping.rest.model.RestMindmapList;
2012-02-13 01:57:11 +01:00
import com.wisemapping.service.MindmapService;
import org.springframework.beans.factory.annotation.Autowired;
2012-02-13 01:57:11 +01:00
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
2012-02-13 01:57:11 +01:00
import java.io.IOException;
2012-02-20 18:42:07 +01:00
import java.util.ArrayList;
import java.util.List;
2012-02-13 01:57:11 +01:00
@Controller
public class MindmapController {
@Autowired
2012-02-13 01:57:11 +01:00
private MindmapService mindmapService;
@RequestMapping(method = RequestMethod.GET, value = "/map/{id}", produces = {"text/xml", "application/json", "text/html"})
2012-02-13 01:57:11 +01:00
@ResponseBody
public ModelAndView getMindmap(@PathVariable int id) throws IOException {
2012-02-13 01:57:11 +01:00
final MindMap mindMap = mindmapService.getMindmapById(id);
final RestMindmap map = new RestMindmap(mindMap);
return new ModelAndView("mapView", "map", map);
2012-02-13 01:57:11 +01:00
}
2012-02-20 18:42:07 +01:00
@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();
2012-02-20 18:42:07 +01:00
final List<MindmapUser> mapsByUser = mindmapService.getMindmapUserByUser(user);
final List<MindMap> mindmaps = new ArrayList<MindMap>();
for (MindmapUser mindmapUser : mapsByUser) {
mindmaps.add(mindmapUser.getMindMap());
}
final RestMindmapList restMindmapList = new RestMindmapList(mindmaps);
return new ModelAndView("mapsView", "list", restMindmapList);
}
2012-02-13 01:57:11 +01:00
}