Enable MindmapController rests.

This commit is contained in:
Paulo Gustavo Veiga 2014-01-25 03:13:51 -03:00
parent 2ccb4bfb83
commit 9b3f1c79a6
7 changed files with 119 additions and 104 deletions

View File

@ -120,7 +120,8 @@ public class User
} }
public char getAutheticationTypeCode() { 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) { public void setAutheticationTypeCode(char code) {

View File

@ -77,7 +77,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
@Api(value="mindmap",description = "User Mindmap Objects.") @Api(value = "mindmap", description = "User Mindmap Objects.")
@Controller @Controller
public class MindmapController extends BaseController { public class MindmapController extends BaseController {
@ -116,7 +116,6 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewFreemind", values); return new ModelAndView("transformViewFreemind", values);
} }
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"text/plain"}, params = {"download=txt"}) @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"text/plain"}, params = {"download=txt"})
@ResponseBody @ResponseBody
public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException, MapCouldNotFoundException { public ModelAndView retrieveDocumentAsText(@PathVariable int id) throws IOException, MapCouldNotFoundException {
@ -137,7 +136,6 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewMMap", values); return new ModelAndView("transformViewMMap", values);
} }
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.ms-excel"}, params = {"download=xls"}) @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/vnd.ms-excel"}, params = {"download=xls"})
@ResponseBody @ResponseBody
public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException, MapCouldNotFoundException { public ModelAndView retrieveDocumentAsExcel(@PathVariable int id) throws IOException, MapCouldNotFoundException {
@ -158,7 +156,6 @@ public class MindmapController extends BaseController {
return new ModelAndView("transformViewOdt", values); 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 { public RestMindmapList retrieveList(@RequestParam(required = false) String q) throws IOException {
final User user = Utils.getUser(); final User user = Utils.getUser();
@ -176,7 +173,6 @@ public class MindmapController extends BaseController {
return new RestMindmapList(mindmaps, user); 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 { public RestMindmapHistoryList retrieveHistory(@PathVariable int id) throws IOException {
final List<MindMapHistory> histories = mindmapService.findMindmapHistory(id); final List<MindMapHistory> histories = mindmapService.findMindmapHistory(id);
@ -187,7 +183,6 @@ public class MindmapController extends BaseController {
return result; return result;
} }
@RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST) @RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.NO_CONTENT) @ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException, IOException { public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException, IOException {
@ -221,7 +216,9 @@ public class MindmapController extends BaseController {
} }
// Could the map be updated ? // Could the map be updated ?
if (session != null) {
verifyLock(mindmap, user, session, timestamp); verifyLock(mindmap, user, session, timestamp);
}
// Update collaboration properties ... // Update collaboration properties ...
final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(user); final CollaborationProperties collaborationProperties = mindmap.findCollaborationProperties(user);
@ -239,8 +236,12 @@ public class MindmapController extends BaseController {
// Update edition timeout ... // Update edition timeout ...
final LockManager lockManager = mindmapService.getLockManager(); final LockManager lockManager = mindmapService.getLockManager();
long result = -1;
if (session != null) {
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user); final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user);
return lockInfo.getTimestamp(); result = lockInfo.getTimestamp();
}
return result;
} }
@ApiIgnore @ApiIgnore
@ -264,7 +265,6 @@ public class MindmapController extends BaseController {
return mindmapHistory.getUnzipXml(); return mindmapHistory.getUnzipXml();
} }
private void verifyLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws WiseMappingException { 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. // The lock was lost, reclaim as the ownership of it.
@ -347,7 +347,6 @@ public class MindmapController extends BaseController {
return result; 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) @ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException { public void updateTitle(@RequestBody String title, @PathVariable int id) throws WiseMappingException {
@ -407,7 +406,6 @@ 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 { public RestCollaborationList retrieveList(@PathVariable int id) throws MapCouldNotFoundException {
final Mindmap mindMap = findMindmapById(id); final Mindmap mindMap = findMindmapById(id);
@ -424,7 +422,6 @@ public class MindmapController extends BaseController {
return result; 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) @ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateDescription(@RequestBody String description, @PathVariable int id) throws WiseMappingException { public void updateDescription(@RequestBody String description, @PathVariable int id) throws WiseMappingException {
@ -465,7 +462,7 @@ public class MindmapController extends BaseController {
@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) @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 Mindmap mindmap = findMindmapById(id);
final User user = Utils.getUser(); final User user = Utils.getUser();

View File

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

View File

@ -25,17 +25,16 @@ import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import com.wisemapping.security.Utils; import com.wisemapping.security.Utils;
import com.wisemapping.util.TimeUtils; 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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@XmlRootElement(name = "map") @XmlRootElement(name = "map")
@XmlAccessorType(XmlAccessType.PROPERTY) @XmlAccessorType(XmlAccessType.PROPERTY)
@ -63,27 +62,48 @@ public class RestMindmapInfo {
} }
public String getCreationTime() { 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() { public String getDescription() {
return mindmap.getDescription(); return mindmap.getDescription();
} }
public void setDescription(String description) {
mindmap.setDescription(description);
}
public String getTags() { public String getTags() {
return mindmap.getTags(); return mindmap.getTags();
} }
public void setTags(String tags) {
mindmap.setTags(tags);
}
public String getTitle() { public String getTitle() {
return mindmap.getTitle(); return mindmap.getTitle();
} }
public void setTitle(String title) {
mindmap.setTitle(title);
}
public int getId() { public int getId() {
return mindmap.getId(); return mindmap.getId();
} }
public void setId(int id) {
}
public String getCreator() { 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() { public void setCreator() {
@ -104,18 +124,21 @@ public class RestMindmapInfo {
return user != null ? user.getFullName() : "unknown"; return user != null ? user.getFullName() : "unknown";
} }
public void setLastModifierUser(String value) {
}
public String getLastModificationTime() { public String getLastModificationTime() {
final Calendar calendar = mindmap.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() { public boolean isPublic() {
return mindmap.isPublic(); return mindmap.isPublic();
} }
public void setId(int id) {
}
public boolean getStarred() { public boolean getStarred() {
return mindmap.isStarred(collaborator); 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 @JsonIgnore
public Mindmap getDelegated() { public Mindmap getDelegated() {
return this.mindmap; 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) # This properties are used for REST API Documentation( http://localhost:8080/doc/rest/index.html)
# Change the URL for proper documentation console setup. # 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 documentation.services.version=3.0.1

View File

@ -66,6 +66,11 @@
<entry key="mmap" value="application/vnd.mindjet.mindmanager"/> <entry key="mmap" value="application/vnd.mindjet.mindmanager"/>
</map> </map>
</property> </property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
</list>
</property>
<property name="defaultViews"> <property name="defaultViews">
<list> <list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <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.exceptions.WiseMappingException;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmap; import com.wisemapping.rest.model.RestMindmap;
import com.wisemapping.rest.model.RestMindmapInfo;
import com.wisemapping.rest.model.RestMindmapList; import com.wisemapping.rest.model.RestMindmapList;
import com.wisemapping.rest.model.RestUser; import com.wisemapping.rest.model.RestUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.crypto.codec.Base64; import org.springframework.security.crypto.codec.Base64;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
@ -28,7 +32,7 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
@Test @Test
public class RestMindmapTCase { public class RestMindmapITCase {
private String userEmail = "admin@wisemapping.com"; private String userEmail = "admin@wisemapping.com";
private static final String HOST_PORT = "http://localhost:8080"; private static final String HOST_PORT = "http://localhost:8080";
@ -132,7 +136,7 @@ public class RestMindmapTCase {
template.postForLocation(BASE_REST_URL + "/maps", createUserEntity); template.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
} catch (HttpClientErrorException cause) { } catch (HttpClientErrorException cause) {
final String responseBodyAsString = cause.getResponseBodyAsString(); final String responseBodyAsString = cause.getResponseBodyAsString();
assert(responseBodyAsString.contains("Map name already exists.")); assert (responseBodyAsString.contains("You have already a map"));
return; return;
} }
fail("Wrong response"); fail("Wrong response");