@ RequestMapping ( method = RequestMethod . POST , params = "action=addFolder" ) public ModelAndView addFolder ( HttpServletRequest request , HttpServletResponse response , @ RequestParam ( "targetId" ) String targetId , @ RequestParam ( value = "siblingId" , required = false ) String siblingId , @ RequestBody ( required = false ) Map < String , Map < String , String > > attributes ) { IUserLayoutManager ulm = userInstanceManager . getUserInstance ( request ) . getPreferencesManager ( ) . getUserLayoutManager ( ) ; final Locale locale = RequestContextUtils . getLocale ( request ) ; if ( ! ulm . getNode ( targetId ) . isAddChildAllowed ( ) ) { response . setStatus ( HttpServletResponse . SC_FORBIDDEN ) ; return new ModelAndView ( "jsonView" , Collections . singletonMap ( "error" , getMessage ( "error.add.element" , "Unable to add element" , locale ) ) ) ; } UserLayoutFolderDescription newFolder = new UserLayoutFolderDescription ( ) ; newFolder . setHidden ( false ) ; newFolder . setImmutable ( false ) ; newFolder . setAddChildAllowed ( true ) ; newFolder . setFolderType ( IUserLayoutFolderDescription . REGULAR_TYPE ) ; // Update the attributes based on the supplied JSON (optional request body name-value pairs) if ( attributes != null && ! attributes . isEmpty ( ) ) { setObjectAttributes ( newFolder , request , attributes ) ; } ulm . addNode ( newFolder , targetId , siblingId ) ; try { ulm . saveUserLayout ( ) ; } catch ( PortalException e ) { return handlePersistError ( request , response , e ) ; } Map < String , Object > model = new HashMap <> ( ) ; model . put ( "response" , getMessage ( "success.add.folder" , "Added a new folder" , locale ) ) ; model . put ( "folderId" , newFolder . getId ( ) ) ; model . put ( "immutable" , newFolder . isImmutable ( ) ) ; return new ModelAndView ( "jsonView" , model ) ; }
Add a new folder to the layout .