1 /**
  2  * Workflow to add a request to the preview system given a list of asset Id's using a REST call
  3  *
  4  */
  5 var REST = library.REST.REST();
  6 var myData = {};
  7 var myFormat;
  8 var myScale;
  9 var myRes;
 10 var myDestcolor;
 11 var myPath;
 12 /**
 13  * Submits the asset to the preview system and adds a JSON object containing the id of the asset to myData
 14  * context transformation variables include
 15  * format
 16  * scale
 17  * res
 18  * destcolor
 19  * path - output path(loading dock if not given)
 20  * @param theAssetId the asset ID
 21  */
 22 function submit(theAssetId) {
 23   var aFile = fileManager.getFileObjectById(theAssetId);
 24   if (aFile == null) {
 25     REST.submitError(theAssetId, "The file does not exist");
 26     return;
 27   }
 28   var aParameters = new Parameters();
 29   var aFolderOfPath = null;
 30   if (myPath != null && myPath != "") {
 31     if (!fileManager.isFolder(myPath)) {
 32       REST.submitError(theAssetId, "Invalid path " + myPath);
 33       return;
 34     }
 35     aFolderOfPath = fileManager.folderNewByPath(myPath);
 36     aParameters.put("outputPath", aFolderOfPath.path + aFile.name);
 37   }
 38 
 39   aParameters.put("quota", 10248000000);
 40   if (myFormat != "") {
 41     aParameters.put("format", myFormat);
 42   }
 43   if (myDestcolor != "") {
 44     aParameters.put("destinationColorspace", myDestcolor);
 45   }
 46   if (myScale != "") {
 47     aParameters.put("scale", myScale);
 48   }
 49   if (myRes != "") {
 50     aParameters.put("resolution", myRes);
 51   }
 52   previewManager.addRequestForAsset(theAssetId, context.getUser(), aParameters);
 53   if (myPath != "") {
 54     myData[aFolderOfPath.path + aFile.name] = theAssetId;
 55   } else {
 56     if (myData["LoadingDock"] == null) {
 57       myData["LoadingDock"] = [];
 58     }
 59     myData["LoadingDock"][myData["LoadingDock"].length] = theAssetId;
 60   }
 61 }
 62 
 63 /**
 64  * Submits assets to the preview system.
 65  * @description Locates assets by the list of assetIDs in 'src', submits each of them using the preview system parameters, and returns their path values. 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.
 66  * @example 'MBurl'/wf/restapi/1/submitAssets?src=["AssetID"]&format='JPEG'&scale='50x50'&res='72dpi'&destcolor='RGB'&path='Destination/Path'
 67  * @example <a target="_blank" href='http://127.0.0.1:55555/wf/restapi/1/submitAssets?src=["12345"]&format="JPEG"&scale="50x50"&res="72dpi"&destcolor="RGB"'>http://127.0.0.1:55555/wf/restapi/1/submitAssets?src=["12345"]&format="JPEG"&scale="50x50"&res="72dpi"&destcolor="RGB"</a>
 68  * @class Submits assets to the preview system.
 69  * @name SubmitAssets
 70  * @param src AssetID/list of AssetIDs of assets to be submitted.
 71  * @param format the format, e.g. "JPEG"
 72  * @param scale the scale to convert to. E.g. "50%x50%".
 73  * @param res the resolution to convert to. E.g. "72dpi", "300dpi", or "350x400" (pixels).
 74  * @param destcolor the colorspace to convert to. E.g. "RGB".
 75  * @param path Specifies the path of the submitted asset (to the Loading Dock if not given).
 76  * @returns ( {"AssetID": "path",...} )
 77  */
 78 function main() {
 79   myFormat = REST.getParameter("format", false);
 80   myScale = REST.getParameter("scale", false);
 81   myRes = REST.getParameter("res", false);
 82   myDestcolor = REST.getParameter("destcolor", false);
 83   myPath = REST.getParameter("path", false);
 84 
 85   var aParameters = REST.getParametersToIterate("src");
 86   if (myData.error != null) {
 87     return REST.formatResponse();
 88   }
 89   REST.iterateThroughParameters(aParameters, submit);
 90   return REST.formatResponse();
 91 }
 92 main();
 93