Figure 10-37. CheckAndOrder: the starting activity of AndyNailsProcess
Example 10-39. The complete code of custom class AndyNailsService
package com.farata.lc.warehouse;
import java.util.Date;
import java.util.List;
import com.farata.datasource.InventoryDAO;
import com.farata.datasource.OrderLineItemDAO;
import com.farata.datasource.dto.InventoryItemDTO;
import com.farata.datasource.dto.OrderLineItemSumDTO;
@SuppressWarnings("unchecked")
Orchestrating Processes with Asynchronous Events s | | 557
Best pdf to jpg converter for - Convert PDF to JPEG images in C#.net, ASP.NET MVC, WinForms, WPF project
How to convert PDF to JPEG using C#.NET PDF to JPEG conversion / converter library control SDK
convert pdf file to jpg; convert .pdf to .jpg online
Best pdf to jpg converter for - VB.NET PDF Convert to Jpeg SDK: Convert PDF to JPEG images in vb.net, ASP.NET MVC, WinForms, WPF project
Online Tutorial for PDF to JPEG (JPG) Conversion in VB.NET Image Application
convert pdf document to jpg; convert pdf to jpg file
IManufacturerService{
LineItemNotFoundException{
InventoryDAO dao = new InventoryDAO();
if ( lineItems.size() > 0 ){
InventoryItemDTO lineItemDTO = lineItems.get(0);
long currentQuantity = lineItemDTO.QUANTITY;
OrderLineItemDAO orderDao = new OrderLineItemDAO();
Date endDate = new Date();
OrderLineItemSumDTO sum = result.get(0);
double lastWeekDemand = sum.QUANTITY;
if ( currentQuantity - lastWeekDemand < 0 ){
return createSupplierOrder
(
lineItemDTO.LINEITEM_ID,
(new Double(lastWeekDemand)).longValue()
);
}else{
data.setOrderCreated( false );
return data;
}
}
else
}
}
While configuring the event (-based) start point, you can set the filter, similar to the
message selector. Remember the line:
props.put("ManufacturerCode", mnfCode );
from the 
EventsHelper
class from Example 10-36? Now look at Figure 10-38, which
illustrates the start point filter for AndyNailsProcess. The filter is being set to 
Manufac
turer_Code=nail
and, accordingly, events that do not contain 
"nail"
as the value of the
Manufacturer_Code
will not start the process instance.
Besides specifying a filter, you need to tell the LiveCycle engine how to map the in-
coming event data into variables of the process. Figure 10-39 illustrates how the process
variable 
LineItemId
is prescribed to take, upon the event’s arrival, the value of
lineItemId
, which was set by the 
props.put("LineItemId", lineItemId)
line of 
Even
tHelper
.
558 | | Chapter 10: Developing Flex Applications for LiveCycle Enterprise Suite
Online Convert PDF to Jpeg images. Best free online PDF JPEG
Online PDF to JPEG Converter. Download Free Trial. Convert a PDF File to JPG. Drag and drop your PDF in the box above and we'll convert the files for you.
convert pdf images to jpg; .net pdf to jpg
Online Convert Jpeg to PDF file. Best free online export Jpg image
Online JPEG to PDF Converter. Download Free Trial. Convert a JPG to PDF. You can drag and drop your JPG file in the box, and then start
pdf to jpg converter; change pdf to jpg
And so you have decomposed a complex process into a set of the simple ones:
SupplierProcessAndyNailsProcessDanielHammersProcess, and, for that matter, any
other process that will react to the 
LineItemChanged
event.
Here is the rest of the AndyNailsProcess logic. Upon return from the
AndyNailsProcess.checkAndOrder()
operation, the database might already contain a
new record in the 
supplier_order
table. In this case, the process will expect an approval
by a representative of Andy’s Nails. For the sake of simplicity, naïvely assume that such
approval is enough for the palettes with boxes of nails to magically appear in a ware-
house. The 
SupplierService.getSupplierOrderStatus()
process might need to increase
values in the 
inventory
table using 
SupplierService.increaseInventory()
.
Otherwise—if the inventory did not need to be replenished, or if the manufacturer did
not approve the order—the 
inventory
will not get changed.
Now that you know how to create custom services, plug them into processes, and
coordinate these processes with events, let’s see how to ignite it all with LiveCycle API
calls from inside your Flex application.
Figure 10-38. Setup of the event filter
Orchestrating Processes with Asynchronous Events s | | 559
C# WPF PDF Viewer SDK to convert and export PDF document to other
Best PDF Viewer control as well as a powerful .NET WinForms application to image file formats with high quality, support converting PDF to PNG, JPG, BMP and
convert pdf to jpg for; best program to convert pdf to jpg
C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
Best PDF converter SDK for Visual Studio .NET for converting PDF to image in C#.NET Support exporting PDF to multiple image forms, including Jpg, Png, Bmp
best way to convert pdf to jpg; convert pdf into jpg
Blending the LiveCycle API with Custom Flex Applications
We have armed ourselves with customer services. We have completed the Supplier-
Process and modeled a Manufacturer’s process with AndyNailsProcess. We coordinated
all processes via an asynchronous event. Now, it’s time to tie it all to the end-user UI.
We will limit the explanation to a single use case: how to start the process from the
custom Flex application. Figure 10-40 represents the screen as it is seen by the retailer
when placing an order.
The snippet of the 
Create Order VBox
from this screen is shown in Example 10-40 (see
Example 10-44 for the complete code of the corresponding CreateRequest.mxml).
Figure 10-39. Mapping the event data to the process variables
560 | | Chapter 10: Developing Flex Applications for LiveCycle Enterprise Suite
C# Create PDF from images Library to convert Jpeg, png images to
Best and professional C# image to PDF converter SDK for Visual Studio .NET. Batch convert PDF documents from multiple image formats, including Jpg, Png, Bmp, Gif
pdf to jpg converter; change file from pdf to jpg on
VB.NET PDF - Convert PDF with VB.NET WPF PDF Viewer
Best WPF PDF Viewer control as well as a powerful PDF converter. PDF to image file formats with high quality, support converting PDF to PNG, JPG, BMP and GIF.
changing pdf to jpg; convert pdf file to jpg format
Figure 10-40. Retailer starts the SupplierProcess by clicking Submit
Example 10-40. The fragment of the CreateOrder VBox
<?xml version="1.0" encoding="UTF-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete()"
>.  .  .
<mx:Label text="Create Order" width="100%" color="white" />
<mx:Button label="Submit" click="submitRequest()"/>
<mx:Button label="Cancel" click="cancelRequest()"/>
</mx:HBox>
<mx:Form width="100%">
</mx:FormItem>
<mx:FormItem label="Retailer Name: ">
<mx:Label text="{retailers.getItemAt(0).RETAILER_NAME}"/>
</mx:FormItem>
</mx:Form>
width="100%" editable="true">
</mx:columns>
</mx:DataGrid>
 .  .  .
