diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/MindmapSharingController.java b/wise-webapp/src/main/java/com/wisemapping/controller/MindmapSharingController.java deleted file mode 100644 index 4c618950..00000000 --- a/wise-webapp/src/main/java/com/wisemapping/controller/MindmapSharingController.java +++ /dev/null @@ -1,92 +0,0 @@ -/* -* Copyright [2011] [wisemapping] -* -* Licensed under WiseMapping Public License, Version 1.0 (the "License"). -* It is basically the Apache License, Version 2.0 (the "License") plus the -* "powered by wisemapping" text requirement on every single page; -* you may not use this file except in compliance with the License. -* You may obtain a copy of the license at -* -* http://www.wisemapping.org/license -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package com.wisemapping.controller; - -import com.wisemapping.model.ColaborationEmail; -import com.wisemapping.model.CollaborationRole; -import com.wisemapping.model.MindMap; -import com.wisemapping.model.User; -import com.wisemapping.security.Utils; -import com.wisemapping.service.InvalidColaboratorException; -import com.wisemapping.view.MindMapBean; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class MindmapSharingController extends BaseMultiActionController { - private static final String COLABORATOR_ID = "colaboratorId"; - - public ModelAndView addCollaborator(HttpServletRequest request, HttpServletResponse response) - throws InvalidColaboratorException { - logger.info("Sharing Controller: add collaborators action"); - addColaborator(request, CollaborationRole.EDITOR); - return new ModelAndView("closeDialog"); - } - - public ModelAndView addViewer(HttpServletRequest request, HttpServletResponse response) - throws InvalidColaboratorException { - logger.info("Sharing Controller: add viewer action"); - addColaborator(request, CollaborationRole.VIEWER); - return new ModelAndView("closeDialog"); - } - - public ModelAndView removeCollaborator(HttpServletRequest request, HttpServletResponse response) { - logger.info("Sharing Controller: remove collaborator action"); - final MindMap mindmap = removeColaborator(request); - return new ModelAndView("mindmapCollaborator", "mindmap", new MindMapBean(mindmap)); - } - - private MindMap removeColaborator(HttpServletRequest request) { - final MindMap mindmap = getMindmapFromRequest(request); - final String colaboratorId = request.getParameter(COLABORATOR_ID); - long colaborator = Long.parseLong(colaboratorId); - getMindmapService().removeCollaboratorFromMindmap(mindmap, colaborator); - return mindmap; - } - - private String[] getEmailsToAdd(final HttpServletRequest request) { - final String[] result; - String collaboratorEmails = request.getParameter(MINDMAP_EMAILS_PARAMNAME); - if (collaboratorEmails != null && collaboratorEmails.trim().length() > 0) { - result = collaboratorEmails.split("\\s*[,|\\;|\\s]\\s*"); - } else { - result = null; - } - return result; - } - - private MindMapBean addColaborator(HttpServletRequest request, CollaborationRole role) throws InvalidColaboratorException { - final MindMap mindMap = getMindmapFromRequest(request); - User user = Utils.getUser(); - if (!mindMap.getOwner().equals(user)) { - throw new IllegalStateException("No enought right to execute this operation"); - } - - - final String[] emails = getEmailsToAdd(request); - - final ColaborationEmail email = new ColaborationEmail(); - email.setSubject(request.getParameter("subject")); - email.setMessage(request.getParameter("message")); - getMindmapService().addCollaborators(mindMap, emails, role, email); - - return new MindMapBean(mindMap); - } -} \ No newline at end of file diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java index 52ca9db4..0790ece2 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManager.java @@ -19,12 +19,13 @@ package com.wisemapping.dao; import com.wisemapping.model.*; +import org.jetbrains.annotations.NotNull; import java.util.List; public interface MindmapManager { - Collaborator getCollaboratorBy(String email); + Collaborator getCollaboratorBy(@NotNull String email); Collaborator getCollaboratorBy(long id); @@ -48,11 +49,11 @@ public interface MindmapManager { void updateMindmap(MindMap mindMap, boolean saveHistory); - void removeCollaborator(Collaborator collaborator); + void removeCollaborator(@NotNull Collaborator collaborator); void removeMindmap(MindMap mindap); - void removeMindmapUser(Collaboration collaboration); + void removeCollaboration(Collaboration collaboration); public List search(MindMapCriteria criteria); diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java index 23b7a6bf..c93695fd 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/MindmapManagerImpl.java @@ -122,6 +122,7 @@ public class MindmapManagerImpl public List getMindmapUserByRole(final CollaborationRole collaborationRole) { return getHibernateTemplate().find("from com.wisemapping.model.Collaboration mindmapUser where roleId=?", collaborationRole.ordinal()); } + @Override public Collaboration getMindmapUserBy(final int mindmapId, final User user) { final Collaboration result; @@ -138,17 +139,17 @@ public class MindmapManagerImpl @Override public void addCollaborator(Collaborator collaborator) { - assert collaborator != null : "ADD MINDMAP COLABORATOR: Collaborator is required!"; + assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!"; getHibernateTemplate().save(collaborator); } @Override - public void removeMindmapUser(Collaboration collaboration) { + public void removeCollaboration(Collaboration collaboration) { getHibernateTemplate().delete(collaboration); } @Override - public void removeCollaborator(Collaborator collaborator) { + public void removeCollaborator(@NotNull Collaborator collaborator) { getHibernateTemplate().delete(collaborator); } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java index d80fc754..17ad13b6 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/Collaboration.java @@ -36,7 +36,7 @@ public class Collaboration { this.collaborator = collaborator; // Guarantee referential integrity - mindmap.addMindmapUser(this); + mindmap.addCollaboration(this); collaborator.addMindmapUser(this); } @@ -60,6 +60,10 @@ public class Collaboration { return role; } + public void setRole(@NotNull CollaborationRole role) { + this.role = role; + } + public boolean isOwner() { return getRole() == CollaborationRole.OWNER; } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/ColaborationEmail.java b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationEmail.java similarity index 91% rename from wise-webapp/src/main/java/com/wisemapping/model/ColaborationEmail.java rename to wise-webapp/src/main/java/com/wisemapping/model/CollaborationEmail.java index db60ca97..01afe38c 100755 --- a/wise-webapp/src/main/java/com/wisemapping/model/ColaborationEmail.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationEmail.java @@ -18,12 +18,12 @@ package com.wisemapping.model; -public class ColaborationEmail +public class CollaborationEmail { private String subject; private String message; - public ColaborationEmail(){} + public CollaborationEmail(){} public String getSubject() { return subject; diff --git a/wise-webapp/src/main/java/com/wisemapping/model/MindmapCollaborationProperties.java b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java similarity index 86% rename from wise-webapp/src/main/java/com/wisemapping/model/MindmapCollaborationProperties.java rename to wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java index 918501ba..c545cb31 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/MindmapCollaborationProperties.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java @@ -20,19 +20,19 @@ package com.wisemapping.model; import org.jetbrains.annotations.NotNull; -public class MindmapCollaborationProperties { +public class CollaborationProperties { private long id; private boolean starred; private Collaborator collaborator; private MindMap mindmap; - public MindmapCollaborationProperties(@NotNull Collaborator collaborator, @NotNull MindMap mindmap) { + public CollaborationProperties(@NotNull Collaborator collaborator, @NotNull MindMap mindmap) { this.collaborator = collaborator; this.mindmap = mindmap; } - public MindmapCollaborationProperties(){ + public CollaborationProperties(){ } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java b/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java index efe4599c..1a806ea6 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java @@ -20,6 +20,7 @@ package com.wisemapping.model; import com.wisemapping.util.ZipUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -42,7 +43,7 @@ public class MindMap { private String lastModifierUser; private Set collaborations = new HashSet(); - private Set collaboratorProperties = new HashSet(); + private Set collaborationProperties = new HashSet(); private User owner; private String properties; @@ -55,10 +56,6 @@ public class MindMap { public MindMap() { } - public MindMap(Set collaborations) { - this.collaborations = collaborations; - } - //~ Methods .............................................................................................. public void setXml(byte[] xml) { @@ -119,10 +116,26 @@ public class MindMap { this.collaborations = collaborations; } - public void addMindmapUser(Collaboration collaboration) { + public void addCollaboration(@NotNull Collaboration collaboration) { collaborations.add(collaboration); } + public void removedCollaboration(@NotNull Collaboration collaboration) { + collaborations.add(collaboration); + } + + @Nullable + public Collaboration findCollaborationByEmail(@NotNull String email) { + Collaboration result = null; + for (Collaboration collaboration : collaborations) { + if (collaboration.getCollaborator().getEmail().equals(email)) { + result = collaboration; + break; + } + } + return result; + } + public boolean isPublic() { return isPublic; } @@ -222,18 +235,18 @@ public class MindMap { return owner; } - public Set getCollaboratorProperties() { - return collaboratorProperties; + public Set getCollaborationProperties() { + return collaborationProperties; } - public void setCollaboratorProperties(@NotNull Set collaboratorProperties) { - this.collaboratorProperties = collaboratorProperties; + public void setCollaborationProperties(@NotNull Set collaborationProperties) { + this.collaborationProperties = collaborationProperties; } - private MindmapCollaborationProperties findUserProperty(@NotNull Collaborator collaborator) { - final Set collaboratorProperties = this.getCollaboratorProperties(); - MindmapCollaborationProperties result = null; - for (MindmapCollaborationProperties collaboratorProperty : collaboratorProperties) { + private CollaborationProperties findUserProperty(@NotNull Collaborator collaborator) { + final Set collaborationProp = this.getCollaborationProperties(); + CollaborationProperties result = null; + for (CollaborationProperties collaboratorProperty : collaborationProp) { final Collaborator propCollab = collaboratorProperty.getCollaborator(); if (propCollab != null && propCollab.getEmail().equals(collaborator.getEmail())) { result = collaboratorProperty; @@ -244,20 +257,20 @@ public class MindMap { } public void setStarred(@NotNull Collaborator collaborator, boolean value) { - if(collaborator==null){ - throw new IllegalStateException("Collaborator can not be null"); + if (collaborator == null) { + throw new IllegalStateException("Collaborator can not be null"); } - MindmapCollaborationProperties collaboratorProperties = this.findUserProperty(collaborator); + CollaborationProperties collaboratorProperties = this.findUserProperty(collaborator); if (collaboratorProperties == null) { - collaboratorProperties = new MindmapCollaborationProperties(collaborator, this); + collaboratorProperties = new CollaborationProperties(collaborator, this); } collaboratorProperties.setStarred(value); - this.getCollaboratorProperties().add(collaboratorProperties); + this.getCollaborationProperties().add(collaboratorProperties); } public boolean isStarred(@NotNull Collaborator collaborator) { - final MindmapCollaborationProperties collaboratorProperty = this.findUserProperty(collaborator); + final CollaborationProperties collaboratorProperty = this.findUserProperty(collaborator); return collaboratorProperty != null && collaboratorProperty.getStarred(); } diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java index da8619ce..22e2a17b 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java @@ -11,6 +11,7 @@ import com.wisemapping.service.MindmapService; import com.wisemapping.view.MindMapBean; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @@ -26,10 +27,7 @@ public class MindmapController { private String baseUrl; - MindmapController() { - - } - + @Qualifier("mindmapService") @Autowired private MindmapService mindmapService; @@ -186,7 +184,7 @@ public class MindmapController { } private List findMindMapBeanList(@NotNull User user) { - final List userMindmaps = mindmapService.getMindmapUserByUser(user); + final List userMindmaps = mindmapService.getCollaborationsBy(user); final List mindMapBeans = new ArrayList(userMindmaps.size()); for (Collaboration mindmap : userMindmaps) { diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 7275f26c..e6056200 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -24,17 +24,15 @@ import com.wisemapping.importer.ImportFormat; import com.wisemapping.importer.Importer; import com.wisemapping.importer.ImporterException; import com.wisemapping.importer.ImporterFactory; -import com.wisemapping.model.Collaboration; -import com.wisemapping.model.MindMap; -import com.wisemapping.model.User; -import com.wisemapping.rest.model.RestMindmap; -import com.wisemapping.rest.model.RestMindmapInfo; -import com.wisemapping.rest.model.RestMindmapList; +import com.wisemapping.model.*; +import com.wisemapping.rest.model.*; import com.wisemapping.security.Utils; +import com.wisemapping.service.InvalidCollaborationException; import com.wisemapping.service.MindmapService; import com.wisemapping.validator.MapInfoValidator; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.validation.BeanPropertyBindingResult; @@ -50,14 +48,14 @@ import java.util.*; @Controller public class MindmapController extends BaseController { + @Qualifier("mindmapService") @Autowired private MindmapService mindmapService; - @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}", produces = {"application/json", "application/xml", "text/html"}) @ResponseBody public ModelAndView retrieve(@PathVariable int id) throws IOException { - final User user = com.wisemapping.security.Utils.getUser(); + final User user = Utils.getUser(); final MindMap mindMap = mindmapService.getMindmapById(id); final RestMindmap map = new RestMindmap(mindMap, user); @@ -70,7 +68,7 @@ public class MindmapController extends BaseController { final MindMap mindMap = mindmapService.getMindmapById(id); final Map values = new HashMap(); - final User user = com.wisemapping.security.Utils.getUser(); + final User user = Utils.getUser(); values.put("mindmap", new RestMindmap(mindMap, user)); values.put("filename", mindMap.getTitle()); return new ModelAndView("transformViewWise", values); @@ -88,13 +86,13 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "/maps/", produces = {"application/json", "text/html", "application/xml"}) public ModelAndView retrieveList(@RequestParam(required = false) String q) throws IOException { - final User user = com.wisemapping.security.Utils.getUser(); + final User user = Utils.getUser(); final MindmapFilter filter = MindmapFilter.parse(q); + final List collaborations = mindmapService.getCollaborationsBy(user); - final List mapsByUser = mindmapService.getMindmapUserByUser(user); final List mindmaps = new ArrayList(); - for (Collaboration collaboration : mapsByUser) { + for (Collaboration collaboration : collaborations) { final MindMap mindmap = collaboration.getMindMap(); if (filter.accept(mindmap, user)) { mindmaps.add(mindmap); @@ -107,9 +105,13 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/history", produces = {"application/json", "text/html", "application/xml"}) public ModelAndView retrieveHistory(@PathVariable int id) throws IOException { - final User user = com.wisemapping.security.Utils.getUser(); - - return null; + final MindMap mindMap = mindmapService.getMindmapById(id); + final Set collaborations = mindMap.getCollaborations(); + final RestCollaborationList result = new RestCollaborationList(); + for (Collaboration collaboration : collaborations) { + result.addCollaboration(new RestCollaboration(collaboration)); + } + return new ModelAndView("collabView", "list", result); } @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) @@ -203,20 +205,56 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "text/html", "application/xml"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void updateCollabs(@PathVariable int id) throws WiseMappingException { - + public void updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws InvalidCollaborationException { final MindMap mindMap = mindmapService.getMindmapById(id); final User user = Utils.getUser(); + if (!mindMap.getOwner().equals(user)) { + throw new IllegalArgumentException("No enough permissions"); + } + + // Compare one by one if some of the elements has been changed .... + final Set collabsToRemove = new HashSet(mindMap.getCollaborations()); + for (RestCollaboration restCollab : restCollabs.getCollaborations()) { + final Collaboration collaboration = mindMap.findCollaborationByEmail(restCollab.getEmail()); + + if (CollaborationRole.valueOf(restCollab.getRole()) != CollaborationRole.OWNER) { + + // Validate role ... + String roleStr = restCollab.getRole(); + if (roleStr == null) { + throw new IllegalArgumentException(roleStr + " is not a valid role"); + } + final CollaborationRole role = CollaborationRole.valueOf(roleStr.toUpperCase()); + mindmapService.addCollaboration(mindMap, restCollab.getEmail(), role); + } + + if (collaboration != null) { + collabsToRemove.remove(collaboration); + } + + } + + // Remove all collaborations that no applies anymore .. + for (final Collaboration collaboration : collabsToRemove) { + mindmapService.removeCollaboration(collaboration); + } } + @RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/collabs", produces = {"application/json", "text/html", "application/xml"}) - public ModelAndView retrieveList(@PathVariable int id) throws IOException { + public ModelAndView retrieveList(@PathVariable int id) { final MindMap mindMap = mindmapService.getMindmapById(id); - final User user = Utils.getUser(); final Set collaborations = mindMap.getCollaborations(); + final List collabs = new ArrayList(); + for (Collaboration collaboration : collaborations) { + collabs.add(new RestCollaboration(collaboration)); + } - return new ModelAndView("mapsView", "list", collaborations); + final RestCollaborationList restCollaborationList = new RestCollaborationList(); + restCollaborationList.setCollaborations(collabs); + + return new ModelAndView("collabsView", "list", restCollaborationList); } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaboration.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaboration.java index 1c5e3933..b5057e87 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaboration.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaboration.java @@ -1,6 +1,7 @@ package com.wisemapping.rest.model; +import com.wisemapping.model.Collaboration; import com.wisemapping.model.CollaborationRole; import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonIgnore; @@ -10,7 +11,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -@XmlRootElement(name = "collaborators") +@XmlRootElement(name = "collaboration") @XmlAccessorType(XmlAccessType.PROPERTY) @JsonAutoDetect( fieldVisibility = JsonAutoDetect.Visibility.NONE, @@ -18,11 +19,13 @@ import javax.xml.bind.annotation.XmlRootElement; isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY) public class RestCollaboration { - @JsonIgnore private String email; + private String role; - @JsonIgnore - private CollaborationRole role; + public RestCollaboration(@NotNull Collaboration collaboration) { + this.email = collaboration.getCollaborator().getEmail(); + this.role = collaboration.getRole().name(); + } public RestCollaboration() { @@ -32,19 +35,21 @@ public class RestCollaboration { if (value == null) { throw new IllegalStateException("role can not be null"); } + // Only check ... + CollaborationRole.valueOf(value.toUpperCase()); + role = value; - role = CollaborationRole.valueOf(value.toUpperCase()); } public String getRole() { - return role.toString().toLowerCase(); + return role; } public String getEmail() { return email; } - public void setEmail(String email) { + public void setEmail(@NotNull String email) { this.email = email; } } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborationList.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborationList.java index 265b5050..5604509a 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborationList.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestCollaborationList.java @@ -10,9 +10,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; @XmlRootElement(name = "collaboration") @XmlAccessorType(XmlAccessType.PROPERTY) @@ -25,7 +23,7 @@ public class RestCollaborationList { private List collaborations; public RestCollaborationList() { - + collaborations = new ArrayList(); } public int getCount() { @@ -36,11 +34,15 @@ public class RestCollaborationList { } - @XmlElement(name = "collaborate") + @XmlElement(name = "collaborations") public List getCollaborations() { return collaborations; } + public void addCollaboration(@NotNull RestCollaboration collaboration) { + collaborations.add(collaboration); + } + public void setCollaborations(@NotNull List collaborations) { this.collaborations = collaborations; } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java index dfb66647..9861fe78 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmap.java @@ -39,11 +39,11 @@ public class RestMindmap { } public RestMindmap() { - this(new MindMap(), Utils.getUser()); + this(new MindMap(), null); } - public RestMindmap(@NotNull MindMap mindmap, @NotNull Collaborator collaborator) { + public RestMindmap(@NotNull MindMap mindmap, @Nullable Collaborator collaborator) { this.mindmap = mindmap; this.collaborator = collaborator; } @@ -131,7 +131,8 @@ public class RestMindmap { } public String getOwner() { - return mindmap.getOwner().getEmail(); + final User owner = mindmap.getOwner(); + return owner != null ? owner.getEmail() : null; } public void setCreator(String creatorUser) { diff --git a/wise-webapp/src/main/java/com/wisemapping/service/InvalidColaboratorException.java b/wise-webapp/src/main/java/com/wisemapping/service/InvalidCollaborationException.java similarity index 87% rename from wise-webapp/src/main/java/com/wisemapping/service/InvalidColaboratorException.java rename to wise-webapp/src/main/java/com/wisemapping/service/InvalidCollaborationException.java index a938cfe1..65579364 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/InvalidColaboratorException.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/InvalidCollaborationException.java @@ -18,10 +18,10 @@ package com.wisemapping.service; -public class InvalidColaboratorException +public class InvalidCollaborationException extends Exception { - public InvalidColaboratorException(String msg) + public InvalidCollaborationException(String msg) { super(msg); } diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java index a3fb0b67..75cdba5d 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapService.java @@ -35,25 +35,23 @@ public interface MindmapService { public MindMap getMindmapByTitle(String title, User user); - public List getMindmapUserByUser(User user); + public List getCollaborationsBy(@NotNull User user); public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException; public void addMindmap(MindMap map, User user) throws WiseMappingException; - public void addCollaborators(MindMap mindmap, String[] collaboratorEmails, CollaborationRole role, ColaborationEmail email) - throws InvalidColaboratorException; + public void addCollaboration(@NotNull MindMap mindmap, @NotNull String email, @NotNull CollaborationRole role) + throws InvalidCollaborationException; + + public void removeCollaboration(@NotNull Collaboration collaboration); public void addTags(MindMap mindmap, String tags); - public void removeCollaboratorFromMindmap(@NotNull final MindMap mindmap, long colaboratorId); - public void removeMindmap(@NotNull final MindMap mindmap, @NotNull final User user) throws WiseMappingException; public List search(MindMapCriteria criteria); - public List getPublicMaps(int cant); - public List getMindMapHistory(int mindmapId); public boolean isAllowedToView(User user, MindMap map, CollaborationRole allowedRole); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java index ee9d5939..deca9509 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/MindmapServiceImpl.java @@ -84,18 +84,22 @@ public class MindmapServiceImpl return mindmapManager.getMindmapUserBy(mindmapId, user); } + @Override public MindMap getMindmapByTitle(String title, User user) { return mindmapManager.getMindmapByTitle(title, user); } + @Override public MindMap getMindmapById(int mindmapId) { return mindmapManager.getMindmapById(mindmapId); } - public List getMindmapUserByUser(@NotNull User user) { + @Override + public List getCollaborationsBy(@NotNull User user) { return mindmapManager.getMindmapUserByCollaborator(user.getId()); } + @Override public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException { if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) { throw new WiseMappingException("The tile can not be empty"); @@ -104,39 +108,35 @@ public class MindmapServiceImpl mindmapManager.updateMindmap(mindMap, saveHistory); } - public List getPublicMaps(int cant) { - return mindmapManager.search(null, cant); - } - + @Override public List search(MindMapCriteria criteria) { return mindmapManager.search(criteria); } - public void removeCollaboratorFromMindmap(@NotNull MindMap mindmap, long userId) { + @Override + public void removeCollaboration(@NotNull Collaboration collaboration) { // remove collaborator association - Set mindmapusers = mindmap.getCollaborations(); - Collaboration mindmapuserToDelete = null; - for (Collaboration mindmapuser : mindmapusers) { - if (mindmapuser.getCollaborator().getId() == userId) { - mindmapuserToDelete = mindmapuser; - break; - } - } - if (mindmapuserToDelete != null) { - // When you delete an object from hibernate you have to delete it from *all* collections it exists in... - mindmapusers.remove(mindmapuserToDelete); - mindmapManager.removeMindmapUser(mindmapuserToDelete); - } + final MindMap mindMap = collaboration.getMindMap(); + Set collaborations = mindMap.getCollaborations(); + + // When you delete an object from hibernate you have to delete it from *all* collections it exists in... + collaborations.remove(collaboration); + mindmapManager.removeCollaboration(collaboration); } + @Override public void removeMindmap(@NotNull MindMap mindmap, @NotNull User user) throws WiseMappingException { if (mindmap.getOwner().equals(user)) { mindmapManager.removeMindmap(mindmap); } else { - this.removeCollaboratorFromMindmap(mindmap, user.getId()); + final Collaboration collaboration = mindmap.findCollaborationByEmail(user.getEmail()); + if (collaboration != null) { + this.removeCollaboration(collaboration); + } } } + @Override public void addMindmap(@NotNull MindMap map, @NotNull User user) throws WiseMappingException { final String title = map.getTitle(); @@ -165,29 +165,52 @@ public class MindmapServiceImpl mindmapManager.addMindmap(dbUser, map); } - public void addCollaborators(MindMap mindmap, String[] collaboratorEmails, CollaborationRole role, ColaborationEmail email) - throws InvalidColaboratorException { - if (collaboratorEmails != null && collaboratorEmails.length > 0) { - final Collaborator owner = mindmap.getOwner(); - final Set collaborations = mindmap.getCollaborations(); + @Override + public void addCollaboration(@NotNull MindMap mindmap, @NotNull String email, @NotNull CollaborationRole role) + throws InvalidCollaborationException { - for (String colaboratorEmail : collaboratorEmails) { - if (owner.getEmail().equals(colaboratorEmail)) { - throw new InvalidColaboratorException("The user " + owner.getEmail() + " is the owner"); - } - Collaboration collaboration = getMindmapUserBy(colaboratorEmail, collaborations); - if (collaboration == null) { - addCollaborator(colaboratorEmail, role, mindmap, email); - } else if (collaboration.getRole() != role) { - // If the relationship already exists and the role changed then only update the role - collaboration.setRoleId(role.ordinal()); - mindmapManager.updateMindmap(mindmap, false); - } - } + // Validate + final Collaborator owner = mindmap.getOwner(); + final Set collaborations = mindmap.getCollaborations(); + if (owner.getEmail().equals(email)) { + throw new InvalidCollaborationException("The user " + owner.getEmail() + " is the owner"); + } + + Collaboration collaboration = getCollaborationBy(email, collaborations); + if (collaboration == null) { + final Collaborator collaborator = addCollaborator(email); + collaboration = new Collaboration(role, collaborator, mindmap); + mindmap.getCollaborations().add(collaboration); + mindmapManager.saveMindmap(mindmap); + + // Sent collaboration email ... + final Map model = new HashMap(); + model.put("role", role); + model.put("map", mindmap); + model.put("message", "message"); + mailer.sendEmail(mailer.getSiteEmail(), email, "Collaboration", model, "newColaborator.vm"); + + } else if (collaboration.getRole() != role) { + // If the relationship already exists and the role changed then only update the role + collaboration.setRole(role); + mindmapManager.updateMindmap(mindmap, false); } } - public void addTags(MindMap mindmap, String tags) { + private Collaborator addCollaborator(String email) { + // Add a new collaborator ... + Collaborator collaborator = mindmapManager.getCollaboratorBy(email); + if (collaborator == null) { + collaborator = new Collaborator(); + collaborator.setEmail(email); + collaborator.setCreationDate(Calendar.getInstance()); + mindmapManager.addCollaborator(collaborator); + } + return collaborator; + } + + @Override + public void addTags(@NotNull MindMap mindmap, String tags) { mindmap.setTags(tags); mindmapManager.updateMindmap(mindmap, false); if (tags != null && tags.length() > 0) { @@ -233,7 +256,7 @@ public class MindmapServiceImpl updateMindmap(map, false); } - private Collaboration getMindmapUserBy(String email, Set collaborations) { + private Collaboration getCollaborationBy(String email, Set collaborations) { Collaboration collaboration = null; for (Collaboration user : collaborations) { @@ -245,27 +268,6 @@ public class MindmapServiceImpl return collaboration; } - private void addCollaborator(String colaboratorEmail, CollaborationRole role, MindMap mindmap, ColaborationEmail email) { - - Collaborator collaborator = mindmapManager.getCollaboratorBy(colaboratorEmail); - if (collaborator == null) { - collaborator = new Collaborator(); - collaborator.setEmail(colaboratorEmail); - collaborator.setCreationDate(Calendar.getInstance()); - mindmapManager.addCollaborator(collaborator); - } - - final Collaboration newCollaboration = new Collaboration(role, collaborator, mindmap); - mindmap.getCollaborations().add(newCollaboration); - - mindmapManager.saveMindmap(mindmap); - - final Map model = new HashMap(); - model.put("role", role); - model.put("map", mindmap); - model.put("message", email.getMessage()); - mailer.sendEmail(mailer.getSiteEmail(), colaboratorEmail, email.getSubject(), model, "newColaborator.vm"); - } public void setMindmapManager(MindmapManager mindmapManager) { this.mindmapManager = mindmapManager; diff --git a/wise-webapp/src/main/resources/com/wisemapping/model/MindMap.hbm.xml b/wise-webapp/src/main/resources/com/wisemapping/model/MindMap.hbm.xml index 5aaf8ef9..31e3df32 100644 --- a/wise-webapp/src/main/resources/com/wisemapping/model/MindMap.hbm.xml +++ b/wise-webapp/src/main/resources/com/wisemapping/model/MindMap.hbm.xml @@ -11,7 +11,7 @@ - + @@ -23,17 +23,17 @@ - + cascade="all,delete-orphan" + inverse="true"> + - + - + diff --git a/wise-webapp/src/main/resources/com/wisemapping/model/MindmapCollaborationProperties.hbm.xml b/wise-webapp/src/main/resources/com/wisemapping/model/MindmapCollaborationProperties.hbm.xml index b5ded9e2..108cb089 100644 --- a/wise-webapp/src/main/resources/com/wisemapping/model/MindmapCollaborationProperties.hbm.xml +++ b/wise-webapp/src/main/resources/com/wisemapping/model/MindmapCollaborationProperties.hbm.xml @@ -5,7 +5,7 @@ - + diff --git a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml index 535ee2ae..50c7464e 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/defs/definitions.xml @@ -10,7 +10,6 @@ - @@ -85,12 +84,6 @@ - - - - - - @@ -152,12 +145,6 @@ - - - - - - diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml index 4e5ab45e..bdb3d236 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-aop.xml @@ -23,6 +23,7 @@ + save* update* add* remove* diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml index ebd572b5..734d380d 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-servlet.xml @@ -26,7 +26,6 @@ - @@ -34,13 +33,6 @@ - - - - - - - @@ -136,7 +128,6 @@ userController - sharingController loginController forgotPasswordController activationController diff --git a/wise-webapp/src/main/webapp/jsp/mindmapCollaborator.jsp b/wise-webapp/src/main/webapp/jsp/mindmapCollaborator.jsp deleted file mode 100644 index 0104c39e..00000000 --- a/wise-webapp/src/main/webapp/jsp/mindmapCollaborator.jsp +++ /dev/null @@ -1,141 +0,0 @@ -<%@ include file="/jsp/init.jsp" %> - - - - - - - - -

- : - '${mindmap.title}'

- -
-
- -
-

- -

- " - onclick="toogleUserType(this.value)" - style="border: 1px solid #39C;padding: 5px;margin:5px;background-color: #838383;color: white;font-weight: bold;"/> - " - onclick="toogleUserType(this.value)" - style="border: 1px solid black;padding: 5px;margin:5px;background-color: #838383;color: white;font-weight: bold;"/> - -
- -
- -
- - -
- - - -
- - " class="btn-secondary" id="cancelBtn"/> -
- -
-

- (${mindmap.countColaborators}) -

- - - - - - - - - - -
- ${mindmapCollaborator.username} - - <spring:message code=" border="0"/> -
- -

- (${mindmap.countViewers}) -

- - - - - - - - - - -
- ${mindmapViewer.username} - - <spring:message code=" border="0"/> -
-
- - -
-
- - - \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/jsp/mindmapCooker.jsp b/wise-webapp/src/main/webapp/jsp/mindmapCooker.jsp deleted file mode 100644 index e9d28b5c..00000000 --- a/wise-webapp/src/main/webapp/jsp/mindmapCooker.jsp +++ /dev/null @@ -1,29 +0,0 @@ -<%@ include file="/jsp/init.jsp" %> - -

Mindmap Cooker

- -
-
- - - - - - - - - - - - - -
- Native XML: - - -
  - " class="btn-primary"/> - " class="btn-primary"/> -
-
-
diff --git a/wise-webapp/src/main/webapp/jsp/mindmapPublicView.jsp b/wise-webapp/src/main/webapp/jsp/mindmapPublicView.jsp deleted file mode 100644 index fce049d7..00000000 --- a/wise-webapp/src/main/webapp/jsp/mindmapPublicView.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%@ include file="/jsp/init.jsp" %> -

- -

- - - - - -
- - -
\ No newline at end of file diff --git a/wise-webapp/src/main/webapp/jsp/mindmapShare.jsp b/wise-webapp/src/main/webapp/jsp/mindmapShare.jsp index adb8aba1..d315e3d1 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapShare.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapShare.jsp @@ -61,7 +61,7 @@ return role; } - function addCollaborator(email, role) { + function addCollaboration(email, role) { // Add row to the table ... var tableElem = $("#collabsTable"); var rowTemplate = '\ @@ -106,17 +106,24 @@ }; $(function() { - var loadedCollabs = [ - {email:'paulo1@pveiga.com.ar',role:'viewer'}, - {email:'paulo2@pveiga.com.ar',role:'editor'}, - {email:'paulo3@pveiga.com.ar',role:'editor'} - ]; + jQuery.ajax("service/maps/${mindmap.id}/collabs", { + async:false, + dataType: 'json', + type: 'GET', + contentType:"text/plain", + success : function(data, textStatus, jqXHR) { + // Init table will all values ... + var collabs = data.collaborations; + for (var i = 0; i < collabs.length; i++) { + var collab = collabs[i]; + addCollaboration(collab.email, collab.role); + } - // Init table will all values ... - for (var i = 0; i < loadedCollabs.length; i++) { - var collab = loadedCollabs[i]; - addCollaborator(collab.email, collab.role); - } + }, + error:function(jqXHR, textStatus, errorThrown) { + alert(textStatus); + } + }); }); $("#addBtn").click(function(event) { @@ -164,7 +171,7 @@ $("#collabEmails").val(""); for (i = 0; i < emails.length; i++) { email = emails[i]; - addCollaborator(email, role); + addCollaboration(email, role); } } else { @@ -190,20 +197,38 @@ } function buildCollabModel() { - return $('#collabsTable tr').map(function() { + var collabs = $('#collabsTable tr').map(function() { return { email: $(this).attr('data-collab'), role: $(this).attr('data-role') }; }); + collabs = jQuery.makeArray(collabs); + return { + count:collabs.length, + collaborations:collabs + }; } // Hook for interaction with the main parent window ... var submitDialogForm = function() { console.log(buildCollabModel()); + jQuery.ajax("service/maps/${mindmap.id}/collabs", { + async:false, + dataType: 'json', + type: 'PUT', + data: JSON.stringify(buildCollabModel()), + contentType:"application/json", + success : function(data, textStatus, jqXHR) { + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(textStatus); + } + + }); } diff --git a/wise-webapp/src/main/webapp/jsp/mindmapViewer.jsp b/wise-webapp/src/main/webapp/jsp/mindmapViewer.jsp deleted file mode 100644 index 6501a292..00000000 --- a/wise-webapp/src/main/webapp/jsp/mindmapViewer.jsp +++ /dev/null @@ -1,87 +0,0 @@ -<%@ include file="/jsp/init.jsp" %> - - - - - <spring:message code="SITE.TITLE"/> - - - !--[if lt IE 9]> - - - - - - - - -

${mindmap.title}

- -
${mindmap.description}
-
${mindmap.userRole}
- -
"> - - - -
-
- - - - - - - - - - -
-
- -
- "> - " - onclick="window.location=''"> -
-
-
-
- - - - - - - -
- ${mindmapViewer} - - " - alt=""/> -
-
-
-
-
-
- -
"> - - - -
- - - \ No newline at end of file diff --git a/wise-webapp/src/test/java/com/wisemapping/test/model/JsonTest.java b/wise-webapp/src/test/java/com/wisemapping/test/model/JsonTest.java index 41e638b0..4b087946 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/model/JsonTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/model/JsonTest.java @@ -1,13 +1,12 @@ package com.wisemapping.test.model; -import com.wisemapping.rest.model.RestMindmap; -import com.wisemapping.rest.model.RestMindmapInfo; -import com.wisemapping.rest.model.RestUser; +import com.wisemapping.rest.model.*; import org.codehaus.jackson.map.ObjectMapper; import org.testng.annotations.Test; import java.io.IOException; +import java.util.List; @Test public class JsonTest { @@ -29,7 +28,6 @@ public class JsonTest { @Test void serialize() throws IOException { - String mapJson = "{\"id\":\"1\",\"xml\":\"\",\"properties\":\"{\\\"zoom\\\":0.85}\"}"; ObjectMapper mapper = new ObjectMapper(); final RestMindmap value = new RestMindmap(); @@ -39,5 +37,18 @@ public class JsonTest { System.out.println(restMindmap); } + @Test + void deserializeCollbsList() throws IOException { + String collbsJson = "{\"count\":1,\"collaborations\":[{\"email\":\"paulo@pveiga.com.ar\",\"role\":\"editor\"}]}"; + ObjectMapper mapper = new ObjectMapper(); + + final RestCollaborationList list = mapper.readValue(collbsJson, RestCollaborationList.class); + final List collaborations = list.getCollaborations(); + for (RestCollaboration collaboration : collaborations) { + final String role = collaboration.getRole(); + final String email = collaboration.getEmail(); + } + } + }