本文整理汇总了Java中me.kafeitu.activiti.chapter17.jpa.LeaveJpaEntity类的典型用法代码示例。如果您正苦于以下问题:Java LeaveJpaEntity类的具体用法?Java LeaveJpaEntity怎么用?Java LeaveJpaEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LeaveJpaEntity类属于me.kafeitu.activiti.chapter17.jpa包,在下文中一共展示了LeaveJpaEntity类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSaveEntity
import me.kafeitu.activiti.chapter17.jpa.LeaveJpaEntity; //导入依赖的package包/类
@Deployment(resources = "chapter17/leave-jpa.bpmn")
public void testSaveEntity() {
LeaveJpaEntity leave = new LeaveJpaEntity();
leave.setReason("测试");
EntityManager manager = entityManagerFactory.createEntityManager();
manager.getTransaction().begin();
manager.persist(leave);
manager.flush();
manager.getTransaction().commit();
manager.close();
}
示例2: testJpaInActiviti
import me.kafeitu.activiti.chapter17.jpa.LeaveJpaEntity; //导入依赖的package包/类
/**
* 一个完整的测试
*/
@Deployment(resources = "chapter17/leave-jpa.bpmn")
public void testJpaInActiviti() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave-jpa").singleResult();
// 设置当前用户
String currentUserId = "henryyan";
identityService.setAuthenticatedUserId(currentUserId);
// 保存请假实体
Calendar ca = Calendar.getInstance();
LeaveJpaEntity leave = new LeaveJpaEntity();
leave.setUserId(currentUserId);
leave.setStartTime(ca.getTime());
ca.add(Calendar.DAY_OF_MONTH, 2); // 当前日期加2天
leave.setEndTime(ca.getTime());
leave.setApplyTime(new Date());
leave.setReason("学习在Activiti中使用JPA");
EntityManager manager = entityManagerFactory.createEntityManager();
manager.getTransaction().begin();
manager.persist(leave);
manager.flush();
manager.getTransaction().commit();
manager.close();
assertNotNull(leave.getId());
// 启动流程
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("leave", leave);
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), variables);
assertNotNull(processInstance);
Object varLeave = runtimeService.getVariable(processInstance.getId(), "leave");
assertNotNull(varLeave);
LeaveJpaEntity leaveInVar = (LeaveJpaEntity) varLeave;
assertEquals(leaveInVar.getId(), leave.getId());
// 部门领导审批通过
Task deptLeaderTask = taskService.createTaskQuery().taskCandidateGroup("deptLeader").singleResult();
Map<String, String> variablesString = new HashMap<String, String>();
variablesString.put("deptLeaderApproved", "true");
formService.submitTaskFormData(deptLeaderTask.getId(), variablesString);
// 人事审批通过
Task hrTask = taskService.createTaskQuery().taskCandidateGroup("hr").singleResult();
variablesString = new HashMap<String, String>();
variablesString.put("hrApproved", "true");
formService.submitTaskFormData(hrTask.getId(), variablesString);
// 销假(根据申请人的用户ID读取)
Task reportBackTask = taskService.createTaskQuery().taskAssignee(currentUserId).singleResult();
variablesString = new HashMap<String, String>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
variablesString.put("reportBackDate", sdf.format(ca.getTime()));
formService.submitTaskFormData(reportBackTask.getId(), variablesString);
// 验证请假实体的reportBackDate属性已经被更改
manager = entityManagerFactory.createEntityManager();
manager.getTransaction().begin();
LeaveJpaEntity jpaEntity = manager.find(LeaveJpaEntity.class, leave.getId());
manager.getTransaction().commit();
assertNotNull(jpaEntity.getReportBackDate());
}