Creating a review template and uploading support documents using Flex APIThe following code uploads supporting documents and creates a review template. package customsolution
{
import com.adobe.livecycle.rca.model.CustomAttribute;
import com.adobe.livecycle.rca.model.ReviewContext;
import com.adobe.livecycle.rca.model.constant.DocumentType;
import com.adobe.livecycle.rca.model.constant.DurationUnit;
import com.adobe.livecycle.rca.model.constant.StageTypes;
import com.adobe.livecycle.rca.model.document.DocumentCollection;
import com.adobe.livecycle.rca.model.document.SupportingDocument;
import com.adobe.livecycle.rca.model.participant.Approver;
import com.adobe.livecycle.rca.model.participant.ApproverCollection;
import com.adobe.livecycle.rca.model.participant.Reviewer;
import com.adobe.livecycle.rca.model.participant.ReviewerCollection;
import com.adobe.livecycle.rca.model.stage.ApprovalStage;
import com.adobe.livecycle.rca.model.stage.ReviewStage;
import com.adobe.livecycle.rca.model.stage.StageCollection;
import com.adobe.livecycle.rca.service.ServiceProvider;
import com.adobe.livecycle.rca.service.core.IReviewCommentingAndApprovalService;
import com.adobe.livecycle.rca.token.IAsyncToken;
import flash.events.*;
import flash.net.*;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.livecycle.DocumentReference;
import mx.rpc.remoting.RemoteObject;
import mx.utils.ObjectUtil;
/**
* This sample stores a review template with 2 supporting document.
* Also it shows how to upload a document to LiveCycle file upload servlet.
*
* There is a public filerefence variable defined in the class.
* To use it, create a button and bind its click with filerefence.browse();
*
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2
*/
public class StoreReviewTemplateWithSupportingDocument
{
public static var username:String;
public static var password:String;
public static var server_url:String;
public static var server_port:String;
public static var amfChannelURI:String;
public var _channelSet:ChannelSet = null;
public var rc : ReviewContext = null;
public var rcaService:IReviewCommentingAndApprovalService = null;
// File reference public variables
public var supportingDocFileRef : FileReference = new FileReference();
private var supportingDocRef : DocumentReference;
public function init():void
{
server_url="http://localhost";
server_port="8080";
amfChannelURI="/remoting/messagebroker/amf";
username= "administrator";
password = "password";
_channelSet = new ChannelSet();
_channelSet.addChannel(new AMFChannel('amf-channel',server_url+":"+server_port+amfChannelURI));
_channelSet.login(username, password);
//fileRef event handlers
supportingDocFileRef.addEventListener(Event.SELECT, supportingDocSelectHandler);
supportingDocFileRef.addEventListener(IOErrorEvent.IO_ERROR,
ioErrorHandler);
supportingDocFileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,
supportingDocFileUploaded);
rcaService =
ServiceProvider.getReviewCommentingAndApprovalService(_channelSet);
}
public function StoreReviewTemplateWithSupportingDocument()
{
init();
}
private function ioErrorHandler(event : IOErrorEvent) {
trace(ObjectUtil.toString(event));
}
private function supportingDocSelectHandler(event:Event):void {
var authTokenService:RemoteObject = new RemoteObject("LC.FileUploadAuthenticator");
authTokenService.addEventListener("result", supportingDocTokenReceived);
authTokenService.channelSet = _channelSet;
authTokenService.getFileUploadToken();
}
private function supportingDocTokenReceived(event:ResultEvent):void
{
var token:String = event.result as String;
var urlString:String = server_url + ":" + server_port;
var request:URLRequest = DocumentReference.constructRequestForUpload(urlString, token);
supportingDocFileRef.upload(request);
}
private function supportingDocFileUploaded(event:DataEvent):void {
supportingDocRef = new DocumentReference();
supportingDocRef.contentType = "application/pdf";
// assumption that the uploaded document is pdf, else define the content type for specific doc.
supportingDocRef.url = event.data;
supportingDocRef.referenceType = DocumentReference.REF_TYPE_URL;
}
private function createReviewTemplate() : void
{
rc = new ReviewContext();
rc.templateName = "CustomSolutionTemplateWithSD";
rc.templateDesc = "Sample Template";
rc.stages = new StageCollection();
//create stage
var reviewStage:ReviewStage = new ReviewStage();
reviewStage.name = "ParallelReviewStage";
reviewStage.type = StageTypes.PARALLEL_REVIEW;
reviewStage.duration = 1;
reviewStage.durationUnit= DurationUnit.DAYS;
//add reviewers
reviewStage.reviewers = new ReviewerCollection();
var reviewer:Reviewer = new Reviewer();
reviewer.canonicalName = "apink";
reviewer.domain = "DefaultDom";
reviewer.isGroup = false;
reviewer.isOptional = false;
//add review to reviewer collection
reviewStage.reviewers.addItem(reviewer);
//add stage to stage collection
rc.stages.addStage(reviewStage);
//create stage
var approvalStage:ApprovalStage = new ApprovalStage();
approvalStage.type = StageTypes.PARALLEL_APPROVAL;
approvalStage.name = "ParallelApprovalStage";
approvalStage.duration = 1;
approvalStage.durationUnit= DurationUnit.DAYS;
//add reviewers
approvalStage.approvers = new ApproverCollection();
var approver:Approver = new Approver();
approver.canonicalName = "apink";
approver.domain = "DefaultDom";
approver.isGroup = false;
//add review to reviewer collection
approvalStage.approvers.addItem(approver);
//add stage to stage collection
rc.stages.addStage(approvalStage);
//add custom attributes
var customAttributes:ArrayCollection = new ArrayCollection();
var attr1:CustomAttribute = new CustomAttribute();
attr1.attrKey = "DEPARTMENT";
attr1.attrValue = "LC";
customAttributes.addItem(attr1);
var attr2:CustomAttribute = new CustomAttribute();
attr2.attrKey = "REVISION";
attr2.attrValue = "9.5";
customAttributes.addItem(attr2);
rc.customAttributes = customAttributes;
}
public function storeTemplate() : void
{
createReviewTemplate();
var supportingDocCollection : DocumentCollection = new
DocumentCollection();
var supportingDoc1 : SupportingDocument = new SupportingDocument();
supportingDoc1.type = DocumentType.REF;
supportingDoc1.uri = "www.adobe.com";
supportingDoc1.description = "Sample reference type supporting document";
supportingDocCollection.addSupportingDocument(supportingDoc1);
var supportingDoc2 : SupportingDocument = new SupportingDocument();
supportingDoc2.type = DocumentType.DOCUMENT;
supportingDoc2.document = supportingDocRef;
supportingDoc2.name = "Supporting Doc Sample";
supportingDoc2.description = "Sample document type supporting document";
supportingDocCollection.addSupportingDocument(supportingDoc2);
var token:IAsyncToken = rcaService.storeReviewTemplate(rc,
supportingDocCollection.source);
token.addHandlers(handleStoreTemplateResult, handleStoreTemplateFault);
}
public function handleStoreTemplateResult(event: ResultEvent):void{
Alert.show("Template Stored Successfully.");
trace(ObjectUtil.toString(event));
}
public function handleStoreTemplateFault(event: FaultEvent):void{
trace(ObjectUtil.toString(event));
}
}
}
|
|
// Ethnio survey code removed