</mx:VBox>
Remember now you want LiveCycle to store as little data as possible in its internal
database? Here is the two-step algorithm:
• The function 
submitRequest()
will remote (asynchronously) to the Java method
that persists the order to the business database.
• Upon success, the “result” event handler will remote to yet another Java method
to actually start the LiveCycle process instance, passing 
orderId
as the only
parameter.
Let’s make it happen, unraveling the steps in the reverse order.
Blending the LiveCycle API with Custom Flex Applications s | | 561
VB.NET Create PDF from images Library to convert Jpeg, png images
Best and professional image to PDF converter SDK for Visual Studio .NET. Support create PDF from multiple image formats in VB.NET, including Jpg, Png, Bmp
best pdf to jpg converter; convert pdf file into jpg format
VB.NET PDF Convert to Images SDK: Convert PDF to png, gif images
Best adobe PDF to image converter SDK for Visual Studio .NET. Convert PDF documents to multiple image formats, including Jpg, Png, Bmp, Gif, Tiff, Bitmap
convert pdf file to jpg file; convert pdf image to jpg online
Invoking a LiveCycle Process on the Server
Short of DAO methods, we will concentrate all Java methods to remote to a single Java
facade
class, 
WorkflowAssembler
. It will span methods to start the process, get a list of
tasks, complete a task, and so on:
package com.farata.warehouse.wf;
 .  .
