1 var REST = library.REST.REST();
  2 var myLimit;
  3 var myOrder;
  4 
  5 /**
  6  * Pushes the discussion data to the response
  7  */
  8 function getDiscussion(theManagedFile) {
  9   // Get the discussion.
 10   var aDiscussionSet = theManagedFile.xmp.meta.getField(
 11     new Property("http://brightech.com/ns/mb", "discussion")
 12   );
 13   REST.push(
 14     theManagedFile,
 15     { discussion: REST.formatDiscussionList(aDiscussionSet, myLimit, myOrder) },
 16     true
 17   );
 18 }
 19 
 20 /**
 21  * @name GetDiscussion
 22  * @class Collects the discussions for the assets.
 23  * @description Given a resolver URL or an array of Id's, this endpoint returns asset data for each asset as well as its discussion.
 24  * @param [ids] The asset id's.
 25  * @param [resolver] A resolver url.
 26  * @param [order="ASC"] display the discussion ascending "asc" or descending "DESC" order. "ASC" is chronological order.
 27  * @param [limit=no limit] the number of discussions to show for each asset.
 28  * @param [verbose=false] Setting this to true will collect a variety of default values for each asset.
 29  * @param [FILTERS] Filtering can be applied to the "id", "name", "path", "height", "width", "bytes", "lastModified", "mimeType", and "resolver" properties if verbose=true.
 30  * @param [fields] An array of field id's to collect the values for each asset
 31  * @returns [{assetInfo}, ... ]
 32  *
 33  * @example /wf/restapi/v2/getDiscussion
 34  *
 35  * Properties:
 36  * ids=[201624287,201624288]
 37  *
 38  * Response:
 39  [
 40 	 {
 41 	   "discussion": [
 42 		 {
 43 		   "date": "Thu, 12 Oct 2017 15:59:07 -0500",
 44 		   "endTime": "-1.0",
 45 		   "globalAdminEdited": "false",
 46 		   "startTime": "-1.0",
 47 		   "text": "Message in the discussion",
 48 		   "dateEdited": "Thu, 12 Oct 2017 15:59:07 -0500",
 49 		   "page": "1",
 50 		   "user": "root",
 51 		   "uid": "A69D9135-4076-03F7-4D48-56AED2C3110F"
 52 		 },
 53 		 {
 54 		   "date": "Thu, 12 Oct 2017 15:59:20 -0500",
 55 		   "endTime": "-1.0",
 56 		   "globalAdminEdited": "false",
 57 		   "startTime": "-1.0",
 58 		   "text": "Second message",
 59 		   "dateEdited": "Thu, 12 Oct 2017 15:59:20 -0500",
 60 		   "page": "1",
 61 		   "user": "root",
 62 		   "uid": "19CFCB3A-DA75-9955-A3DC-738A686CB"
 63 		 }
 64 	   ],
 65 	   "id": 201624287
 66 	 },
 67 	 {
 68 	   "discussion": [
 69 		 {
 70 		   "date": "Thu, 12 Oct 2017 15:59:42 -0500",
 71 		   "endTime": "-1.0",
 72 		   "globalAdminEdited": "false",
 73 		   "startTime": "-1.0",
 74 		   "text": "New Discussion",
 75 		   "dateEdited": "Thu, 12 Oct 2017 15:59:42 -0500",
 76 		   "page": "1",
 77 		   "user": "root",
 78 		   "uid": "9F1DBF1C-992B-B2B3-A0DA-F1EE2C8AE9EA"
 79 		 }
 80 	   ],
 81 	   "id": 201624288
 82 	 }
 83  ]
 84  * @example /wf/restapi/v2/getDiscussion
 85  *
 86  * Properties:
 87  * ids=[201624287]
 88  * verbose=true
 89  *
 90  * Response:
 91  [
 92 	 {
 93 	   "discussion": [
 94 		 {
 95 		   "date": "Thu, 12 Oct 2017 15:59:07 -0500",
 96 		   "endTime": "-1.0",
 97 		   "globalAdminEdited": "false",
 98 		   "startTime": "-1.0",
 99 		   "text": "Message in the discussion",
100 		   "dateEdited": "Thu, 12 Oct 2017 15:59:07 -0500",
101 		   "page": "1",
102 		   "user": "root",
103 		   "uid": "A69D9135-4076-03F7-4D48-56AED2C3110F"
104 		 },
105 		 {
106 		   "date": "Thu, 12 Oct 2017 15:59:20 -0500",
107 		   "endTime": "-1.0",
108 		   "globalAdminEdited": "false",
109 		   "startTime": "-1.0",
110 		   "text": "Second message",
111 		   "dateEdited": "Thu, 12 Oct 2017 15:59:20 -0500",
112 		   "page": "1",
113 		   "user": "root",
114 		   "uid": "19CFCB3A-DA75-9955-A3DC-738A686CB"
115 		 }
116 	   ],
117 	   "id": 201624287,
118 	   "name": "opo0006_orig.tif",
119 	   "path": "hubble/opo0006_orig.tif",
120 	   "height": 1480,
121 	   "width": 2292,
122 	   "bytes": 10180918,
123 	   "lastModified": 1506954271000,
124 	   "mimeType": "image/tiff",
125 	   "previews": {
126 		 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323837",
127 		 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323837",
128 		 "downloadUrl": "../servlet/dload?id=pe_323031363234323837"
129 	   }
130 	 }
131  ]
132 
133  * @example /wf/restapi/v2/getDiscussion
134  *
135  * Properties:
136  * ids=[201624287]
137  * order=ASC
138  * limit=1
139  *
140  * Response:
141  [
142 	 {
143 	   "discussion": [
144 		 {
145 		   "date": "Thu, 12 Oct 2017 15:59:07 -0500",
146 		   "endTime": "-1.0",
147 		   "globalAdminEdited": "false",
148 		   "startTime": "-1.0",
149 		   "text": "Message in the discussion",
150 		   "dateEdited": "Thu, 12 Oct 2017 15:59:07 -0500",
151 		   "page": "1",
152 		   "user": "root",
153 		   "uid": "A69D9135-4076-03F7-4D48-56AED2C3110F"
154 		 }
155 	   ],
156 	   "id": 201624287
157 	 }
158  ]
159 
160  * @example /wf/restapi/v2/getDiscussion
161  *
162  * Properties:
163  * ids=[201624287,201624288]
164  * order=DESC
165  * limit=1
166  *
167  * Response:
168  [
169 	 {
170 	   "discussion": [
171 		 {
172 		   "date": "Thu, 12 Oct 2017 15:59:20 -0500",
173 		   "endTime": "-1.0",
174 		   "globalAdminEdited": "false",
175 		   "startTime": "-1.0",
176 		   "text": "Second message",
177 		   "dateEdited": "Thu, 12 Oct 2017 15:59:20 -0500",
178 		   "page": "1",
179 		   "user": "root",
180 		   "uid": "19CFCB3A-DA75-9955-A3DC-738A686CB"
181 		 }
182 	   ],
183 	   "id": 201624287
184 	 }
185  ]
186  */
187 function main() {
188   myOrder = context.getParameter("order"); //'desc' or 'asc'
189   myOrder = !!myOrder ? myOrder.toLowerCase() : null; //normalize string
190   myLimit = context.getParameter("limit"); //# of discussions to show per asset
191   REST.setCallback(getDiscussion);
192   return REST.execute();
193 }
194 main();
195