Hide Table of Contents
View DataReviewer - Execute Ad Hoc Batch Validation live sample
DataReviewer - Execute Ad Hoc Batch Validation

Description

This sample shows how to execute Ad Hoc Batch Validation in ArcGIS Data Reviewer for Server. Batch validation checks data based on business rules stored in a Reviewer Batch Job (.rbj) file. Ad Hoc Batch Validation runs immediately and one time only. Validation results are written to a Reviewer dataset. Validation requires a Reviewer Batch Job (.rbj) file which is authored using ArcGIS Data Reviewer for Desktop or provided by an Esri solution team. This sample allows you to validate data on a hosted instance of Data Reviewer for Server. You can execute an Adhoc batch job by entering the inputs. You choose an existing uploaded Batch Job file and click on the Execute Batch Job button. Once a job is submitted, the Ad Hoc Job Id will be visible and you can check the status of the job by clicking on the Get Execution Details button. To execute an Ad Hoc Batch Validation on your Data Reviewer for Server instance, update both the drsSoeUrl variable (sample) and the uploadsUrl variable (uploadPopup function) to point to a local Data Reviewer for Server.

Code

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Execute Adhoc Job Sample</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.29/dijit/themes/claro/claro.css" />
<script src="https://js.arcgis.com/3.29/"></script>
<style>
.reviewerForm {
	width: 530px;
	font-size: .7em;
	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
.submitButton {
	float: right;
	padding: 5px;
	width: 150px;
	font-size: 1.1em;
	border: 2px solid #CCC;
	margin: 0px 0px 10px 0px;
}	
h1
{
	width:100%; 
	background: #f1f1f1; 
	padding:10px;
	font-size:1.1em; 
	margin: 0 0 15px 0;
}
input, textarea{
	padding: 5px;
	width: 371px;
	margin: 0px 0px 10px 0px;
	border: 2px solid #CCC;
	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
}	
select{
	padding: 5px;
	width: 385px;
	margin: 0px 0px 10px 0px;
	border: 2px solid #CCC;
}

label {
	float: left;
	text-align: right;
	margin-right: 15px;
	width: 130px;
	padding-top: 5px;
}
#executionDetailsDiv,
#createReviewerSessionDiv {
    position: absolute;
}

#createReviewerSessionDiv {
    z-index: 10;
}

.message {
	float: right;
	padding: 5px;
	width: 280px;
}
.successMessage {
	float: right;
	padding: 5px;
	width: 280px;
	color: #048313;
}
.errorMessage{
	float: right;
	padding: 5px;
	width: 280px;
	color: #C41111;
}
</style>

