link label to mindmaps

This commit is contained in:
Ezequiel Bergamaschi
2014-01-28 02:28:16 -03:00
committed by Ezequiel Bergamaschi
parent 72a46367d6
commit 2ec941e1a0
10 changed files with 94 additions and 3 deletions

View File

@@ -1,12 +1,18 @@
package com.wisemapping.rest;
import com.wisemapping.exceptions.LabelCouldNotFoundException;
import com.wisemapping.exceptions.MapCouldNotFoundException;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Label;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestLabel;
import com.wisemapping.rest.model.RestLabelList;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.security.Utils;
import com.wisemapping.service.LabelService;
import com.wisemapping.service.MindmapService;
import com.wisemapping.validator.LabelValidator;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +21,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -22,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@Controller
@@ -31,6 +37,9 @@ public class LabelController extends BaseController {
@Qualifier("labelService")
@Autowired
private LabelService labelService;
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
@RequestMapping(method = RequestMethod.POST, value = "/labels", consumes = {"application/json"})
@@ -45,7 +54,7 @@ public class LabelController extends BaseController {
// Validate ...
final BindingResult result = new BeanPropertyBindingResult(restLabel, "");
new LabelValidator().validate(label, result);
new LabelValidator(labelService).validate(label, result);
if (result.hasErrors()) {
throw new ValidationException(result);
}
@@ -67,4 +76,20 @@ public class LabelController extends BaseController {
return new RestLabelList(all);
}
@RequestMapping(method = RequestMethod.PUT, value = "/labels/{id}/maps", consumes = {"text/plain"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void linkToMindMaps(@PathVariable int id, @RequestBody String ids) throws WiseMappingException {
final Label label = labelService.getLabelById(id);
if (label == null) {
throw new LabelCouldNotFoundException("Label could not be found. Id: " + id);
}
for (String mindmapId : ids.split(",")) {
final Mindmap mindmap = mindmapService.findMindmapById(Integer.parseInt(mindmapId));
if (mindmap == null) {
throw new MapCouldNotFoundException("Map could not be found. Id:" + id);
}
mindmap.addLabel(label);
mindmapService.updateMindmap(mindmap, false);
}
}
}