Enable MindmapController rests.

This commit is contained in:
Paulo Gustavo Veiga 2014-01-25 03:13:51 -03:00
parent 686e011f9b
commit 5e62eb3279
7 changed files with 119 additions and 104 deletions

View File

@ -120,7 +120,8 @@ public class User
}
public char getAutheticationTypeCode() {
return this.authenticationType != null ? this.authenticationType.getCode() : null;
// Default authentication is database ....
return this.authenticationType != null ? this.authenticationType.getCode() : AuthenticationType.DATABASE.getCode();
}
public void setAutheticationTypeCode(char code) {

View File

@ -77,7 +77,7 @@ import java.util.Map;
import java.util.Set;
@Api(value="mindmap",description = "User Mindmap Objects.")
@Api(value = "mindmap", description = "User Mindmap Objects.")
@Controller
public class MindmapController extends BaseController {
@ -116,7 +116,6 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewFreemind", values);
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"text/plain"}, params = {"download=txt"})
@ResponseBody
public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException, MapCouldNotFoundException {
@ -137,7 +136,6 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewMMap", values);
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.ms-excel"}, params = {"download=xls"})
@ResponseBody
public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException, MapCouldNotFoundException {
@ -158,8 +156,7 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewOdt", values);
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json", "application/xml"})
public RestMindmapList retrieveList(@RequestParam(required = false) String q) throws IOException {
final User user = Utils.getUser();
@ -176,8 +173,7 @@ public class MindmapController extends BaseController {
return new RestMindmapList(mindmaps, user);
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/history", produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/history", produces = {"application/json", "application/xml"})
public RestMindmapHistoryList retrieveHistory(@PathVariable int id) throws IOException {
final List<MindMapHistory> histories = mindmapService.findMindmapHistory(id);
final RestMindmapHistoryList result = new RestMindmapHistoryList();
@ -187,7 +183,6 @@ public class MindmapController extends BaseController {
return result;
}
@RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException, IOException {
@ -207,7 +202,7 @@ public class MindmapController extends BaseController {
}
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "application/xml"})
@ResponseBody
public long updateDocument(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor, @RequestParam(required = false) Long timestamp, @RequestParam(required = false) Long session) throws WiseMappingException, IOException {
@ -221,7 +216,9 @@ public class MindmapController extends BaseController {
}
// Could the map be updated ?
verifyLock(mindmap, user, session, timestamp);
if (session != null) {
verifyLock(mindmap, user, session, timestamp);
}
// Update collaboration properties ...
final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(user);
@ -239,8 +236,12 @@ public class MindmapController extends BaseController {
// Update edition timeout ...
final LockManager lockManager = mindmapService.getLockManager();
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user);
return lockInfo.getTimestamp();
long result = -1;
if (session != null) {
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user);
result = lockInfo.getTimestamp();
}
return result;
}
@ApiIgnore
@ -264,7 +265,6 @@ public class MindmapController extends BaseController {
return mindmapHistory.getUnzipXml();
}
private void verifyLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws WiseMappingException {
// The lock was lost, reclaim as the ownership of it.
@ -295,7 +295,7 @@ public class MindmapController extends BaseController {
/**
* The intention of this method is the update of several properties at once ...
*/
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}", consumes = {"application/xml", "application/json"}, produces = {"application/json", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateProperties(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
@ -347,8 +347,7 @@ public class MindmapController extends BaseController {
return result;
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/title", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/title", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException {
@ -367,7 +366,7 @@ public class MindmapController extends BaseController {
mindmapService.updateMindmap(mindMap, !true);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
@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 updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id);
@ -407,8 +406,7 @@ public class MindmapController extends BaseController {
}
}
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/collabs", produces = {"application/json", "application/xml"})
@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);
@ -424,8 +422,7 @@ public class MindmapController extends BaseController {
return result;
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/description", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/description", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateDescription(@RequestBody String description, @PathVariable int id) throws WiseMappingException {
@ -438,7 +435,7 @@ public class MindmapController extends BaseController {
mindmapService.updateMindmap(mindMap, !true);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/publish", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/publish", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updatePublishState(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
@ -463,9 +460,9 @@ public class MindmapController extends BaseController {
mindmapService.removeMindmap(mindmap, user);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/starred", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@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 @ApiParam(defaultValue = "false", allowableValues = "true,false") String value, @PathVariable int id) throws WiseMappingException {
final Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser();
@ -481,7 +478,7 @@ public class MindmapController extends BaseController {
}
@ApiIgnore
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/lock", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@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 {
final User user = Utils.getUser();

View File

@ -20,18 +20,23 @@ package com.wisemapping.rest.model;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.*;
import com.wisemapping.model.CollaborationProperties;
import com.wisemapping.model.CollaborationRole;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import com.wisemapping.util.TimeUtils;
import org.codehaus.jackson.annotate.*;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@XmlRootElement(name = "map")
@XmlAccessorType(XmlAccessType.PROPERTY)
@ -65,6 +70,9 @@ public class RestMindmap {
}
}
public void setCreationTime(final String creationTime){
// Ignore
}
public String getCreationTime() {
final Calendar creationTime = mindmap.getCreationTime();
@ -79,22 +87,43 @@ public class RestMindmap {
return mindmap.getDescription();
}
public void setDescription(String description) {
mindmap.setDescription(description);
}
public String getTags() {
return mindmap.getTags();
}
public void setTags(String tags) {
mindmap.setTags(tags);
}
public String getTitle() {
return mindmap.getTitle();
}
public void setTitle(String title) {
mindmap.setTitle(title);
}
public int getId() {
return mindmap.getId();
}
public String getCreator() {
return mindmap.getCreator().getEmail();
public void setId(int id) {
mindmap.setId(id);
}
public String getCreator() {
final User creator = mindmap.getCreator();
return creator != null ? creator.getEmail() : null;
}
public void setCreator(String creatorUser) {
}
public RestCollaborator getLastModifierUser() {
final User lastEditor = mindmap.getLastEditor();
@ -105,6 +134,9 @@ public class RestMindmap {
return result;
}
public void setLastModifierUser(RestUser lastModifierUser) {
}
public String getLastModificationTime() {
final Calendar date = mindmap.getLastModificationTime();
String result = null;
@ -114,11 +146,13 @@ public class RestMindmap {
return result;
}
public void setLastModificationTime(final String value) {
}
public boolean isPublic() {
return mindmap.isPublic();
}
public void setPublic(boolean value) {
// return mindmap.isPublic();
}
@ -127,50 +161,19 @@ public class RestMindmap {
return mindmap.getXmlStr();
}
public void setXml(@Nullable String xml) throws IOException {
if (xml != null)
mindmap.setXmlStr(xml);
}
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 setOwner(String owner) {
}
public String getOwner() {
final User owner = mindmap.getCreator();
return owner != null ? owner.getEmail() : null;
}
public void setCreator(String creatorUser) {
}
public void setOwner(String owner) {
public void setProperties(@Nullable String properties) {
this.properties = properties;
}
public void setLastModificationTime(final String value) {
}
public void setLastModifierUser(String lastModifierUser) {
}
@Nullable
@ -178,6 +181,10 @@ public class RestMindmap {
return properties;
}
public void setProperties(@Nullable String properties) {
this.properties = properties;
}
public boolean getStarred() {
boolean result = false;
if (collaborator != null) {

View File

@ -25,17 +25,16 @@ import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import com.wisemapping.util.TimeUtils;
import org.codehaus.jackson.annotate.*;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
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.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@XmlRootElement(name = "map")
@XmlAccessorType(XmlAccessType.PROPERTY)
@ -63,27 +62,48 @@ public class RestMindmapInfo {
}
public String getCreationTime() {
return TimeUtils.toISO8601(mindmap.getCreationTime().getTime());
final Calendar creationTime = mindmap.getCreationTime();
return creationTime != null ? TimeUtils.toISO8601(creationTime.getTime()) : null;
}
public String getDescription() {
return mindmap.getDescription();
}
public void setDescription(String description) {
mindmap.setDescription(description);
}
public String getTags() {
return mindmap.getTags();
}
public void setTags(String tags) {
mindmap.setTags(tags);
}
public String getTitle() {
return mindmap.getTitle();
}
public void setTitle(String title) {
mindmap.setTitle(title);
}
public int getId() {
return mindmap.getId();
}
public void setId(int id) {
}
public String getCreator() {
return mindmap.getCreator().getFullName();
final User creator = mindmap.getCreator();
return creator!=null?creator.getFullName():null;
}
public void setCreator(String email) {
}
public void setCreator() {
@ -104,18 +124,21 @@ public class RestMindmapInfo {
return user != null ? user.getFullName() : "unknown";
}
public void setLastModifierUser(String value) {
}
public String getLastModificationTime() {
final Calendar calendar = mindmap.getLastModificationTime();
return TimeUtils.toISO8601(calendar.getTime());
return calendar!=null?TimeUtils.toISO8601(calendar.getTime()):null;
}
public void setLastModificationTime(String value) {
}
public boolean isPublic() {
return mindmap.isPublic();
}
public void setId(int id) {
}
public boolean getStarred() {
return mindmap.isStarred(collaborator);
}
@ -124,28 +147,6 @@ public class RestMindmapInfo {
}
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 email) {
}
public void setLastModificationTime(String value) {
}
public void setLastModifierUser(String value) {
}
@JsonIgnore
public Mindmap getDelegated() {
return this.mindmap;

View File

@ -146,7 +146,7 @@ security.openid.enabled=false
#
# This properties are used for REST API Documentation( http://localhost:8080/doc/rest/index.html)
# Change the URL for proper documentation console setup.
documentation.services.basePath=http://localhost:8080/wisemapping/service
documentation.services.basePath=http://localhost:8080/service
documentation.services.version=3.0.1

View File

@ -66,6 +66,11 @@
<entry key="mmap" value="application/vnd.mindjet.mindmanager"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">

View File

@ -2,13 +2,17 @@ package com.wisemapping.test.rest;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmap;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.http.*;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.web.client.HttpClientErrorException;
@ -28,7 +32,7 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@Test
public class RestMindmapTCase {
public class RestMindmapITCase {
private String userEmail = "admin@wisemapping.com";
private static final String HOST_PORT = "http://localhost:8080";
@ -132,7 +136,7 @@ public class RestMindmapTCase {
template.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
} catch (HttpClientErrorException cause) {
final String responseBodyAsString = cause.getResponseBodyAsString();
assert(responseBodyAsString.contains("Map name already exists."));
assert (responseBodyAsString.contains("You have already a map"));
return;
}
fail("Wrong response");