<script type="text/javascript">
var bvTask,uploadsUrl;
var drsSoeUrl="https://datareviewer.arcgisonline.com/arcgis/rest/services/Samples/reviewerWriteResults/MapServer/exts/DataReviewerServer";
require(
[
 "dojo/dom",
 "dojo/on", 
 "esri/tasks/datareviewer/BatchValidationTask",
 "esri/tasks/datareviewer/BatchValidationParameters",
 "esri/tasks/datareviewer/SessionOptions",
 "dojo/domReady!"
],function(dom, on, BatchValidationTask, BatchValidationParameters,SessionOptions) {
    // specify proxy for request with URL lengths > 2k characters
    esriConfig.defaults.io.proxyUrl = "/proxy/";

     // configure button click events
     on(dom.byId("btnExecuteAdhocJob"), "click", executeJob);
     on(dom.byId("btnGetExecutionDetails"), "click", getExecutionDetails);
     on(dom.byId("linkToCreateSession"), "click", openCreateNewSessionDiv);
     on(dom.byId("selectSession"), "change", hideCreateNewSessionDiv);
     on(dom.byId("btnCreateReviewerSession"), "click", createNewSession);
     //Create BatchValidationTask using the SOE url
     bvTask = new BatchValidationTask(drsSoeUrl);
     getReviewerSessions();
     //Get a list of reviewer sessions in Reviewer workspace
     function getReviewerSessions(session)
     {
         var deferred=bvTask.getReviewerSessions();
         deferred.then(function(response) {
            var reviewerSessions = response.reviewerSessions;
            for (var i = 0; i < reviewerSessions.length; i++) {
                dom.byId("selectSession")[i+1] = new Option(reviewerSessions[i].toString(), reviewerSessions[i].toString());
                if (session!==null ||session!==undefined)
                {
                    if (reviewerSessions[i].sessionName==session)
                    {
                        dom.byId("selectSession")[i+1].selected=true;
                    }
                }
            }
          }, function(error) {
               showMessage("executeJobMessages", "Error getting Sessions Lsit " + error.message, "errorMessage");
               dom.byId("executionDetailsDiv").style.visibility = "hidden";
          });
    }
     function executeJob() {
        //clear textbox and text area
        dom.byId("executionDetailsDiv").style.visibility = "hidden";
        dom.byId("createReviewerSessionDiv").style.visibility = "hidden";
        dom.byId("jobIdValue").value = "";
        dom.byId("textarea").value = "";
        //clear any error message status...
        showMessage("executeJobMessages", "");

        // check the form inputs
        //1. Title (Optional)
        //2. Session (Required)
        //3. File Item ID (Required)
        //4. CreatedBy (Optional)
        if((!dom.byId("selectSession").value) || (!(dom.byId("inputFileItemId").value))) {
           alert("Please fill out Adhoc execute inputs");
           return;
        }

        //Set Batch Validation Parameters based on user input
        var bvParameters = new BatchValidationParameters();
        bvParameters.title = dom.byId("inputTitle").value;
        bvParameters.fileItemId = dom.byId("inputFileItemId").value;
        bvParameters.sessionString = dom.byId("selectSession").value;
        bvParameters.changedFeaturesOnly = false;
        bvParameters.createdBy = dom.byId("inputCreatedBy").value;
        bvParameters.analysisArea = null;

        //Execute Job
        var deferred = bvTask.executeJob(bvParameters);

        //Display progress of execute job call
        showMessage("executeJobMessages", "Executing Job....");

        //Deferred callback and errback function
        deferred.then(function(response) {
           showMessage("executeJobMessages", "", "successMessage");
           dom.byId("executionDetailsDiv").style.visibility = "visible";
           dom.byId("jobIdValue").value = response.jobId;

        }, function(error) {
           showMessage("executeJobMessages", "Error executing Adhoc Job " + error.message, "errorMessage");
        });
     }

    // Create New Reviewer Session
     function createNewSession(){
         if((!dom.byId("sessionName").value) || (!(dom.byId("userName").value))) {
           alert("Please fill out Create Reviewer Session inputs");
           return;
         }
         var sessionOptions=new SessionOptions();
         //The user account to associate with a session.
         sessionOptions.userName=dom.byId("userName").value;
         //Indicates an enterprise geodatabase version to associate with the session. 
         sessionOptions.versionName=dom.byId("versionName").value;
         //Indicates how to handle duplicate results when writing the results to the Reviewer workspace.
         sessionOptions.duplicateFilter=dom.byId("duplicateFilter").value;
         //Indicates if validation result geometries are stored in the Reviewer workspace.
         sessionOptions.storeGeometry=dom.byId("chkStoreGeometry").checked;
         //Create a new Reviewer Session that will store sessions in a reviewer workspace. The function accepts two parameters. Session Name and SessionOptions
         var newSessionDeferred=bvTask.createReviewerSession(dom.byId("sessionName").value,sessionOptions);
         newSessionDeferred.then(function(response) {
           // Populate Session list with the updated sesison list
           getReviewerSessions(response.reviewerSession.sessionName);
           //Hide Create Reviewer Session Div
           dom.byId("createReviewerSessionDiv").style.visibility = "hidden";
        }, function(error) {
           showMessage("createReviewerSessionMessages", "Error Creating New Session " + error.message, "errorMessage");
           dom.byId("executionDetailsDiv").style.visibility = "hidden";
        });
     }
     function getExecutionDetails() {
        //Clear any error messages...
        showMessage("executionDetailsMessages", "");
        // we're using dojo deferred 'then' function to call a callback function and errback function
        var deferred = bvTask.getJobExecutionDetails(dom.byId("jobIdValue").value);

        //Display progress of getting job execution details.
        showMessage("executionDetailsMessages", "Getting Job Execution Details...", "sucessMessage");

        //Deferred callback and errback function
        deferred.then(function(response) {
           showMessage("executionDetailsMessages", "");
           var jobDetails = response.jobInfo.status;
           if(response.jobInfo.messages !== null) {
              jobDetails = jobDetails + "\n" + response.jobInfo.messages;
              dom.byId("textarea").value = jobDetails;
           }
           else
           {
            dom.byId("textarea").value = jobDetails;
           }
        }, function(error) {
           showMessage("executionDetailsMessages", "Error:" + error.message, "errorMessage");
        });
     }

     function showMessage(divName, text, className) {
        var messageDiv = dom.byId(divName);
        messageDiv.innerHTML = "";
        messageDiv.className = className || "";
        messageDiv.innerHTML = text;
     }
    function openCreateNewSessionDiv(){
        dom.byId("executionDetailsDiv").style.visibility = "hidden";
        dom.byId("createReviewerSessionDiv").style.visibility = "visible";
        dom.byId("duplicateFilter").value= "None";
        return false;
     }
     function hideCreateNewSessionDiv(){
        dom.byId("createReviewerSessionDiv").style.visibility = "hidden";
     }
    });
    function uploadPopup() {
      var uploadsUrl = "../datareviewer_helper/SelectBatchJob.html";
      //When using a local Data Reviewer Server replace above line with  
      //var uploadsUrl = "https://<drsSoeServerName>:6080/arcgis/rest/services/reviewer/MapServer/uploads/upload"
      newwindow = window.open(uploadsUrl, 'name', 'height=400,width=600');
      if(window.focus) {
          newwindow.focus();
      }
      return false;
    }
