Sample Java code for creating a workflow
This sample Java™ code creates a workflow, creates the steps for the workflow, defines the routing order for the steps, assigns performers to the steps, and specifies validation rules for each step. There are two samples; one for creating an item workflow and one for creating a category workflow.
Sample Java code for creating an item workflow
Context ctx = PIMContextFactory.getContext("Admin","trinitron","junitdb");
WorkflowManager wmgr = ctx.getWorkflowManager();
//Creating an Item Workflow.
Workflow wfl = wmgr.createItemWorkflow("Item Workflow1", "This is a test");
//Add a General Type Workflow Step
WorkflowStep step1 = wfl.addStep("Step 1", "step 1 description", WorkflowStep.Type.GENERAL_STEP);
//Adding performers to the workflow step.
OrganizationManager omgr = ctx.getOrganizationManager();
Role r = omgr.getRole("japiRole");
step1.addPerformer(r);
WorkflowStep initialStep = wfl.getInitialStep();
WorkflowStep successStep = wfl.getSuccessStep();
//Connecting the steps
initialStep.setNextStep("Success", step1);
step1.setNextStep("DONE", successStep);
AttributeCollectionManager amgr = ctx.getAttributeCollectionManager();
AttributeCollection ac = amgr.getAttributeCollection("WorkflowStepCollection3");
List list = new ArrayList();
list.add(ac);
step1.setEditableAttributeCollections(list, ScreenType.ITEM_SINGLE_EDIT);
wfl.save();
Sample Java code for creating a category workflow
Context ctx = PIMContextFactory.getContext("Admin","trinitron","junitdb");
WorkflowManager wmgr = ctx.getWorkflowManager();
//Creating an Item Workflow.
Workflow wfl = wmgr.createCategoryWorkflow("Category Workflow1", "This is a test");
//Add a General Type Workflow Step
WorkflowStep step1 = wfl.addStep("Step 1", "step 1 description", WorkflowStep.Type.GENERAL_STEP);
//Adding performers to the workflow step.
OrganizationManager omgr = ctx.getOrganizationManager();
Role r = omgr.getRole("japiRole");
step1.addPerformer(r);
WorkflowStep initialStep = wfl.getInitialStep();
WorkflowStep successStep = wfl.getSuccessStep();
//Connecting the steps
initialStep.setNextStep("Success", step1);
step1.setNextStep("DONE", successStep);
AttributeCollectionManager amgr = ctx.getAttributeCollectionManager();
AttributeCollection ac = amgr.getAttributeCollection("WorkflowStepCollection3");
List list = new ArrayList();
list.add(ac);
step1.setEditableAttributeCollections(list, ScreenType.CATEGORY_SINGLE_EDIT);
wfl.save();