1 /**
  2  * Workflow to write a xmp packet to an asset
  3  */
  4 var REST = library.REST.REST();
  5 
  6 /**
  7  *  Set the xmp for the asset.
  8  *
  9  * @param theJSON {"id": <assetID>, "xmp": "<theXmpString>"}
 10  */
 11 function setXmp(theJSON) {
 12   var aFile = fileManager.getFileObjectById(theJSON.id);
 13   if (aFile == null) {
 14     REST.pushError(REST.errors.e404, "The file does not exist:" + theJSON.id);
 15     return;
 16   }
 17   aFile.xmp = theJSON.xmp;
 18   if (!aFile.writeXmp()) {
 19     REST.pushError(
 20       REST.errors.e500,
 21       "Failed to write the xmp string to the file:" + theJSON.id
 22     );
 23     return;
 24   }
 25   aFile = fileManager.getFileObjectById(theJSON.id);
 26   REST.push(aFile, { xmp: aFile.xmp.asString() });
 27 }
 28 
 29 /**
 30  * @name SetXmp
 31  * @class Set the XMP for an asset
 32  * @description For every asset defined in "data", this endpoint sets the xmp from the given xmp string
 33  * @param data An array of assets an the xmp string to set. [{"id": 123456, "xmp": "theXmpString"},..]
 34  * @param [verbose=false] Setting this to true will collect a variety of default values for each asset.
 35  * @param [fields] An array of field id's to collect the values for each asset
 36  * @returns [{assetInfo}, ... ]
 37  *
 38  * @example /wf/restapi/v2/setXmp
 39  *
 40  * Parameters:
 41  * verbose=true
 42  * data=
 43  * <xmp>
 44  [
 45 	 {
 46 	   "xmp": "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"MediaBeacon XMP 1.0\">\n<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:iX=\"http://ns.adobe.com/iX/1.0/\"><rdf:Description rdf:about=\"uuid:321FB501-1364-40FA-85F1-0CC4A584346F\"><xap:MetadataDate xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">2017-10-12T16:24:01.943-05:00</xap:MetadataDate><xap:ModifyDate xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">2017-10-12</xap:ModifyDate><mbmm:rawFileSize xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">10180918</mbmm:rawFileSize><xmpMM:DocumentID xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">mediabeacon:docid:BDECD-A000E-0D52B-6BF87-28FE5-4EC95-201624287-E9A860AA-DC85-4B19-AD20-03A54685C8B1</xmpMM:DocumentID><xmpMM:InstanceID xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">590AB634-27C9-49D9-AC0E-046B5BA9BF87</xmpMM:InstanceID><xmpMM:ManagerVariant xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">C409EB69-9E0A-486A-8616-6946B07710DD</xmpMM:ManagerVariant><xmpMM:Manager xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">Brightech MediaBeacon 3.0</xmpMM:Manager><mbmm:format xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">Graphics:TIFF</mbmm:format><mb:file_creation_date xmlns:mb=\"http://brightech.com/ns/mb\">2017-09-07T13:07:31Z</mb:file_creation_date><mbmm:uploadUser xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">root</mbmm:uploadUser><mbmm:storageSyncDate xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">2017-10-12T16:05:24.811-05:00</mbmm:storageSyncDate><exif:ColorSpace xmlns:exif=\"http://ns.adobe.com/exif/1.0/\">SRGB</exif:ColorSpace><mb:preview_modified_date xmlns:mb=\"http://brightech.com/ns/mb\">2017-10-12 16:05:24.809</mb:preview_modified_date><mbmm:colorprofile xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\"><rdf:Bag><rdf:li>438CCB</rdf:li><rdf:li>5574B9</rdf:li><rdf:li>598627</rdf:li><rdf:li>6ECFF7</rdf:li><rdf:li>754C24</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>9D0A0F</rdf:li><rdf:li>A0410D</rdf:li><rdf:li>A36109</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>F26522</rdf:li><rdf:li>F26C4E</rdf:li><rdf:li>F26D7C</rdf:li><rdf:li>F68D56</rdf:li><rdf:li>F7977A</rdf:li><rdf:li>FAAE5D</rdf:li></rdf:Bag></mbmm:colorprofile><mb:rotate xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:rotate><mb:video_status xmlns:mb=\"http://brightech.com/ns/mb\">-1</mb:video_status><mb:duration xmlns:mb=\"http://brightech.com/ns/mb\">-1</mb:duration><mb:file_type2 xmlns:mb=\"http://brightech.com/ns/mb\">TIFF</mb:file_type2><mb:bundle_flag xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:bundle_flag><mb:file_type xmlns:mb=\"http://brightech.com/ns/mb\">10</mb:file_type><mb:last_post xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:last_post><mb:version_of xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:version_of><mb:date_entered xmlns:mb=\"http://brightech.com/ns/mb\">2017-09-07T00:00:00.000-05:00</mb:date_entered><mb:orig_y xmlns:mb=\"http://brightech.com/ns/mb\">1480</mb:orig_y><mb:directory_id xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:directory_id><mb:orig_x xmlns:mb=\"http://brightech.com/ns/mb\">2292</mb:orig_x><mb:checkout xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:checkout><mb:needs_xmp_auto xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:needs_xmp_auto><mb:viewex_y xmlns:mb=\"http://brightech.com/ns/mb\">331</mb:viewex_y><mb:page_count xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:page_count><mb:viewex_x xmlns:mb=\"http://brightech.com/ns/mb\">512</mb:viewex_x><mb:xmp_volatile xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:xmp_volatile><mb:caches_ok xmlns:mb=\"http://brightech.com/ns/mb\">14</mb:caches_ok><mb:file_name xmlns:mb=\"http://brightech.com/ns/mb\">opo0006_orig.tif</mb:file_name><mb:zoom xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:zoom><mb:mb_id xmlns:mb=\"http://brightech.com/ns/mb\">BDECD-A000E-0D52B-6BF87-28FE5-4EC95</mb:mb_id><mb:high_x xmlns:mb=\"http://brightech.com/ns/mb\">1920</mb:high_x><mb:high_y xmlns:mb=\"http://brightech.com/ns/mb\">1240</mb:high_y><mb:file_size xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:file_size><mb:discussion_count xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:discussion_count><mb:record_id xmlns:mb=\"http://brightech.com/ns/mb\">201624287</mb:record_id><mb:file_date_modified xmlns:mb=\"http://brightech.com/ns/mb\">1506954271000</mb:file_date_modified><mb:view_sched xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:view_sched><mb:usermodified xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:usermodified><mb:thumbnails_x xmlns:mb=\"http://brightech.com/ns/mb\">118</mb:thumbnails_x><mb:thumbnails_y xmlns:mb=\"http://brightech.com/ns/mb\">76</mb:thumbnails_y><mb:dimensions xmlns:mb=\"http://brightech.com/ns/mb\">2292x1480 (.79inx.9in),479dpi</mb:dimensions><mb:discussion xmlns:mb=\"http://brightech.com/ns/mb\"><rdf:Seq><rdf:li rdf:parseType=\"Resource\"><mb:user>root</mb:user><mb:uid>A69D9135-4076-03F7-4D48-56AED2C3110F</mb:uid><mb:globalAdminEdited>false</mb:globalAdminEdited><mb:text>Message in the discussion</mb:text><mb:date>Thu, 12 Oct 2017 15:59:07 -0500</mb:date><mb:dateEdited>Thu, 12 Oct 2017 15:59:07 -0500</mb:dateEdited><mb:page>1</mb:page><mb:endTime>-1.0</mb:endTime><mb:startTime>-1.0</mb:startTime></rdf:li><rdf:li rdf:parseType=\"Resource\"><mb:user>root</mb:user><mb:uid>19CFCB3A-DA75-9955-A3DC-738A686CB</mb:uid><mb:globalAdminEdited>false</mb:globalAdminEdited><mb:text>Second message</mb:text><mb:date>Thu, 12 Oct 2017 15:59:20 -0500</mb:date><mb:dateEdited>Thu, 12 Oct 2017 15:59:20 -0500</mb:dateEdited><mb:page>1</mb:page><mb:endTime>-1.0</mb:endTime><mb:startTime>-1.0</mb:startTime></rdf:li></rdf:Seq></mb:discussion></rdf:Description></rdf:RDF>\n</x:xmpmeta><?xpacket end='w'?>\n",
 47 	   "id": 201624287,
 48     }
 49  ]</xmp>
 50  *
 51  * Response:
 52  * <xmp>
 53  [
 54 	 {
 55 	   "xmp": "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"MediaBeacon XMP 1.0\">\n<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:iX=\"http://ns.adobe.com/iX/1.0/\"><rdf:Description rdf:about=\"uuid:321FB501-1364-40FA-85F1-0CC4A584346F\"><xap:MetadataDate xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">2017-10-12T16:24:01.943-05:00</xap:MetadataDate><xap:ModifyDate xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">2017-10-12</xap:ModifyDate><mbmm:rawFileSize xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">10180918</mbmm:rawFileSize><xmpMM:DocumentID xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">mediabeacon:docid:BDECD-A000E-0D52B-6BF87-28FE5-4EC95-201624287-E9A860AA-DC85-4B19-AD20-03A54685C8B1</xmpMM:DocumentID><xmpMM:InstanceID xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">590AB634-27C9-49D9-AC0E-046B5BA9BF87</xmpMM:InstanceID><xmpMM:ManagerVariant xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">C409EB69-9E0A-486A-8616-6946B07710DD</xmpMM:ManagerVariant><xmpMM:Manager xmlns:xmpMM=\"http://ns.adobe.com/xap/1.0/mm/\">Brightech MediaBeacon 3.0</xmpMM:Manager><mbmm:format xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">Graphics:TIFF</mbmm:format><mb:file_creation_date xmlns:mb=\"http://brightech.com/ns/mb\">2017-09-07T13:07:31Z</mb:file_creation_date><mbmm:uploadUser xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">root</mbmm:uploadUser><mbmm:storageSyncDate xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\">2017-10-12T16:05:24.811-05:00</mbmm:storageSyncDate><exif:ColorSpace xmlns:exif=\"http://ns.adobe.com/exif/1.0/\">SRGB</exif:ColorSpace><mb:preview_modified_date xmlns:mb=\"http://brightech.com/ns/mb\">2017-10-12 16:05:24.809</mb:preview_modified_date><mbmm:colorprofile xmlns:mbmm=\"http://mediabeacon.com/ns/default/1.0/\"><rdf:Bag><rdf:li>438CCB</rdf:li><rdf:li>5574B9</rdf:li><rdf:li>598627</rdf:li><rdf:li>6ECFF7</rdf:li><rdf:li>754C24</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>8C6239</rdf:li><rdf:li>9D0A0F</rdf:li><rdf:li>A0410D</rdf:li><rdf:li>A36109</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>A57C52</rdf:li><rdf:li>F26522</rdf:li><rdf:li>F26C4E</rdf:li><rdf:li>F26D7C</rdf:li><rdf:li>F68D56</rdf:li><rdf:li>F7977A</rdf:li><rdf:li>FAAE5D</rdf:li></rdf:Bag></mbmm:colorprofile><mb:rotate xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:rotate><mb:video_status xmlns:mb=\"http://brightech.com/ns/mb\">-1</mb:video_status><mb:duration xmlns:mb=\"http://brightech.com/ns/mb\">-1</mb:duration><mb:file_type2 xmlns:mb=\"http://brightech.com/ns/mb\">TIFF</mb:file_type2><mb:bundle_flag xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:bundle_flag><mb:file_type xmlns:mb=\"http://brightech.com/ns/mb\">10</mb:file_type><mb:last_post xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:last_post><mb:version_of xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:version_of><mb:date_entered xmlns:mb=\"http://brightech.com/ns/mb\">2017-09-07T00:00:00.000-05:00</mb:date_entered><mb:orig_y xmlns:mb=\"http://brightech.com/ns/mb\">1480</mb:orig_y><mb:directory_id xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:directory_id><mb:orig_x xmlns:mb=\"http://brightech.com/ns/mb\">2292</mb:orig_x><mb:checkout xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:checkout><mb:needs_xmp_auto xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:needs_xmp_auto><mb:viewex_y xmlns:mb=\"http://brightech.com/ns/mb\">331</mb:viewex_y><mb:page_count xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:page_count><mb:viewex_x xmlns:mb=\"http://brightech.com/ns/mb\">512</mb:viewex_x><mb:xmp_volatile xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:xmp_volatile><mb:caches_ok xmlns:mb=\"http://brightech.com/ns/mb\">14</mb:caches_ok><mb:file_name xmlns:mb=\"http://brightech.com/ns/mb\">opo0006_orig.tif</mb:file_name><mb:zoom xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:zoom><mb:mb_id xmlns:mb=\"http://brightech.com/ns/mb\">BDECD-A000E-0D52B-6BF87-28FE5-4EC95</mb:mb_id><mb:high_x xmlns:mb=\"http://brightech.com/ns/mb\">1920</mb:high_x><mb:high_y xmlns:mb=\"http://brightech.com/ns/mb\">1240</mb:high_y><mb:file_size xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:file_size><mb:discussion_count xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:discussion_count><mb:record_id xmlns:mb=\"http://brightech.com/ns/mb\">201624287</mb:record_id><mb:file_date_modified xmlns:mb=\"http://brightech.com/ns/mb\">1506954271000</mb:file_date_modified><mb:view_sched xmlns:mb=\"http://brightech.com/ns/mb\">0</mb:view_sched><mb:usermodified xmlns:mb=\"http://brightech.com/ns/mb\">1</mb:usermodified><mb:thumbnails_x xmlns:mb=\"http://brightech.com/ns/mb\">118</mb:thumbnails_x><mb:thumbnails_y xmlns:mb=\"http://brightech.com/ns/mb\">76</mb:thumbnails_y><mb:dimensions xmlns:mb=\"http://brightech.com/ns/mb\">2292x1480 (.79inx.9in),479dpi</mb:dimensions><mb:discussion xmlns:mb=\"http://brightech.com/ns/mb\"><rdf:Seq><rdf:li rdf:parseType=\"Resource\"><mb:user>root</mb:user><mb:uid>A69D9135-4076-03F7-4D48-56AED2C3110F</mb:uid><mb:globalAdminEdited>false</mb:globalAdminEdited><mb:text>Message in the discussion</mb:text><mb:date>Thu, 12 Oct 2017 15:59:07 -0500</mb:date><mb:dateEdited>Thu, 12 Oct 2017 15:59:07 -0500</mb:dateEdited><mb:page>1</mb:page><mb:endTime>-1.0</mb:endTime><mb:startTime>-1.0</mb:startTime></rdf:li><rdf:li rdf:parseType=\"Resource\"><mb:user>root</mb:user><mb:uid>19CFCB3A-DA75-9955-A3DC-738A686CB</mb:uid><mb:globalAdminEdited>false</mb:globalAdminEdited><mb:text>Second message</mb:text><mb:date>Thu, 12 Oct 2017 15:59:20 -0500</mb:date><mb:dateEdited>Thu, 12 Oct 2017 15:59:20 -0500</mb:dateEdited><mb:page>1</mb:page><mb:endTime>-1.0</mb:endTime><mb:startTime>-1.0</mb:startTime></rdf:li></rdf:Seq></mb:discussion></rdf:Description></rdf:RDF>\n</x:xmpmeta><?xpacket end='w'?>\n",
 56 	   "id": 201624287,
 57 	   "name": "opo0006_orig.tif",
 58 	   "path": "hubble/opo0006_orig.tif",
 59 	   "height": 1480,
 60 	   "width": 2292,
 61 	   "bytes": 10180918,
 62 	   "lastModified": 1506954271000,
 63 	   "mimeType": "image/tiff",
 64 	   "previews": {
 65 		 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323837",
 66 		 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323837",
 67 		 "downloadUrl": "../servlet/dload?id=pe_323031363234323837"
 68 	   }
 69 	 }
 70  ]</xmp>
 71  */
 72 function main() {
 73   if (!context.getUser().isGlobalAdmin()) {
 74     REST.pushError(REST.errors.e403, "Global Admin User Required");
 75     return REST.execute();
 76   }
 77   REST.setCallback(setXmp);
 78   return REST.execute("data");
 79 }
 80 main();
 81