</script>
</head>
   <body class="claro">
      <h2 align="center">Execute Adhoc Job Sample</h2>
      <div style="width: 100%;  overflow-x: auto;">
         <div style="padding: 0px 20px 0px 20px; float:left; margin-bottom: 20px">
            <div class="reviewerForm">
               <h1>Execute Adhoc Job Inputs</h1>
               <label for="inputTitle"> Title</label>
               <input type="text" id="inputTitle" value="" placeholder="Title for Adhoc Job execution" />
               <label for="inputSessionString">Session</label>
               <select id="selectSession" style="width:230px"><option value="">Select Session</option>
               	</select>
               	<a id="linkToCreateSession" title="Create Reviewer Session." href="#" target="_self">Create Reviewer Session</a> 
               <label for="inputFileItemId"> File Item ID</label>
               <input type="text" id="inputFileItemId" style="width:275px" placeholder="e.g. i3d87e200-490d-44fb-838b-17558cca16dc" placeholder="Uploaded batch job file item ID"/>
               <a style="padding-top: 5px" id="linkToRestUploads" title="Use REST endpoint to upload a batch job." onclick="return uploadPopup()" href="#" target="_blank">Click to select</a>
               <label for="inputCreatedBy" > Created By</label>
               <input type="text" id="inputCreatedBy" value="" placeholder="Adhoc Job Created By" />
               <button id="btnExecuteAdhocJob" class="submitButton">
                  Execute Adhoc Job
               </button>
               <div id="executeJobMessages" class="message"></div>
            </div>
         </div>
         <div style="padding: 0px 20px 0px 20px; float:left; visibility: hidden">
            <div id="executionDetailsDiv"  class="reviewerForm" >
               <label for="jobIdValue"> Adhoc Job Id </label>
               <input type="text" disabled=true id="jobIdValue" value=""/>
               <label for="textarea">Job Execution Details</label>
               <textarea id="textarea" rows="15" cols="30"></textarea>
               <button id="btnGetExecutionDetails" class="submitButton" >
                  Get Executions Details
               </button>
               <div id="executionDetailsMessages" class="message"></div>
            </div>
             <div id="createReviewerSessionDiv"  class="reviewerForm" >
             	  <h1>Create Reviewer Session Inputs:</h1>
               <label for="sessionName"> Session Name </label>
               <input type="text" id="sessionName" value="" placeholder="The name of the Reviewer Session to create."/>
               <label for="userName"> User Name </label>
               <input type="text" id="userName" placeholder="The user name when writing results to the session."/>
               <label for="versionName"> Version Name </label>
               <input type="text" id="versionName" value="Default" disabled="true"/>
                <label for="duplicateFilter"> Duplicate Filter </label>
               <select id="duplicateFilter">
               	<option value="None" selected="true">None</option>
               	<option value="Session">Session</option>
               	<option value="Database">Database</option>
               </select>
               <label for="chkStoreGeometry"> Store Geometry </label> <input type="checkbox" id="chkStoreGeometry" checked="true" style="margin:5px 0px 0px -178px; border:0px none;">
               <button id="btnCreateReviewerSession" class="submitButton" style="width:160px;">
                  Create Reviewer Session
               </button>
               <div id="createReviewerSessionMessages" class="message"></div>
            
            </div>
         </div>
      </div>
   </body>
</html>
 
          
Show Modal