Finding Specific Data Entities in the Server

Problem

You want to find specific Data Entities stored within the PReS Connect Server based on a set of search criteria.

Solution

The solution is to create a request using the following URI and method type and submit it to the server via the Entity REST service:

Find Data Entity /rest/serverengine/entity/find PUT

Example

HTML5

e-find-data-entity.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Find Data Entity Example</title>
        <script src="../../common/lib/js/jquery-3.4.1.min.js"></script>
        <script src="../../common/js/common.js"></script>
        <script src="js/e-find-data-entity.js"></script>
        <link rel="stylesheet" href="../../common/css/styles.css">
        <link rel="stylesheet" href="css/styles.css">
    </head>
    <body>
        <h2>Entity Service - Find Data Entity Example</h2>
        <form>
            <fieldset>
                <legend>Search Parameters</legend>
                <div>
                    <label for="entity">Entity Type:</label>
                    <select id="entity">
                        <option value="DATARECORDS">Data Records</option>
                        <option value="DATASETS">Data Sets</option>
                        <option value="CONTENTITEMS">Content Items</option>
                        <option value="CONTENTSETS">Content Sets</option>
                        <option value="JOBS">Jobs</option>
                        <option value="JOBSETS">Job Sets</option>
                    </select>
                </div>
            </fieldset>
            <fieldset id="search">
                <legend>Search Rules</legend>
                <div class="form-only">
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="NONE">No Rules</option>
                    </select>
                </div>
                <div id="RULESET" class="rule">
                    <label for="rule">Rules:</label>
                    <div id="rule" class="rule-body">
                        <div class="sub-rules">
                            <label>No Rules</label>
                        </div>
                        <div>
                            <label for="condition">Rules Condition:</label>
                            <select id="condition">
                                <option value="ALL">Match All Rules</option>
                                <option value="ANY">Match Any Rule</option>
                                <option value="NOTALL">Not Match All Rules</option>
                                <option value="NOTANY">Not Match Any Rule</option>
                            </select>
                        </div>
                        <div class="form-only">
                            <input id="add-rule" type="button" value="Add Search Rule">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset id="sorting">
                <legend>Sorting Rules</legend>
                <div class="form-only">
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="NONE">No Rules</option>
                    </select>
                </div>
                <div id="RULESET" class="rule">
                    <label for="rule">Rules:</label>
                    <div id="rule" class="rule-body">
                        <div class="sub-rules">
                            <label>No Rules</label>
                        </div>
                        <div class="form-only">
                            <input id="add-rule" type="button" value="Add Sorting Rule">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset id="grouping">
                <legend>Grouping Rules</legend>
                <div class="form-only">
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="NONE">No Rules</option>
                    </select>
                </div>
                <div id="RULESET" class="rule">
                    <label for="rule">Rules:</label>
                    <div id="rule" class="rule-body">
                        <div class="sub-rules">
                            <label>No Rules</label>
                        </div>
                        <div class="form-only">
                            <input id="add-rule" type="button" value="Add Grouping Rule">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <legend>Actions</legend>
                <div>
                    <input id="reset" type="button" value="Reset">
                    <input id="submit" type="submit" value="Submit">
                </div>
            </fieldset>
        </form>
    </body>
</html>

rules.html