public class WorkflowAssembler
{
public String startProcess(   String orderId ){
. . .
}
public void completeTask ( long taskId ){
. . .
}
}
To remote to this class, create the following destination in remoting-config.xml:
<destination id="WorkflowAssembler">
<properties>
<source>com.farata.warehouse.wf.WorkflowAssembler</source>
</properties>
</destination>
Now look at the implementation of the 
startProcess()
method. All roads lead to Rome.
All Java API calls require an instance of 
ServiceClientFactory
from the
com.adobe.idp.dsc.clientsdk.ServiceClientFactory
package. Example 10-41 presents
the helper method 
getServiceClientFactory()
, a part of the 
WorkflowAssembler
that
builds such a factory.
Example 10-41. A fragment of WorkflowAssember: building the ServiceClientFactory
// Obtain user login name from the FlexSession
 .  .
String loginName = .  .  .
// Obtain password via loginName from the user table
String password = .  .  .
final Properties properties = new Properties();
properties.setProperty("DSC_TRANSPORT_PROTOCOL","EJB");
properties.setProperty("DSC_SERVER_TYPE", "JBoss");
properties.setProperty("DSC_CREDENTIAL_USERNAME", loginName);
properties.setProperty("DSC_CREDENTIAL_PASSWORD", password);
properties
);
562 | | Chapter 10: Developing Flex Applications for LiveCycle Enterprise Suite
return serviceClientFactory;
}
Now that you have the factory, you can invoke SupplierProcess as shown in Exam-
ple 10-42. (Here, assume that an administrator has granted the authority to 
invoke()
the process to the user authenticated with LiveCycle via 
loginName
and 
password
. In our
case, that should be a retailer, although during the setup of the samples, we recommend
granting the invoke right to all principals from the Farata enterprise domain.)
Example 10-42. A fragment of WorkflowAssember: starting the SupplierProcess
package com.farata.warehouse.wf;
 .  .
