Add delete map rest operation.
This commit is contained in:
@@ -89,7 +89,7 @@ public class MindmapController extends BaseMultiActionController {
|
||||
final User user = Utils.getUser(request);
|
||||
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
getMindmapService().removeColaboratorFromMindmap(mindmap, user.getId());
|
||||
getMindmapService().removeCollaboratorFromMindmap(mindmap, user.getId());
|
||||
|
||||
return list(request, response);
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ public class MindmapSharingController extends BaseMultiActionController {
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
final String colaboratorId = request.getParameter(COLABORATOR_ID);
|
||||
long colaborator = Long.parseLong(colaboratorId);
|
||||
getMindmapService().removeColaboratorFromMindmap(mindmap, colaborator);
|
||||
getMindmapService().removeCollaboratorFromMindmap(mindmap, colaborator);
|
||||
return mindmap;
|
||||
}
|
||||
|
||||
|
@@ -103,7 +103,7 @@ public class AdminController extends BaseController {
|
||||
userService.changePassword(user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "admin/users/{id}", produces = {"application/json", "text/html", "application/xml"})
|
||||
@RequestMapping(method = RequestMethod.DELETE)
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void getUserByEmail(@PathVariable long id) throws IOException, WiseMappingException {
|
||||
final User user = userService.getUserBy(id);
|
||||
|
@@ -25,14 +25,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Pendings:
|
||||
* Change map title
|
||||
* List with filter
|
||||
* Clone
|
||||
* Delete map
|
||||
* Discard Changed
|
||||
* Public ?
|
||||
* Admin operations for get/update
|
||||
* Check visibility
|
||||
* Change map title
|
||||
* List with filter
|
||||
* Clone
|
||||
* Discard Changed
|
||||
* Public ?
|
||||
* Admin operations for get/update
|
||||
* Check visibility
|
||||
*/
|
||||
@Controller
|
||||
public class MindmapController extends BaseController {
|
||||
@@ -86,6 +85,15 @@ public class MindmapController extends BaseController {
|
||||
updateMindmap(minor, mindMap, user);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/maps/{id}")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateMap(@PathVariable int id) throws IOException, WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final MindMap mindmap = mindmapService.getMindmapById(id);
|
||||
mindmapService.removeMindmap(mindmap, user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/xml", consumes = {"application/xml"}, produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateMapXml(@RequestBody String xml, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
|
||||
@@ -102,7 +110,7 @@ public class MindmapController extends BaseController {
|
||||
updateMindmap(minor, mindMap, user);
|
||||
}
|
||||
|
||||
private void updateMindmap(boolean minor, MindMap mindMap, User user) throws WiseMappingException {
|
||||
private void updateMindmap(boolean minor, @NotNull final MindMap mindMap, @NotNull final User user) throws WiseMappingException {
|
||||
final Calendar now = Calendar.getInstance();
|
||||
mindMap.setLastModificationTime(now);
|
||||
mindMap.setLastModifierUser(user.getUsername());
|
||||
|
@@ -0,0 +1,101 @@
|
||||
package com.wisemapping.rest.model;
|
||||
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import org.codehaus.jackson.annotate.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@XmlRootElement(name = "map")
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
@JsonAutoDetect(
|
||||
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
setterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY
|
||||
)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RestMindmapInfo {
|
||||
|
||||
@JsonIgnore
|
||||
private MindMap mindmap;
|
||||
|
||||
public RestMindmapInfo() {
|
||||
this(new MindMap());
|
||||
|
||||
}
|
||||
|
||||
public RestMindmapInfo(@NotNull MindMap mindmap) {
|
||||
this.mindmap = mindmap;
|
||||
}
|
||||
|
||||
public Calendar getCreationTime() {
|
||||
return mindmap.getCreationTime();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return mindmap.getDescription();
|
||||
}
|
||||
|
||||
public String getTags() {
|
||||
return mindmap.getTags();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mindmap.getTitle();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return mindmap.getId();
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return mindmap.getCreator();
|
||||
}
|
||||
|
||||
public String getLastModifierUser() {
|
||||
return mindmap.getLastModifierUser();
|
||||
}
|
||||
|
||||
public Date getLastModificationDate() {
|
||||
return mindmap.getLastModificationDate();
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return mindmap.isPublic();
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
mindmap.setId(id);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
mindmap.setTitle(title);
|
||||
}
|
||||
|
||||
public void setTags(String tags) {
|
||||
mindmap.setTags(tags);
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
mindmap.setDescription(description);
|
||||
}
|
||||
|
||||
public void setCreator(String creatorUser) {
|
||||
|
||||
}
|
||||
|
||||
public void setLastModificationTime(Calendar lastModificationTime) {
|
||||
}
|
||||
|
||||
public void setLastModifierUser(String lastModifierUser) {
|
||||
}
|
||||
}
|
@@ -3,9 +3,7 @@ package com.wisemapping.rest.model;
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@@ -24,21 +22,21 @@ import java.util.List;
|
||||
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
||||
public class RestMindmapList {
|
||||
|
||||
private List<RestMindmap> mindmaps;
|
||||
private List<RestMindmapInfo> mindmapsInfo;
|
||||
|
||||
public RestMindmapList() {
|
||||
this(Collections.<MindMap>emptyList());
|
||||
}
|
||||
|
||||
public RestMindmapList(@NotNull List<MindMap> mindmaps) {
|
||||
this.mindmaps = new ArrayList<RestMindmap>();
|
||||
this.mindmapsInfo = new ArrayList<RestMindmapInfo>();
|
||||
for (MindMap mindMap : mindmaps) {
|
||||
this.mindmaps.add(new RestMindmap(mindMap));
|
||||
this.mindmapsInfo.add(new RestMindmapInfo(mindMap));
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.mindmaps.size();
|
||||
return this.mindmapsInfo.size();
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
@@ -46,11 +44,11 @@ public class RestMindmapList {
|
||||
}
|
||||
|
||||
@XmlElement(name = "map")
|
||||
public List<RestMindmap> getMindmaps() {
|
||||
return mindmaps;
|
||||
public List<RestMindmapInfo> getMindmapsInfo() {
|
||||
return mindmapsInfo;
|
||||
}
|
||||
|
||||
public void setMindmaps(List<RestMindmap> mindmaps) {
|
||||
this.mindmaps = mindmaps;
|
||||
public void setMindmapsInfo(List<RestMindmapInfo> mindmapsInfo) {
|
||||
this.mindmapsInfo = mindmapsInfo;
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.model.*;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
@@ -45,9 +46,9 @@ public interface MindmapService {
|
||||
|
||||
public void addTags(MindMap mindmap, String tags);
|
||||
|
||||
public void removeColaboratorFromMindmap(MindMap mindmap, long colaboratorId);
|
||||
public void removeCollaboratorFromMindmap(@NotNull final MindMap mindmap, long colaboratorId);
|
||||
|
||||
public void removeMindmap(MindMap mindmap, User user) throws WiseMappingException;
|
||||
public void removeMindmap(@NotNull final MindMap mindmap, @NotNull final User user) throws WiseMappingException;
|
||||
|
||||
public List<MindMap> search(MindMapCriteria criteria);
|
||||
|
||||
|
@@ -113,26 +113,13 @@ public class MindmapServiceImpl
|
||||
return mindmapManager.search(criteria);
|
||||
}
|
||||
|
||||
public void removeColaboratorFromMindmap(MindMap mindmap, long colaboratorId) {
|
||||
public void removeCollaboratorFromMindmap(@NotNull MindMap mindmap, long userId) {
|
||||
// remove colaborator association
|
||||
Set<MindmapUser> mindmapusers = mindmap.getMindmapUsers();
|
||||
MindmapUser mindmapuserToDelete = null;
|
||||
for (MindmapUser mindmapuser : mindmapusers) {
|
||||
if (mindmapuser.getCollaborator().getId() == colaboratorId) {
|
||||
if (mindmapuser.getCollaborator().getId() == userId) {
|
||||
mindmapuserToDelete = mindmapuser;
|
||||
//@TODO evaluar si el colaborador no tiene mas asociaciones si hay que eliminarlo, por ahora NO
|
||||
// final List<MindmapUser> otherAsociations = mindmapManager.getMindmapUserByCollaborator(colaboratorId);
|
||||
// if (otherAsociations != null)
|
||||
// {
|
||||
//
|
||||
// final User user = userService.getUserBy(colaboratorId);
|
||||
// // Is not a User
|
||||
// if (user == null)
|
||||
// {
|
||||
// final Collaborator col = mindmapManager.getCollaboratorBy(colaboratorId);
|
||||
// mindmapManager.removeCollaborator(col);
|
||||
// }
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -143,12 +130,11 @@ public class MindmapServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMindmap(MindMap mindmap, User user) throws WiseMappingException {
|
||||
public void removeMindmap(@NotNull MindMap mindmap, @NotNull User user) throws WiseMappingException {
|
||||
if (mindmap.getOwner().equals(user)) {
|
||||
|
||||
mindmapManager.removeMindmap(mindmap);
|
||||
} else {
|
||||
this.removeColaboratorFromMindmap(mindmap, user.getId());
|
||||
this.removeCollaboratorFromMindmap(mindmap, user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +146,7 @@ public class MindmapServiceImpl
|
||||
throw new IllegalArgumentException("The tile can not be empty");
|
||||
}
|
||||
|
||||
if (user==null) {
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User can not be null");
|
||||
}
|
||||
|
||||
@@ -227,8 +213,7 @@ public class MindmapServiceImpl
|
||||
final MindMap savedWelcome = getMindmapById(Constants.WELCOME_MAP_ID);
|
||||
|
||||
// Is there a welcomed map configured ?
|
||||
if(savedWelcome!=null)
|
||||
{
|
||||
if (savedWelcome != null) {
|
||||
final MindMap welcomeMap = new MindMap();
|
||||
welcomeMap.setTitle(savedWelcome.getTitle() + " " + user.getFirstname());
|
||||
welcomeMap.setDescription(savedWelcome.getDescription());
|
||||
|
Reference in New Issue
Block a user