<!-- OL Connect REST API Cookbook - Working Examples [Rules HTML Snippet] -->
<div id="search-rules" class="search">
    <div id="VALUE" class="rule entity-DATARECORDS entity-CONTENTITEMS">
        <label for="rule">Data Value Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="fieldName">Field Name:</label>
                <input id="fieldName" type="text" placeholder="Field Name" required />
            </div>
            <div class="form-only">
                <label for="fieldType">Field Type:</label>
                <select id="fieldType" class="options-selector">
                    <option value="string">String</option>
                    <option value="number">Number</option>
                    <option value="boolean">Boolean</option>
                    <option value="date">Date</option>
                </select>
            </div>
            <div class="option fieldType-string compareType- condition-">
                <label for="condition">Condition:</label>
                <select id="condition" class="options-selector" data-type="enum-condition-string"/>
            </div>
            <div class="option fieldType-number compareType- condition-">
                <label for="condition">Condition:</label>
                <select id="condition" class="options-selector" data-type="enum-condition-number"/>
            </div>
            <div class="option fieldType-date compareType- condition-">
                <label for="condition">Condition:</label>
                <select id="condition" class="options-selector" data-type="enum-condition-date"/>
            </div>
            <div class="option fieldType-boolean compareType- condition-">
                <label for="condition">Condition:</label>
                <select id="condition" class="options-selector" data-type="enum-condition-boolean"/>
            </div>
            <div class="form-only option fieldType-string fieldType-number fieldType-date compareType- condition-">
                <label for="compareType">Compare Type:</label>
                <select id="compareType" class="options-selector">
                    <option value="name">Field Name</option>
                    <option value="value" selected="selected">Field Value</option>
                </select>
            </div>
            <div class="form-only option fieldType-boolean compareType- condition-EQ condition-NE">
                <label for="compareType">Compare Type:</label>
                <select id="compareType" class="options-selector">
                    <option value="name">Field Name</option>
                    <option value="value" selected="selected">Field Value</option>
                </select>
            </div>
            <div class="option fieldType-string compareType-value condition-">
                <label for="value1">Value:</label>
                <input id="value1" type="text" placeholder="Value" required />
            </div>
            <div class="option fieldType-number compareType-value condition-">
                <label for="value1">Value:</label>
                <input id="value1" type="number" step="0.001" placeholder="Value" required />
            </div>
            <div class="option fieldType-boolean compareType-value condition-EQ condition-NE">
                <label for="value1">Value:</label>
                <input id="value1" type="checkbox" />
            </div>
            <div class="option fieldType-date compareType-value condition-">
                <label for="value1">Value:</label>
                <input id="value1" type="date" required />
            </div>
            <div class="option fieldType-date compareType-value condition-BETWEEN">
                <label for="value2">Value 2:</label>
                <input id="value2" type="date" required />
            </div>
            <div class="option fieldType-string fieldType-number fieldType-date compareType-name condition-">
                <label for="value1">Field Name:</label>
                <input id="value1" type="text" placeholder="Field Name" required />
            </div>
            <div class="option fieldType-boolean compareType-name condition-EQ condition-NE">
                <label for="value1">Field Name:</label>
                <input id="value1" type="text" placeholder="Field Name" required />
            </div>
            <div class="option fieldType-date compareType-name condition-BETWEEN">
                <label for="value2">Field Name 2:</label>
                <input id="value2" type="text" placeholder="Field Name" required />
            </div>
        </div>
    </div>
    <div id="PROPERTY" class="rule entity-">
        <label for="rule">Property Value Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="property">Property:</label>
                <input id="property" type="text" placeholder="Property" required />
            </div>
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-property"/>
            </div>
            <div class="option compareType- form-only entity-DATARECORDS entity-CONTENTITEMS">
                <label for="compareType">Compare Type:</label>
                <select id="compareType" class="options-selector">
                    <option value="name">Field Name</option>
                    <option value="value" selected="selected">Field Value</option>
                </select>
            </div>
            <div class="option compareType- form-only entity-DATASETS entity-CONTENTSETS entity-JOBS entity-JOBSETS">
                <label for="compareType">Compare Type:</label>
                <select id="compareType" class="options-selector">
                    <option value="value" selected="selected">Field Value</option>
                </select>
            </div>
            <div class="option compareType-value">
                <label for="value">Value:</label>
                <input id="value" type="text" placeholder="Value" required />
            </div>
            <div class="option compareType-name entity-DATARECORDS entity-CONTENTITEMS">
                <label for="value">Field Name:</label>
                <input id="value" type="text" placeholder="Field Name" required />
            </div>
        </div>
    </div>
    <div id="VALUEIN" class="rule entity-">
        <label for="rule">Value In Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="field">Field:</label>
                <input id="field" type="text" placeholder="Field" required />
            </div>
            <div class="option dataType- entity-DATASETS entity-CONTENTSETS entity-JOBS entity-JOBSETS">
                <label for="dataType">Data Type:</label>
                <select id="dataType" class="options-selector">
                    <option value="PROPERTY" selected="selected">Property</option>
                </select>
            </div>
            <div class="option dataType- entity-DATARECORDS entity-CONTENTITEMS">
                <label for="dataType">Data Type:</label>
                <select id="dataType" class="options-selector">
                    <option value="FIELD">Field</option>
                    <option value="PROPERTY" selected="selected">Property</option>
                </select>
            </div>
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-in"/>
            </div>
            <div>
                <label for="values">Values:</label>
                <input id="values" type="text" placeholder="Value1, Value2, Value3, ..." required />
            </div>
        </div>
    </div>
    <div id="IDIN" class="rule entity-">
        <label for="rule">ID In Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-in"/>
            </div>
            <div>
                <label for="values-number">Values:</label>
                <input id="values-number" type="text" placeholder="1234, 2345, 3456, ..." required />
            </div>
        </div>
    </div>
    <div id="DOCMEDIA" class="rule entity-CONTENTITEMS">
        <label for="rule">Document Media Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="attribute">Attribute:</label>
                <select id="attribute" class="options-selector">
                    <option value="NAME">Name</option>
                    <option value="FRONT_COATING">Front Coating</option>
                    <option value="BACK_COATING">Back Coating</option>
                </select>
            </div>
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-contains"/>
            </div>
            <div class="option attribute-NAME">
                <label for="name">Name:</label>
                <input id="name" type="text" placeholder="Name" required />
            </div>
            <div class="option attribute-FRONT_COATING attribute-BACK_COATING">
                <label for="coating">Coating:</label>
                <select id="coating" data-type="enum-coating"/>
            </div>
        </div>
    </div>
    <div id="DOCBINDING" class="rule entity-CONTENTITEMS">
        <label for="rule">Document Binding Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="attribute">Attribute:</label>
                <select id="attribute" class="options-selector">
                    <option value="STYLE">Style</option>
                    <option value="SIDE">Side</option>
                    <option value="LOCATION">Location</option>
                    <option value="ANGLE">Angle</option>
                </select>
            </div>
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-contains"/>
            </div>
            <div class="option attribute-STYLE">
                <label for="bindingStyle">Binding Style:</label>
                <select id="bindingStyle" data-type="enum-bindingstyle"/>
            </div>
            <div class="option attribute-SIDE">
                <label for="bindingEdge">Binding Edge:</label>
                <select id="bindingEdge" data-type="enum-bindingedge"/>
            </div>
            <div class="option attribute-LOCATION">
                <label for="bindingType">Binding Type:</label>
                <select id="bindingType" data-type="enum-bindingtype"/>
            </div>
            <div class="option attribute-ANGLE">
                <label for="bindingAngle">Binding Angle:</label>
                <select id="bindingAngle" data-type="enum-bindingangle"/>
            </div>
        </div>
    </div>
    <div id="DOCSIZE" class="rule entity-CONTENTITEMS">
        <label for="rule">Document Size Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="entity">Entity:</label>
                <select id="entity">
                    <option value="PAGE">Pages</option>
                    <option value="SHEET">Sheets</option>
                    <option value="SECTION">Sections</option>
                </select>
            </div>
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-number"/>
            </div>
            <div>
                <label for="value">Value:</label>
                <input id="value" type="number" step="1" placeholder="1234" required />
            </div>
        </div>
    </div>
    <div id="DUPLEX" class="rule entity-CONTENTITEMS">
        <label for="rule">Duplex Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-duplex"/>
            </div>
        </div>
    </div>
    <div id="TEMPLATE" class="rule entity-CONTENTITEMS entity-CONTENTSETS">
        <label for="rule">Template Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition-equal"/>
            </div>
            <div>
                <label for="name">Name:</label>
                <input id="name" type="text" placeholder="Name" required />
            </div>
        </div>
    </div>
    <div id="RULESET" class="rule entity-">
        <label for="rule">Rule Set:</label>
        <div id="rule" class="rule-body">
            <div class="sub-rules">
                <label>No Rules</label>
            </div>
            <div>
                <label for="condition">Rules Condition:</label>
                <select id="condition">
                    <option value="ALL">Match All Rules</option>
                    <option value="ANY">Match Any Rule</option>
                    <option value="NOTALL">Not Match All Rules</option>
                    <option value="NOTANY">Not Match Any Rule</option>
                </select>
            </div>
        </div>
    </div>
