mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +01:00
Add delete map rest operation.
This commit is contained in:
parent
b52da56739
commit
0e3b0754cd
@ -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);
|
||||
|
@ -28,7 +28,6 @@ import java.util.List;
|
||||
* Change map title
|
||||
* List with filter
|
||||
* Clone
|
||||
* Delete map
|
||||
* Discard Changed
|
||||
* Public ?
|
||||
* Admin operations for get/update
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
@ -19,6 +19,7 @@
|
||||
<property name="classesToBeBound">
|
||||
<list>
|
||||
<value>com.wisemapping.rest.model.RestMindmap</value>
|
||||
<value>com.wisemapping.rest.model.RestMindmapInfo</value>
|
||||
<value>com.wisemapping.rest.model.RestMindmapList</value>
|
||||
<value>com.wisemapping.rest.model.RestUser</value>
|
||||
</list>
|
||||
|
@ -2,8 +2,8 @@ package com.wisemapping.test.model;
|
||||
|
||||
|
||||
import com.wisemapping.rest.model.RestMindmap;
|
||||
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -20,8 +20,5 @@ public class JsonTest {
|
||||
|
||||
String userJson = "{\"username\":\"admin\",\"email\":\"admin@wisemapping.org\",\"tags\":[],\"creationDate\":1329706800000,\"firstname\":\"Wise\",\"lastname\":\"test\",\"password\":\"test\"}";
|
||||
final RestUser restUser = mapper.readValue(userJson, RestUser.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.wisemapping.test.rest;
|
||||
|
||||
|
||||
import com.wisemapping.rest.model.RestMindmapInfo;
|
||||
import com.wisemapping.rest.model.RestMindmap;
|
||||
import com.wisemapping.rest.model.RestMindmapList;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.security.crypto.codec.Base64;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -25,12 +24,11 @@ import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
|
||||
@Test
|
||||
public class RestMindmapTCase {
|
||||
|
||||
private String userEmail = "admin@wisemapping.com";
|
||||
private static final String HOST_PORT = "http://127.0.0.1:8080";
|
||||
private static final String HOST_PORT = "http://localhost:8080";
|
||||
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||
|
||||
@BeforeClass
|
||||
@ -58,11 +56,11 @@ public class RestMindmapTCase {
|
||||
|
||||
// Validate that the two maps are there ...
|
||||
final RestMindmapList body = response.getBody();
|
||||
final List<RestMindmap> mindmaps = body.getMindmaps();
|
||||
final List<RestMindmapInfo> mindmaps = body.getMindmapsInfo();
|
||||
|
||||
boolean found1 = false;
|
||||
boolean found2 = false;
|
||||
for (RestMindmap mindmap : mindmaps) {
|
||||
for (RestMindmapInfo mindmap : mindmaps) {
|
||||
if (mindmap.getTitle().equals(title1)) {
|
||||
found1 = true;
|
||||
}
|
||||
@ -74,31 +72,50 @@ public class RestMindmapTCase {
|
||||
|
||||
}
|
||||
|
||||
private URI addNewMap(HttpHeaders requestHeaders, RestTemplate templateRest, String title) {
|
||||
final RestMindmap restMindmap = new RestMindmap();
|
||||
restMindmap.setTitle(title);
|
||||
restMindmap.setDescription("My Map Desc");
|
||||
// Create a new map ...
|
||||
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
|
||||
return templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void createMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
public void deleteMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate templateRest = createTemplate();
|
||||
|
||||
// Create a sample map ...
|
||||
final String title = "My Map " + mediaType.toString();
|
||||
final String title1 = "Map to delete - " + mediaType.toString();
|
||||
final URI resourceLocation = addNewMap(requestHeaders, templateRest, title1);
|
||||
|
||||
// Now remove it ...
|
||||
templateRest.delete(HOST_PORT + resourceLocation.toString());
|
||||
|
||||
// Check that has been removed ...
|
||||
try {
|
||||
findMap(requestHeaders, templateRest, resourceLocation);
|
||||
fail("Map could not be removed:" + resourceLocation);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private URI addNewMap(HttpHeaders requestHeaders, RestTemplate templateRest, String title) {
|
||||
final RestMindmapInfo restMindmap = new RestMindmapInfo();
|
||||
restMindmap.setTitle(title);
|
||||
restMindmap.setDescription("My Map Desc");
|
||||
|
||||
// Create a new map ...
|
||||
HttpEntity<RestMindmapInfo> createUserEntity = new HttpEntity<RestMindmapInfo>(restMindmap, requestHeaders);
|
||||
return templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void discardChange(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||
final RestTemplate templateRest = createTemplate();
|
||||
|
||||
// Create a sample map ...
|
||||
final String title = "Add map to discard " + mediaType.toString();
|
||||
final URI resourceLocation = addNewMap(requestHeaders, templateRest, title);
|
||||
|
||||
// Check that the map has been created ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
assertEquals(response.getBody().getTitle(), title);
|
||||
// Update with "minor" flag ...
|
||||
|
||||
// Revert the change ...
|
||||
|
||||
// Check that the map is the
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
@ -118,11 +135,15 @@ public class RestMindmapTCase {
|
||||
templateRest.put(resourceUrl + "/xml", updateEntity);
|
||||
|
||||
// Check that the map has been updated ...
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
assertEquals(response.getBody().getXml(), newXmlContent);
|
||||
final RestMindmap response = findMap(requestHeaders, templateRest, resourceLocation);
|
||||
assertEquals(response.getXml(), newXmlContent);
|
||||
}
|
||||
|
||||
private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate templateRest, URI resourceLocation) {
|
||||
final HttpEntity findMapEntity = new HttpEntity(requestHeaders);
|
||||
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class);
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ContentType-Provider-Function")
|
||||
public void updateMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||
|
Loading…
Reference in New Issue
Block a user