当前位置: 首页>>代码示例>>Java>>正文


Java LeaveJpaEntity类代码示例

本文整理汇总了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();
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:14,代码来源:LeaveJpaEntityTest.java

示例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());
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:69,代码来源:LeaveJpaEntityTest.java


注:本文中的me.kafeitu.activiti.chapter17.jpa.LeaveJpaEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。