</div>
<div id="sorting-grouping-rules" class="sorting grouping">
    <div id="value" class="rule entity-DATARECORDS entity-CONTENTITEMS">
        <label for="rule">Data Value Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="name">Name:</label>
                <input id="name" type="text" placeholder="Name" required />
            </div>
            <div>
                <label for="numeric">Numeric:</label>
                <input id="numeric" type="checkbox" />
            </div>
            <div>
                <label for="order">Order:</label>
                <select id="order">
                    <option value="ASC">Ascending</option>
                    <option value="DESC">Descending</option>
                </select>
            </div>
        </div>
    </div>
    <div id="property" class="rule entity-">
        <label for="rule">Property Value Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="name">Name:</label>
                <input id="name" type="text" placeholder="Name" required />
            </div>
            <div>
                <label for="order">Order:</label>
                <select id="order">
                    <option value="ASC">Ascending</option>
                    <option value="DESC">Descending</option>
                </select>
            </div>
        </div>
    </div>
</div>
<div id="rule-data-types">
    <select id="enum-condition-string-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
        <option value="CONTAINS">Contains</option>
        <option value="NOT_CONTAINS">Not Contains</option>
        <option value="STARTS_WITH">Starts with</option>
        <option value="ENDS_WITH">Ends with</option>
        <option value="LIKE">Like</option>
        <option value="NOT_LIKE">Not Like</option>
    </select>
    <select id="enum-condition-number-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
        <option value="LT">&lt;</option>
        <option value="GT">&gt;</option>
        <option value="LTE">&lt;=</option>
        <option value="GTE">&gt;=</option>
    </select>
    <select id="enum-condition-date-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
        <option value="LT">&lt;</option>
        <option value="GT">&gt;</option>
        <option value="LTE">&lt;=</option>
        <option value="GTE">&gt;=</option>
        <option value="BETWEEN">Between</option>
    </select>
    <select id="enum-condition-boolean-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
        <option value="IS_TRUE">Is True</option>
        <option value="IS_FALSE">Is False</option>
    </select>
    <select id="enum-condition-property-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
        <option value="LT">&lt;</option>
        <option value="GT">&gt;</option>
        <option value="LTE">&lt;=</option>
        <option value="GTE">&gt;=</option>
        <option value="CONTAINS">Contains</option>
        <option value="NOT_CONTAINS">Not Contains</option>
        <option value="STARTS_WITH">Starts with</option>
        <option value="ENDS_WITH">Ends with</option>
        <option value="LIKE">Like</option>
        <option value="NOT_LIKE">Not Like</option>
    </select>
    <select id="enum-condition-equal-options">
        <option value="EQ" selected="selected">=</option>
        <option value="NE">!=</option>
    </select>
    <select id="enum-condition-contains-options">
        <option value="CONTAINS" selected="selected">Contains</option>
        <option value="NOT_CONTAINS">Not Contains</option>
    </select>
    <select id="enum-condition-in-options">
        <option value="IN" selected="selected">In</option>
        <option value="NOT_IN">Not In</option>
    </select>
    <select id="enum-condition-duplex-options">
        <option value="SIMPLEX_ONLY" selected="selected">Simplex Only</option>
        <option value="HAS_DUPLEX">Has Duplex</option>
    </select>
    <select id="enum-coating-options">
        <option value="UNSPECIFIED" >Unspecified</option>
        <option value="NONE" selected="selected">None</option>
        <option value="COATED">Coated</option>
        <option value="GLOSSY">Glossy</option>
        <option value="HIGH_GLOSS">High Gloss</option>
        <option value="INKJET">Inkjet</option>
        <option value="MATTE">Matte</option>
        <option value="SATIN">Satin</option>
        <option value="SEMI_GLOSS">Semi Gloss</option>
    </select>
    <select id="enum-bindingstyle-options">
        <option value="NONE">None</option>
        <option value="DEFAULT" selected="selected">Default</option>
        <option value="STAPLED">Stapled</option>
        <option value="GLUED">Glued</option>
        <option value="STITCHED">Stitched</option>
        <option value="ADHESIVE">Adhesive</option>
        <option value="SPINETAPING">Spine Taping</option>
        <option value="RING">Ring</option>
        <option value="WIREDCOMB">Wired Comb</option>
        <option value="PLASTICCOMB">Plastic Comb</option>
        <option value="COIL">Coil</option>
    </select>
    <select id="enum-bindingedge-options">
        <option value="DEFAULT" selected="selected">Default</option>
        <option value="LEFT">Left</option>
        <option value="RIGHT">Right</option>
        <option value="TOP">Top</option>
        <option value="BOTTOM">Bottom</option>
    </select>
    <select id="enum-bindingtype-options">
        <option value="DEFAULT" selected="selected">Default</option>
        <option value="SADDLE">Saddle</option>
        <option value="SIDE">Side</option>
        <option value="CORNER">Corner</option>
    </select>
    <select id="enum-bindingangle-options">
        <option value="DEFAULT" selected="selected">Default</option>
        <option value="VERTICAL">Vertical</option>
        <option value="HORIZONTAL">Horizontal</option>
        <option value="ANGLE">Angle</option>
    </select>