public class WorkflowAssembler
{
public String startProcess(   String orderId ){
try   {
Map<String, String> params = new HashMap<String, String>();
params.put("orderId", orderId ) ;
InvocationRequest request =  factory.createInvocationRequest
(
"Supplier Process",
"invoke",
params,
false
) ;
InvocationResponse response = serviceClient.invoke(request);
JobId jobId = new JobId(response.getInvocationId());
return jobId.getId() ;
}
catch(Exception e){
}
}
{
 .  .
}
}
Starting a Process Instance from the Flex Application
Once you have the Java code to instantiate the SupplierProcess, the sky’s the limit. The
following snippet shows the remoting destination that you add to our Flex application’s
remoting-config.xml file to reach the 
WorkflowAssembler
class from ActionScript:
Blending the LiveCycle API with Custom Flex Applications s | | 563
<destination id="WorkflowAssembler">
<properties>
<source>com.farata.warehouse.wf.WorkflowAssembler</source>
</properties>
</destination>
In Chapter 6, we explained how to update several database tables from ActionScript
in a single database (and JEE) transaction without writing a custom Java code. Piggy-
backing on this technique, you can include one more destination in the remoting-
config.xml file:
<destination id="batchGateway">
<properties>
<source>com.theriabook.remoting.BatchGateway</source>
</properties>
</destination>
And now you can send changes to collections of orders and order items (see Exam-
ple 10-45) in a single transaction by calling 
batchService.sendBatch()
. Associating the
ResultEvent.RESULT
with the 
orderSubmitted()
method, you can ensure that the actual
start of the process is executed only if the retailer’s order has been saved in the database,
as shown in Example 10-43. The complete code of CreateRequest.mxml is shown in
Example 10-44.
Example 10-43. The fragment of WorkflowAssember: starting the SupplierProcess
private function submitRequest():void{
if ( ! isValid() )
return;
 .  .
if ( selectedItems.length > 0 && order ){
 .  .
// Update tables supplier_order and order_lineitem tables with
// in a single JEE transaction, passing changes in
var batchService:BatchService = new BatchService();
batchService.registerCollection( orderItems,1 );
batchService.registerCollection( ordersCollection,0);
var batch:Array = batchService.batchRegisteredCollections();
var token:AsyncToken = batchService.sendBatch( batch );
token.orderId = order.ORDER_ID;
}
}
private function orderSubmitted( event:ResultEvent ):void{
var orderId:String = event.token.orderId;
const workflowAssembler:RemoteObject = new RemoteObject();
workflowAssembler.destination = "WorkflowAssembler";
workflowAssembler.addEventListener(
FaultEvent.FAULT,
564 | | Chapter 10: Developing Flex Applications for LiveCycle Enterprise Suite
function error( event:FaultEvent ):void{
Alert.show( event.message.toString() );
}
);
const token:AsyncToken = workflowAssembler.startProcess( orderId );
}
Example 10-44. Complete code of CreateRequest.mxml
<?xml version="1.0" encoding="UTF-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete()"
>
<mx:Metadata>
[Event(name="back", type="mx.events.FlexEvent")]
</mx:Metadata>
color="white" paddingLeft="4"/>
<mx:Button label="Cancel" cornerRadius="0" paddingRight="5"
click="cancelRequest()"/>
</mx:HBox>
<mx:Form width="100%">
<mx:TextInput id="descriptionText" width="90%" maxChars="249"
fontWeight="normal"/>
</mx:FormItem>
<mx:FormItem label="Retailer Name: ">
<mx:Label text="{retailers.getItemAt(0).RETAILER_NAME}"/>
</mx:FormItem>
</mx:Form>
width="100%" editable="true">
<mx:columns>
<mx:DataGridColumn width="5" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas width="100%" height="100%">
width="18"
horizontalCenter="0" verticalCenter="0"
/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
width="100" editable="false"/>
Blending the LiveCycle API with Custom Flex Applications s | | 565
editable="false" textAlign="center"/>
<mx:DataGridColumn dataField="PRICE" headerText="Price"
labelFunction="priceFunction" width="20"
editable="false" textAlign="center" />
width="25" editable="false"/>
</mx:columns>
</mx:DataGrid>
<mx:Script>
<![CDATA[
import warehouse.collections.OrdersCollection;
import warehouse.collections.OrderLineItemsCollection;
import com.farata.datasource.dto.UpdatableRetailerOrderDTO;
import warehouse.collections.RetailersCollection;
import warehouse.collections.InventoryItemsCollection;
import com.farata.datasource.dto.UpdatableOrderLineItemDTO;
import com.farata.datasource.dto.OrderLineItemDTO;
import com.farata.datasource.dto.InventoryItemDTO;
import warehouse.orderClasses.OrderStatus;
import mx.rpc.AsyncToken;
import mx.formatters.CurrencyFormatter;
import mx.formatters.NumberBase;
import mx.formatters.NumberFormatter;
import mx.rpc.events.ResultEvent;
import com.farata.datasource.dto.RetailerDTO;
import warehouse.security.ISecurityContext;
import warehouse.security.SecurityContext;
import com.theriabook.remoting.BatchService;
import mx.utils.UIDUtil;
import com.farata.datasource.dto.RetailerOrderDTO;
import mx.controls.CheckBox;
import mx.events.FlexEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.logging.Log;
import mx.logging.ILogger;
import com.theriabook.rpc.remoting.*;
import com.theriabook.collections.DataCollection;
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.events.CollectionEvent;
import mx.formatters.DateFormatter;
[Bindable]private var inventoryItems:DataCollection;
[Bindable]private var retailers:DataCollection;
[Bindable]private var ordersCollection:DataCollection;
[Bindable]private var log : ArrayCollection;
private function onCreationComplete() : void {
566 | | Chapter 10: Developing Flex Applications for LiveCycle Enterprise Suite
Documents you may be interested
Documents you may be interested