Finding Specific Data Entities in the Server

Problem

You want to find specific Data Entities stored within the PlanetPress 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.2.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>
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="value">Data Value</option>
                        <option value="property">Property Value</option>
                        <option value="IN">In List</option>
                        <option value="NOT IN">Not In List</option>
                        <option value="finishing">Finishing</option>
                        <option value="doclength">Document Length</option>
                        <option value="templatename">Template Name</option>
                        <option value="group">Rule Group</option>
                    </select>
                </div>
                <div id="group" 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="operator">Rules Operator:</label>
                            <select id="operator">
                                <option value="AND">Match All Rules</option>
                                <option value="OR">Match Any Rule</option>
                            </select>
                        </div>
                        <div>
                            <input id="add-search" type="button" value="Add Search Rule">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset id="sorting">
                <legend>Sorting Rules</legend>
                <div>
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="value">Data Value</option>
                        <option value="property">Property Value</option>
                    </select>
                </div>
                <div id="group" class="rule">
                    <label for="rule">Rules:</label>
                    <div id="rule" class="rule-body">
                        <div class="sub-rules">
                            <label>No Rules</label>
                        </div>
                        <div>
                            <input id="add-sorting" type="button" value="Add Sorting Rule">
                        </div>
                    </div>
                </div>
            </fieldset>
            <fieldset id="grouping">
                <legend>Grouping Rules</legend>
                <div>
                    <label for="rule-type">Rule Type Selector:</label>
                    <select id="rule-type">
                        <option value="value">Data Value</option>
                        <option value="property">Property Value</option>
                    </select>
                </div>
                <div id="group" class="rule">
                    <label for="rule">Rules:</label>
                    <div id="rule" class="rule-body">
                        <div class="sub-rules">
                            <label>No Rules</label>
                        </div>
                        <div>
                            <input id="add-grouping" 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">
    <div id="group" class="rule">
        <label for="rule">Rule Group:</label>
        <div id="rule" class="rule-body">
            <div class="sub-rules">
                <label>No Rules</label>
            </div>
            <div>
                <label for="operator">Rules Operator:</label>
                <select id="operator">
                    <option value="AND">Match All Rules</option>
                    <option value="OR">Match Any Rule</option>
                </select>
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Group" />
                <input id="add-search" type="button" value="Add Search Rule" />
            </div>
        </div>
    </div>
    <div id="value" class="rule">
        <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="condition">Condition:</label>
                <select id="condition" data-type="enum-condition3"/>
            </div>
            <div>
                <label for="value">Value:</label>
                <input id="value" type="text" placeholder="Value" required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="property" class="rule">
        <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="condition">Condition:</label>
                <select id="condition" data-type="enum-condition3"/>
            </div>
            <div>
                <label for="value">Value:</label>
                <input id="value" type="text" placeholder="Value" required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="IN" class="rule">
        <label for="rule">In List Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="identifiers">Identifiers:</label>
                <input id="identifiers" type="text" placeholder="1234, 2345, 3456, ..." required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="NOT IN" class="rule">
        <label for="rule">Not In List Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="identifiers">Identifiers:</label>
                <input id="identifiers" type="text" placeholder="1234, 2345, 3456, ..." required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="finishing" class="rule">
        <label for="rule">Finishing Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="finishing-type">Type:</label>
                <select id="finishing-type">
                    <option value="medianame">Media Name</option>
                    <option value="duplex">Duplex</option>
                    <option value="coating">Coating</option>
                    <option value="binding">Binding</option>
                </select>
            </div>
            <div class="option">
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition1"/>
            </div>
            <div class="option">
                <label for="medianame">Media Name:</label>
                <input id="medianame" type="text" placeholder="Name" required />
            </div>
            <div class="option">
                <label for="duplex">Duplex:</label>
                <input id="duplex" type="checkbox" />
            </div>
            <div class="option">
                <label for="frontcoating">Front Coating:</label>
                <div class="input-group">
                    <select id="frontcoating" data-type="enum-coating" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div class="option">
                <label for="backcoating">Back Coating:</label>
                <div class="input-group">
                    <select id="backcoating" data-type="enum-coating" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div class="option">
                <label for="bindingstyle">Binding Style:</label>
                <div class="input-group">
                    <select id="bindingstyle" data-type="enum-bindingstyle" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div class="option">
                <label for="bindingedge">Binding Edge:</label>
                <div class="input-group">
                    <select id="bindingedge" data-type="enum-bindingedge" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div class="option">
                <label for="bindingtype">Binding Type:</label>
                <div class="input-group">
                    <select id="bindingtype" data-type="enum-bindingtype" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div class="option">
                <label for="bindingangle">Binding Angle:</label>
                <div class="input-group">
                    <select id="bindingangle" data-type="enum-bindingangle" />
                    <input class="use-option" type="checkbox" checked />
                </div>
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="doclength" class="rule">
        <label for="rule">Document Length Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition2"/>
            </div>
            <div>
                <label for="value">Value:</label>
                <input id="value" type="text" placeholder="Value" required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="templatename" class="rule">
        <label for="rule">Template Name Rule:</label>
        <div id="rule" class="rule-body">
            <div>
                <label for="condition">Condition:</label>
                <select id="condition" data-type="enum-condition1"/>
            </div>
            <div>
                <label for="template">Template:</label>
                <input id="template" type="text" placeholder="Name" required />
            </div>
            <div>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