</div>

JavaScript/jQuery

e-find-data-entity.js

/* Entity Service - Find Data Entity Example */
(function ($, c) {
    "use strict";
    $(function () {

        const
            MSG_LOAD_RULE_FAIL = "Loading of Search Rules Unsuccessful!\n\n" +
            "Unable to load the search rules from the search rules template. " +
            "Searching is currently disabled.",

            MSG_INCOMPAT_RULES = "The entity type selected isn't compatible " +
            "with some of the existing rules and these will need to be " +
            "removed.\n\nAre you sure you wish to continue ?",

            MSG_MULTIPLE_RULES = "The rule set rule being removed contains " +
            "multiple rules.\n\nAre you sure you wish to continue ?",

            MSG_RESET_RULES = "Are you sure you wish to continue ?";

        c.setupExample();

        var $allRules;

        /* Load Rules */
        (function () {
            var $temp = $("<div>");
            $temp.load("snippets/rules.html", function (response, status) {
                var success = (status === "success");
                if (!success)
                    alert(MSG_LOAD_RULE_FAIL);
                else {
                    $allRules = $temp;
                    ["search", "sorting", "grouping"].forEach(function (category) {
                        var $selector = $("fieldset#" + category)
                                        .find("#rule-type")
                                        .empty();
                        $allRules
                            .find("div." + category + " div.rule")
                            .each(function (index, rule) {
                                var label = $(rule)
                                            .children("label").text()
                                            .replace(/(\sRule)?\:$/, '');
                                $selector.append($("<option>")
                                            .attr("value", rule.id)
                                            .attr("class", $(rule).attr("class"))
                                            .text(label));
                        });
                    });
                    $("#entity").trigger("change");
                }
                $("input, select").prop("disabled", !success);
            });
        }());

        /* Common Load Rule Function */
        function loadRule(category, ruleType) {
            var $rule = $allRules
                            .children("div." + category)
                            .find("div.rule[id='" + ruleType + "']")
                            .clone();

            /* Populate any Data Type References */
            $rule.find("select[data-type]").each(function (index, element) {
                var $element = $(element),
                    dataType = $element.attr("data-type");
                var options = $allRules
                            .find("#rule-data-types")
                            .find("#" + dataType + "-options")
                            .children();
                $element
                    .empty()
                    .append(options.clone());
                $element.val($element
                            .find("option[selected]")
                            .val());
            });

            /* Allow Rules to be Draggable by Label */
            $rule.children("label")
                .prop("draggable", true)
                .addClass("draggable");

            /* Append Add / Remove Rule Buttons */
            var $buttons = $("<div>", { "class": "form-only" }).append(
                    $("<input>", { "id": "remove-rule", "type": "button",
                        "value": "Remove Rule" }));
            if (ruleType === "RULESET") {
                $buttons
                    .append(
                        $("<input>", { "id": "add-rule", "type": "button",
                            "value": "Add Search Rule" }))
                    .children("#remove-rule")
                    .attr("value", "Remove Set");
            }
            $rule.children("div.rule-body").append($buttons);
            return $rule;
        }

        /* Manage the Available Rule Types based on Entity Type */
        $("#entity")
            .on("click", function (event) {
                var $entity = $(event.target);
                $entity.data("previous", $entity.val());
            })
            .on("change", function (event) {
                var $entity = $(event.target),
                    categories = ["search", "sorting", "grouping"],
                    options = {},
                    incompatible = {},
                    reconfigure = {};

                categories.forEach(function (category) {
                    options[category] = [];
                    $("fieldset#" + category)
                        .find("#rule-type")
                        .children("option")
                        .each(function (index, option) {
                            var $option = $(option),
                                allClazz = $entity.attr("id") + "-";

                            if ($option.hasClass(allClazz) ||
                                $option.hasClass(allClazz + $entity.val()))
                                options[category].push($option.val());
                    });
                });

                /**
                 * Prompt User & Remove any Existing Rules that are
                 * incompatible with currently Entity type selected
                 */
                categories.forEach(function (category) {
                    $("fieldset#" + category)
                        .children("div#RULESET")
                        .find("div.rule")
                        .each(function (index, rule) {
                            if ($.inArray(rule.id, options[category]) < 0) {
                                if (incompatible[category] === undefined)
                                    incompatible[category] = [];
                                incompatible[category].push(index);
                            } else
                                $entity
                                    .children("option")
                                    .toArray()
                                    .map(function (option) {
                                        return $(option).val();
                                    }).forEach(function (entity) {
                                        var type = $entity.attr("id") + "-" + entity;
                                        if ($(rule).find("div.option").hasClass(type)) {
                                            if (reconfigure[category] === undefined)
                                                reconfigure[category] = [];
                                            reconfigure[category].push(index);
                                        }
                                    });
                    });
                });
                if (Object.keys(incompatible).length > 0 &&
                    !confirm(MSG_INCOMPAT_RULES)) {
                    $entity.val($entity.data("previous"));
                    return;
                }
                categories.forEach(function (category) {
                    var $rules = $("fieldset#" + category)
                                    .children("div#RULESET")
                                    .find("div.rule");

                    /* Remove any incompatible rules */
                    if (incompatible[category] !== undefined)
                        for (var i = 0; i < incompatible[category].length; i += 1)
                            $($rules[incompatible[category][i]]).remove();

                    /* Reconfigure any incompatible options */
                    if (reconfigure[category] !== undefined)
                        for (var j = 0; j < reconfigure[category].length; j += 1)
                            $($rules[reconfigure[category][j]])
                                .find("div.option")
                                .children("select.options-selector")
                                .trigger("change");

                    /* Restrict Rule Type Selectors to Entity Specific Options */
                    var $selector = $("fieldset#" + category).find("#rule-type"),
                        selection = $selector.val();
                    $selector
                        .children()
                        .each(function (index, option) {
                            var $option = $(option),
                                name = $option.val(),
                                invalid = ($.inArray(name, options[category]) < 0);
                            if (invalid && selection === name)
                                selection = null;
                            $option
                                .prop("disabled", invalid)
                                .prop("hidden", invalid);
                        })
                        .each(function (index, option) {
                            var $option = $(option);
                            if (selection === null && !$option.prop("disabled")) {
                                $selector.val($option.val());
                                return false;
                            }
                        });
                });
            });

        /* Process Rules Function */
        function processRules($rules) {
            var rules = [],
                typeKey = "ruleType";
            if ($rules.closest("fieldset").attr("id") !== "search")
                typeKey = "type";

            $rules
                .children("div.rule")
                .each(function (index, element) {
                    var ruleType = element.id,
                        fieldType = null,
                        $body = $(element).children("div.rule-body"),
                        rule = {};

                    if ($body.find("div:visible #compareType").val() === "name")
                        fieldType = "FIELD";
                    else if ($body.find("div #fieldType").val() === "date")
                        fieldType = "DATE";

                    $body
                        .children("div")
                        .not(".form-only")
                        .children(":visible :input")
                        .each(function (index, input) {
                                var $input = $(input),
                                    id = $input.attr("id"),
                                    type = $input.attr("type"),
                                    value;

                                if (id !== undefined && !$input.prop("disabled")) {
                                    if (id.match(/^value(s|\d*)\-/) !== null) {
                                        type = id.split("-")[1];
                                        id = id.split("-")[0];
                                    }

                                    if (id === "values") {
                                        value = $input.val().split(/\s*,\s*/);
                                        if (type === "number")
                                            for (var i = 0; i < value.length; i += 1)
                                                value[i] = c.valueToNumber(value[i]);
                                    }
                                    if (!Array.isArray(value)) {
                                        if (type === "checkbox")
                                            value = $input.prop("checked");
                                        else if (type === "number")
                                            value = c.valueToNumber($input.val());
                                        else
                                            value = $input.val();
                                    }

                                    if (fieldType !== null && id.match(/^value\d*$/))
                                        value = {
                                            "type": fieldType,
                                            "value": value
                                        };

                                    rule[id] = value;
                                }
                        });

                    if (ruleType === "RULESET")
                        rule.rules = processRules($body.children("div.sub-rules"));

                    rules.push($.extend(true, { [typeKey]: ruleType }, rule));
                });
            return rules;
        }

        $("form")

            /* Add Rule Handler */
            .on("click", "input#add-rule", function (event) {
                var $parent = $(event.target).closest("fieldset"),
                    $rule = loadRule($parent.attr("id"), $parent
                                                            .find("#rule-type")
                                                            .val());
                $(event.target)
                    .closest(".rule")
                    .children("div.rule-body")
                    .children("div.sub-rules")
                    .append($rule);
                $rule
                    .find("div.rule-body div")
                    .children("select.options-selector:visible")
                    .trigger("change");
            })

            /* Remove Rule Handler */
            .on("click", "input#remove-rule", function (event) {
                var $rule = $(event.target).closest(".rule"),
                    remove = true;
                if ($rule.attr("id") === "RULESET" &&
                        $rule.find("div.sub-rules div.rule").length > 1)
                    if (!confirm(MSG_MULTIPLE_RULES))
                        remove = false;

                if (remove) $rule.remove();
            })

            /* "Select Rule Options" Change Handler */
            .on("change", "select.options-selector", function (event) {

                var $entity = $("#entity"),
                    types = $entity
                                .children("option")
                                .toArray()
                                .map(function (option) {
                                    return $(option).val();
                                }),
                    $rule = $(event.target).closest(".rule"),
                    $selectors = $rule
                                    .find("div.rule-body div")
                                    .children("select.options-selector:visible"),
                    unhidden = [];

                $rule
                    .find("div.rule-body div.option")
                    .each(function (optionIndex, option) {
                        var selected = true,
                            $option = $(option),
                            before = $option.prop("hidden"),
                            matched = [];

                        types.forEach(function (type) {
                            var clazz = $entity.attr("id") + "-" + type;
                            if ($option.hasClass(clazz))
                                matched.push(clazz);
                        });
                        if (matched.length)
                            selected = ($.inArray($entity.attr("id") + "-" +
                                $entity.val(), matched) >= 0);

                        $selectors.each(function (selectorIndex, selector) {
                            var allClass = selector.id + "-";
                            if (!$option.hasClass(allClass) &&
                                !$option.hasClass(allClass + $(selector).val())) {
                                selected = false;
                            }
                        });

                        $option
                            .prop("hidden", !selected)
                            .find("input, select")
                            .prop("disabled", !selected);

                        if (before && selected)
                            unhidden.push($option
                                .children("select.options-selector"));
                });

                unhidden.forEach(function (selector) {
                    $(selector).trigger("change");
                });
            })

            /* Submit Form Rules Handler */
            .on("submit", function (event) {

                event.preventDefault();
                if (!c.checkSessionValid()) return;

                /* Process & Add Search Rules */
                var search = {
                    "entity": $("#entity").val(),
                    "search": processRules(($("#search")))[0],
                };

                /* Process & Add Sorting & Grouping Rules */
                ["sort", "group"].forEach(function (type) {
                    var rules = (processRules($("#" + type +"ing")))[0].rules;
                    if (rules.length)
                        search[type] = rules;
                });

                $.ajax({
                    type:        "PUT",
                    url:         "/rest/serverengine/entity/find",
                    data:        JSON.stringify(search),
                    contentType: "application/json"
                })
                    .done(function (response) {
                        c.displayStatus("Request Successful");
                        c.displayHeading("Input Parameters");
                        c.displaySubResult("JSON Search Parameters", c.jsonPrettyPrint(search));
                        c.displayHeading("Search Results");
                        c.displaySubResult("Plain", c.jsonIDListsWithSortKeyToTable(response));
                        c.displaySubResult("JSON Identifier Lists (with Sort Key)", c.jsonPrettyPrint(response));
                    })
                    .fail(c.displayDefaultFailure);
            })

            /* Reset Form Rules Handler */
            .on("click", "#reset", function (event) {
                if (confirm(MSG_RESET_RULES))
                    $("div.sub-rules")
                        .find("div.rule")
                        .remove();
            });
    });
}(jQuery, Common));

