Running an All-In-One Operation (Using JSON)
Problem
You want to run an All-In-One operation to generate either a data set, content set or printed output using one the following input combinations:
Data Mapping Only |
Data File + Data Mapping Configuration |
Data Set |
Data Mapping + Content Creation |
Data File + Data Mapping Configuration + Design Template |
Content Set(s) |
Content Creation Only |
Data Records + Design Template |
Content Set(s) |
Data Mapping + Content Creation + Job Creation |
Data File + Data Mapping Configuration + Design Template |
Job Set |
Content Creation + Job Creation |
Data Records + Design Template |
Job Set |
Content Creation + Job Creation + Output Creation |
Data Records + Design Template + Output Creation Preset |
Printed Output |
Output Creation Only |
Jobs + Output Creation Preset |
Printed Output |
Data Mapping + Content Creation + Job Creation + Output Creation |
Data File + Data Mapping Configuration + Design Template + Output Creation Preset |
Printed Output |
Data Mapping + Content Creation + Job Creation + Output Creation |
Data File + Data Mapping Configuration + Design Template + Job Creation Preset + Output Creation Preset |
Printed Output |
Solution
The solution is to make a series of requests using the following URIs and method types to submit, monitor progress and ultimately retrieve the result of the All-In-One operation. There is also the option of cancelling an operation during processing if required. These requests can be submitted via the All-In-One REST service:
Example
HTML5
aio-process-json.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Process All-In-One (JSON) Example</title>
<script src="../../common/lib/js/jquery-1.11.3.min.js"></script>
<script src="../../common/js/common.js"></script>
<script src="js/aio-process-json.js"></script>
<link rel="stylesheet" href="../../common/css/styles.css">
</head>
<body>
<h2>All-In-One Service - Process All-In-One (JSON) Example</h2>
<form>
<fieldset id="inputs">
<legend>Inputs</legend>
<div>
<label for="datamining">Data Mapping:</label>
<input id="datamining" type="checkbox">
</div>
<div>
<label for="contentcreation">Content Creation:</label>
<input id="contentcreation" type="checkbox">
</div>
<div>
<label for="jobcreation">Job Creation:</label>
<input id="jobcreation" type="checkbox">
</div>
<div>
<label for="outputcreation">Output Creation:</label>
<input id="outputcreation" type="checkbox">
</div>
</fieldset>
<fieldset id="datamining-inputs" disabled>
<legend>Data Mapping</legend>
<div>
<label for="datafile">Data File ID/Name:</label>
<input id="datafile" type="text" placeholder="1234 or Filename" required>
</div>
<div>
<label for="datamapper">Data Mapping Configuration ID/Name:</label>
<input id="datamapper" type="text" placeholder="1234 or Filename" required>
</div>
</fieldset>
<fieldset id="contentcreation-inputs" disabled>
<legend>Content Creation</legend>
<div>
<label for="datarecords">Data Record ID(s):</label>
<input id="datarecords" type="text" placeholder="1234, 2345, 3456, ..." required>
</div>
<div>
<label for="designtemplate">Design Template ID/Name:</label>
<input id="designtemplate" type="text" placeholder="1234 or Filename" required>
</div>
</fieldset>
<fieldset id="jobcreation-inputs" disabled>
<legend>Job Creation</legend>
<div>
<label for="jcpreset">Job Creation Preset ID/Name:</label>
<input id="jcpreset" type="text" placeholder="1234 or Filename" disabled>
</div>
</fieldset>
<fieldset id="outputcreation-inputs" disabled>
<legend>Output Creation</legend>
<div>
<label for="jobs">Job ID(s):</label>
<input id="jobs" type="text" placeholder="1234, 2345, 3456, ..." required>
</div>
<div>
<label for="ocpreset">Output Creation Preset ID/Name:</label>
<input id="ocpreset" type="text" placeholder="1234 or Filename" required>
</div>
</fieldset>
<fieldset>
<legend>Options</legend>
<div>
<label for="createonly">Create Only:</label>
<input id="createonly" type="checkbox" disabled>
</div>
<div>
<label for="resultstxt">Get Results as Text:</label>
<input id="resultstxt" type="checkbox" disabled>
</div>
<div>
<label for="printrange">Print Range:</label>
<input id="printrange" type="text" placeholder="1, 2, 3-5, 6" disabled>
</div>
</fieldset>
<fieldset>
<legend>Progress & Actions</legend>
<div>
<progress value="0" max="100"></progress>
</div>
<div>
<input id="cancel" type="button" value="Cancel" disabled>
<input id="submit" type="submit" value="Submit">
</div>
</fieldset>
</form>
</body>
</html>
JavaScript/jQuery
aio-process-json.js
/* All-In-One Service - Process All-In-One (JSON) Example */
(function ($) {
"use strict";
$(document).ready(function () {
setupExample();
var $form = $("form"),
$inputs = $("#inputs input"),
$datafile = $("#datafile"),
$datamapper = $("#datamapper"),
$datarecords = $("#datarecords"),
$template = $("#designtemplate"),
$jcpreset = $("#jcpreset"),
$jobs = $("#jobs"),
$ocpreset = $("#ocpreset"),
$createonly = $("#createonly"),
$resultstxt = $("#resultstxt"),
$printrange = $("#printrange"),
AIOConfig = null,
outputDesc = null,
operationId = null,
$submitButton = $("#submit"),
$cancelButton = $("#cancel"),
$progressBar = $("progress");
$cancelButton.on("click", function () {
if (operationId !== null) {
/* Cancel an Operation */
$.ajax({
type: "POST",
url: "/rest/serverengine/workflow/print/cancel/" + operationId
}).done(function (response) {
displayInfo("Operation Cancelled!");
operationId = null;
setTimeout(function () {
$progressBar.attr("value", 0);
$submitButton.removeAttr("disabled");
$cancelButton.attr("disabled", "disabled");
}, 100);
}).fail(displayDefaultFailure);
}
});
/**
* @function generateAIOConfig
* @description Validates the workflow selected by the user
* and constructs and an All-In-One Configuration using the relevant
* input fields in the HTML Form.
* Any invalid inputs or workflow selections will be red-flagged in
* the HTML Form. Null can also be returned if no workflow selections
* are made or if the workflow selections made are of an invalid sequence.
* @private
* @returns {Object} The All-In-One Configuration Object or Null
*/
function generateAIOConfig() {
var config = {},
required = [],
i = null,
/* Parse Input Value to JSON Identifier List (Helper Function) */
jsonIDListValue = function ($input) {
return (plainIDListToJson($input.val())).identifiers;
},
/* Parse Input Value to Boolean (Helper Function) */
booleanValue = function ($input) {
return $input.is(":checked");
};
/* Get Input Value and add it to the Configuration (Helper Function) */
function getInputValue($input, process, field, parser) {
var value = $input.val();
if (value !== "") {
if (parser) {
value = parser($input);
}
if (config[process] === undefined) {
config[process] = {};
}
config[process][field] = value;
}
}
/* Get Required & Actual Workflow Selections */
$inputs.each(function () {
if ($(this).prop("checked")) {
config[this.id] = {};
}
$(this).removeAttr("required");
required.push(this.id);
});
var selections = (Object.keys(config)).length;
/* Verify the Workflow Selections and note any omissions */
var matches = 0,
missing = [];
for (i = 0; i < required.length; i += 1) {
var step = required[i];
if (config[step]) {
if (!matches && step === "jobcreation") {
missing.push("contentcreation");
}
matches += 1;
} else {
if (matches !== 0) {
missing.push(step);
}
}
if (matches === selections) {
break;
}
}
/* Add the inputs to the Workflow Selections to Create the All-In-One Configuration */
if (config.datamining) {
getInputValue($datafile, "datamining", "identifier");
getInputValue($datamapper, "datamining", "config");
outputDesc = "Data Set ID";
}
if (config.contentcreation) {
getInputValue($template, "contentcreation", "config");
if (!config.datamining) {
getInputValue($datarecords, "contentcreation", "identifiers", jsonIDListValue);
$datarecords.removeAttr("disabled");
} else {
$datarecords.attr("disabled", "disabled");
}
outputDesc = "Content Set ID(s)";
}
if (config.jobcreation) {
outputDesc = "Job Set ID";
}
if (config.outputcreation) {
getInputValue($ocpreset, "outputcreation", "config");
getInputValue($createonly, "outputcreation", "createOnly", booleanValue);
if (!config.contentcreation) {
getInputValue($jobs, "outputcreation", "identifiers", jsonIDListValue);
$jobs.removeAttr("disabled");
} else {
$jobs.attr("disabled", "disabled");
}
$createonly.removeAttr("disabled");
$resultstxt.removeAttr("disabled");
outputDesc = "Output";
} else {
$createonly.attr("disabled", "disabled");
$resultstxt.attr("disabled", "disabled");
if (!$resultstxt.is(":checked")) { $resultstxt.prop("checked", true); }
}
if (config.datamining && config.contentcreation &&
config.jobcreation && config.outputcreation) {
getInputValue($jcpreset, "jobcreation", "config");
getInputValue($printrange, "printRange", "printRange");
$jcpreset.removeAttr("disabled");
$printrange.removeAttr("disabled");
} else {
$jcpreset.attr("disabled", "disabled");
$printrange.attr("disabled", "disabled");
}
/* Red-flag any omissions in Workflow Selections */
if (!selections || missing.length) {
for (i = 0; i < missing.length; i += 1) {
$("#" + missing[i]).attr("required", "required");
}
return null;
}
return config;
}
$inputs.on("change", function (event) {
var input = event.target;
var process = $("#" + input.id + "-inputs");
if ($(input).prop("checked")) {
process.removeAttr("disabled");
} else {
process.attr("disabled", "disabled");
}
}).trigger("change");
$form.on("change", function (event) {
AIOConfig = generateAIOConfig();
}).trigger("change");
$form.on("submit", function (event) {
event.preventDefault();
if (!checkSessionValid()) { return; }
if (!AIOConfig) {
alert("Invalid All-In-One Configuration!\n\nPlease enter a valid " +
"combination of input fields, and try again.");
return;
}
var getFinalResult = function () {
var results = ($resultstxt.is(":checked")) ? "getResultTxt" : "getResult";
/* Get Result of Operation */
$.ajax({
type: "POST",
url: "/rest/serverengine/workflow/print/" + results + "/" + operationId
}).done(function (response, status, request) {
if (request.getResponseHeader("Content-Type") === "application/octet-stream") {
response = "<<OCTET-STREAM FILE DATA>>";
}
displayHeading("Operation Result");
displaySubResult(outputDesc, response);
}).fail(displayDefaultFailure);
};
/* Process All-In-One (JSON) */
$.ajax({
type: "POST",
url: "/rest/serverengine/workflow/print/submit",
data: JSON.stringify(AIOConfig),
contentType: "application/json"
}).done(function (response, status, request) {
var progress = null;
operationId = request.getResponseHeader("operationId");
$submitButton.attr("disabled", "disabled");
$cancelButton.removeAttr("disabled");
displayStatus("All-In-One Operation Successfully Submitted");
displayHeading("Input Configuration");
displaySubResult("JSON All-In-One Configuration", jsonPrettyPrint(AIOConfig));
displayResult("Operation ID", operationId);
var getProgress = function () {
if (operationId !== null) {
/* Get Progress of Operation */
$.ajax({
type: "GET",
cache: false,
url: "/rest/serverengine/workflow/print/getProgress/" + operationId
}).done(function (response, status, request) {
if (response !== "done") {
if (response !== progress) {
progress = response;
$progressBar.attr("value", progress);
}
setTimeout(getProgress, 1000);
} else {
$progressBar.attr("value", (progress = 100));
displayInfo("Operation Completed");
getFinalResult();
operationId = null;
setTimeout(function () {
$progressBar.attr("value", 0);
$submitButton.removeAttr("disabled");
$cancelButton.attr("disabled", "disabled");
}, 100);
}
}).fail(displayDefaultFailure);
}
};
getProgress();
}).fail(displayDefaultFailure);
});
});
}(jQuery));
Screenshot & Output
Usage
To run the example simply select the input combination of your choosing, populate the appropriate input fields and then check any options that you may require.
The following file based input fields can be referenced by Managed File ID or Name:
- Data file
- Data Mapping configuration
- Design template
- Job Creation preset
- Output Creation preset
The following options are only available if the input combination includes an output creation step:
- Create Only - Create the output in server but do not send spool file to its final destination. In this example this would mean that the output files(s) would not be sent to the output directory specified in the output creation preset.
- Get Results as Text - Return the result as text specifically. If our All-In-One Configuration includes an output creation step, then in this example this would return the absolute path to the output file(s).
- Print Range - Restrict the printed output to a specific range of records in the input data, not a specific range of pages (requires combination with all workflow steps).
Lastly, select the Submit button to start the All-In-One operation.
Once the operation has started processing, the JSON All-In-One Configuration along with the Operation ID will be displayed in the Results area and the Cancel button will become enabled, giving you the option to cancel the running operation.
The progress of the operation will be displayed in the progress bar, and once the All-in-One operation has completed, the result will be returned and displayed to the Results area.
If the All-In-One configuration includes a output creation step, then the result returned will be the output files (either their absolute path(s) or the output file itself). If the configuration does not include an output creation step, then the result returned will be either a Data Set ID, Content Set IDs or Job Set ID.
If the result returned is expected to be file data, then the value <<OCTET-STREAM FILE DATA>> will be displayed.
Further Reading
See the All-In-One Service page of the REST API Reference section for further detail.
|
|