Fix major update integrating with external wisemapping frond end
This commit is contained in:
@@ -18,41 +18,16 @@
|
||||
|
||||
package com.wisemapping.rest;
|
||||
|
||||
import com.mangofactory.swagger.annotations.ApiIgnore;
|
||||
import com.wisemapping.exceptions.ImportUnexpectedException;
|
||||
import com.wisemapping.exceptions.LabelCouldNotFoundException;
|
||||
import com.wisemapping.exceptions.MapCouldNotFoundException;
|
||||
import com.wisemapping.exceptions.MultipleSessionsOpenException;
|
||||
import com.wisemapping.exceptions.SessionExpiredException;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.exceptions.*;
|
||||
import com.wisemapping.importer.ImportFormat;
|
||||
import com.wisemapping.importer.Importer;
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.importer.ImporterFactory;
|
||||
import com.wisemapping.model.Collaboration;
|
||||
import com.wisemapping.model.CollaborationProperties;
|
||||
import com.wisemapping.model.CollaborationRole;
|
||||
import com.wisemapping.model.Label;
|
||||
import com.wisemapping.model.MindMapHistory;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.model.RestCollaboration;
|
||||
import com.wisemapping.rest.model.RestCollaborationList;
|
||||
import com.wisemapping.rest.model.RestLabel;
|
||||
import com.wisemapping.rest.model.RestMindmap;
|
||||
import com.wisemapping.rest.model.RestMindmapHistory;
|
||||
import com.wisemapping.rest.model.RestMindmapHistoryList;
|
||||
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestMindmapList;
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.rest.model.*;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.CollaborationException;
|
||||
import com.wisemapping.service.LabelService;
|
||||
import com.wisemapping.service.LockInfo;
|
||||
import com.wisemapping.service.LockManager;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.service.*;
|
||||
import com.wisemapping.validator.MapInfoValidator;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiParam;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -61,32 +36,20 @@ 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;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Api(value = "mindmap", description = "User Mindmap Objects.")
|
||||
@Controller
|
||||
public class MindmapController extends BaseController {
|
||||
final Logger logger = Logger.getLogger("com.wisemapping");
|
||||
final Logger logger = Logger.getLogger(MindmapController.class);
|
||||
|
||||
private static final String LATEST_HISTORY_REVISION = "latest";
|
||||
|
||||
@@ -118,14 +81,13 @@ public class MindmapController extends BaseController {
|
||||
return new ModelAndView("transformViewWise", values);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/freemind"}, params = {"download=mm","version"})
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/freemind"}, params = {"download=mm"})
|
||||
@ResponseBody
|
||||
public ModelAndView retrieveDocumentAsFreemind(@PathVariable int id, @RequestParam(value = "version") String version) throws IOException, MapCouldNotFoundException {
|
||||
public ModelAndView retrieveDocumentAsFreemind(@PathVariable int id) throws IOException, MapCouldNotFoundException {
|
||||
final Mindmap mindMap = findMindmapById(id);
|
||||
final Map<String, Object> values = new HashMap<String, Object>();
|
||||
values.put("content", mindMap.getXmlStr());
|
||||
values.put("filename", mindMap.getTitle());
|
||||
values.put("version", version);
|
||||
return new ModelAndView("transformViewFreemind", values);
|
||||
}
|
||||
|
||||
@@ -257,7 +219,6 @@ public class MindmapController extends BaseController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/document/xml", "/maps/{id}/document/xml-pub"}, consumes = {"text/plain"}, produces = {"application/xml; charset=UTF-8"})
|
||||
@ResponseBody
|
||||
public byte[] retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
|
||||
@@ -267,7 +228,6 @@ public class MindmapController extends BaseController {
|
||||
return xmlStr.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping(method = RequestMethod.PUT, value = {"/maps/{id}/document/xml"}, consumes = {"text/plain"})
|
||||
@ResponseBody
|
||||
public void updateDocument(@PathVariable int id, @RequestBody String xmlDoc) throws WiseMappingException, IOException {
|
||||
@@ -395,7 +355,7 @@ public class MindmapController extends BaseController {
|
||||
mindmapService.updateMindmap(mindMap, false);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps/{id}/collabs/", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException {
|
||||
final Mindmap mindMap = findMindmapById(id);
|
||||
@@ -435,6 +395,57 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs/", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void addCollab(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException {
|
||||
final Mindmap mindMap = findMindmapById(id);
|
||||
|
||||
// Only owner can change collaborators...
|
||||
final User user = Utils.getUser();
|
||||
if (!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
throw new IllegalArgumentException("No enough permissions");
|
||||
}
|
||||
|
||||
// Has any role changed ?. Just removed it.
|
||||
final Map<String, Collaboration> mapsByEmail = mindMap
|
||||
.getCollaborations()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(collaboration -> collaboration.getCollaborator().getEmail(), collaboration -> collaboration));
|
||||
|
||||
restCollabs
|
||||
.getCollaborations()
|
||||
.forEach(collab->{
|
||||
final String email = collab.getEmail();
|
||||
if(mapsByEmail.containsKey(email)){
|
||||
try {
|
||||
mindmapService.removeCollaboration(mindMap, mapsByEmail.get(email));
|
||||
} catch (CollaborationException e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Great, let's add all the collabs again ...
|
||||
for (RestCollaboration restCollab : restCollabs.getCollaborations()) {
|
||||
final Collaboration collaboration = mindMap.findCollaboration(restCollab.getEmail());
|
||||
// Validate role format ...
|
||||
String roleStr = restCollab.getRole();
|
||||
if (roleStr == null) {
|
||||
throw new IllegalArgumentException(roleStr + " is not a valid role");
|
||||
}
|
||||
|
||||
// Is owner ?
|
||||
final CollaborationRole role = CollaborationRole.valueOf(roleStr.toUpperCase());
|
||||
if (role == CollaborationRole.OWNER) {
|
||||
throw new IllegalArgumentException("Owner can not be added as part of the collaboration list.");
|
||||
}
|
||||
|
||||
mindmapService.addCollaboration(mindMap, restCollab.getEmail(), role, restCollabs.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/collabs", produces = {"application/json", "application/xml"})
|
||||
public RestCollaborationList retrieveList(@PathVariable int id) throws MapCouldNotFoundException {
|
||||
final Mindmap mindMap = findMindmapById(id);
|
||||
@@ -489,10 +500,36 @@ public class MindmapController extends BaseController {
|
||||
mindmapService.removeMindmap(mindmap, user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}/collabs")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void deleteCollabByEmail(@PathVariable int id, @RequestParam(required = false) String email) throws IOException, WiseMappingException {
|
||||
logger.debug("Deleting permission for email:" + email);
|
||||
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
final User user = Utils.getUser();
|
||||
|
||||
// Only owner can change collaborators...
|
||||
if (!mindmap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
throw new IllegalArgumentException("No enough permissions");
|
||||
}
|
||||
|
||||
final Collaboration collab = mindmap.findCollaboration(email);
|
||||
if(collab!=null) {
|
||||
CollaborationRole role = collab.getRole();
|
||||
|
||||
// Owner collab can not be removed ...
|
||||
if (role == CollaborationRole.OWNER) {
|
||||
throw new IllegalArgumentException("Can not remove owner collab");
|
||||
}
|
||||
mindmapService.removeCollaboration(mindmap, collab);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/starred", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateStarredState(@RequestBody @ApiParam(defaultValue = "false", allowableValues = "true,false") String value, @PathVariable int id) throws WiseMappingException {
|
||||
public void updateStarredState(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
|
||||
|
||||
logger.debug("Update starred:" + value);
|
||||
final Mindmap mindmap = findMindmapById(id);
|
||||
final User user = Utils.getUser();
|
||||
|
||||
@@ -506,7 +543,6 @@ public class MindmapController extends BaseController {
|
||||
mindmapService.updateCollaboration(user, collaboration);
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/lock", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateMapLock(@RequestBody String value, @PathVariable int id) throws IOException, WiseMappingException {
|
||||
@@ -522,12 +558,11 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/batch")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void batchDelete(@RequestParam(required = true) String ids) throws IOException, WiseMappingException {
|
||||
public void batchDelete(@RequestParam() String ids) throws IOException, WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final String[] mapsIds = ",".split(ids);
|
||||
final String[] mapsIds = ids.split(",");
|
||||
for (final String mapId : mapsIds) {
|
||||
final Mindmap mindmap = findMindmapById(Integer.parseInt(mapId));
|
||||
mindmapService.removeMindmap(mindmap, user);
|
||||
@@ -536,7 +571,11 @@ public class MindmapController extends BaseController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/maps", consumes = {"application/xml", "application/json", "application/wisemapping+xml"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createMap(@RequestBody RestMindmap restMindmap, @NotNull HttpServletResponse response, @RequestParam(required = false) String title, @RequestParam(required = false) String description) throws IOException, WiseMappingException {
|
||||
public void createMap(@RequestBody(required = false) RestMindmap restMindmap, @NotNull HttpServletResponse response, @RequestParam(required = false) String title, @RequestParam(required = false) String description) throws IOException, WiseMappingException {
|
||||
// If a default maps has not been defined, just create one ...
|
||||
if(restMindmap==null){
|
||||
restMindmap = new RestMindmap();
|
||||
}
|
||||
|
||||
// Overwrite title and description if they where specified by parameter.
|
||||
if (title != null && !title.isEmpty()) {
|
||||
@@ -544,6 +583,8 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
if (description != null && !description.isEmpty()) {
|
||||
restMindmap.setDescription(description);
|
||||
}else {
|
||||
restMindmap.setDescription("");
|
||||
}
|
||||
|
||||
// Validate ...
|
||||
|
Reference in New Issue
Block a user