Add duplicate action.

This commit is contained in:
Paulo Gustavo Veiga
2012-04-07 20:05:50 -03:00
parent 3da0eec842
commit 748ecf7608
4 changed files with 224 additions and 99 deletions

View File

@@ -187,23 +187,15 @@ 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 {
final String title = restMindmap.getTitle();
if (title == null || title.isEmpty()) {
throw new IllegalArgumentException("Map title can not be null");
}
final String description = restMindmap.getDescription();
if (description == null || description.isEmpty()) {
throw new IllegalArgumentException("Map details can not be null");
// Validate ...
final BindingResult result = new BeanPropertyBindingResult(restMindmap, "");
new MapInfoValidator(mindmapService).validate(restMindmap.getDelegated(), result);
if (result.hasErrors()) {
throw new ValidationException(result);
}
// Some basic validations ...
final User user = Utils.getUser();
final MindMap searchByMap = mindmapService.getMindmapByTitle(title, user);
if (searchByMap != null) {
throw new IllegalArgumentException("Map already exists with title '" + title + "'");
}
// Create a shallowCopy of the map ...
final MindMap mindMap = mindmapService.getMindmapById(id);