Screenshot & Output

Usage

To run the example first select the Entity Type that you are searching for. The data entity types available are:

  • Data Sets
  • Data Records
  • Content Sets
  • Content Items
  • Job Sets
  • Jobs

Once a data entity type is selected, various rules can be added to form the search criteria. There are three categories of rules available: search, sorting and grouping rules.

Search Rules

There are eight types of search rules that can be specified as part of the overall search criteria:

  • Data Value – Search for data entities based on the value of a data record field.
  • Property Value – Search for data entities based on the value of a data entity property.
  • Value In – Restrict the search to the data entity values contained within a list.
  • ID In – Restrict the search to data entity identifiers contained within a list.
  • Document Media – The name of the media used as defined in the PReS Connect template, as well as the coating used for the front and back of the page sheet.
  • Document Binding – The binding used for the document including style, edge, type and angle properties.
  • Document Size – The document size. This supports sheet and section size counts in addition to page size counts.
  • Duplex – Whether the document contains any duplex sheets, or not.
  • Template – Search for data entities based on the name of the template used during Content Creation.
  • Rule Set – Used to group search rules into logical sets (or sub-sets) and specifies a group rules operator that can be configured to either match all or any of the rules in the set. This allows quite complex nested rules.

The types of search rules available are specific to the data entity type selected. The following table lists the available combinations:

