1 /**
  2  * Workflow to move a list of assets/folders given their assetID/Path and their destination path using a REST call
  3  */
  4 var REST = library.REST.REST();
  5 var myData = {};
  6 var myDest;
  7 
  8 /**
  9  * Moves the files or folders and adds an object with the ID/path to myData
 10  *@param theSource -assetId or folderPath to move
 11  *@param aDest- the path to the destination folder
 12  */
 13 function move(theSource) {
 14   try {
 15     var aFolderDest = new ManagedFolder(myDest);
 16   } catch (err) {
 17     REST.submitError(myDest, "The dest folder does not exist");
 18     return;
 19   }
 20 
 21   var aFile = fileManager.getFileObjectById(theSource);
 22   var aFolder;
 23   if (aFile == null) {
 24     try {
 25       aFolder = new ManagedFolder(theSource);
 26       aFolder = fileManager.folderMove(aFolder, aFolderDest, aFolder.name);
 27       myData[theSource] = aFolder.path;
 28       return;
 29     } catch (err) {
 30       REST.submitError(theSource, "The src file or folder does not exist");
 31       return;
 32     }
 33   }
 34 
 35   aFile = fileManager.fileMove(aFile, aFolderDest);
 36   myData[theSource] = aFile.path;
 37 }
 38 
 39 /**
 40  * Moves files or folders and returns their new paths.
 41  * @description Moves all of the folders and files specified by assetID in 'src' to the destination 'dest' and returns their paths. These paths are parsed into a text object keyed by AssetID from the JSON file in which they are contained, and by default are displayed to the user.
 42  * @example 'MBurl'/wf/restapi/1/move?src=["AssetID"]&dest="New/Path"
 43  * @example <a target="_blank"href=http://127.0.0.1:55555/wf/restapi/1/move?src=["12345"]&dest="Assets/Library">http://127.0.0.1:55555/wf/restapi/1/move?src=["12345"]&dest="Assets/Library"</a>
 44  * @class Moves files or folders and returns their new paths.
 45  * @name MoveFilesOrFolders
 46  * @param src AssetID/list of assetIDs of folders and files to move.
 47  * @param dest The path to move the selected folders and files to.
 48  * @returns ( {'AssetID': "path",...} )
 49  */
 50 function main() {
 51   var aParameters = REST.getParametersToIterate("src");
 52   myDest = REST.getParameter("dest", true);
 53   if (myData.error != null) {
 54     return REST.formatResponse();
 55   }
 56   REST.iterateThroughParameters(aParameters, move);
 57   return REST.formatResponse();
 58 }
 59 main();
 60