Adhoc Batch Validation
AdhocBatchValidation.mxml
<?xml version="1.0" encoding="utf-8"?> <!-- //////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2008-2014 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. // //////////////////////////////////////////////////////////////////////////////// --> <s:Application minHeight="400" minWidth="600" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:drs="com.esri.drs.*" pageTitle="Execute AdHoc Job Sample" xmlns:tasks="com.esri.ags.tasks.*"> <!-- Data Reviewer’s data validation provides the ability to execute a Reviewer Batch Job, which contains your validation rules, on the server. The results from the validation are written to a Reviewer workspace. This sample allows you to upload a Reviewer Batch Job file (.rbj) using the REST uploads operation and will return a File Item Id. The File Item Id is used to locate the uploaded RBJ file and will execute an adhoc data validation based on the rules and conditions defined in it. --> <fx:Declarations> <!--Create a BatchValidation Task and configure its URL and event handlers --> <drs:BatchValidationTask id="batchvalidationTask" url="{_soeUrl}" getJobExecutionDetailsComplete="bvTask_getJobExecDetailsCompleteHandler(event)" getReviewerSessionsComplete="bvTask_getReviewerSessionsCompleteHandler(event)" createReviewerSessionComplete="bvTask_createReviewerSessionCompleteHandler(event)" fault="faultHandler(event)" showBusyCursor="true" disableClientCaching="true"/> </fx:Declarations> <fx:Script> <![CDATA[ import com.esri.drs.BatchValidationJobExecutionDetails; import com.esri.drs.BatchValidationParameters; import com.esri.drs.DataReviewerTaskEvent; import com.esri.drs.ReviewerSession; import com.esri.drs.SessionProperties; import com.esri.drs.utils.ReviewerMapServerHelper; import mx.controls.Alert; import mx.rpc.Fault; import mx.rpc.events.FaultEvent; import mx.core.IFlexDisplayObject; import mx.events.CloseEvent; import mx.managers.PopUpManager; import mx.events.FlexEvent; import spark.events.IndexChangeEvent; import spark.components.TitleWindow; import flash.external.*; //Job Execution Details [Bindable]private var _jobExecutionDetails:BatchValidationJobExecutionDetails; //Amazon instance for Data Reviewer Server. Change to your Data Reviewer Server SOE URL to run this sample in your environment private var _soeUrl:String = "http://datareviewer.arcgisonline.com/arcgis/rest/services/Samples/reviewerWriteResults/MapServer/exts/DataReviewerServer"; private var _reviewerSessionsDP:ArrayCollection = new ArrayCollection(); // Handles action of choosing/selecting a batch job for Adhoc execution protected function bvChooseJob_clickHandler(event:MouseEvent):void { //Use ArcGIS Server REST's upload operation to upload a batch job to server //before it can be executed by BatchValidationTask //Uncomment the following 4 lines to execute this sample in your own environment //var revMapServerHelper:ReviewerMapServerHelper = new ReviewerMapServerHelper(_soeUrl); //var uploadsUrl:String = revMapServerHelper.getReviewerMapServerUrl() + "/uploads/upload"; //var uploadsURLRequest:URLRequest = new URLRequest(uploadsUrl); //navigateToURL(uploadsURLRequest, "_blank"); //comment the next four lines out to run the sample in your own environment var selectBatchJobWindow:SelectBatchJob = SelectBatchJob(PopUpManager.createPopUp(this,SelectBatchJob, true)); selectBatchJobWindow.targetComponent = bvFileItemID; PopUpManager.centerPopUp(selectBatchJobWindow); //Add Close Event handler selectBatchJobWindow.addEventListener(CloseEvent.CLOSE,closeHandler); } // Executes the adhoc batch validation protected function executeButton_clickHandler(event:MouseEvent):void { //Set Job Execution Details to Null _jobExecutionDetails = null; //Clear any JOB ID if (this.bvAdhocJobId) { this.bvAdhocJobId.text = ""; } //Set state to data currentState = "data"; errorMessage.text = ""; //Check if we have valid inputs and execute batch validation if (validateInputs()) { //Create Batch Validation Parameters object and set all user inputs var bvParams:BatchValidationParameters = new BatchValidationParameters(); bvParams.title = bvTitle.text; //Optional bvParams.sessionString = selectSession.selectedItem; //Mandatory bvParams.fileItemId = bvFileItemID.text; //Mandatory bvParams.createdBy = bvCreatedBy.text; //Optional //Execute Batch Job using BatchValidationTask batchvalidationTask.executeJob(bvParams); //Set current state to Execute from Data currentState = 'execute'; } } // Handles click event for checkJobStatus link button protected function checkJobStatus_clickHandler(event:MouseEvent):void { //Clearing error message if we are dealing with the status of the same Job. //This is done because the job status may have changed and will be handled //again by getJobExectionDetails_Complete handler if (this.bvAdhocJobId.text == batchvalidationTask.executeJobLastResult) { this.errorMessage.text = ""; } // Get job execution details for job id batchvalidationTask.getJobExecutionDetails(batchvalidationTask.executeJobLastResult); } //Handles getJobExecutionDetails Complete event protected function bvTask_getJobExecDetailsCompleteHandler(event:DataReviewerTaskEvent):void { //Update the BatchValidationJobExecutionDetails variable which is already binded //to text area for displaying status of Batch validation execution details. _jobExecutionDetails = batchvalidationTask.getJobExecutionDetailsLastResult as BatchValidationJobExecutionDetails; } // Handles fault for execute, getJobExectionDetails,getReviewerSessions and createReviewerSession methods of Batch Validation Task protected function faultHandler(event:FaultEvent):void { //Set the current state of the application to error currentState = "error"; var fault:Fault = event.fault; var msg:String = fault.faultString; //Get fault content and messages and append to error message text if (fault.content != null && fault.content as Array != null) { msg = fault.content[1].message; } //Set error message to text for displaying errors to user errorMessage.text = "Error : " + msg; } //Private Helper function to valiate Adhoc Job inputs private function validateInputs():Boolean { //validate required inputs for executing a batch validation task if (selectSession.selectedItem == null || selectSession.selectedItem < 1 || bvFileItemID.text == null || bvFileItemID.text.length < 1) { Alert.show("invalid inputs. please complete the form."); return false; } else { return true; } } //Handles close event for PopupManager private function closeHandler(event:Event):void { event.target.removeEventListener(CloseEvent.CLOSE,closeHandler); PopUpManager.removePopUp(event.target as IFlexDisplayObject); } // Handles click event for bvCreateReviewerSession link button protected function bvCreateReviewerSession_clickHandler(event:MouseEvent):void { // Display input parameters for create reviewer session openCreateNewSessionDiv(); } //Populate selectSession DropDownList after it's creation protected function selectSession_creationCompleteHandler(event:FlexEvent):void { batchvalidationTask.getReviewerSessions(); } // Handles click event for createSessionButton button protected function createSessionButton_clickHandler(event:MouseEvent):void { //Create a new reviewer session createNewSession(); } //Private Helper function to create a new reviewer session private function createNewSession():void { //Null check for input parameters if((!bvSessionName.text) || (!(bvUserName.text))) { Alert.show("Please fill out Create Reviewer Session inputs"); return; } var sessionName:String = bvSessionName.text; //The user account to associate with a session. var userName:String = bvUserName.text; //Indicates an enterprise geodatabase version to associate with the session. var versionName:String = bvVersionName.text; //Indicates how to handle duplicate results when writing the results to the Reviewer workspace. var dupFilter:String = bvDupFilter.selectedItem; //Indicates if validation result geometries are stored in the Reviewer workspace. var storeGeometry:Boolean = chkStoreGeometry.selected; //SessionProperties object required for createReviewerSession method var sessionProperties:SessionProperties = new SessionProperties(userName,versionName,dupFilter,storeGeometry); //Create a new Reviewer Session that will store sessions in a reviewer workspace. The function accepts two parameters. Session Name and Session Properties batchvalidationTask.createReviewerSession(sessionName,sessionProperties); } //Hide input parameters for create reviewer session once a session is selected protected function selectSession_changeHandler(event:IndexChangeEvent):void { hideCreateNewSessionDiv(); } //Handles getReviewerSessions Complete event protected function bvTask_getReviewerSessionsCompleteHandler(event:DataReviewerTaskEvent):void { //Re-populates selectSession DropDownList which is binded to _reviewerSessionsDP parameter var reviewerSessionsList:Object = batchvalidationTask.getReviewerSessionsLastResult; if(_reviewerSessionsDP != null && reviewerSessionsList != null) { _reviewerSessionsDP.removeAll(); for each (var revSession:ReviewerSession in reviewerSessionsList) { _reviewerSessionsDP.addItem(revSession.toString()); } } } //Handles createReviewerSession Complete event protected function bvTask_createReviewerSessionCompleteHandler(event:DataReviewerTaskEvent):void { var newReviewerSession:ReviewerSession = batchvalidationTask.createReviewerSessionLastResult as ReviewerSession; if(newReviewerSession != null) { //Add new session to selectSession DropDownList _reviewerSessionsDP.addItem(newReviewerSession.toString()); //Selecte the new session in selectSession DropDownList selectSession.selectedIndex = selectSession.dataProvider.length-1; } hideCreateNewSessionDiv(); currentState = "data"; } // Display input parameters for create reviewer session private function openCreateNewSessionDiv():void { mainContent.width = 560*2; bvInputs.width = mainContent.width/2; createSessionInputs.width = mainContent.width/2; createSessionInputs.visible = true; } // Hide input parameters for create reviewer session private function hideCreateNewSessionDiv():void { mainContent.width = 560; bvInputs.width = mainContent.width; createSessionInputs.width = 0; createSessionInputs.visible = false; } ]]> </fx:Script> <s:states> <s:State name="data"/> <s:State name="execute"/> <s:State name="error"/> </s:states> <s:controlBarContent> <s:Label width="100%" text="The following sample executes a Reviewer Batch Job for validation on an ArcGIS Data Reviewer for Server hosted on Amazon. Provide a title for the data validation. Enter the full session name, Session 1 : <name>. Provide a user name for Created By. Then click Execute Adhoc Job to submit the validation request. To run the sample against your own Data Reviewer Server, see comments in code for _soeUrl variable and bvChooseJob_clickHandler function."/> </s:controlBarContent> <s:Spacer height="50"/> <s:Scroller width="100%" height="100%"> <s:VGroup horizontalCenter="0" paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20"> <s:VGroup id="mainContent" width="560" gap="20"> <s:BorderContainer width="100%" borderAlpha="0.5"> <s:layout> <s:HorizontalLayout gap="0"/> </s:layout> <s:Form id="bvInputs" width="100%"> <s:layout> <s:FormLayout gap="-5"/> </s:layout> <!-- BV input form --> <s:FormHeading label="Execute Adhoc Job Inputs"/> <s:FormItem label="Title "> <s:TextInput id="bvTitle" width="100%" toolTip="Title for Adhoc Job Execution" prompt="Title for Adhoc Job Execution"/> </s:FormItem> <s:FormItem label="Session"> <s:layout> <s:HorizontalLayout gap="0"/> </s:layout> <s:DropDownList id="selectSession" width="100%" prompt="Select Session" dataProvider="{_reviewerSessionsDP}" creationComplete="selectSession_creationCompleteHandler(event)" change="selectSession_changeHandler(event)"> </s:DropDownList> <mx:LinkButton id="bvCreateReviewerSession" label="Create Reviewer Session" toolTip="Create a new Reviewer Session" click="bvCreateReviewerSession_clickHandler(event)"/> </s:FormItem> <s:FormItem label="File Item ID"> <s:layout> <s:HorizontalLayout gap="0"/> </s:layout> <s:TextInput id="bvFileItemID" width="100%" toolTip="File Item ID of Batch Job" prompt="e.g. i3d87e200-490d-44fb-838b-17558cca16dc"/> <mx:LinkButton id="bvFileUpload" label="Click to Select" toolTip="Click to select a batch job" click="bvChooseJob_clickHandler(event)"/> </s:FormItem> <s:FormItem label="Created By"> <s:TextInput id="bvCreatedBy" width="100%" toolTip="Adhoc Job Created By" prompt="Adhoc Job Created By"/> </s:FormItem> <s:FormItem> <s:layout> <s:HorizontalLayout horizontalAlign="right"/> </s:layout> <s:Button id="executeButton" label="Execute Adhoc Job" click="executeButton_clickHandler(event)"/> </s:FormItem> <!-- Error message --> <s:FormItem width="100%" includeIn="error" itemCreationPolicy="immediate"> <s:layout> <s:BasicLayout/> </s:layout> <s:Label id="errorMessage" x="-82" width="337" color="red" includeIn="error" itemCreationPolicy="immediate"/> </s:FormItem> <!-- Execution status and details --> <s:Spacer height="60" includeIn="execute,error" itemCreationPolicy="immediate"/> <s:FormItem label="Adhoc Job Id" includeIn="execute,error" itemCreationPolicy="immediate"> <s:TextInput id="bvAdhocJobId" width="100%" enabled="false" text="{batchvalidationTask.executeJobLastResult}"/> </s:FormItem> <s:FormItem label="Execution Details" includeIn="execute,error" itemCreationPolicy="immediate"> <s:TextArea id="bvExecutionDetails" width="100%" text="{_jobExecutionDetails.messages || _jobExecutionDetails.status}" editable="false"/> </s:FormItem> <s:FormItem includeIn="execute,error" itemCreationPolicy="immediate"> <s:layout> <s:HorizontalLayout horizontalAlign="right"/> </s:layout> <!-- Check Job Status Button should be enabled only when there is a valid Adhoc Job is executing --> <s:Button id="checkJobStatus" enabled="{bvAdhocJobId.text != ''}" label="Get Execution Details" click="checkJobStatus_clickHandler(event)"/> </s:FormItem> </s:Form> <!--Create Reviewer Session Parameters--> <s:Form id="createSessionInputs" width="0" visible="false"> <s:layout> <s:FormLayout gap="-5"/> </s:layout> <s:FormHeading label="Create Reviewer Session"/> <s:FormItem label="Session Name"> <s:TextInput id="bvSessionName" width="100%" toolTip="The name of the Reviewer Session to create." prompt="The name of the Reviewer Session to create."/> </s:FormItem> <s:FormItem label="User Name"> <s:TextInput id="bvUserName" width="100%" toolTip="The user name when writing results to the session." prompt="The user name when writing results to the session."/> </s:FormItem> <s:FormItem label="Version Name"> <s:TextInput id="bvVersionName" width="100%" text="Default" enabled="false"/> </s:FormItem> <s:FormItem label="Duplicate Filter"> <s:DropDownList id="bvDupFilter" width="100%" selectedIndex="0"> <s:ArrayCollection> <fx:String>None</fx:String> <fx:String>Session</fx:String> <fx:String>Database</fx:String> </s:ArrayCollection> </s:DropDownList> </s:FormItem> <s:FormItem label="Session"> <s:layout> <s:HorizontalLayout gap="0"/> </s:layout> <s:CheckBox id="chkStoreGeometry" width="100%" label="Store Geometry" selected="true"> </s:CheckBox> <s:Button id="createSessionButton" label="Create Reviewer Session" click="createSessionButton_clickHandler(event)"/> </s:FormItem> </s:Form> </s:BorderContainer> </s:VGroup> </s:VGroup> </s:Scroller> </s:Application>
Copyright © 1995-2015 Esri. All rights reserved.
2/23/2015