Rule Type Data Records Data Sets Content Items Content Sets Jobs Job Sets
Data Value

 

 

 

 

Property Value

✓^

✓^ ✓^ ✓^
Value In

✓^

✓^ ✓^ ✓^
ID In

Document Media

 

 

 

 

 

Document Binding

 

 

 

 

 

Document Size

 

 

 

 

 

Duplex

 

 

 

 

 

Template

 

 

 

 

Rule Set

^ Note: These rules types are only partially compatible with these entity data types. Only searches specific to property values are permitted.

Search rules can be added by selecting the appropriate Rule Type Selector option and then clicking the Add Search Rule button. They can be removed using the Remove Rule button, and even re-ordered within the form by dragging and dropping a rule by their name label (e.g. Data Value Rule: or Property Value Rule:).

Data Value search rules can be configured by specifying the following options:

  • Name – Name of the data record field to search by
  • Condition – Operator for the comparison of the data record field (e.g. Equals (=), Not Equals (<>), Less Than (<), Greater Than (>), etc.)
  • Value – Value of the data record field to match

Property Value search rules can be configured by specifying the following options:

  • Name – Name of the data entity property to search by
  • Condition – Operator for the comparison of the data entity property (e.g. Equals (=), Not Equals (<>), Less Than (<), Greater Than (>), etc.)
  • Value – Value of the data entity property to match

