1 /**
  2  * @name Fields
  3  * @class Shows the field definitions in MediaBeacon
  4  * @description Displays all of the field definitions in MediaBeacon with their name mappings
  5  * based on user's view level and all visible forms in the valid ACLs of the user's groups.
  6  * <br><br><b>Note:</b>
  7  * To retrieve all fields, use an API key that is linked to an account that belongs to a group with a high view level
  8  * and has an ACL with all the fields within visible forms.
  9  * @returns {
 10 			  fieldId: string;
 11 			  name: string;
 12 			  type: string;
 13 			  namespace: string;
 14 			  mapped_namespace: string;
 15 			  mapped_name: string;
 16 			  is_container: boolean
 17 			}
 18  * @example /wf/restapi/v2/fields
 19  *
 20  * Parameters:
 21  *
 22  Response:
 23  [
 24  {
 25     "fieldId": "http://purl.org/dc/elements/1.1/ subject",
 26     "name": "subject",
 27     "type": "list_string",
 28     "namespace": "http://purl.org/dc/elements/1.1/",
 29     "mapped_namespace": "Dublin Core Properties",
 30     "mapped_name": "Keywords",
 31     "is_container": true
 32   },
 33  {
 34     "fieldId": "http://purl.org/dc/elements/1.1/ title",
 35     "name": "title",
 36     "type": "string",
 37     "namespace": "http://purl.org/dc/elements/1.1/",
 38     "mapped_namespace": "Dublin Core Properties",
 39     "mapped_name": "Title",
 40     "is_container": false
 41   },
 42  {
 43     "fieldId": "http://purl.org/dc/elements/1.1/ type",
 44     "name": "type",
 45     "type": "list_string",
 46     "namespace": "http://purl.org/dc/elements/1.1/",
 47     "mapped_namespace": "Dublin Core Properties",
 48     "mapped_name": "Document Type",
 49     "is_container": true
 50   },...
 51  ]
 52 
 53  */
 54 var REST = library.REST.REST();
 55 
 56 var kDBFields = [
 57   { name: "record_id", mapped_name: "Asset ID" },
 58   { name: "file_name", mapped_name: "File Name" },
 59   { name: "directory", mapped_name: "Directory" },
 60   //TODO not sure the below fields make sense.
 61   //We would need to modify
 62   //{"name": "width", "mapped_name": "Width"},
 63   //{"name": "height", "mapped_name": "Height"},
 64   //{"name": "resolution", "mapped_name": "Resolution"},
 65   //{"name": "colorspace", "mapped_name": "Colorspace"},
 66   //{"name": "colorprofile", "mapped_name": "Colorprofile"}
 67 ];
 68 
 69 function getDBFields() {
 70   var aDBFields = [];
 71   for (var i in kDBFields) {
 72     var aField = kDBFields[i];
 73     var anObj = {
 74       fieldId: "database " + aField.name,
 75       name: aField.name,
 76       type: "string",
 77       namespace: "database",
 78       mapped_namespace: "Database",
 79       mapped_name: aField.mapped_name,
 80       is_container: false,
 81       include_readonly: true,
 82     };
 83     aDBFields[aDBFields.length] = anObj;
 84   }
 85   return aDBFields;
 86 }
 87 
 88 (function main() {
 89   try {
 90     var fields = fieldManager.getAllFields();
 91     var objs = [];
 92     for (var i = 0; i < fields.length; i++) {
 93       var field = fields[i];
 94       var obj = {};
 95       obj["fieldId"] = field.fieldId;
 96       obj["name"] = field.name;
 97       obj["type"] = field.getFieldType();
 98       obj["namespace"] = field.namespace;
 99       obj["mapped_namespace"] = field.mappedNamespace;
100       obj["mapped_name"] = field.mappedName;
101       obj["is_container"] = field.isContainer();
102       objs.push(obj);
103     }
104     return REST.formatResponse(objs.concat(getDBFields()));
105   } catch (e) {
106     logger.error("Error in getFields: \n " + e + "\n" + e.stack);
107     return e;
108   }
109 })();
110