diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java b/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java index a5e504f7..9c95482d 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java @@ -16,15 +16,6 @@ * limitations under the License. */ -// ........................................................................................................... -// (C) Copyright 1996/2007 Fuego Inc. All Rights Reserved -// THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Fuego Inc. -// The copyright notice above does not evidence any actual or intended -// publication of such source code. -// -// Last changed on 2007-04-03 09:29:20 (-0300), by: nachomanz. $Revision$ -// ........................................................................................................... - package com.wisemapping.controller; import com.wisemapping.model.User; diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/ForgotPasswordController.java b/wise-webapp/src/main/java/com/wisemapping/controller/ForgotPasswordController.java index d8a0da0c..8e7cc89e 100755 --- a/wise-webapp/src/main/java/com/wisemapping/controller/ForgotPasswordController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/ForgotPasswordController.java @@ -16,16 +16,6 @@ * limitations under the License. */ - -// ........................................................................................................... -// (C) Copyright 1996/2007 Fuego Inc. All Rights Reserved -// THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Fuego Inc. -// The copyright notice above does not evidence any actual or intended -// publication of such source code. -// -// Last changed on 2007-04-03 09:29:20 (-0300), by: nachomanz. $Revision$ -// ........................................................................................................... - package com.wisemapping.controller; import com.wisemapping.exceptions.EmailNotExistsException; diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java b/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java index c8c5a1f1..4de7b860 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/UserController.java @@ -16,15 +16,6 @@ * limitations under the License. */ -// ........................................................................................................... -// (C) Copyright 1996/2007 Fuego Inc. All Rights Reserved -// THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Fuego Inc. -// The copyright notice above does not evidence any actual or intended -// publication of such source code. -// -// Last changed on 2007-04-03 09:29:20 (-0300), by: nachomanz. $Revision$ -// ........................................................................................................... - package com.wisemapping.controller; import com.wisemapping.model.User; diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/Mailer.java b/wise-webapp/src/main/java/com/wisemapping/mail/Mailer.java index f6c43a46..b02214c7 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/Mailer.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/Mailer.java @@ -16,14 +16,6 @@ * limitations under the License. */ -// ........................................................................................................... -// (C) Copyright 1996/2007 Fuego Inc. All Rights Reserved -// THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Fuego Inc. -// The copyright notice above does not evidence any actual or intended -// publication of such source code. -// -// Last changed on 2007-04-03 09:29:20 (-0300), by: nachomanz. $Revision$ -// ........................................................................................................... package com.wisemapping.mail; 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 01b08db4..bce9e27e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/MindMap.java @@ -16,15 +16,6 @@ * limitations under the License. */ -// ........................................................................................................... -// (C) Copyright 1996/2007 Fuego Inc. All Rights Reserved -// THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Fuego Inc. -// The copyright notice above does not evidence any actual or intended -// publication of such source code. -// -// Last changed on 2007-08-01 19:08:21 (-0300), by: imanzano. $Revision$ -// ........................................................................................................... - package com.wisemapping.model; import com.wisemapping.util.ZipUtils; @@ -93,7 +84,11 @@ public class MindMap { public byte[] getZippedXml() throws IOException { - return ZipUtils.stringToZip(new String(this.xml, UTF_8)); + byte[] result = this.xml; + if (result != null) { + result = ZipUtils.stringToZip(new String(result, UTF_8)); + } + return result; } public void setZippedXml(byte[] xml) @@ -234,4 +229,14 @@ public class MindMap { return result.toString(); } + public MindMap shallowClone() { + final MindMap result = new MindMap(); + result.setDescription(this.getDescription()); + result.setTitle(this.getTitle()); + result.setProperties(this.getProperties()); + result.setXml(this.getXml()); + result.setTags(this.getTags()); + + return result; + } } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/MindmapUser.java b/wise-webapp/src/main/java/com/wisemapping/model/MindmapUser.java index 95429bc8..a628b36e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/MindmapUser.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/MindmapUser.java @@ -62,7 +62,7 @@ public class MindmapUser { return getRole() == UserRole.OWNER; } - public boolean isCollaborator() { + public boolean isColaborator() { return getRole() == UserRole.COLLABORATOR; } 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 4711e38e..a80ad327 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -6,6 +6,7 @@ import com.wisemapping.model.MindMap; import com.wisemapping.model.MindmapUser; 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.security.Utils; import com.wisemapping.service.MindmapService; @@ -25,7 +26,6 @@ import java.util.List; /** * Pendings: - * Change map title * List with filter * Clone * Discard Changed @@ -175,14 +175,52 @@ public class MindmapController extends BaseController { if (xml == null || xml.isEmpty()) { xml = MindMap.getDefaultMindmapXml(restMindmap.getTitle()); } - delegated.setXmlStr(xml); delegated.setOwner(user); + delegated.setXmlStr(xml); // Add new mindmap ... mindmapService.addMindmap(delegated, user); + // Return the new created map ... response.setHeader("Location", "/service/maps/" + delegated.getId()); } + @RequestMapping(method = RequestMethod.POST, value = "/maps/{id}", consumes = {"application/xml", "application/json"}) + @ResponseStatus(value = HttpStatus.CREATED) + public void copyMap(@RequestBody RestMindmapInfo restMindmap, @PathVariable int id, @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 searchByMap = mindmapService.getMindmapByTitle(title, user); + if (searchByMap != null) { + throw new IllegalArgumentException("Map already exists with title '" + title + "'"); + } + + // Create a shallowCopy of the map ... + final MindMap mindMap = mindmapService.getMindmapById(id); + final MindMap clonedMap = mindMap.shallowClone(); + clonedMap.setTitle(restMindmap.getTitle()); + clonedMap.setDescription(restMindmap.getDescription()); + clonedMap.setOwner(user); + + // Add new mindmap ... + mindmapService.addMindmap(clonedMap, user); + + // Return the new created map ... + response.setHeader("Location", "/service/maps/" + clonedMap.getId()); + + } + + } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java index 72e60135..3ac66014 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/model/RestMindmapInfo.java @@ -98,4 +98,9 @@ public class RestMindmapInfo { public void setLastModifierUser(String lastModifierUser) { } + + @JsonIgnore + public MindMap getDelegated(){ + return this.mindmap; + } } diff --git a/wise-webapp/src/main/webapp/html/js/jquery.dataTables.js b/wise-webapp/src/main/webapp/html/js/jquery.dataTables.js index a295d170..44bf356e 100644 --- a/wise-webapp/src/main/webapp/html/js/jquery.dataTables.js +++ b/wise-webapp/src/main/webapp/html/js/jquery.dataTables.js @@ -2667,7 +2667,7 @@ { var oCol; - /* Take an independent copy of the data source so we can bash it about as we wish */ + /* Take an independent shallowCopy of the data source so we can bash it about as we wish */ var aDataIn = ($.isArray(aDataSupplied)) ? aDataSupplied.slice() : $.extend( true, {}, aDataSupplied ); @@ -3113,7 +3113,7 @@ bIncludeHidden = false; } - /* Make a copy of the master layout array, but without the visible columns in it */ + /* Make a shallowCopy of the master layout array, but without the visible columns in it */ for ( i=0, iLen=aoSource.length ; i createUserEntity = new HttpEntity(restMindmap, requestHeaders); - return template.postForLocation(BASE_REST_URL + "/maps", createUserEntity); - } - - @Test(dataProvider = "ContentType-Provider-Function") - public void discardChange(final @NotNull MediaType mediaType) { // Configure media types ... - final HttpHeaders requestHeaders = createHeaders(mediaType); - final RestTemplate template = createTemplate(); - - // Create a sample map ... - final String title = "Add map to discard " + mediaType.toString(); - final URI resourceUri = addNewMap(requestHeaders, template, title); - - // Update with "minor" flag ... - - // Revert the change ... - - // Check that the map is the - } - @Test(dataProvider = "ContentType-Provider-Function") public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); @@ -177,12 +151,31 @@ public class RestMindmapTCase { assertEquals(response.getXml(), newXmlContent); } - private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate template, URI resourceUri) { - final HttpEntity findMapEntity = new HttpEntity(requestHeaders); - final ResponseEntity response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class); - return response.getBody(); + @Test(dataProvider = "ContentType-Provider-Function") + public void cloneMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + final HttpHeaders requestHeaders = createHeaders(mediaType); + final RestTemplate template = createTemplate(); + + // Create a sample map ... + final String title = "Map to clone sample " + mediaType.toString(); + final String xml = ""; + final URI newMapUri = addNewMap(requestHeaders, template, title, xml); + + // Clone map ... + final RestMindmapInfo restMindmap = new RestMindmapInfo(); + restMindmap.setTitle("Cloned map but with previous content." + mediaType.toString()); + restMindmap.setDescription("Cloned map desc"); + + // Create a new map ... + final HttpEntity cloneEntity = new HttpEntity(restMindmap, requestHeaders); + final URI clonedMapUri = template.postForLocation(HOST_PORT + newMapUri, cloneEntity); + + // Check that the map has been updated ... + final RestMindmap response = findMap(requestHeaders, template, clonedMapUri); + assertEquals(response.getXml(), xml); } + @Test(dataProvider = "ContentType-Provider-Function") public void updateMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); @@ -204,12 +197,36 @@ public class RestMindmapTCase { template.put(resourceUrl, updateEntity); // Check that the map has been updated ... - HttpEntity findUserEntity = new HttpEntity(requestHeaders); - final ResponseEntity response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findUserEntity, RestMindmap.class); + HttpEntity findMapEntity = new HttpEntity(requestHeaders); + final ResponseEntity response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class); assertEquals(response.getBody().getXml(), mapToUpdate.getXml()); assertEquals(response.getBody().getProperties(), mapToUpdate.getProperties()); } + private RestMindmap findMap(HttpHeaders requestHeaders, RestTemplate template, URI resourceUri) { + final HttpEntity findMapEntity = new HttpEntity(requestHeaders); + final ResponseEntity response = template.exchange(HOST_PORT + resourceUri.toString(), HttpMethod.GET, findMapEntity, RestMindmap.class); + return response.getBody(); + } + + private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException { + final RestMindmap restMindmap = new RestMindmap(); + restMindmap.setTitle(title); + restMindmap.setDescription("My Map Desc"); + if (xml != null) { + restMindmap.setXml(xml); + } + + // Create a new map ... + HttpEntity createUserEntity = new HttpEntity(restMindmap, requestHeaders); + return template.postForLocation(BASE_REST_URL + "/maps", createUserEntity); + } + + + private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException { + return addNewMap(requestHeaders, template, title, null); + } + private HttpHeaders createHeaders(@NotNull MediaType mediaType) { List acceptableMediaTypes = new ArrayList(); acceptableMediaTypes.add(mediaType);