mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
- Add more tests to save map
- Add new rest operations for saving map content - Fix password encoding bug - Fix bug that allow different users being created with the same password.
This commit is contained in:
parent
8716ff4feb
commit
eb6aac4a5e
4
pom.xml
4
pom.xml
@ -49,10 +49,6 @@
|
|||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.12</version>
|
<version>2.12</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
|
||||||
<version>3.0</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
@ -85,7 +85,7 @@ public class MindmapSharingController extends BaseMultiActionController {
|
|||||||
final ColaborationEmail email = new ColaborationEmail();
|
final ColaborationEmail email = new ColaborationEmail();
|
||||||
email.setSubject(request.getParameter("subject"));
|
email.setSubject(request.getParameter("subject"));
|
||||||
email.setMessage(request.getParameter("message"));
|
email.setMessage(request.getParameter("message"));
|
||||||
getMindmapService().addColaborators(mindMap, emails, role, email);
|
getMindmapService().addCollaborators(mindMap, emails, role, email);
|
||||||
|
|
||||||
return new MindMapBean(mindMap);
|
return new MindMapBean(mindMap);
|
||||||
}
|
}
|
||||||
|
@ -51,25 +51,11 @@ public class NewMindmapController
|
|||||||
mindmap.setTitle(title);
|
mindmap.setTitle(title);
|
||||||
mindmap.setOwner(user);
|
mindmap.setOwner(user);
|
||||||
|
|
||||||
final String xml = getDefaultMindmapXml(title);
|
final String xml = MindMap.getDefaultMindmapXml(title);
|
||||||
mindmap.setXmlStr(xml);
|
mindmap.setXmlStr(xml);
|
||||||
|
|
||||||
final User dbUSer = getUserService().getUserBy(user.getId());
|
service.addMindmap(mindmap, user);
|
||||||
|
|
||||||
service.addMindmap(mindmap, dbUSer);
|
|
||||||
|
|
||||||
return new ModelAndView("redirect:editor.htm?mapId=" + mindmap.getId() + "&action=open");
|
return new ModelAndView("redirect:editor.htm?mapId=" + mindmap.getId() + "&action=open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getDefaultMindmapXml(final String title) {
|
|
||||||
|
|
||||||
final StringBuffer map = new StringBuffer();
|
|
||||||
map.append("<map>");
|
|
||||||
map.append("<topic central=\"true\" text=\"");
|
|
||||||
map.append(title);
|
|
||||||
map.append("\"/></map>");
|
|
||||||
return map.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ public class MindmapManagerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MindMap getMindmapById(int mindmapId) {
|
public MindMap getMindmapById(int mindmapId) {
|
||||||
return (MindMap) getHibernateTemplate().get(MindMap.class, mindmapId);
|
return getHibernateTemplate().get(MindMap.class, mindmapId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MindMap getMindmapByTitle(final String title, final User user) {
|
public MindMap getMindmapByTitle(final String title, final User user) {
|
||||||
|
@ -22,8 +22,10 @@ import com.wisemapping.model.Collaborator;
|
|||||||
import com.wisemapping.model.MindmapUser;
|
import com.wisemapping.model.MindmapUser;
|
||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import com.wisemapping.model.UserLogin;
|
import com.wisemapping.model.UserLogin;
|
||||||
|
import com.wisemapping.security.CustomPasswordEncoder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||||
|
import org.springframework.security.authentication.encoding.PasswordEncoder;
|
||||||
//import org.acegisecurity.providers.encoding.PasswordEncoder;
|
//import org.acegisecurity.providers.encoding.PasswordEncoder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,12 +35,12 @@ public class UserManagerImpl
|
|||||||
extends HibernateDaoSupport
|
extends HibernateDaoSupport
|
||||||
implements UserManager {
|
implements UserManager {
|
||||||
|
|
||||||
// private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
//
|
|
||||||
// public void setEncoder(PasswordEncoder passwordEncoder)
|
public void setEncoder(PasswordEncoder passwordEncoder)
|
||||||
// {
|
{
|
||||||
// this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public List<User> getAllUsers() {
|
public List<User> getAllUsers() {
|
||||||
return getHibernateTemplate().find("from com.wisemapping.model.User user");
|
return getHibernateTemplate().find("from com.wisemapping.model.User user");
|
||||||
@ -99,13 +101,13 @@ public class UserManagerImpl
|
|||||||
@Override
|
@Override
|
||||||
public void createUser(User user) {
|
public void createUser(User user) {
|
||||||
assert user != null : "Trying to store a null user";
|
assert user != null : "Trying to store a null user";
|
||||||
// user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
||||||
getHibernateTemplate().saveOrUpdate(user);
|
getHibernateTemplate().saveOrUpdate(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User createUser(@NotNull User user, @NotNull Collaborator col) {
|
public User createUser(@NotNull User user, @NotNull Collaborator col) {
|
||||||
// user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
||||||
assert user != null : "Trying to store a null user";
|
assert user != null : "Trying to store a null user";
|
||||||
|
|
||||||
final Set<MindmapUser> set = col.getMindmapUsers();
|
final Set<MindmapUser> set = col.getMindmapUsers();
|
||||||
@ -138,7 +140,7 @@ public class UserManagerImpl
|
|||||||
|
|
||||||
public void updateUser(User user) {
|
public void updateUser(User user) {
|
||||||
assert user != null : "user is null";
|
assert user != null : "user is null";
|
||||||
// user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
|
||||||
getHibernateTemplate().update(user);
|
getHibernateTemplate().update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,11 @@ public class MindMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getXmlStr() throws UnsupportedEncodingException {
|
public String getXmlStr() throws UnsupportedEncodingException {
|
||||||
return new String(this.xml, UTF_8);
|
String result = null;
|
||||||
|
if (this.xml != null) {
|
||||||
|
result = new String(this.xml, UTF_8);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getZippedXml()
|
public byte[] getZippedXml()
|
||||||
@ -219,4 +223,15 @@ public class MindMap {
|
|||||||
public User getOwner() {
|
public User getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDefaultMindmapXml(@NotNull final String title) {
|
||||||
|
|
||||||
|
final StringBuilder result = new StringBuilder();
|
||||||
|
result.append("<result version='tango'>");
|
||||||
|
result.append("<topic central=\"true\" text=\"");
|
||||||
|
result.append(title);
|
||||||
|
result.append("\"/></result>");
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,19 @@ public class AdminController extends BaseController {
|
|||||||
return new ModelAndView("userView", "user", new RestUser(user));
|
return new ModelAndView("userView", "user", new RestUser(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "admin/users/username/{username}", produces = {"application/json", "text/html", "application/xml"})
|
||||||
|
@ResponseBody
|
||||||
|
public ModelAndView getUserByUsername(@PathVariable String username) throws IOException {
|
||||||
|
final User user = userService.getUserByUsername(username);
|
||||||
|
if (user == null) {
|
||||||
|
throw new IllegalArgumentException("User '" + username + "' could not be found");
|
||||||
|
}
|
||||||
|
return new ModelAndView("userView", "user", new RestUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "admin/users", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
@RequestMapping(method = RequestMethod.POST, value = "admin/users", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
||||||
@ResponseStatus(value = HttpStatus.CREATED)
|
@ResponseStatus(value = HttpStatus.CREATED)
|
||||||
public void getUserByEmail(@RequestBody RestUser user, HttpServletResponse response) throws IOException, WiseMappingException {
|
public void createUser(@RequestBody RestUser user, HttpServletResponse response) throws IOException, WiseMappingException {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new IllegalArgumentException("User could not be found");
|
throw new IllegalArgumentException("User could not be found");
|
||||||
}
|
}
|
||||||
@ -52,6 +62,16 @@ public class AdminController extends BaseController {
|
|||||||
throw new IllegalArgumentException("User already exists with this email.");
|
throw new IllegalArgumentException("User already exists with this email.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String username = user.getUsername();
|
||||||
|
if (username == null || username.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("username can not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userService.getUserByUsername(username) != null) {
|
||||||
|
throw new IllegalArgumentException("User already exists with this username.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run some other validations ...
|
||||||
final User delegated = user.getDelegated();
|
final User delegated = user.getDelegated();
|
||||||
final String lastname = delegated.getLastname();
|
final String lastname = delegated.getLastname();
|
||||||
if (lastname == null || lastname.isEmpty()) {
|
if (lastname == null || lastname.isEmpty()) {
|
||||||
@ -63,13 +83,9 @@ public class AdminController extends BaseController {
|
|||||||
throw new IllegalArgumentException("firstname can not be null");
|
throw new IllegalArgumentException("firstname can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
final String username = delegated.getUsername();
|
// Finally create the user ...
|
||||||
if (username == null || username.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("username can not be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
userService.createUser(delegated, false);
|
userService.createUser(delegated, false);
|
||||||
response.setHeader("Location","/service/admin/users/" + user.getId());
|
response.setHeader("Location", "/service/admin/users/" + user.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.PUT, value = "admin/users/{id}/password", consumes = {"text/plain"})
|
@RequestMapping(method = RequestMethod.PUT, value = "admin/users/{id}/password", consumes = {"text/plain"})
|
||||||
|
@ -7,14 +7,17 @@ import com.wisemapping.model.MindmapUser;
|
|||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import com.wisemapping.rest.model.RestMindmap;
|
import com.wisemapping.rest.model.RestMindmap;
|
||||||
import com.wisemapping.rest.model.RestMindmapList;
|
import com.wisemapping.rest.model.RestMindmapList;
|
||||||
|
import com.wisemapping.rest.model.RestUser;
|
||||||
import com.wisemapping.security.Utils;
|
import com.wisemapping.security.Utils;
|
||||||
import com.wisemapping.service.MindmapService;
|
import com.wisemapping.service.MindmapService;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -55,43 +58,83 @@ public class MindmapController extends BaseController {
|
|||||||
final MindMap mindMap = mindmapService.getMindmapById(id);
|
final MindMap mindMap = mindmapService.getMindmapById(id);
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
|
|
||||||
|
// Validate arguments ...
|
||||||
final String properties = restMindmap.getProperties();
|
final String properties = restMindmap.getProperties();
|
||||||
|
if (properties == null) {
|
||||||
|
throw new IllegalArgumentException("Map properties can not be null");
|
||||||
|
}
|
||||||
mindMap.setProperties(properties);
|
mindMap.setProperties(properties);
|
||||||
|
|
||||||
final Calendar now = Calendar.getInstance();
|
// Validate content ...
|
||||||
mindMap.setLastModificationTime(now);
|
|
||||||
mindMap.setLastModifierUser(user.getUsername());
|
|
||||||
|
|
||||||
final Calendar lastModification = Calendar.getInstance();
|
|
||||||
lastModification.setTime(new Date());
|
|
||||||
mindMap.setLastModificationTime(lastModification);
|
|
||||||
|
|
||||||
final String xml = restMindmap.getXml();
|
final String xml = restMindmap.getXml();
|
||||||
|
if (xml == null) {
|
||||||
|
throw new IllegalArgumentException("Map xml can not be null");
|
||||||
|
}
|
||||||
mindMap.setXmlStr(xml);
|
mindMap.setXmlStr(xml);
|
||||||
mindmapService.updateMindmap(mindMap, minor);
|
|
||||||
|
// Update map ...
|
||||||
|
updateMindmap(minor, mindMap, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/maps", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/xml", consumes = {"application/xml"}, produces = {"application/json", "text/html", "application/xml"})
|
||||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||||
public void createMap(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
|
public void updateMapXml(@RequestBody String xml, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
|
||||||
|
|
||||||
final MindMap mindMap = mindmapService.getMindmapById(id);
|
final MindMap mindMap = mindmapService.getMindmapById(id);
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser();
|
||||||
|
|
||||||
final String properties = restMindmap.getProperties();
|
if (xml == null || xml.isEmpty()) {
|
||||||
mindMap.setProperties(properties);
|
throw new IllegalArgumentException("Map xml can not be null");
|
||||||
|
}
|
||||||
|
mindMap.setXmlStr(xml);
|
||||||
|
|
||||||
|
// Update map ...
|
||||||
|
updateMindmap(minor, mindMap, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void updateMindmap(boolean minor, MindMap mindMap, User user) throws WiseMappingException {
|
||||||
final Calendar now = Calendar.getInstance();
|
final Calendar now = Calendar.getInstance();
|
||||||
mindMap.setLastModificationTime(now);
|
mindMap.setLastModificationTime(now);
|
||||||
mindMap.setLastModifierUser(user.getUsername());
|
mindMap.setLastModifierUser(user.getUsername());
|
||||||
|
|
||||||
final Calendar lastModification = Calendar.getInstance();
|
|
||||||
lastModification.setTime(new Date());
|
|
||||||
mindMap.setLastModificationTime(lastModification);
|
|
||||||
|
|
||||||
final String xml = restMindmap.getXml();
|
|
||||||
mindMap.setXmlStr(xml);
|
|
||||||
mindmapService.updateMindmap(mindMap, minor);
|
mindmapService.updateMindmap(mindMap, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = "/maps", consumes = {"application/xml", "application/json"})
|
||||||
|
@ResponseStatus(value = HttpStatus.CREATED)
|
||||||
|
public void createMap(@RequestBody RestMindmap restMindmap, @NotNull HttpServletResponse response) throws IOException, WiseMappingException {
|
||||||
|
|
||||||
|
final String title = restMindmap.getTitle();
|
||||||
|
if (title == null || title.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Map title can not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String description = restMindmap.getDescription();
|
||||||
|
if (description == null || description.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Map details can not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some basic validations ...
|
||||||
|
final User user = Utils.getUser();
|
||||||
|
final MindMap mindMap = mindmapService.getMindmapByTitle(title, user);
|
||||||
|
if (mindMap != null) {
|
||||||
|
throw new IllegalArgumentException("Map already exists with title '" + title + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user has not specified the xml content, add one ...
|
||||||
|
final MindMap delegated = restMindmap.getDelegated();
|
||||||
|
String xml = restMindmap.getXml();
|
||||||
|
if (xml == null || xml.isEmpty()) {
|
||||||
|
xml = MindMap.getDefaultMindmapXml(restMindmap.getTitle());
|
||||||
|
}
|
||||||
|
delegated.setXmlStr(xml);
|
||||||
|
delegated.setOwner(user);
|
||||||
|
|
||||||
|
// Add new mindmap ...
|
||||||
|
mindmapService.addMindmap(delegated, user);
|
||||||
|
|
||||||
|
// Return the new created map ...
|
||||||
|
response.setHeader("Location", "/service/maps/" + delegated.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ package com.wisemapping.rest.model;
|
|||||||
import com.wisemapping.model.MindMap;
|
import com.wisemapping.model.MindMap;
|
||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import org.codehaus.jackson.annotate.*;
|
import org.codehaus.jackson.annotate.*;
|
||||||
|
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
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;
|
||||||
@ -21,6 +23,7 @@ import java.util.Date;
|
|||||||
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
|
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY
|
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY
|
||||||
)
|
)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class RestMindmap {
|
public class RestMindmap {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@ -35,10 +38,6 @@ public class RestMindmap {
|
|||||||
this.mindmap = mindmap;
|
this.mindmap = mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
return mindmap.getOwner().getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Calendar getCreationTime() {
|
public Calendar getCreationTime() {
|
||||||
return mindmap.getCreationTime();
|
return mindmap.getCreationTime();
|
||||||
}
|
}
|
||||||
@ -79,8 +78,9 @@ public class RestMindmap {
|
|||||||
return mindmap.getXmlStr();
|
return mindmap.getXmlStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setXml(@NotNull String xml) throws IOException {
|
public void setXml(@Nullable String xml) throws IOException {
|
||||||
|
|
||||||
|
if (xml != null)
|
||||||
mindmap.setXmlStr(xml);
|
mindmap.setXmlStr(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,11 +101,10 @@ public class RestMindmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(User owner) {
|
public void setOwner(User owner) {
|
||||||
mindmap.setOwner(owner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreator(String creatorUser) {
|
public void setCreator(String creatorUser) {
|
||||||
mindmap.setCreator(creatorUser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,11 +113,9 @@ public class RestMindmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModificationTime(Calendar lastModificationTime) {
|
public void setLastModificationTime(Calendar lastModificationTime) {
|
||||||
mindmap.setLastModificationTime(lastModificationTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModifierUser(String lastModifierUser) {
|
public void setLastModifierUser(String lastModifierUser) {
|
||||||
mindmap.setLastModifierUser(lastModifierUser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperties() {
|
public String getProperties() {
|
||||||
|
@ -16,8 +16,10 @@ import java.util.List;
|
|||||||
|
|
||||||
@XmlRootElement(name = "maps")
|
@XmlRootElement(name = "maps")
|
||||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
@JsonAutoDetect(
|
||||||
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||||
|
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
||||||
public class RestMindmapList {
|
public class RestMindmapList {
|
||||||
|
|
||||||
private List<RestMindmap> mindmaps;
|
private List<RestMindmap> mindmaps;
|
||||||
|
@ -4,6 +4,8 @@ package com.wisemapping.rest.model;
|
|||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
|
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
@ -14,8 +16,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
@XmlRootElement(name = "user")
|
@XmlRootElement(name = "user")
|
||||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
@JsonAutoDetect(
|
||||||
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||||
|
isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class RestUser {
|
public class RestUser {
|
||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
|
@ -40,7 +40,7 @@ public interface MindmapService {
|
|||||||
|
|
||||||
public void addMindmap(MindMap map, User user) throws WiseMappingException;
|
public void addMindmap(MindMap map, User user) throws WiseMappingException;
|
||||||
|
|
||||||
public void addColaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
|
public void addCollaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
|
||||||
throws InvalidColaboratorException;
|
throws InvalidColaboratorException;
|
||||||
|
|
||||||
public void addTags(MindMap mindmap, String tags);
|
public void addTags(MindMap mindmap, String tags);
|
||||||
@ -61,7 +61,7 @@ public interface MindmapService {
|
|||||||
|
|
||||||
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole);
|
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole);
|
||||||
|
|
||||||
public boolean isAllowedToColaborate(User user, MindMap map, UserRole grantedRole);
|
public boolean isAllowedToCollaborate(User user, MindMap map, UserRole grantedRole);
|
||||||
|
|
||||||
public void addWelcomeMindmap(User user) throws WiseMappingException;
|
public void addWelcomeMindmap(User user) throws WiseMappingException;
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ import com.wisemapping.dao.MindmapManager;
|
|||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
import com.wisemapping.mail.Mailer;
|
import com.wisemapping.mail.Mailer;
|
||||||
import com.wisemapping.model.*;
|
import com.wisemapping.model.*;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -36,7 +38,7 @@ public class MindmapServiceImpl
|
|||||||
|
|
||||||
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole) {
|
public boolean isAllowedToColaborate(User user, int mapId, UserRole grantedRole) {
|
||||||
final MindMap map = mindmapManager.getMindmapById(mapId);
|
final MindMap map = mindmapManager.getMindmapById(mapId);
|
||||||
return isAllowedToColaborate(user, map, grantedRole);
|
return isAllowedToCollaborate(user, map, grantedRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowedToView(User user, int mapId, UserRole grantedRole) {
|
public boolean isAllowedToView(User user, int mapId, UserRole grantedRole) {
|
||||||
@ -51,13 +53,13 @@ public class MindmapServiceImpl
|
|||||||
if (map.isPublic()) {
|
if (map.isPublic()) {
|
||||||
isAllowed = true;
|
isAllowed = true;
|
||||||
} else if (user != null) {
|
} else if (user != null) {
|
||||||
isAllowed = isAllowedToColaborate(user, map, grantedRole);
|
isAllowed = isAllowedToCollaborate(user, map, grantedRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isAllowed;
|
return isAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowedToColaborate(User user, MindMap map, UserRole grantedRole) {
|
public boolean isAllowedToCollaborate(@NotNull User user, @Nullable MindMap map, UserRole grantedRole) {
|
||||||
boolean isAllowed = false;
|
boolean isAllowed = false;
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
if (map.getOwner().getId() == user.getId()) {
|
if (map.getOwner().getId() == user.getId()) {
|
||||||
@ -99,6 +101,7 @@ public class MindmapServiceImpl
|
|||||||
if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) {
|
if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) {
|
||||||
throw new WiseMappingException("The tile can not be empty");
|
throw new WiseMappingException("The tile can not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
mindmapManager.updateMindmap(mindMap, saveHistory);
|
mindmapManager.updateMindmap(mindMap, saveHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +152,7 @@ public class MindmapServiceImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMindmap(MindMap map, User user) throws WiseMappingException {
|
public void addMindmap(@NotNull MindMap map, @NotNull User user) throws WiseMappingException {
|
||||||
|
|
||||||
final String title = map.getTitle();
|
final String title = map.getTitle();
|
||||||
|
|
||||||
@ -169,13 +172,15 @@ public class MindmapServiceImpl
|
|||||||
map.setLastModificationTime(creationTime);
|
map.setLastModificationTime(creationTime);
|
||||||
map.setOwner(user);
|
map.setOwner(user);
|
||||||
|
|
||||||
final MindmapUser mindmapUser = new MindmapUser(UserRole.OWNER.ordinal(), user, map);
|
// Hack to reload dbuser ...
|
||||||
|
final User dbUser = userService.getUserBy(user.getId());
|
||||||
|
final MindmapUser mindmapUser = new MindmapUser(UserRole.OWNER.ordinal(), dbUser, map);
|
||||||
map.getMindmapUsers().add(mindmapUser);
|
map.getMindmapUsers().add(mindmapUser);
|
||||||
|
|
||||||
mindmapManager.addMindmap(user, map);
|
mindmapManager.addMindmap(user, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addColaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
|
public void addCollaborators(MindMap mindmap, String[] colaboratorEmails, UserRole role, ColaborationEmail email)
|
||||||
throws InvalidColaboratorException {
|
throws InvalidColaboratorException {
|
||||||
if (colaboratorEmails != null && colaboratorEmails.length > 0) {
|
if (colaboratorEmails != null && colaboratorEmails.length > 0) {
|
||||||
final Collaborator owner = mindmap.getOwner();
|
final Collaborator owner = mindmap.getOwner();
|
||||||
@ -187,7 +192,7 @@ public class MindmapServiceImpl
|
|||||||
}
|
}
|
||||||
MindmapUser mindmapUser = getMindmapUserBy(colaboratorEmail, mindmapUsers);
|
MindmapUser mindmapUser = getMindmapUserBy(colaboratorEmail, mindmapUsers);
|
||||||
if (mindmapUser == null) {
|
if (mindmapUser == null) {
|
||||||
addColaborator(colaboratorEmail, role, mindmap, email);
|
addCollaborator(colaboratorEmail, role, mindmap, email);
|
||||||
} else if (mindmapUser.getRole() != role) {
|
} else if (mindmapUser.getRole() != role) {
|
||||||
// If the relationship already exists and the role changed then only update the role
|
// If the relationship already exists and the role changed then only update the role
|
||||||
mindmapUser.setRoleId(role.ordinal());
|
mindmapUser.setRoleId(role.ordinal());
|
||||||
@ -260,7 +265,7 @@ public class MindmapServiceImpl
|
|||||||
return mindmapUser;
|
return mindmapUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addColaborator(String colaboratorEmail, UserRole role, MindMap mindmap, ColaborationEmail email) {
|
private void addCollaborator(String colaboratorEmail, UserRole role, MindMap mindmap, ColaborationEmail email) {
|
||||||
|
|
||||||
Collaborator collaborator = mindmapManager.getCollaboratorBy(colaboratorEmail);
|
Collaborator collaborator = mindmapManager.getCollaboratorBy(colaboratorEmail);
|
||||||
if (collaborator == null) {
|
if (collaborator == null) {
|
||||||
|
@ -65,7 +65,7 @@ public class MapInfoValidator implements Validator {
|
|||||||
}
|
}
|
||||||
ValidatorUtils.rejectIfExceeded(errors,
|
ValidatorUtils.rejectIfExceeded(errors,
|
||||||
"description",
|
"description",
|
||||||
"The description must have less than "+Constants.MAX_MAP_DESCRIPTION_LENGTH + " characters.",
|
"The description must have less than " + Constants.MAX_MAP_DESCRIPTION_LENGTH + " characters.",
|
||||||
desc,
|
desc,
|
||||||
Constants.MAX_MAP_DESCRIPTION_LENGTH);
|
Constants.MAX_MAP_DESCRIPTION_LENGTH);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<bean id="userManager" class="com.wisemapping.dao.UserManagerImpl">
|
<bean id="userManager" class="com.wisemapping.dao.UserManagerImpl">
|
||||||
<property name="hibernateTemplate" ref="hibernateTemplate"/>
|
<property name="hibernateTemplate" ref="hibernateTemplate"/>
|
||||||
<!--<property name="encoder" ref="encoder"/>-->
|
<property name="encoder" ref="encoder"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="mindmapManager" class="com.wisemapping.dao.MindmapManagerImpl">
|
<bean id="mindmapManager" class="com.wisemapping.dao.MindmapManagerImpl">
|
||||||
|
@ -62,6 +62,5 @@
|
|||||||
<bean id="userDetailsService" class="com.wisemapping.security.UserDetailsService">
|
<bean id="userDetailsService" class="com.wisemapping.security.UserDetailsService">
|
||||||
<property name="userManager" ref="userManager"/>
|
<property name="userManager" ref="userManager"/>
|
||||||
<property name="adminUser" value="${admin.user}"/>
|
<property name="adminUser" value="${admin.user}"/>
|
||||||
|
|
||||||
</bean>
|
</bean>
|
||||||
</beans>
|
</beans>
|
@ -26,8 +26,8 @@ import java.util.List;
|
|||||||
public class RestAdminITCase {
|
public class RestAdminITCase {
|
||||||
|
|
||||||
@NonNls
|
@NonNls
|
||||||
private static final String HOST_PORT = "http://localhost:8080/";
|
private static final String HOST_PORT = "http://localhost:8080";
|
||||||
private static final String BASE_REST_URL = HOST_PORT + "service";
|
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||||
|
|
||||||
@Test(dataProvider = "ContentType-Provider-Function")
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
public void changePassword(final @NotNull MediaType mediaType) { // Configure media types ...
|
public void changePassword(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||||
@ -35,13 +35,7 @@ public class RestAdminITCase {
|
|||||||
final RestTemplate templateRest = createTemplate();
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
// Fill user data ...
|
// Fill user data ...
|
||||||
final RestUser restUser = new RestUser();
|
final RestUser restUser = createDummyUser();
|
||||||
final String email = "foo-to-change" + System.nanoTime() + "@example.org";
|
|
||||||
restUser.setEmail(email);
|
|
||||||
restUser.setUsername("foo");
|
|
||||||
restUser.setFirstname("foo first name");
|
|
||||||
restUser.setLastname("foo last name");
|
|
||||||
restUser.setPassword("foo password");
|
|
||||||
|
|
||||||
// User has been created ...
|
// User has been created ...
|
||||||
final URI location = createUser(requestHeaders, templateRest, restUser);
|
final URI location = createUser(requestHeaders, templateRest, restUser);
|
||||||
@ -52,7 +46,6 @@ public class RestAdminITCase {
|
|||||||
// Change password ...
|
// Change password ...
|
||||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||||
HttpEntity<String> createUserEntity = new HttpEntity<String>("some-new-password", requestHeaders);
|
HttpEntity<String> createUserEntity = new HttpEntity<String>("some-new-password", requestHeaders);
|
||||||
System.out.println("Changed password to:" + email);
|
|
||||||
templateRest.put(BASE_REST_URL + "/admin/users/{id}/password", createUserEntity, result.getBody().getId());
|
templateRest.put(BASE_REST_URL + "/admin/users/{id}/password", createUserEntity, result.getBody().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,14 +55,7 @@ public class RestAdminITCase {
|
|||||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
final RestTemplate templateRest = createTemplate();
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
// Fill user data ...
|
final RestUser restUser = createDummyUser();
|
||||||
final RestUser restUser = new RestUser();
|
|
||||||
final String email = "foo-to-delete" + System.nanoTime() + "@example.org";
|
|
||||||
restUser.setEmail(email);
|
|
||||||
restUser.setUsername("foo");
|
|
||||||
restUser.setFirstname("foo first name");
|
|
||||||
restUser.setLastname("foo last name");
|
|
||||||
restUser.setPassword("foo password");
|
|
||||||
|
|
||||||
// User has been created ...
|
// User has been created ...
|
||||||
final URI location = createUser(requestHeaders, templateRest, restUser);
|
final URI location = createUser(requestHeaders, templateRest, restUser);
|
||||||
@ -89,22 +75,33 @@ public class RestAdminITCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dataProvider = "ContentType-Provider-Function")
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
public void createNewUser(final @NotNull MediaType mediaType) {
|
public void findUserByUsername(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
|
final RestUser restUser = createDummyUser();
|
||||||
|
|
||||||
|
// User has been created ...
|
||||||
|
createUser(requestHeaders, templateRest, restUser);
|
||||||
|
|
||||||
|
// Check that the user has been created ...
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
final ResponseEntity<RestUser> responseEntity = templateRest.exchange(BASE_REST_URL + "/admin/users/username/" + restUser.getUsername(), HttpMethod.GET, findUserEntity, RestUser.class);
|
||||||
|
|
||||||
|
assertEquals(responseEntity.getBody().getUsername(), restUser.getUsername());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createNewUser(final @NotNull MediaType mediaType) {
|
||||||
|
|
||||||
// Configure media types ...
|
// Configure media types ...
|
||||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
final RestTemplate templateRest = createTemplate();
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
// Fill user data ...
|
// Fill user data ...
|
||||||
final RestUser restUser = new RestUser();
|
final RestUser restUser = createDummyUser();
|
||||||
|
|
||||||
final String email = "foo" + System.nanoTime() + "@example.org";
|
|
||||||
restUser.setEmail(email);
|
|
||||||
restUser.setUsername("foo");
|
|
||||||
restUser.setFirstname("foo first name");
|
|
||||||
restUser.setLastname("foo last name");
|
|
||||||
restUser.setPassword("foo password");
|
|
||||||
|
|
||||||
// Create a new user ...
|
// Create a new user ...
|
||||||
final URI location = createUser(requestHeaders, templateRest, restUser);
|
final URI location = createUser(requestHeaders, templateRest, restUser);
|
||||||
@ -113,16 +110,21 @@ public class RestAdminITCase {
|
|||||||
ResponseEntity<RestUser> result = findUser(requestHeaders, templateRest, location);
|
ResponseEntity<RestUser> result = findUser(requestHeaders, templateRest, location);
|
||||||
assertEquals(result.getBody(), restUser, "Returned object object seems not be the same.");
|
assertEquals(result.getBody(), restUser, "Returned object object seems not be the same.");
|
||||||
|
|
||||||
|
|
||||||
// Find by email and check ...
|
// Find by email and check ...
|
||||||
result = findUserByEmail(requestHeaders, templateRest, email);
|
result = findUserByEmail(requestHeaders, templateRest, restUser.getEmail());
|
||||||
assertEquals(result.getBody(), restUser, "Returned object object seems not be the same.");
|
assertEquals(result.getBody(), restUser, "Returned object object seems not be the same.");
|
||||||
|
|
||||||
|
return restUser.getEmail();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
|
public void createUser(final @NotNull MediaType mediaType) {
|
||||||
|
this.createNewUser(mediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseEntity<RestUser> findUser(HttpHeaders requestHeaders, RestTemplate templateRest, URI location) {
|
private ResponseEntity<RestUser> findUser(HttpHeaders requestHeaders, RestTemplate templateRest, URI location) {
|
||||||
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
final String url = "http://localhost:8080" + location;
|
final String url = HOST_PORT + location;
|
||||||
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class);
|
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ public class RestAdminITCase {
|
|||||||
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
|
||||||
// Add extension only to avoid the fact that the last part is extracted ...
|
// Add extension only to avoid the fact that the last part is extracted ...
|
||||||
final String url = "http://localhost:8080/service/admin/users/email/{email}.json";
|
final String url = BASE_REST_URL + "/admin/users/email/{email}.json";
|
||||||
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class, email);
|
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ public class RestAdminITCase {
|
|||||||
return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity);
|
return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpHeaders createHeaders(MediaType mediaType) {
|
private HttpHeaders createHeaders(@NotNull MediaType mediaType) {
|
||||||
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
||||||
acceptableMediaTypes.add(mediaType);
|
acceptableMediaTypes.add(mediaType);
|
||||||
final HttpHeaders requestHeaders = new HttpHeaders();
|
final HttpHeaders requestHeaders = new HttpHeaders();
|
||||||
@ -164,6 +166,19 @@ public class RestAdminITCase {
|
|||||||
return new RestTemplate(s);
|
return new RestTemplate(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RestUser createDummyUser() {
|
||||||
|
final RestUser restUser = new RestUser();
|
||||||
|
final String username = "foo-to-delete" + System.nanoTime();
|
||||||
|
final String email = username + "@example.org";
|
||||||
|
restUser.setEmail(email);
|
||||||
|
restUser.setUsername(username);
|
||||||
|
restUser.setFirstname("foo first name");
|
||||||
|
restUser.setLastname("foo last name");
|
||||||
|
restUser.setPassword("admin");
|
||||||
|
return restUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@DataProvider(name = "ContentType-Provider-Function")
|
@DataProvider(name = "ContentType-Provider-Function")
|
||||||
public Object[][] contentTypes() {
|
public Object[][] contentTypes() {
|
||||||
return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}};
|
return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.wisemapping.test.rest;
|
package com.wisemapping.test.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wisemapping.rest.model.RestMindmap;
|
||||||
import com.wisemapping.rest.model.RestUser;
|
import com.wisemapping.rest.model.RestUser;
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -8,6 +9,8 @@ import org.springframework.http.*;
|
|||||||
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.RestTemplate;
|
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.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -24,32 +27,102 @@ import static org.testng.Assert.fail;
|
|||||||
@Test
|
@Test
|
||||||
public class RestMindmapTCase {
|
public class RestMindmapTCase {
|
||||||
|
|
||||||
@NonNls
|
private String userEmail = "admin@wisemapping.com";
|
||||||
private static final String HOST_PORT = "http://localhost:8080/";
|
private static final String HOST_PORT = "http://localhost:8080";
|
||||||
private static final String BASE_REST_URL = HOST_PORT + "service";
|
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||||
|
|
||||||
private URI createUser(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate templateRest) {
|
@BeforeClass
|
||||||
final RestUser restUser = new RestUser();
|
void createUser() {
|
||||||
final String email = "foo-to-delete" + System.nanoTime() + "@example.org";
|
|
||||||
restUser.setEmail(email);
|
|
||||||
restUser.setUsername("foo");
|
|
||||||
restUser.setFirstname("foo first name");
|
|
||||||
restUser.setLastname("foo last name");
|
|
||||||
restUser.setPassword("foo password");
|
|
||||||
|
|
||||||
HttpEntity<RestUser> createUserEntity = new HttpEntity<RestUser>(restUser, requestHeaders);
|
final RestAdminITCase restAdminITCase = new RestAdminITCase();
|
||||||
return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity);
|
userEmail = restAdminITCase.createNewUser(MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dataProvider = "ContentType-Provider-Function")
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
public void createMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
public void createMap(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||||
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
final RestTemplate templateRest = createTemplate();
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
|
// Create a sample map ...
|
||||||
|
final RestMindmap restMindmap = new RestMindmap();
|
||||||
|
final String title = "My Map " + mediaType.toString();
|
||||||
|
restMindmap.setTitle(title);
|
||||||
|
restMindmap.setDescription("My Map Desc");
|
||||||
|
|
||||||
|
// Create a new map ...
|
||||||
|
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
|
||||||
|
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||||
|
|
||||||
|
// Check that the map has been created ...
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class);
|
||||||
|
assertEquals(response.getBody().getTitle(), title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpHeaders createHeaders(MediaType mediaType) {
|
|
||||||
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
|
public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
|
// Create a sample map ...
|
||||||
|
final RestMindmap restMindmap = new RestMindmap();
|
||||||
|
final String title = "Update XML sample " + mediaType.toString();
|
||||||
|
restMindmap.setTitle(title);
|
||||||
|
restMindmap.setDescription("My Map Desc");
|
||||||
|
|
||||||
|
// Create a new map ...
|
||||||
|
HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(restMindmap, requestHeaders);
|
||||||
|
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||||
|
|
||||||
|
// Update map xml content ...
|
||||||
|
final String resourceUrl = HOST_PORT + resourceLocation.toString();
|
||||||
|
requestHeaders.setContentType(MediaType.APPLICATION_XML);
|
||||||
|
final String newXmlContent = "<map>this is not valid</map>";
|
||||||
|
HttpEntity<String> updateEntity = new HttpEntity<String>(newXmlContent, requestHeaders);
|
||||||
|
templateRest.put(resourceUrl + "/xml", updateEntity);
|
||||||
|
|
||||||
|
// Check that the map has been updated ...
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class);
|
||||||
|
assertEquals(response.getBody().getXml(), newXmlContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
|
public void updateMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate templateRest = createTemplate();
|
||||||
|
|
||||||
|
// Create a sample map ...
|
||||||
|
final RestMindmap newRestMindmap = new RestMindmap();
|
||||||
|
final String title = "Update sample " + mediaType.toString();
|
||||||
|
newRestMindmap.setTitle(title);
|
||||||
|
newRestMindmap.setDescription("My Map Desc");
|
||||||
|
|
||||||
|
// Create a new map ...
|
||||||
|
final HttpEntity<RestMindmap> createUserEntity = new HttpEntity<RestMindmap>(newRestMindmap, requestHeaders);
|
||||||
|
final URI resourceLocation = templateRest.postForLocation(BASE_REST_URL + "/maps", createUserEntity);
|
||||||
|
|
||||||
|
// Build map to update ...
|
||||||
|
final RestMindmap mapToUpdate = new RestMindmap();
|
||||||
|
mapToUpdate.setXml("<map>this is not valid</map>");
|
||||||
|
mapToUpdate.setProperties("{zoom:x}");
|
||||||
|
|
||||||
|
// Update map ...
|
||||||
|
final String resourceUrl = HOST_PORT + resourceLocation.toString();
|
||||||
|
requestHeaders.setContentType(MediaType.APPLICATION_XML);
|
||||||
|
final HttpEntity<RestMindmap> updateEntity = new HttpEntity<RestMindmap>(mapToUpdate, requestHeaders);
|
||||||
|
templateRest.put(resourceUrl, updateEntity);
|
||||||
|
|
||||||
|
// Check that the map has been updated ...
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
final ResponseEntity<RestMindmap> response = templateRest.exchange(HOST_PORT + resourceLocation.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class);
|
||||||
|
assertEquals(response.getBody().getXml(), mapToUpdate.getXml());
|
||||||
|
assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createHeaders(@NotNull MediaType mediaType) {
|
||||||
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
||||||
acceptableMediaTypes.add(mediaType);
|
acceptableMediaTypes.add(mediaType);
|
||||||
final HttpHeaders requestHeaders = new HttpHeaders();
|
final HttpHeaders requestHeaders = new HttpHeaders();
|
||||||
@ -65,11 +138,10 @@ public class RestMindmapTCase {
|
|||||||
super.prepareConnection(connection, httpMethod);
|
super.prepareConnection(connection, httpMethod);
|
||||||
|
|
||||||
//Basic Authentication for Police API
|
//Basic Authentication for Police API
|
||||||
String authorisation = "admin@wisemapping.org" + ":" + "admin";
|
String authorization = userEmail + ":" + "admin";
|
||||||
byte[] encodedAuthorisation = Base64.encode(authorisation.getBytes());
|
byte[] encodedAuthorisation = Base64.encode(authorization.getBytes());
|
||||||
connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
|
connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
return new RestTemplate(s);
|
return new RestTemplate(s);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user