2012-05-29 22:36:32 -03:00
/ *
* 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 .
* /
2012-02-12 21:57:11 -03:00
package com.wisemapping.rest ;
2012-02-21 14:22:43 -03:00
import com.wisemapping.exceptions.WiseMappingException ;
2012-06-03 19:19:48 -03:00
import com.wisemapping.importer.ImportFormat ;
import com.wisemapping.importer.Importer ;
import com.wisemapping.importer.ImporterException ;
import com.wisemapping.importer.ImporterFactory ;
2012-06-09 22:49:54 -03:00
import com.wisemapping.model.* ;
import com.wisemapping.rest.model.* ;
2012-02-21 14:22:43 -03:00
import com.wisemapping.security.Utils ;
2012-06-09 22:55:55 -03:00
import com.wisemapping.service.CollaborationException ;
2012-02-12 21:57:11 -03:00
import com.wisemapping.service.MindmapService ;
2012-04-07 12:45:35 -03:00
import com.wisemapping.validator.MapInfoValidator ;
2012-03-14 01:49:05 -03:00
import org.jetbrains.annotations.NotNull ;
2012-02-16 01:16:51 -03:00
import org.springframework.beans.factory.annotation.Autowired ;
2012-06-09 22:49:54 -03:00
import org.springframework.beans.factory.annotation.Qualifier ;
2012-02-21 20:04:17 -03:00
import org.springframework.http.HttpStatus ;
2012-02-12 21:57:11 -03:00
import org.springframework.stereotype.Controller ;
2012-04-07 12:45:35 -03:00
import org.springframework.validation.BeanPropertyBindingResult ;
import org.springframework.validation.BindingResult ;
2012-02-21 14:22:43 -03:00
import org.springframework.web.bind.annotation.* ;
2012-02-16 01:16:51 -03:00
import org.springframework.web.servlet.ModelAndView ;
2012-02-12 21:57:11 -03:00
2012-03-14 01:49:05 -03:00
import javax.servlet.http.HttpServletResponse ;
2012-06-03 19:19:48 -03:00
import java.io.ByteArrayInputStream ;
2012-02-12 21:57:11 -03:00
import java.io.IOException ;
2012-06-03 11:16:38 -03:00
import java.util.* ;
2012-02-12 21:57:11 -03:00
2012-03-14 22:10:44 -03:00
2012-02-12 21:57:11 -03:00
@Controller
2012-03-13 15:57:30 -03:00
public class MindmapController extends BaseController {
2012-06-09 22:49:54 -03:00
@Qualifier ( " mindmapService " )
2012-02-16 01:16:51 -03:00
@Autowired
2012-02-12 21:57:11 -03:00
private MindmapService mindmapService ;
2012-06-03 11:16:38 -03:00
@RequestMapping ( method = RequestMethod . GET , value = " /maps/{id} " , produces = { " application/json " , " application/xml " , " text/html " } )
2012-02-12 21:57:11 -03:00
@ResponseBody
2012-06-03 11:16:38 -03:00
public ModelAndView retrieve ( @PathVariable int id ) throws IOException {
2012-06-09 22:49:54 -03:00
final User user = Utils . getUser ( ) ;
2012-02-12 21:57:11 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
2012-05-29 22:36:32 -03:00
final RestMindmap map = new RestMindmap ( mindMap , user ) ;
2012-06-03 11:16:38 -03:00
2012-02-16 01:16:51 -03:00
return new ModelAndView ( " mapView " , " map " , map ) ;
2012-02-12 21:57:11 -03:00
}
2012-02-17 10:42:20 -03:00
2012-06-03 11:16:38 -03:00
@RequestMapping ( method = RequestMethod . GET , value = " /maps/{id} " , produces = { " application/wisemapping+xml " } , params = { " download=wxml " } )
@ResponseBody
public ModelAndView retrieveAsWise ( @PathVariable int id ) throws IOException {
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final Map < String , Object > values = new HashMap < String , Object > ( ) ;
2012-06-09 22:49:54 -03:00
final User user = Utils . getUser ( ) ;
2012-06-03 11:16:38 -03:00
values . put ( " mindmap " , new RestMindmap ( mindMap , user ) ) ;
values . put ( " filename " , mindMap . getTitle ( ) ) ;
return new ModelAndView ( " transformViewWise " , values ) ;
}
@RequestMapping ( method = RequestMethod . GET , value = " /maps/{id} " , produces = { " application/freemind " } , params = { " download=mm " } )
@ResponseBody
public ModelAndView retrieveDocumentAsFreemind ( @PathVariable int id ) throws IOException {
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final Map < String , Object > values = new HashMap < String , Object > ( ) ;
values . put ( " content " , mindMap . getXmlStr ( ) ) ;
values . put ( " filename " , mindMap . getTitle ( ) ) ;
return new ModelAndView ( " transformViewFreemind " , values ) ;
}
2012-06-03 19:19:48 -03:00
@RequestMapping ( method = RequestMethod . GET , value = " /maps/ " , produces = { " application/json " , " text/html " , " application/xml " } )
2012-06-03 11:16:38 -03:00
public ModelAndView retrieveList ( @RequestParam ( required = false ) String q ) throws IOException {
2012-06-09 22:49:54 -03:00
final User user = Utils . getUser ( ) ;
2012-02-17 10:42:20 -03:00
2012-05-23 21:54:03 -03:00
final MindmapFilter filter = MindmapFilter . parse ( q ) ;
2012-06-09 22:49:54 -03:00
final List < Collaboration > collaborations = mindmapService . getCollaborationsBy ( user ) ;
2012-05-23 21:54:03 -03:00
2012-02-20 14:42:07 -03:00
final List < MindMap > mindmaps = new ArrayList < MindMap > ( ) ;
2012-06-09 22:49:54 -03:00
for ( Collaboration collaboration : collaborations ) {
2012-06-09 15:49:19 -03:00
final MindMap mindmap = collaboration . getMindMap ( ) ;
2012-05-23 21:54:03 -03:00
if ( filter . accept ( mindmap , user ) ) {
mindmaps . add ( mindmap ) ;
}
2012-02-20 14:42:07 -03:00
}
2012-05-29 22:36:32 -03:00
final RestMindmapList restMindmapList = new RestMindmapList ( mindmaps , user ) ;
2012-02-20 14:42:07 -03:00
return new ModelAndView ( " mapsView " , " list " , restMindmapList ) ;
2012-02-17 10:42:20 -03:00
}
2012-02-21 14:22:43 -03:00
2012-06-07 19:45:22 -03:00
@RequestMapping ( method = RequestMethod . GET , value = " /maps/{id}/history " , produces = { " application/json " , " text/html " , " application/xml " } )
public ModelAndView retrieveHistory ( @PathVariable int id ) throws IOException {
2012-06-09 22:49:54 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final Set < Collaboration > collaborations = mindMap . getCollaborations ( ) ;
final RestCollaborationList result = new RestCollaborationList ( ) ;
for ( Collaboration collaboration : collaborations ) {
result . addCollaboration ( new RestCollaboration ( collaboration ) ) ;
}
return new ModelAndView ( " collabView " , " list " , result ) ;
2012-06-07 19:45:22 -03:00
}
2012-05-23 20:05:16 -03:00
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id}/document " , consumes = { " application/xml " , " application/json " } , produces = { " application/json " , " text/html " , " application/xml " } )
2012-02-21 20:04:17 -03:00
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-05-23 20:05:16 -03:00
public void updateDocument ( @RequestBody RestMindmap restMindmap , @PathVariable int id , @RequestParam ( required = false ) boolean minor ) throws IOException , WiseMappingException {
2012-02-21 14:22:43 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
2012-03-14 01:49:05 -03:00
// Validate arguments ...
2012-02-21 14:22:43 -03:00
final String properties = restMindmap . getProperties ( ) ;
2012-03-14 01:49:05 -03:00
if ( properties = = null ) {
throw new IllegalArgumentException ( " Map properties can not be null " ) ;
}
2012-02-21 14:22:43 -03:00
mindMap . setProperties ( properties ) ;
2012-03-14 01:49:05 -03:00
// Validate content ...
2012-02-21 14:22:43 -03:00
final String xml = restMindmap . getXml ( ) ;
2012-03-14 01:49:05 -03:00
if ( xml = = null ) {
throw new IllegalArgumentException ( " Map xml can not be null " ) ;
}
2012-02-21 14:22:43 -03:00
mindMap . setXmlStr ( xml ) ;
2012-03-14 01:49:05 -03:00
// Update map ...
2012-06-03 11:16:38 -03:00
saveMindmap ( minor , mindMap , user ) ;
2012-02-21 14:22:43 -03:00
}
2012-02-21 20:04:17 -03:00
2012-05-23 20:05:16 -03:00
/ * *
* The intention of this method is the update of several properties at once . . .
* /
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id} " , consumes = { " application/xml " , " application/json " } , produces = { " application/json " , " text/html " , " application/xml " } )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-06-03 11:16:38 -03:00
public void update ( @RequestBody RestMindmap restMindmap , @PathVariable int id , @RequestParam ( required = false ) boolean minor ) throws IOException , WiseMappingException {
2012-05-23 20:05:16 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
// Update document properties ...
final String properties = restMindmap . getProperties ( ) ;
if ( properties ! = null ) {
mindMap . setProperties ( properties ) ;
}
final String xml = restMindmap . getXml ( ) ;
if ( xml ! = null ) {
mindMap . setXmlStr ( xml ) ;
}
// Update title ...
final String title = restMindmap . getTitle ( ) ;
if ( title ! = null & & ! title . equals ( mindMap . getTitle ( ) ) ) {
if ( mindmapService . getMindmapByTitle ( title , user ) ! = null ) {
throw buildValidationException ( " title " , " You already have a map with this title " ) ;
}
mindMap . setTitle ( title ) ;
}
// Update description ...
final String description = restMindmap . getDescription ( ) ;
if ( description ! = null ) {
mindMap . setDescription ( description ) ;
}
final String tags = restMindmap . getTags ( ) ;
if ( tags ! = null ) {
mindMap . setTags ( tags ) ;
}
// Update map ...
2012-06-03 11:16:38 -03:00
saveMindmap ( minor , mindMap , user ) ;
2012-05-23 20:05:16 -03:00
}
2012-03-15 01:47:42 -03:00
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id}/title " , consumes = { " text/plain " } , produces = { " application/json " , " text/html " , " application/xml " } )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-06-03 11:16:38 -03:00
public void updateTitle ( @RequestBody String title , @PathVariable int id ) throws WiseMappingException {
2012-03-15 01:47:42 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
// Is there a map with the same name ?
if ( mindmapService . getMindmapByTitle ( title , user ) ! = null ) {
2012-05-23 20:05:16 -03:00
throw buildValidationException ( " title " , " You already have a mindmap with this title " ) ;
2012-03-15 01:47:42 -03:00
}
// Update map ...
final MindMap mindmap = mindmapService . getMindmapById ( id ) ;
mindmap . setTitle ( title ) ;
2012-06-03 11:16:38 -03:00
saveMindmap ( true , mindMap , user ) ;
2012-03-15 01:47:42 -03:00
}
2012-06-09 15:49:19 -03:00
@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 )
2012-06-09 22:55:55 -03:00
public void updateCollabs ( @PathVariable int id , @NotNull @RequestBody RestCollaborationList restCollabs ) throws CollaborationException {
2012-06-09 15:49:19 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
2012-06-09 22:49:54 -03:00
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 < Collaboration > collabsToRemove = new HashSet < Collaboration > ( mindMap . getCollaborations ( ) ) ;
for ( RestCollaboration restCollab : restCollabs . getCollaborations ( ) ) {
2012-06-09 22:55:55 -03:00
final Collaboration collaboration = mindMap . findCollaboration ( restCollab . getEmail ( ) ) ;
// Validate role format ...
String roleStr = restCollab . getRole ( ) ;
if ( roleStr = = null ) {
throw new IllegalArgumentException ( roleStr + " is not a valid role " ) ;
}
2012-06-09 22:49:54 -03:00
2012-06-09 22:55:55 -03:00
// Is owner ?
final CollaborationRole role = CollaborationRole . valueOf ( roleStr . toUpperCase ( ) ) ;
if ( role ! = CollaborationRole . OWNER ) {
2012-06-09 22:49:54 -03:00
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 ) ;
}
2012-06-09 15:49:19 -03:00
}
2012-06-09 22:49:54 -03:00
2012-06-09 15:49:19 -03:00
@RequestMapping ( method = RequestMethod . GET , value = " /maps/{id}/collabs " , produces = { " application/json " , " text/html " , " application/xml " } )
2012-06-09 22:49:54 -03:00
public ModelAndView retrieveList ( @PathVariable int id ) {
2012-06-09 15:49:19 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final Set < Collaboration > collaborations = mindMap . getCollaborations ( ) ;
2012-06-09 22:49:54 -03:00
final List < RestCollaboration > collabs = new ArrayList < RestCollaboration > ( ) ;
for ( Collaboration collaboration : collaborations ) {
collabs . add ( new RestCollaboration ( collaboration ) ) ;
}
final RestCollaborationList restCollaborationList = new RestCollaborationList ( ) ;
restCollaborationList . setCollaborations ( collabs ) ;
2012-06-09 15:49:19 -03:00
2012-06-09 22:49:54 -03:00
return new ModelAndView ( " collabsView " , " list " , restCollaborationList ) ;
2012-06-09 15:49:19 -03:00
}
2012-03-15 01:47:42 -03:00
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id}/description " , consumes = { " text/plain " } , produces = { " application/json " , " text/html " , " application/xml " } )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-06-03 11:16:38 -03:00
public void updateDescription ( @RequestBody String description , @PathVariable int id ) throws WiseMappingException {
2012-03-15 01:47:42 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
// Update map ...
final MindMap mindmap = mindmapService . getMindmapById ( id ) ;
mindmap . setDescription ( description ) ;
2012-06-03 11:16:38 -03:00
saveMindmap ( true , mindMap , user ) ;
2012-03-15 01:47:42 -03:00
}
2012-05-20 21:46:55 -03:00
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id}/publish " , consumes = { " text/plain " } , produces = { " application/json " , " text/html " , " application/xml " } )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-05-29 22:36:32 -03:00
public void updatePublishState ( @RequestBody String value , @PathVariable int id ) throws WiseMappingException {
2012-05-20 21:46:55 -03:00
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
if ( ! mindMap . getOwner ( ) . equals ( user ) ) {
throw new IllegalArgumentException ( " No enough to execute this operation " ) ;
}
// Update map status ...
mindMap . setPublic ( Boolean . parseBoolean ( value ) ) ;
2012-06-03 11:16:38 -03:00
saveMindmap ( true , mindMap , user ) ;
2012-05-20 21:46:55 -03:00
}
2012-03-15 01:21:46 -03:00
2012-05-29 22:36:32 -03:00
@RequestMapping ( method = RequestMethod . PUT , value = " /maps/{id}/starred " , consumes = { " text/plain " } , produces = { " application/json " , " text/html " , " application/xml " } )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
public void updateStarredState ( @RequestBody String value , @PathVariable int id ) throws WiseMappingException {
final MindMap mindMap = mindmapService . getMindmapById ( id ) ;
final User user = Utils . getUser ( ) ;
// Update map status ...
mindMap . setStarred ( user , Boolean . parseBoolean ( value ) ) ;
2012-06-03 11:16:38 -03:00
saveMindmap ( true , mindMap , user ) ;
2012-05-29 22:36:32 -03:00
}
2012-03-15 01:21:46 -03:00
@RequestMapping ( method = RequestMethod . DELETE , value = " /maps/{id} " )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-05-23 20:05:16 -03:00
public void updateMap ( @PathVariable int id ) throws IOException , WiseMappingException {
2012-03-15 01:21:46 -03:00
final User user = Utils . getUser ( ) ;
final MindMap mindmap = mindmapService . getMindmapById ( id ) ;
mindmapService . removeMindmap ( mindmap , user ) ;
}
2012-04-06 17:05:42 -03:00
@RequestMapping ( method = RequestMethod . DELETE , value = " /maps/batch " )
@ResponseStatus ( value = HttpStatus . NO_CONTENT )
2012-05-19 21:36:34 -03:00
public void batchDelete ( @RequestParam ( required = true ) String ids ) throws IOException , WiseMappingException {
2012-04-06 17:05:42 -03:00
final User user = Utils . getUser ( ) ;
final String [ ] mapsIds = ids . split ( " , " ) ;
for ( final String mapId : mapsIds ) {
final MindMap mindmap = mindmapService . getMindmapById ( Integer . parseInt ( mapId ) ) ;
mindmapService . removeMindmap ( mindmap , user ) ;
}
}
2012-06-06 00:48:46 -03:00
@RequestMapping ( method = RequestMethod . POST , value = " /maps " , consumes = { " application/xml " , " application/json " , " application/wisemapping+xml " } )
2012-03-14 01:49:05 -03:00
@ResponseStatus ( value = HttpStatus . CREATED )
2012-06-06 00:48:46 -03:00
public void createMap ( @RequestBody RestMindmap restMindmap , @NotNull HttpServletResponse response , @RequestParam ( required = false ) String title , @RequestParam ( required = false ) String description ) throws IOException , WiseMappingException {
// Overwrite title and description if they where specified by parameter.
if ( title ! = null & & ! title . isEmpty ( ) ) {
restMindmap . setTitle ( title ) ;
}
if ( description ! = null & & ! description . isEmpty ( ) ) {
restMindmap . setDescription ( description ) ;
}
2012-03-13 15:57:30 -03:00
2012-04-07 12:45:35 -03:00
// Validate ...
final BindingResult result = new BeanPropertyBindingResult ( restMindmap , " " ) ;
new MapInfoValidator ( mindmapService ) . validate ( restMindmap . getDelegated ( ) , result ) ;
if ( result . hasErrors ( ) ) {
throw new ValidationException ( result ) ;
2012-03-14 01:49:05 -03:00
}
// 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 ( ) ) ;
}
2012-03-15 21:13:47 -03:00
delegated . setXmlStr ( xml ) ;
2012-03-14 01:49:05 -03:00
// Add new mindmap ...
2012-06-06 00:48:46 -03:00
final User user = Utils . getUser ( ) ;
2012-03-14 01:49:05 -03:00
mindmapService . addMindmap ( delegated , user ) ;
// Return the new created map ...
response . setHeader ( " Location " , " /service/maps/ " + delegated . getId ( ) ) ;
2012-04-06 20:28:25 -03:00
response . setHeader ( " ResourceId " , Integer . toString ( delegated . getId ( ) ) ) ;
2012-03-13 15:57:30 -03:00
}
2012-06-03 19:19:48 -03:00
@RequestMapping ( method = RequestMethod . POST , value = " /maps " , consumes = { " application/freemind " } )
@ResponseStatus ( value = HttpStatus . CREATED )
2012-06-06 01:42:24 -03:00
public void createMapFromFreemind ( @RequestBody byte [ ] freemindXml , @RequestParam ( required = true ) String title , @RequestParam ( required = false ) String description , @NotNull HttpServletResponse response ) throws IOException , WiseMappingException {
2012-06-03 19:19:48 -03:00
// Convert map ...
2012-06-06 01:42:24 -03:00
final MindMap mindMap ;
try {
final Importer importer = ImporterFactory . getInstance ( ) . getImporter ( ImportFormat . FREEMIND ) ;
final ByteArrayInputStream stream = new ByteArrayInputStream ( freemindXml ) ;
mindMap = importer . importMap ( title , " " , stream ) ;
} catch ( ImporterException e ) {
2012-06-07 19:45:22 -03:00
// @Todo: This should be an illegal argument exception. Review the all the other cases.
2012-06-06 01:42:24 -03:00
throw buildValidationException ( " xml " , " The selected file does not seems to be a valid Freemind or WiseMapping file. Contact support in case the problem persists. " ) ;
}
2012-06-03 19:19:48 -03:00
// Save new map ...
final User user = Utils . getUser ( ) ;
2012-06-06 00:48:46 -03:00
createMap ( new RestMindmap ( mindMap , user ) , response , title , description ) ;
2012-06-03 19:19:48 -03:00
}
2012-03-15 21:13:47 -03:00
@RequestMapping ( method = RequestMethod . POST , value = " /maps/{id} " , consumes = { " application/xml " , " application/json " } )
@ResponseStatus ( value = HttpStatus . CREATED )
2012-06-03 11:16:38 -03:00
public void createDuplicate ( @RequestBody RestMindmapInfo restMindmap , @PathVariable int id , @NotNull HttpServletResponse response ) throws IOException , WiseMappingException {
2012-05-20 21:46:55 -03:00
// Validate ...
2012-04-07 20:05:50 -03:00
final BindingResult result = new BeanPropertyBindingResult ( restMindmap , " " ) ;
new MapInfoValidator ( mindmapService ) . validate ( restMindmap . getDelegated ( ) , result ) ;
if ( result . hasErrors ( ) ) {
throw new ValidationException ( result ) ;
2012-03-15 21:13:47 -03:00
}
// Some basic validations ...
final User user = Utils . getUser ( ) ;
// 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 ( ) ) ;
2012-04-07 12:45:35 -03:00
response . setHeader ( " ResourceId " , Integer . toString ( clonedMap . getId ( ) ) ) ;
2012-03-15 21:13:47 -03:00
}
2012-06-06 00:48:46 -03:00
private void saveMindmap ( boolean minor , @NotNull final MindMap mindMap , @NotNull final User user ) throws WiseMappingException {
final Calendar now = Calendar . getInstance ( ) ;
mindMap . setLastModificationTime ( now ) ;
mindMap . setLastModifierUser ( user . getUsername ( ) ) ;
mindmapService . updateMindmap ( mindMap , minor ) ;
}
private ValidationException buildValidationException ( @NotNull String fieldName , @NotNull String message ) throws ValidationException {
final BindingResult result = new BeanPropertyBindingResult ( new RestMindmap ( ) , " " ) ;
result . rejectValue ( fieldName , " error.not-specified " , null , message ) ;
return new ValidationException ( result ) ;
}
2012-02-12 21:57:11 -03:00
}