1 /**
  2  * Workflow to write a xmp packet to an asset
  3  */
  4 var REST = library.REST.REST();
  5 var myData = {};
  6 
  7 /**
  8  * Writes the xmp string to the asset with the given asset id
  9  * @description Writes the xmp string in the xmp parameter to the asset with the id. The Returned JSON is keyed by the provided asset and its value displays the new xmp
 10  * @example 'MBurl'/wf/restapi/1/setXmp?src=["AssetID"]&xmp=<xml>data</xml>
 11  * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/setXmp?src=["12345"]&xmp=%3Cxml%3Edata%3C%2Fxml%3E>http://127.0.0.1:55555/wf/restapi/1/getXmp?src=["12345"]&xmp=<xml>data</xml></a>
 12  * @class Writes the xmp string to the asset with the given asset id
 13  * @name SetXMP
 14  * @param src AssetID to write the XMP to.
 15  * @param xmp the Xmp packet to write to the asset(works best to put ths parameter in the body of the post (application/x-www-form-urlencoded))
 16  * @returns ( {'AssetID': "New XMP Packet Values",...} )
 17  */
 18 function main() {
 19   var aAssetId = REST.getParameter("src", true);
 20   var aXmpString = REST.getParameter("xmp", true);
 21   if (myData.error != null) {
 22     return REST.formatResponse();
 23   }
 24   var aFile = fileManager.getFileObjectById(aAssetId);
 25   if (aFile == null) {
 26     REST.submitError(aAssetId, "The file does not exist");
 27     return REST.formatResponse();
 28   }
 29   aFile.xmp = aXmpString;
 30   if (!aFile.writeXmp()) {
 31     REST.submitError(aAssetId, "Failed to write the xmp string to the file");
 32     return REST.formatResponse();
 33   }
 34   myData[aAssetId] = aFile.xmp.asString();
 35   return REST.formatResponse();
 36 }
 37 main();
 38