1 /**
  2  * Workflow to return information about dictionaries.
  3  *
  4  */
  5 var REST = library.REST.REST();
  6 
  7 /**
  8  * Gets a dictionary and a list of words and put them into myData.
  9  *
 10  * @param theDictionaryName
 11  */
 12 function getDictionary() {
 13   // How many words should we return?  (Default:  1000)
 14   var aWordLimit = context.getParameter("wordLimit", 1000);
 15 
 16   var aDictionaries = dictionaryManager.listDictionaryNames();
 17   for (var i in aDictionaries) {
 18     // Parse out the objects.
 19     var aDictionaryJSON = {
 20       name: aDictionaries[i],
 21     };
 22     if (REST.filterMatch(aDictionaryJSON)) {
 23       aDictionaryJSON.words = dictionaryManager.findWords(
 24         aDictionaries[i],
 25         "%",
 26         aWordLimit,
 27         false
 28       );
 29       REST.push(null, aDictionaryJSON);
 30     }
 31   }
 32 }
 33 
 34 /**
 35  * @name Dictionary
 36  * @class Shows the dictionaries and their words
 37  * @description Displays the dictionaries defined in MediaBeacon and the words in each dictionary.  Filtering can be applied to the "name" parameter to limit the dictionaries returned
 38  * @param [FILTERS] Filtering can be applied to the "name" properties.
 39  * @param [wordLimit=1000] the number of words per dictionary to include in the response.
 40  * @returns [{"name":"theDictionaryName", "words":[anArray of dictionary words]}, ... ]
 41  * @example /wf/restapi/v2/dictionary
 42  *
 43  * Parameters: none
 44  *
 45  Response:
 46  [
 47 	 {
 48 	   "name": "Status:Approval",
 49 	   "words": [
 50 		 "Approved",
 51 		 "Pending",
 52 		 "Rejected"
 53 	   ]
 54 	 },
 55 	 {
 56 	   "name": "Status:General",
 57 	   "words": [
 58 		 "Approved",
 59 		 "Complete",
 60 		 "In Progress",
 61 		 "Not Allowed",
 62 		 "Not Started",
 63 		 "Pending",
 64 		 "Pending Legal Approval",
 65 		 "Pending License",
 66 		 "Pending Regional Approval",
 67 		 "Rejected",
 68 		 "To Do"
 69 	   ]
 70     }
 71     , all Dictionaries...
 72  ]
 73  * @example /wf/restapi/v2/dictionary
 74  *
 75  * Parameters:
 76  * name=Status:Approval
 77  *
 78  Response:
 79  [
 80 	 {
 81 	   "name": "Status:Approval",
 82 	   "words": [
 83 		 "Approved",
 84 		 "Pending",
 85 		 "Rejected"
 86 	   ]
 87 	 }
 88  ]
 89  * @example /wf/restapi/v2/dictionary
 90  *
 91  * Parameters:
 92  * name=Status:Approval
 93  * wordLimit=2
 94  *
 95  Response:
 96  [
 97 	 {
 98 	   "name": "Status:Approval",
 99 	   "words": [
100 		 "Approved",
101 		 "Pending"
102 	   ]
103 	 }
104  ]
105  * @example /wf/restapi/v2/dictionary
106  *
107  * Parameters:
108  * name=Status*
109  *
110  Response:
111  [
112 	 {
113 	   "name": "Status:Approval",
114 	   "words": [
115 		 "Approved",
116 		 "Pending",
117 		 "Rejected"
118 	   ]
119 	 },
120 	 {
121 	   "name": "Status:General",
122 	   "words": [
123 		 "Approved",
124 		 "Complete",
125 		 "In Progress",
126 		 "Not Allowed",
127 		 "Not Started",
128 		 "Pending",
129 		 "Pending Legal Approval",
130 		 "Pending License",
131 		 "Pending Regional Approval",
132 		 "Rejected",
133 		 "To Do"
134 	   ]
135 	 }
136  ]
137  */
138 function main() {
139   REST.setCallback(getDictionary);
140   return REST.execute();
141 }
142 main();
143