09-07-2012 08:45 AM
package com.rolta.onv.ui.customerregistration;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.activiti.cdi.BusinessProcess;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.log4j.Logger;
import com.rolta.onv.ui.util.CustomerUtil;
@ManagedBean(name="customerService")
@RequestScoped
public class CustomerService {
private static Logger sLog = Logger.getLogger(CustomerService.class.getName());
public static final String VARNAME_CUSTOMER_ID = "customerId";
public static final String PROCESS_KEY = "uimediator";
private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("Worksample");
EntityManager entityManager= factory.createEntityManager();
private BusinessProcess businessProcess;
private CustomerEO customer;
@ManagedProperty(value="#{customerUtil}")
private CustomerUtil customerUtil;
public CustomerEO getCustomer()
{
if(customer==null)
{
Long customerId = businessProcess.getVariable(VARNAME_CUSTOMER_ID);
customer = entityManager.find(CustomerEO.class, customerId);
}
return customer;
}
public CustomerEO getNewOrder() {
if (customer == null) {
customer = new CustomerEO();
}
return customer;
}
public CustomerService() {
}
public CustomerUtil getCustomerUtil() {
return customerUtil;
}
public void setCustomerUtil(CustomerUtil customerUtil) {
this.customerUtil = customerUtil;
}
public ProcessInstance startCustomerRegistration() {
if (customer == null) {
customer = new CustomerEO();
}
entityManager.getTransaction().begin();
customer.setFirstname(customerUtil.getUserName());
customer.setLastname(customerUtil.getLastName());
entityManager.persist(customer);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(VARNAME_CUSTOMER_ID, customer.getId());
this.customer = null;
entityManager.getTransaction().commit();
System.out.println("variables—————"+variables);
return businessProcess.startProcessByKey(PROCESS_KEY, variables);
}
}
09-11-2012 11:47 AM
@Inject private BusinessProcess businessProcess;
But you must use Activiti CDI first in your configuration. See manual.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.