camunda用户的一些简单操作
阅读原文时间:2023年07月08日阅读:1

act_id_group:存放组信息
act_id_membership:存放用户与组的相关信息
act_id_user:存放用户
act_id_info:存放用户个人信息
act_id_tenant:存放租户信息
act_id_tenant_member:存放租户与用户或者组的相关信息

/**
* 操作用户
*/
public class ZccIdentifuService {
IdentityService identityService;
@Before
public void init(){
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("camunda.cfg.xml");
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
identityService = processEngine.getIdentityService();
System.out.println("identityService:"+identityService);
}
@Test
public void getIdentityService(){
init();
}

/\*\*  
 \* insert into ACT\_ID\_USER (ID\_, FIRST\_, LAST\_, EMAIL\_, PWD\_, SALT\_, REV\_) values ( ?, ?, ?, ?, ?, ?, 1 )  Update counts: \[1\]  
 \* Parameters: zcc1(String), zcc(String), zcc(String), zcc@qq.com(String), 1(String), 1(String)  
 \*/  
@Test  
public void saveUser(){  
    UserEntity userEntity=new UserEntity();  
    userEntity.setId("zcc1");  
    userEntity.setEmail("zcc@qq.com");  
    userEntity.setFirstName("zcc");  
    userEntity.setLastName("zcc");  
    userEntity.setDbPassword("1");  
    userEntity.setSalt("1");  
    identityService.saveUser(userEntity);  
}  
@Test  
public void saveUser2(){  
    UserEntity userEntity=new UserEntity();  
    userEntity.setId("zcc2");  
    userEntity.setEmail("zcc2@qq.com");  
    userEntity.setFirstName("zcc");  
    userEntity.setLastName("zcc");  
    userEntity.setPassword("1");  
    identityService.saveUser(userEntity);  
}

/\*\*  
 \* select distinct RES.\* from ACT\_ID\_USER RES order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \*/  
@Test  
public void createUserQuery(){  
    UserQuery userQuery = identityService.createUserQuery();  
    List<User> list = userQuery.list();  
    for (int i=0;i<list.size();i++){  
        User user = list.get(i);  
        System.out.println(user.getFirstName());  
        System.out.println(user.getLastName());  
        System.out.println(user.getId());  
        System.out.println(user.getPassword());  
        System.out.println(user.getEmail());  
    }

}

/\*\*  
 \* select distinct RES.\* from ACT\_ID\_USER RES WHERE RES.ID\_ in ( ? , ? ) order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \*/  
@Test  
public void createUserQuery2(){  
    UserQuery userQuery = identityService.createUserQuery();  
    List<User> list = userQuery.userIdIn("zcc1","zcc2").  
            list();  
    for (int i=0;i<list.size();i++){  
        User user = list.get(i);  
        System.out.println(user.getFirstName());  
        System.out.println(user.getLastName());  
        System.out.println(user.getId());  
        System.out.println(user.getPassword());  
        System.out.println(user.getEmail());  
    }

}

/\*\*  
 \* select distinct RES.\* from ACT\_ID\_USER RES order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \* Parameters: 3(Integer), 0(Integer)  
 \*/  
@Test  
public void listPage(){  
    int maxResult=3;  
    int fistResult=maxResult\*(1-1);  
    UserQuery userQuery = identityService.createUserQuery();  
    List<User> list = userQuery.listPage(fistResult,maxResult);  
    for (int i=0;i<list.size();i++){  
        User user = list.get(i);  
        System.out.println(user.getFirstName());  
        System.out.println(user.getLastName());  
        System.out.println(user.getId());  
        System.out.println(user.getPassword());  
        System.out.println(user.getEmail());  
    }

}

/\*\*  
 \* delete from ACT\_ID\_USER where ID\_ = ? and REV\_ = ?  
 \* delete from ACT\_ID\_MEMBERSHIP where USER\_ID\_ = ?    Update counts: \[0\]  
 \* Result 1:   delete from ACT\_ID\_TENANT\_MEMBER where USER\_ID\_ = ?    Update counts: \[0\]  
 \* Result 2:   delete from ACT\_ID\_USER where ID\_ = ? and REV\_ = ? Update counts: \[1\]  
 \*/  
@Test  
public void deleteUser(){  
    String userId="zcc1";  
    identityService.deleteUser(userId);

}

/\*\*  
 \* insert into ACT\_ID\_GROUP (ID\_, NAME\_, TYPE\_, REV\_) values ( ?, ?, ?, 1 )  
 \* Parameters: group1(String), 项目1(String), 工作流(String)  
 \*/  
@Test  
public  void saveGroup(){  
    GroupEntity groupEntity=new GroupEntity();  
    groupEntity.setId("group1");  
    groupEntity.setName("项目1");  
    groupEntity.setType("工作流");  
    identityService.saveGroup(groupEntity);  
}

/\*\*  
 \* select distinct RES.\* from ACT\_ID\_GROUP RES order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \* 组查询可以和用户查询一样添加查询条件  
 \*/  
@Test  
public  void createGroupQuery(){

    GroupQuery groupQuery = identityService.createGroupQuery();  
    List<Group> list = groupQuery.list();  
    for (int i=0;i<list.size();i++){  
        Group group = list.get(i);  
        System.out.println(group.getId());  
        System.out.println(group.getName());  
        System.out.println(group.getType());  
    }  
}

/\*\*  
 \* 创建组和用户的联系  
 \* insert into ACT\_ID\_MEMBERSHIP (USER\_ID\_, GROUP\_ID\_) values ( ?, ? )  
 \*/  
@Test  
public  void createMembership(){  
    String userId="zcc2";String groupId="group1";  
    identityService.createMembership(userId,groupId);  
}

/\*\*  
 \* delete from ACT\_ID\_GROUP where ID\_ = ? and REV\_ = ?  
 \* delete from ACT\_ID\_MEMBERSHIP where GROUP\_ID\_ = ?   Update counts: \[1\]  
 \* delete from ACT\_ID\_TENANT\_MEMBER where GROUP\_ID\_ = ?    Update counts: \[0\]  
 \*delete from ACT\_ID\_GROUP where ID\_ = ? and REV\_ = ?  Update counts: \[1\]  
 \*/  
@Test  
public  void deleteGroup(){  
    String groupId="group1";  
    identityService.deleteGroup(groupId);  
}

/\*\*  
 \* 租户存在的目的就是区分不同的系统,A系统和B系统的用户是不一样的,所以要区分  
 \* insert into ACT\_ID\_TENANT (ID\_, NAME\_, REV\_) values ( ?, ?, 1 )  
 \* Parameters: A(String), A系统(String)  
 \*/  
@Test  
public  void saveTenant(){  
    TenantEntity tenantEntity=new TenantEntity();  
    tenantEntity.setId("A");  
    tenantEntity.setName("A系统");  
    identityService.saveTenant(tenantEntity);  
}

/\*\*  
 \* 租户和用户  
 \*  insert into ACT\_ID\_TENANT\_MEMBER (ID\_, TENANT\_ID\_, USER\_ID\_, GROUP\_ID\_) values ( ?, ?, ?, ? )  
 \*   Parameters: 101(String), A(String), zcc2(String), null  
 \*/  
@Test  
public  void createTenantUserMembership(){  
    String tenantId="A";String userId="zcc2";  
    identityService.createTenantUserMembership(tenantId,userId);  
}

/\*\*  
 \* 租户和组  
 \* insert into ACT\_ID\_TENANT\_MEMBER (ID\_, TENANT\_ID\_, USER\_ID\_, GROUP\_ID\_) values ( ?, ?, ?, ? )  
 \* 201(String), A(String), null, group1(String)  
 \*/  
@Test  
public  void createTenantGroupMembership(){  
    String tenantId="A";String groupId="group1";  
    identityService.createTenantGroupMembership(tenantId,groupId);  
}

/\*\*  
 \* 查询租户下面有哪些用户  
 \* select distinct RES.\* from ACT\_ID\_USER RES inner join ACT\_ID\_TENANT\_MEMBER TM on RES.ID\_ = TM.USER\_ID\_ WHERE TM.TENANT\_ID\_ = ? order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \*  Parameters: A(String), 2147483647(Integer), 0(Integer)  
 \*/  
@Test  
public  void createUserQueryMemberOfTenant(){  
    String tenantId="A";  
    UserQuery userQuery = identityService.createUserQuery();  
    List<User> list = userQuery.memberOfTenant(tenantId).list();  
    for (int i=0;i<list.size();i++){  
        User user = list.get(i);  
        System.out.println(user.getFirstName());  
        System.out.println(user.getLastName());  
        System.out.println(user.getId());  
        System.out.println(user.getPassword());  
        System.out.println(user.getEmail());  
    }  
}  
/\*\*  
 \* 查询租户下面有哪些组  
 \*select distinct RES.\* from ACT\_ID\_GROUP RES inner join ACT\_ID\_TENANT\_MEMBER TM on RES.ID\_ = TM.GROUP\_ID\_ WHERE TM.TENANT\_ID\_ = ? order by RES.ID\_ asc LIMIT ? OFFSET ?  
 \* Parameters: A(String), 2147483647(Integer), 0(Integer)  
 \*/  
@Test  
public  void createGroupQueryMemberOfTenant(){  
    String tenantId="A";  
    GroupQuery groupQuery = identityService.createGroupQuery();  
    List<Group> list = groupQuery.memberOfTenant(tenantId).list();  
    for (int i=0;i<list.size();i++){  
        Group group = list.get(i);  
        System.out.println(group.getId());  
        System.out.println(group.getName());  
        System.out.println(group.getType());  
    }  
}

/\*\*  
 \* 添加用户相关信息  
 \* insert into ACT\_ID\_INFO (ID\_, USER\_ID\_, TYPE\_, KEY\_, VALUE\_, PASSWORD\_, PARENT\_ID\_, REV\_) values ( ?, ?, ?, ?, ?, ?, ?, 1 )  
 \* Parameters: 301(String), zcc2(String), account(String), zccAccountName(String), zccAccountUsername(String), java.io.ByteArrayInputStream@5ef0d29e(ByteArrayInputStream), null  
 \*/  
@Test  
public  void setUserAccount(){  
    String userId="zcc2";  
    String userPassword="1";  
    String accountName="zccAccountName";  
    String accountUsername="zccAccountUsername";  
    String accountPassword="zccAccountPassword";  
    Map<String, String> accountDetails=new HashMap<>();  
    accountDetails.put("a","a");  
    identityService.setUserAccount(userId,userPassword,accountName,accountUsername,accountPassword,accountDetails);

}

/\*\*  
 \* 查询用户相关信息  
 \* select \* from ACT\_ID\_INFO where USER\_ID\_ = ? and KEY\_ = ? and PARENT\_ID\_ is null  
 \* Parameters: zcc2(String), zccAccountName(String)  
 \*/  
@Test  
public void  getUserAccount(){  
    String userId="zcc2";  
    String userPassword="1";  
    String accountName="zccAccountName";  
    Account userAccount = identityService.getUserAccount(userId, userPassword, accountName);  
    System.out.println("@@@@@");  
    System.out.println(userAccount);  
}

@Test  
public void  setUserInfo(){  
    String userId="zcc2";  
    String key="b";  
    String value="b";  
    // void setUserInfo(String userId, String key, String value);  
   identityService.setUserInfo(userId,key,value);  
}

/\*\*  
 \* 添加用户图像信息  
 \* insert into ACT\_ID\_INFO (ID\_, USER\_ID\_, TYPE\_, KEY\_, VALUE\_, PASSWORD\_, PARENT\_ID\_, REV\_) values ( ?, ?, ?, ?, ?, ?, ?, 1 )   
 \*  Parameters: 501(String), zcc2(String), null, picture(String), 502(String), null, null  
 \*  insert into ACT\_GE\_BYTEARRAY(ID\_, NAME\_, BYTES\_, DEPLOYMENT\_ID\_, TENANT\_ID\_, TYPE\_, CREATE\_TIME\_, ROOT\_PROC\_INST\_ID\_, REMOVAL\_TIME\_, REV\_) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )   
 \*  Parameters: 502(String), jpg(String), java.io.ByteArrayInputStream@58bf8650(ByteArrayInputStream), null, null, 1(Integer), 2019-10-07 01:56:06.029(Timestamp), null, null  
 \*/  
@Test  
public void  setUserPicture(){  
    String userId="zcc2";  
    /\*\*  
     \* public Picture(byte\[\] bytes, String mimeType) {  
     \*     this.bytes = bytes;  
     \*     this.mimeType = mimeType;  
     \*   }  
     \*/  
    byte\[\] bytes = IoUtil.fileAsByteArray(new File("src/main/resources/2.jpg"));  
    Picture picture=new Picture(bytes,"jpg");  
    //void setUserPicture(String userId, Picture picture);  
    identityService.setUserPicture(userId,picture);  
}  

}