Ad Hoc Batch Validation
Description
This sample shows how to execute Ad Hoc Batch Validation in ArcGIS Data Reviewer for Server using the JavaScript API. Batch validation checks data based on business rules within an .rbj file. Ad Hoc Batch Validation runs immediately and one time only. Validation results are written to a Reviewer workspace.
Validation requires an .rbj file. The live sample allows you to validate data on a hosted instance of Data Reviewer for Server. You choose an existing, previously uploaded .rbj file to use for validation. It does not allow you to upload an .rbj file.
The following code allows you to upload an .rbj file to ArcGIS for Server using the REST uploads operation. This operation returns a File Item Id. Data Reviewer for Server locates the uploaded .rbj file using the File Item Id. It then uses the rules and conditions specified in the file to validate data. You must specify the URL of your own Data Reviewer for Server and relative paths to your local copies of drs.js, style.css, and proxy.ashx.
The Data Reviewer API for JavaScript 3.4 or later requires a proxy page to support POST requests and ArcGIS token-based authentication.
Code
The following code sample executes Ad Hoc Batch Validation.
<!DOCTYPE html>
<!--
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011-2015 Esri
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this software, with or without
// modification, provided you include the original copyright and use
// restrictions. See use restrictions in the file use_restrictions.txt.
//
////////////////////////////////////////////////////////////////////////////////
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.13/dijit/themes/claro/claro.css">
<link rel="stylesheet" type="text/css" href="../style.css"/>
<title>Execute Adhoc Job Sample</title>
<!-- Configure Dojo -->
<script>
dojoConfig = {
async : true,
parseOnLoad : true
};
</script>
<!-- load esri api and dojo -->
<script src="http://js.arcgis.com/3.13/"></script>
<!-- load drs api -->
<script src="../drs_js_api/drs.js"></script>
<script type="text/javascript">
var bvTask,uploadsUrl;
var drsSoeUrl="http://datareviewer.arcgisonline.com/arcgis/rest/services/Samples/reviewerWriteResults/MapServer/exts/DataReviewerServer";
require(
[
"dojo/dom",
"dojo/on",
"drs/BatchValidationTask",
"drs/BatchValidationParameters",
"drs/SessionProperties",
"dojo/domReady!"
],
function(dom, on, BatchValidationTask, BatchValidationParameters,SessionProperties) {
//identify proxy page to use
esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
esri.config.defaults.io.alwaysUseProxy = false;
// 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;
// we're using dojo deferred 'then' function to do callback function
//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 sessionProperties=new SessionProperties();
//The user account to associate with a session.
sessionProperties.userName=dom.byId("userName").value;
//Indicates an enterprise geodatabase version to associate with the session.
sessionProperties.versionName=dom.byId("versionName").value;
//Indicates how to handle duplicate results when writing the results to the Reviewer workspace.
sessionProperties.duplicateFilter=dom.byId("duplicateFilter").value;
//Indicates if validation result geometries are stored in the Reviewer workspace.
sessionProperties.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 Session Properties
var newSessionDeferred=bvTask.createReviewerSession(dom.byId("sessionName").value,sessionProperties);
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.jobExecutionDetails.status;
if(response.jobExecutionDetails.messages != null) {
jobDetails = jobDetails + "\n" + response.jobExecutionDetails.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 = "SelectBatchJob.html"
//When using a local Data Reviewer Server replace above line with
//var uploadsUrl = "http://<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>