1 /**
  2  * Workflow to return url of the contact sheet given a list of asset Id's using a REST call
  3  *
  4  */
  5 var REST = library.REST.REST();
  6 var myData = {};
  7 var myContactSheet;
  8 var myType;
  9 
 10 /**
 11  * uses assets ids from 'src' array from context or the resolver string given
 12  * @returns {*}
 13  */
 14 function getAssets(theAssetOrResolver) {
 15   if (isNaN(theAssetOrResolver)) {
 16     myContactSheet.addResolver(theAssetOrResolver);
 17   } else {
 18     myContactSheet.addAsset(theAssetOrResolver);
 19   }
 20 }
 21 /**
 22  * Adds Uri's to the contact sheet url(and specific fields if Summary contact sheet
 23  *
 24  * @returns {*}
 25  */
 26 function configureSchemaOrSummary(theType) {
 27   var aSchema = REST.getParameter("schema", true);
 28   aSchema = REST.toArray(aSchema);
 29 
 30   if (theType == "schema") {
 31     for (var i = 0; i < aSchema.length; i++) {
 32       myContactSheet.addSchema(aSchema[i]);
 33     }
 34   } else {
 35     var aField = REST.getParameter("field", true);
 36     aField = REST.toArray(aField);
 37 
 38     if (getAssets.length != aSchema.length) {
 39       REST.submitError("format", "field count and schema count do not equal");
 40       return;
 41     } else {
 42       for (var i = 0; i < aField.length; i++) {
 43         myContactSheet.addSummaryField(aSchema[i], aField[i]);
 44       }
 45     }
 46   }
 47 }
 48 
 49 function configureOptions(
 50   theTitle,
 51   theDescription,
 52   theHighRes,
 53   theBarcode,
 54   theType
 55 ) {
 56   myContactSheet = new ContactSheet(theTitle, theDescription, theType);
 57   myContactSheet.setIpAndPort(context.getBaseUrl());
 58   if (theHighRes == true) {
 59     myContactSheet.enableHighRes();
 60   }
 61   if (theBarcode == true) {
 62     myContactSheet.enableBarcode();
 63   }
 64   configureSchemaOrSummary(theType);
 65 }
 66 
 67 /**
 68  * Creates a contact sheet and returns the contact sheet's URL.
 69  * @description  Configures and creates a custom contact sheet based on the parameters provided. The contact sheet URL
 70  * is parsed into a text object keyed by AssetID from the JSON file in which they are contained, and by default are
 71  * displayed to the user.
 72  * @example 'MBurl'/wf/restapi/1/generateContactSheet?src=['AssetID']&title='Title of Contact Sheet'&description='Description of Contact Sheet'&hires='true'&barcode='true'&type='Summary'&schema='Schema Title'&field='Field Name'
 73  * @example <a target="_blank" href='http://127.0.0.1:55555/wf/restapi/1/generateContactSheet?src=["12345"]&title="Title of Contact Sheet"&description="Description of Contact Sheet"&hires="true"&barcode="true"&type="Summary"&schema="http://purl.org/dc/elements/1.1/"&field="subject"'>http://127.0.0.1:55555/wf/restapi/1/generateContactSheet?src=['12345']&title='Title of Contact Sheet'&description='Description of Contact Sheet'&hires='true'&barcode='true'&type='Summary'&schema='http://purl.org/dc/elements/1.1/'&field='subject'</a>
 74  * @class Creates a contact sheet and returns the contact sheet's URL.
 75  * @name GenerateContactSheet
 76  * @param src List of assetIDs.
 77  * @param title Title of contact sheet.
 78  * @param description Description of contact sheet.
 79  * @param hires High Resolution photos boolean flag selection.
 80  * @param barcode Barcode boolean flag selection.
 81  * @param type "Detail","Summary", or "Schema" selection.
 82  * @param schema URI of schema desired for "Summary" or "Schema" sheet types.
 83  * @param field Field name of desired field for Summary sheet type.
 84  * @returns ( {'AssetID': "Contact Sheet URL",...} )
 85  */
 86 function main() {
 87   var aParameters = REST.getParametersToIterate("src");
 88   var aTitle = REST.getParameter("title", false);
 89   var aDescription = REST.getParameter("description", false);
 90   var aHighRes = REST.getParameter("hires", false);
 91   var aBarcode = REST.getParameter("barcode", false);
 92   var aType = REST.getParameter("type", true);
 93   configureOptions(aTitle, aDescription, aHighRes, aBarcode, aType);
 94 
 95   if (myData.error != null) {
 96     return REST.formatResponse();
 97   }
 98   REST.iterateThroughParameters(aParameters, getAssets);
 99   try {
100     myData[aTitle] = myContactSheet.generateContactSheetUrl();
101   } catch (anE) {
102     REST.submitError(aTitle, "Failed to create ContactSheet: " + anE);
103   }
104   return REST.formatResponse();
105 }
106 main();
107