Submit Print Job via GCP Service (Single)
Prints a file specified by a File-type Data Item with a specified printer, and stores its communication log in a String-type data item.
2016 © Questetra, Inc. (MIT License)
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • B: Set Printer ID *
  • C: Select FILE DATA for Print *
  • D: Select STRING/SELECT for Cloud Job Ticket
  • X: Select STRING DATA for Access Log (update)
Script
//// == 工程コンフィグの参照 / Config Retrieving ==
var oauth2 = configs.get( "conf_OAuth2" );
var printerId = configs.get( "conf_DataIdB" ) + "";
var dataIdC = configs.get( "conf_DataIdC" ); // (returns Number)
var dataIdD = configs.get( "conf_DataIdD" ); // (returns Number)
var dataIdX = configs.get( "conf_DataIdX" ) + ""; // (returns Number)

//// == ワークフローデータの参照 / Data Retrieving ==
var files = data.get( dataIdC );
var cloudJobTicket = "";
if( data.get( dataIdD ) instanceof java.util.ArrayList ){
  cloudJobTicket = data.get( dataIdD ).get(0).getValue() + "";
}else if( data.get( dataIdD ) instanceof java.lang.String ){
  cloudJobTicket = data.get( dataIdD ) + "";
}
if( cloudJobTicket === "" ){
  cloudJobTicket = '{"version": "1.0", "print": {}}';
}
var jobTitle = "Questetra-" + processInstance.getProcessInstanceId() + "";

//// == 演算 / Calculating ==
var accessLog = "";
var token = httpClient.getOAuth2Token( oauth2 );

for( var i = 0; i < files.size(); i++  ){
  var uri = "https://www.google.com/cloudprint/submit";
  var response = httpClient.begin()
    .bearer( token )
    .multipart( "printerid", printerId )
    .multipart( "title", jobTitle )
    .multipart( "ticket", cloudJobTicket )
    .multipart( "content", files.get(i) )
    .post( uri );
  accessLog += "---POST request--- " + response.getStatusCode() + "\n";
  accessLog += response.getResponseAsString() + "\n";
}

//// == ワークフローデータへの代入 / Data Updating ==
if( dataIdX !== "" ){
  retVal.put( dataIdX, accessLog );
}

Download

Capture

Notes

  • It is necessary to register OAuth2 Communication in the Google API Manager in advance
  • If a Cloud Job Ticket isn’t specified, they will be printed out in the standard settings of the printer {“version”: “1.0”, “print”: {}}
  • B&W 2 copies: {“version”:”1.0″,”print”:{“vendor_ticket_item”: [],”color”:{“type”: “STANDARD_MONOCHROME”}, “copies”: {“copies”: 2}}}
  • Single version specifies Printer ID in the automated step config

See also

%d bloggers like this: