Firt version of publish dialog.

This commit is contained in:
Paulo Gustavo Veiga
2012-05-20 21:46:55 -03:00
parent 93da41dcf5
commit fdc4a20667
13 changed files with 223 additions and 273 deletions

View File

@@ -1,69 +0,0 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.controller;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MindmapPublishController extends BaseMultiActionController {
protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException noSuchRequestHandlingMethodException, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
final MindMap mindmap = this.getMindmapFromRequest(httpServletRequest);
if (mindmap == null) {
throw new IllegalStateException("Map could not be found");
}
return new ModelAndView("mindmapPublish", "mindmap", mindmap);
}
public ModelAndView save(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws WiseMappingException {
final MindMap mindmap = this.getMindmapFromRequest(httpServletRequest);
if (mindmap == null) {
throw new IllegalStateException("Map could not be found");
}
User user = Utils.getUser();
if (!mindmap.getOwner().equals(user)) {
throw new IllegalStateException("No enought right to execute this operation");
}
final String publicViewStr = httpServletRequest.getParameter("publicView");
boolean publicView = Boolean.valueOf(publicViewStr);
if (mindmap.isPublic() != publicView) {
mindmap.setPublic(publicView);
getMindmapService().updateMindmap(mindmap, false);
}
return new ModelAndView("closeDialog");
}
}

View File

@@ -49,9 +49,16 @@ public class MindmapController {
return view;
}
@RequestMapping(value = "map/{id}/publish")
public ModelAndView showPublishPage(@PathVariable int id) {
final MindMap mindmap = findMindmap(id);
final ModelAndView view = new ModelAndView("mindmapPublish", "mindmap", mindmap);
view.addObject("user", Utils.getUser());
return view;
}
@RequestMapping(value = "map/{id}/edit")
public ModelAndView editMap(@PathVariable int id, @NotNull HttpServletRequest request)
{
public ModelAndView editMap(@PathVariable int id, @NotNull HttpServletRequest request) {
ModelAndView view;
final UserAgent userAgent = UserAgent.create(request);
if (userAgent.needsGCF()) {

View File

@@ -110,10 +110,26 @@ public class MindmapController extends BaseController {
updateMindmap(true, mindMap, user);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/publish", consumes = {"text/plain"}, produces = {"application/json", "text/html", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void changeMapPublish(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
final MindMap mindMap = mindmapService.getMindmapById(id);
final User user = Utils.getUser();
if (!mindMap.getOwner().equals(user)) {
throw new IllegalArgumentException("No enough to execute this operation");
}
// Update map status ...
mindMap.setPublic(Boolean.parseBoolean(value));
updateMindmap(true, mindMap, user);
}
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateMap(@PathVariable int id) throws IOException, WiseMappingException {
public void updateMap( @PathVariable int id) throws IOException, WiseMappingException {
final User user = Utils.getUser();
final MindMap mindmap = mindmapService.getMindmapById(id);
mindmapService.removeMindmap(mindmap, user);
@@ -187,7 +203,7 @@ public class MindmapController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"})
@ResponseStatus(value = HttpStatus.CREATED)
public void copyMap(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
// Validate ...
// Validate ...
final BindingResult result = new BeanPropertyBindingResult(restMindmap, "");
new MapInfoValidator(mindmapService).validate(restMindmap.getDelegated(), result);
if (result.hasErrors()) {

View File

@@ -70,6 +70,15 @@ public class RestMindmapInfo {
return mindmap.getCreator();
}
public String getOwnerEmail() {
return mindmap.getOwner().getEmail();
}
public String getOwner() {
final User owner = mindmap.getOwner();
return owner.getUsername();
}
public String getLastModifierUser() {
return mindmap.getLastModifierUser();
}
@@ -109,6 +118,12 @@ public class RestMindmapInfo {
public void setLastModifierUser(String value) {
}
public void setOwnerEmail(String value) {
}
public void setOwner(String value) {
}
@JsonIgnore
public MindMap getDelegated() {
return this.mindmap;