</div>
<div id="sorting-grouping-rules">
    <div id="value" class="rule">
        <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>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
    <div id="property" class="rule">
        <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>
                <input id="remove-rule" type="button" value="Remove Rule" />
            </div>
        </div>
    </div>
</div>
<div id="rule-data-types">
    <select id="enum-condition1-options">
        <option value="EQUAL" selected="selected">=</option>
        <option value="NOTEQUAL">&lt;&gt;</option>
    </select>
    <select id="enum-condition2-options">
        <option value="EQUAL" selected="selected">=</option>
        <option value="NOTEQUAL">&lt;&gt;</option>
        <option value="LESS">&lt;</option>
        <option value="GREAT">&gt;</option>
        <option value="LESSEQUAL">&lt;=</option>
        <option value="GREATEQUAL">&gt;=</option>
    </select>
    <select id="enum-condition3-options">
        <option value="EQUAL" selected="selected">=</option>
        <option value="NOTEQUAL">&lt;&gt;</option>
        <option value="LESS">&lt;</option>
        <option value="GREAT">&gt;</option>
        <option value="LESSEQUAL">&lt;=</option>
        <option value="GREATEQUAL">&gt;=</option>
        <option value="STARTSWITH">Starts with</option>
        <option value="ENDSWITH">Ends with</option>
        <option value="CONTAINS">Contains</option>
        <option value="LIKE">Like</option>
        <option value="NLIKE">Not Like</option>
        <option value="IN">In List</option>
        <option value="NOT IN">Not In List</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 () {

        c.setupExample();

        var $allRules;

        /* Load Search Rules */
        (function () {
            var $temp = $("<div>");
            $temp.load("snippets/rules.html", function (response, status, xhr) {
                var success = (status === "success");
                if (success)
                    $allRules = $temp;
                else
                    alert("Loading of Search Rules Unsuccessful!\n\nUnable to load the search rules " +
                        "from the search rules template. Searching is currently disabled.");
                $("input[type='submit']").prop("disabled", !success);
                $("input[type='button']").prop("disabled", !success);
            });
        }());

        /* Common Load Rule Function */
        function loadRule(ruleCategory, ruleName) {
            var $rule = $allRules.find("#" + ruleCategory +
                "-rules div.rule[id='" + ruleName + "']").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");
            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),
                    type = $entity.val(),
                    options = ["property", "IN", "NOT IN", "group"];

                if (type === "DATARECORDS" || type === "CONTENTITEMS")
                    options.unshift("value");
                if (type === "CONTENTITEMS")
                    options.push("finishing", "doclength");
                if (type === "CONTENTITEMS" || type === "CONTENTSETS")
                    options.push("templatename");

                /* Set Rule Type Selector (Helper Function) */
                function setRuleTypeSelector(type, options) {
                    var $typeSelector = $("fieldset#" + type).find("#rule-type"),
                        selection = $typeSelector.val();
                    $typeSelector
                        .children()
                        .each(function (index, element) {
                            var $element = $(element),
                                name = $element.val(),
                                invalid = ($.inArray(name, options) < 0);
                            if (invalid && selection === name)
                                selection = null;
                            $element.prop("disabled", invalid);
                            $element.prop("hidden", invalid);
                        })
                        .each(function (index, element) {
                            var $element = $(element);
                            if (selection === null && !$element.prop("disabled")) {
                                $typeSelector.val($element.val());
                                return false;
                            }
                        });
                }

                /**
                 * Prompt User & Remove any Existing Rules that are
                 * incompatible with currently Entity type selected
                 */
                var $existingRules = $("div.rule"),
                    incompatible = [];
                $existingRules.each(function (index, element) {
                    if ($.inArray(element.id, options) < 0)
                        incompatible.push(index);
                });
                if (incompatible.length > 0)
                    if (confirm("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 ?")) {
                        for (i = 0; i < incompatible.length; i += 1)
                            $($existingRules[incompatible[i]]).remove();
                    } else {
                        $entity.val($entity.data("previous"));
                        return;
                    }

                /* Restrict Rule Type Selectors to Entity Specific Options */
                var types = ["search", "sorting", "grouping"],
                    i;
                for (i = 0; i < types.length; i += 1)
                    setRuleTypeSelector(types[i], options);
            })
            .trigger("change");

        /* Add the Value & Property "Condition" Change Handler */
        var conditionPlaceholder = function (event) {
            var $rule = $(event.target).closest(".rule"),
                condition = $(event.target).val(),
                label = "Value:",
                placeholder = "Value";
            if (condition === "IN" || condition === "NOT IN") {
                label = "Value(s):";
                placeholder = "Value1, Value2, Value3, ...";
            }
            $rule
                .find("label[for='value']")
                .html(label);
            $rule
                .find("#value")
                .attr("placeholder", placeholder);
        };

        /* "Select Finishing Type" Change Handler */
        var selectFinishingType = function (event) {
            var $rule = $(event.target).closest(".rule"),
                type = $(event.target).val(),
                options;
            if (type === "medianame")
                options = ["condition", "medianame"];
            else if (type === "duplex")
                options = ["duplex"];
            else if (type === "coating")
                options = ["condition", "frontcoating", "backcoating"];
            else if (type === "binding")
                options = ["condition", "bindingstyle", "bindingtype",
                    "bindingedge", "bindingangle"];
            if (options)
                $rule
                    .find("div.rule-body div.option")
                    .each(function (index, element) {
                        var $element = $(element),
                            $input = $element.find("input, select"),
                            unavailable = ($.inArray($input.attr("id"), options) < 0);
                        $element.prop("hidden", unavailable);
                        $input.prop("disabled", unavailable);
                        $rule
                            .find(":visible input.use-option")
                            .trigger("change", [ false ]);
                    });
        };

        /* "Toggle Finishing" Options Change Handler */
        var useFinishingOption = function (event, validate) {
            event.stopImmediatePropagation();
            var $target = $(event.target);
            $target
                .siblings("select")
                .each(function (index, sibling) {
                    $(sibling).prop("disabled", !($target.prop("checked")));
                });
            if (validate === undefined || validate) {
                var $available = $target
                                    .closest("div.rule-body")
                                    .find(":visible input.use-option"),
                    checked = 0;
                $available.each(function (index, check) {
                    var $check = $(check);
                    $check.prop("required", false);
                    if ($check.prop("checked")) checked++;
                });
                if (checked < 1) $target.prop("required", true);
            }
        };

        /* Process Search Rule Function */
        function processSearchRule($rules) {
            var rules = [];
            $rules
                .children("div.rule")
                .each(function (index, element) {
                    var type = element.id,
                        $body = $(element).children("div.rule-body"),
                        rule = { "type": type };
                    if (type === "IN" || type === "NOT IN") {
                        var json = c.plainIDListToJson($body
                                                        .find("div>#identifiers")
                                                        .val());
                        rule.identifiers = json.identifiers;
                    } else if (type === "templatename") {
                        rule.template = $body
                                            .find("div>#template")
                                            .val();
                        rule.condition = $body
                                            .find("div>#condition")
                                            .val();
                    } else if (type === "finishing") {
                        $body
                            .find(":visible :input")
                            .each(function (index, element) {
                                var $child = $(element),
                                    id = $child.attr("id");
                                if (id !== undefined && !$child.prop("disabled"))
                                    if (id === "duplex")
                                        rule[id] = $child.prop("checked");
                                    else if (id !== "finishing-type" && id !== "remove-rule")
                                        rule[id] = $child.val();
                            });
                    } else if (type === "group") {
                        rule = {
                            "operator": $body
                                            .children("div")
                                            .children("#operator")
                                            .val(),
                            "rules": processSearchRule($body.children("div.sub-rules"))
                        };
                    } else {
                        var condition = $body
                                            .find("div>#condition")
                                            .val();
                        rule.value = $body
                                        .find("div>#value")
                                        .val();

                        if (type === "doclength")
                            rule.value = c.valueToNumber(rule.value);
                        else
                            rule.name = $body
                                            .find("div>#name")
                                            .val();

                        if (condition === "IN" || condition === "NOT IN")
                            rule.value = rule.value.split(/\s*,\s*/);
                        if (condition !== "EQUAL")
                            rule.condition = condition;
                    }
                    if (rule.condition) {
                        var temp = rule.condition;
                        delete rule.condition;
                        rule.condition = temp;
                    }
                    rules.push(rule);
                });
            return rules;
        }

        /* Add Sorting/Grouping Rule Function */
        function addSortGroupRule(event) {
            var id = event.target.id,
                $rules = $("#" + id.substring(id.indexOf("-") + 1, id.length)),
                type = $rules
                            .find("#rule-type")
                            .val();
            $rules
                .find("div.sub-rules")
                .append(loadRule("sorting-grouping", type));
        }

        $("form")
            /* Value, Property & Finishing Rule Change Handlers */
            .on("change", "#value.rule #condition", conditionPlaceholder)
            .on("change", "#property.rule #condition", conditionPlaceholder)
            .on("change", "#finishing.rule #finishing-type", selectFinishingType)
            .on("change", "#finishing.rule input.use-option", useFinishingOption)

            /* Remove Rule Handler */
            .on("click", "input#remove-rule", function (event) {
                var $rule = $(event.target).closest(".rule"),
                    remove = true;
                if ($rule.attr("id") === "group" &&
                        $rule.find("div.sub-rules div.rule").length > 1)
                    if (!confirm("The group rule being removed " +
                                "contains multiple rules.\n\nAre " +
                                "you sure you wish to continue ?"))
                        remove = false;

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

            /* Add Search Rule Handler */
            .on("click", "#add-search", function (event) {
                var type = $("#search")
                                .find("#rule-type")
                                .val(),
                    $rule = loadRule("search", type);

                $(event.target)
                    .closest(".rule")
                    .children("div.rule-body")
                    .children("div.sub-rules")
                    .append($rule);

                if (type === "finishing")
                    $rule
                        .find("#finishing-type")
                        .trigger("change");
            })

            /* Add Sorting/Grouping Rule Handler */
            .on("click", "#add-sorting", addSortGroupRule)
            .on("click", "#add-grouping", addSortGroupRule)

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

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

                /* Process & Add Search Rules */
                var $body = $("#search>div#group").children("div.rule-body"),
                    search = {
                        "entity": $("#entity").val(),
                        "search": {
                            "operator": $body
                                            .children("div")
                                            .children("#operator")
                                            .val(),
                            "rules": processSearchRule($body.children("div.sub-rules"))
                        }
                    };

                /* Add Sorting & Grouping Rules */
                ["sort", "group"].forEach(function (type) {
                    $("#" + type + "ing div.sub-rules div.rule")
                        .each(function (index, element) {
                            var $body = $(element).children("div.rule-body"),
                                rule = {
                                    "name":     $body
                                                    .find("#name")
                                                    .val(),
                                    "order":    $body
                                                    .find("#order")
                                                    .val(),
                                    "type":     element.id
                                },
                                $numeric = $body.find("#numeric");

                            if ($numeric.length)
                                    rule.numeric = $numeric.prop("checked");

                            if (!search[type]) search[type] = [];
                            search[type].push(rule);
                        });
                });
                $.ajax({
                    type:           "PUT",
                    url:            "/rest/serverengine/entity/find",
                    data:           JSON.stringify(search),
                    contentType:    "application/json; charset=utf-8"
                })
                    .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("Are you sure you wish to continue ?"))
                    $("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
  • In List – Restrict the search to the data entity identifiers contained within a list
  • Not In List – Restrict the search to data entity identifiers not contained within a list
  • Finishing – Search for data entities based on a finishing option:
    • Media Name – The name of a media used as defined in the PlanetPress Connect design template
    • Duplex – Whether the page sheet is duplex or not
    • Coating – The coating used for the front and back of the page sheet
    • Binding – The binding used for the document including style, edge, type & angle properties
  • Document Length – Search for data entities based on the document length (number of pages)
  • Template Name – Search for data entities based on the name of the design template used during Content Creation
  • Rule Group – Used to group search rules into logical groups (or sub-groups) and specifies a group rules operator that can be configured to either match all or any of the rules in the group

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

In List

Not In List

Finishing

 

 

 

 

 

Document Length

 

 

 

 

 

Template Name

 

 

 

 

Rule Group


Search rules can be added using the Add Search 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 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

In List and Not In List search rules can be configured by specifying the following options:

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

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

  • Type – Type of finishing option to compare (e.g. Media Name, Duplex, Coating or Binding)

Finishing search rules with a Type set to 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)

Finishing search rules with a Type set to Duplex can be further configured by specifying the following options:

  • Duplex – Whether the page sheet is duplex or not

Finishing search rules with a Type set to 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.)

Finishing search rules with a Type set to Binding 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 Length 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 Name 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 Groups can be configured by specifying the following options:

  • Rules Operator – Operator for the matching of search rules contained in the group (e.g. Match All Rules (AND) or Match Any Rules (OR))

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

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 PlanetPress 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.

 
   
  • Last Topic Update: Jan-22-2018 13:07
  • Last Published: 2018-05-14 : 9:58 AM