Value In and ID In search rules can be configured by specifying the following options:

  • Identifiers – List of data entity identifiers to match or not match against

Document Media search rules for Media Name can be further configured by specifying the following options:

  • Condition – Operator for the comparison of the media name (e.g. Equals (=) or Not Equals (<>))
  • Value – Value of the media name to match (e.g. Plain Letter Paper)

Document Media search rules for Coating can be further configured by specifying the following options:

  • Condition – Operator for the comparison of the coating (e.g. Equals (=) or Not Equals (<>))
  • Front Coating – The type of front coating to match (e.g. Semi Gloss, Satin, Matte, Glossy, None, etc.)
  • Back Coating – The type of back coating to match (e.g. Semi Gloss, Satin, Matte, Glossy, None, etc.)

Document Binding search rules can be further configured by specifying the following options:

  • Binding Style – The style of binding to match (e.g. Stapled, Glued, Stitched, Coil, etc.)
  • Binding Edge – The edge (or side on which the binding occurs) to match (e.g. Left, Right, Top or Bottom)
  • Binding Type – The type or location of the binding to match (e.g. Saddle, Side or Corner)
  • Binding Angle – The binding angle to match (e.g. Vertical, Horizontal or Angle)

Document Size search rules can be configured by specifying the following options:

  • Condition – Operator for the comparison of the document length (e.g. Equals (=), Not Equals (<>), Less Than (<), Greater Than (>), etc.)
  • Value – Value of the document length to match

