Add clone REST service.

This commit is contained in:
Paulo Gustavo Veiga
2012-03-15 21:13:47 -03:00
parent 731df774a8
commit 5aca99a24f
10 changed files with 119 additions and 90 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -62,7 +62,7 @@ public class MindmapUser {
return getRole() == UserRole.OWNER;
}
public boolean isCollaborator() {
public boolean isColaborator() {
return getRole() == UserRole.COLLABORATOR;
}

View File

@@ -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());
}
}

View File

@@ -98,4 +98,9 @@ public class RestMindmapInfo {
public void setLastModifierUser(String lastModifierUser) {
}
@JsonIgnore
public MindMap getDelegated(){
return this.mindmap;
}
}