2012-02-12 21:57:11 -03:00
|
|
|
package com.wisemapping.rest;
|
|
|
|
|
|
|
|
|
2012-02-21 14:22:43 -03:00
|
|
|
import com.wisemapping.exceptions.WiseMappingException;
|
2012-02-12 21:57:11 -03:00
|
|
|
import com.wisemapping.model.MindMap;
|
2012-02-17 10:42:20 -03:00
|
|
|
import com.wisemapping.model.MindmapUser;
|
|
|
|
import com.wisemapping.model.User;
|
2012-02-19 21:07:24 -03:00
|
|
|
import com.wisemapping.rest.model.RestMindmap;
|
2012-02-20 14:42:07 -03:00
|
|
|
import com.wisemapping.rest.model.RestMindmapList;
|
2012-02-21 14:22:43 -03:00
|
|
|
import com.wisemapping.security.Utils;
|
2012-02-12 21:57:11 -03:00
|
|
|
import com.wisemapping.service.MindmapService;
|
2012-02-16 01:16:51 -03:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2012-02-21 20:04:17 -03:00
|
|
|
import org.springframework.http.HttpStatus;
|
2012-02-12 21:57:11 -03:00
|
|
|
import org.springframework.stereotype.Controller;
|
2012-02-21 14:22:43 -03:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2012-02-16 01:16:51 -03:00
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
2012-02-12 21:57:11 -03:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2012-02-20 14:42:07 -03:00
|
|
|
import java.util.ArrayList;
|
2012-02-21 14:22:43 -03:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
2012-02-17 10:42:20 -03:00
|
|
|
import java.util.List;
|
2012-02-12 21:57:11 -03:00
|
|
|
|
|
|
|
@Controller
|
2012-02-21 20:04:17 -03:00
|
|
|
public class MindmapController extends BaseController{
|
2012-02-16 01:16:51 -03:00
|
|
|
@Autowired
|
2012-02-12 21:57:11 -03:00
|
|
|
private MindmapService mindmapService;
|
|
|
|
|
2012-02-21 17:41:51 -03:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/json", "text/html", "application/xml"})
|
2012-02-12 21:57:11 -03:00
|
|
|
@ResponseBody
|
2012-02-16 01:16:51 -03:00
|
|
|
public ModelAndView getMindmap(@PathVariable int id) throws IOException {
|
2012-02-12 21:57:11 -03:00
|
|
|
final MindMap mindMap = mindmapService.getMindmapById(id);
|
2012-02-19 21:07:24 -03:00
|
|
|
final RestMindmap map = new RestMindmap(mindMap);
|
2012-02-16 01:16:51 -03:00
|
|
|
return new ModelAndView("mapView", "map", map);
|
2012-02-12 21:57:11 -03:00
|
|
|
}
|
2012-02-17 10:42:20 -03:00
|
|
|
|
2012-02-21 17:41:51 -03:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/maps", produces = {"application/json", "text/html", "application/xml"})
|
2012-02-17 10:42:20 -03:00
|
|
|
public ModelAndView getMindmaps() throws IOException {
|
|
|
|
final User user = com.wisemapping.security.Utils.getUser();
|
|
|
|
|
2012-02-20 14:42:07 -03: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-17 10:42:20 -03:00
|
|
|
}
|
2012-02-21 14:22:43 -03:00
|
|
|
|
2012-02-21 18:14:28 -03:00
|
|
|
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
2012-02-21 20:04:17 -03:00
|
|
|
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
|
|
|
public void updateMap(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
|
2012-02-21 14:22:43 -03:00
|
|
|
|
|
|
|
final MindMap mindMap = mindmapService.getMindmapById(id);
|
|
|
|
final User user = Utils.getUser();
|
|
|
|
|
|
|
|
final String properties = restMindmap.getProperties();
|
|
|
|
mindMap.setProperties(properties);
|
|
|
|
|
|
|
|
final Calendar now = Calendar.getInstance();
|
|
|
|
mindMap.setLastModificationTime(now);
|
|
|
|
mindMap.setLastModifierUser(user.getUsername());
|
|
|
|
|
|
|
|
final Calendar lastModification = Calendar.getInstance();
|
|
|
|
lastModification.setTime(new Date());
|
|
|
|
mindMap.setLastModificationTime(lastModification);
|
|
|
|
|
|
|
|
final String xml = restMindmap.getXml();
|
|
|
|
mindMap.setXmlStr(xml);
|
2012-02-21 18:14:28 -03:00
|
|
|
mindmapService.updateMindmap(mindMap, minor);
|
2012-02-21 14:22:43 -03:00
|
|
|
}
|
2012-02-21 20:04:17 -03:00
|
|
|
|
2012-02-12 21:57:11 -03:00
|
|
|
}
|