Template search rules can be configured by specifying the following options:

  • Condition – Operator for the comparison of the template name (e.g. Equals (=) or Not Equals (<>))
  • Value – Value of the template name to match (e.g. letter-ol)

Rule Set can be configured by specifying the following conditions:

  • Rules Conditions – Conditions for the matching of search rules contained in the rule set. The options are Match All Rules (ALL); Match Any Rule (ANY); Not Match All Rules (NOTALL); Not Match Any Rule (NOTANY)

Individual rules can be added to a Rule Set by selecting the appropriate Rule Type Selector option and then clicking the Add Search Rule button within the Rule Set box.

Individual rules can be removed by clicking the associated Remove Rule button within the Rule Set box.

Rule Sets can be removed using the Remove Set button, and in situations where removing a rule set would remove multiple rules, you will be prompted to confirm the removal of the rule set.

Lastly, select the Rules Operator for the matching of search rules contained in the base rules list (e.g. Match All Rules (AND) or Match Any Rules (OR))

Sorting Rules

There are also two types of sorting rules that can be used as part of the overall search criteria:

  • Data Value – Sort the search results by the value of a data record field
  • Property Value – Sort the search results by the value of a data entity property

The types of sorting rules available are also specific to the data entity type selected. The following table lists the available combinations:

Rule Type Data Records Data Sets Content Items Content Sets Jobs Job Sets
Data Value

 

 

 

 

Property Value


Sorting rules can be added using the Add Sorting Rule button, removed using the Remove Rule button, and even re-ordered within the form.

Rules can be re-ordered by dragging and dropping a rule by it's name label (e.g. Data Value Rule: or Property Value Rule:).

Data Value sorting rules can be configured by specifying the following options:

  • Name – Name of the data record field to sort the search results by
  • Numeric – Sort the search results for this data record field numerically
  • Order – Sort the search results for this data record field in a specific order (e.g. Ascending or Descending)

Property Value sorting rules can be configured by specifying the following options:

  • Name – Name of the data entity property to sort the search results by
  • Order – Sort the search results for this data entity property in a specific order (e.g. Ascending or Descending)

Grouping Rules

There are also two types of grouping rules that can be used as part of the overall search criteria:

  • Data Value – Group the search results by the value of a data record field
  • Property Value – Group the search results by the value of a data entity property

The types of grouping rules available are also specific to the data entity type selected. The following table lists the available combinations:

Rule Type Data Records Data Sets Content Items Content Sets Jobs Job Sets
Data Value

 

 

 

 

Property Value


Grouping rules can be added using the Add Grouping Rule button, removed using the Remove Rule button, and even re-ordered within the form.

Rules can be re-ordered by dragging and dropping a rule by it's name label (e.g. Data Value Rule: or Property Value Rule:).

Data Value grouping rules can be configured by specifying the following options:

  • Name – Name of the data record field to group the search results by
  • Numeric – Group the search results for this data record field numerically
  • Order – Group the search results for this data record field in a specific order (e.g. Ascending or Descending)

Property Value grouping rules can be configured by specifying the following options:

  • Name – Name of the data entity property to group the search results by
  • Order – Group the search results for this data entity property in a specific order (e.g. Ascending or Descending)

By default, comparison conditions in search rules are evaluated alphanumerically, regardless of the type of value.

Numeric evaluation of comparison conditions is not currently supported in the PReS Connect REST API.

The only exception to this rule is the ability to numerically sort or group results by specifying sorting or grouping rules of a Data Value type.

The Entity Type selected for the search criteria can be changed during or even after rules have been added. But because certain rules are only available for certain data entity types, some of the existing rules in the search criteria may become incompatible.

In situations where incompatible rules are found in the existing search criteria, you will be prompted to confirm the change of entity type. If you then proceed with the change of entity type, any incompatible rules found in the existing search criteria will be removed.

Once the search criteria is constructed, and the required inputs populated, simply select the Submit button. This will submit the request to the server and display the search criteria specified as input to the Results area in JSON Search Parameters format.

The result will then be returned as a list of Data Entity IDs which will be appended to the Results area in both Plain table and JSON Identifier Lists (with Sort Key) formats.

To construct a new search criteria, the Reset button can be selected. This will reset the form, removing all existing rules.

Further Reading

See the Entity Service page of the REST API Reference section for further detail.