Scheduled Batch Validation
ScheduledBatchValidation.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="Schedule Batch Validation Job Sample"> <!-- Data Reviewer’s data validation provides the ability to schedule a Reviewer Batch Job, which contains your validation rules, and execute it 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 a scheduled data validation based on the rules and conditions defined in it. Scheduled data validations run repeatedly according to a schedule and terminate once the maxNumberOfExecutions has been exceeded or the executionEndDate has passed. This sample allows you to specify an hourly, daily or weekly schedule. The hourly schedule executes every one hour from the nearest hour. The daily schedule executes at 12:00 PM (noon). The weekly schedule executes every Friday at 12:00 PM (noon). --> <fx:Declarations> <drs:BatchValidationTask id="batchvalidationTask" url="{_soeUrl}" scheduleJobComplete="batchvalidationTask_scheduleJobCompleteHandler(event)" getReviewerSessionsComplete="batchvalidationTask_getReviewerSessionsCompleteHandler(event)" createReviewerSessionComplete="batchvalidationTask_createReviewerSessionCompleteHandler(event)" fault="faultHandler(event)" showBusyCursor="true" disableClientCaching="true"/> </fx:Declarations> <fx:Script> <![CDATA[ import com.esri.drs.BatchValidationJobDetails; 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.controls.Text; import mx.core.IFlexDisplayObject; import mx.events.CloseEvent; import mx.events.FlexEvent; import mx.managers.PopUpManager; import mx.rpc.Fault; import mx.rpc.events.FaultEvent; import spark.components.TitleWindow; import spark.events.IndexChangeEvent; //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 the 'BatchValidationTask scheduleJob completed' event protected function batchvalidationTask_scheduleJobCompleteHandler(event:DataReviewerTaskEvent):void { currentState="schedule"; bvScheduleJobDetails.text=""; } // 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); } // Schedules the batch job protected function scheduleJob_clickHandler(event:MouseEvent):void { //Set state to data currentState="data"; if (validateInputs()) { // Set up the DataReviewer SOE URL batchvalidationTask.url=_soeUrl; //Create Batch Validation Parameters object and set all user inputs var bvParams:BatchValidationParameters=new BatchValidationParameters(); //title of the batch job bvParams.title=bvTitle.text; //Optional // set session id. Session Id is full reviewer session (eg: Session 1 : Session 1) bvParams.sessionString=selectSession.selectedItem; //Mandatory // set uploaded rbj file item id bvParams.fileItemId=bvFileItemID.text; //Mandatory //set the name of the user bvParams.createdBy=bvCreatedBy.text; //Mandatory //set the cronExpression for job schedule bvParams.cronExpression=bvRecurrence.selectedItem.data; //Mandatory //set the number of times the job will execute bvParams.maxNumberOfExecutions=Number(bvMaxExecutions.text); //Optional //schedule new job using BatchValidationTask batchvalidationTask.scheduleJob(bvParams); } } // Handles click event for Get Scheduled Job Details button protected function getDetails_clickHandler(event:MouseEvent):void { batchvalidationTask.getJobDetails(batchvalidationTask.scheduleJobLastResult); } //Handles fault protected function faultHandler(event:FaultEvent):void { currentState="error"; var msg:String=event.fault.faultString; if (msg == null || msg.length == 0) { msg="Empty server response received."; } errorMessage.text="Error: " + msg; } //Private Helper function to validate Schedule Job inputs private function validateInputs():Boolean { if (selectSession.selectedItem.length == 0 || bvFileItemID.text.length == 0) { Alert.show("Invalid Inputs. Please complete the form."); return false; } 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(); } //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 batchvalidationTask_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 batchvalidationTask_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"; } //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); } // 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="schedule"/> <s:State name="error"/> </s:states> <s:controlBarContent> <s:Label width="100%" text="The following sample schedules 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>. Specify a recurrence and number of executions. Then click Schedule Job to submit the scheduled 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%" horizontalCenter="0" verticalCenter="0"> <s:VGroup horizontalCenter="0" paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20"> <s:VGroup id="mainContent" width="590" verticalAlign="middle" 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="Schedule Job Inputs"/> <s:FormItem label="Title"> <s:TextInput id="bvTitle" width="100%" toolTip="Title of the scheduled batch job" prompt="Title for scheduled batch job"/> </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)"/> <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="bvChooseJob" 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="Schedule Job Created By" prompt="Schedule Job Created By"/> </s:FormItem> <s:FormItem label="Recurrence"> <s:DropDownList id="bvRecurrence" width="100%" selectedIndex="0"> <s:ArrayCollection> <fx:Object data="0 0/15 * * * ?" label="15 Minutes"/> <fx:Object data="0 0/30 * * * ?" label="30 Minutes"/> <fx:Object data="0 0 12 1 1 ? *" label="Hourly"/> </s:ArrayCollection> </s:DropDownList> </s:FormItem> <s:FormItem label="No. of Executions"> <s:TextInput id="bvMaxExecutions" width="100%" maxChars="1" toolTip="Maximum number of scheduled executions" restrict="[1-3]" text="1" prompt="Maximum number of scheduled executions"/> </s:FormItem> <s:FormItem> <s:layout> <s:HorizontalLayout horizontalAlign="right"/> </s:layout> <s:Button id="scheduleJob" label="Schedule Job" click="scheduleJob_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"/> </s:FormItem> <!-- Scheduled job details --> <s:Spacer height="60" includeIn="schedule"/> <s:FormItem label="Scheduled Job Id" includeIn="schedule"> <s:TextInput id="bvScheduleJobId" width="100%" text="{batchvalidationTask.scheduleJobLastResult}" editable="false"/> </s:FormItem> <s:FormItem label="Scheduled Job Details" includeIn="schedule"> <s:TextArea id="bvScheduleJobDetails" width="100%" text="{JSON.stringify(batchvalidationTask.getJobDetailsLastResult)}" editable="false"/> </s:FormItem> <s:FormItem includeIn="schedule"> <s:layout> <s:HorizontalLayout horizontalAlign="right"/> </s:layout> <s:Button id="getScheduleJobDetails" label="Get Scheduled Job Details" click="getDetails_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