Java Code Examples for org.activiti.engine.identity.Group#setName()

The following examples show how to use org.activiti.engine.identity.Group#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaveGroup.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	
	IdentityService identityService = engine.getIdentityService();
	
	Random ran = new Random(10);
	for (int i = 0; i < 10; i++) {
		Group group = identityService.newGroup(String.valueOf(i));
		group.setName("Group_" + ran.nextInt(10));
		group.setType("TYPE_" + ran.nextInt(10));
		identityService.saveGroup(group);
	}

	// 关闭流程引擎
	engine.close();
}
 
Example 2
Source File: SpringSecurityActivitiApplication.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
InitializingBean usersAndGroupsInitializer(IdentityService identityService) {
    return new InitializingBean() {
        public void afterPropertiesSet() throws Exception {
            User user = identityService.newUser("activiti_user");
            user.setPassword("pass");
            identityService.saveUser(user);

            Group group = identityService.newGroup("user");
            group.setName("ROLE_USER");
            group.setType("USER");
            identityService.saveGroup(group);
            identityService.createMembership(user.getId(), group.getId());
        }
    };
}
 
Example 3
Source File: SaveGroup.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	
	IdentityService identityService = engine.getIdentityService();
	
	Random ran = new Random(10);
	for (int i = 0; i < 10; i++) {
		Group group = identityService.newGroup(String.valueOf(i));
		group.setName("Group_" + ran.nextInt(10));
		group.setType("TYPE_" + ran.nextInt(10));
		identityService.saveGroup(group);
	}

	// 关闭流程引擎
	engine.close();
}
 
Example 4
Source File: IdentityServiceTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 组管理API演示
 */
@Test
public void testGroup() throws Exception {
    // 创建一个组对象
    Group group = identityService.newGroup("deptLeader");
    group.setName("部门领导");
    group.setType("assignment");

    // 保存组
    identityService.saveGroup(group);

    // 验证组是否已保存成功,首先需要创建组查询对象
    List<Group> groupList = identityService.createGroupQuery().groupId("deptLeader").list();
    assertEquals(1, groupList.size());

    // 删除组
    identityService.deleteGroup("deptLeader");

    // 验证是否删除成功
    groupList = identityService.createGroupQuery().groupId("deptLeader").list();
    assertEquals(0, groupList.size());
}
 
Example 5
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGroupOptimisticLockingException() {
  Group group = identityService.newGroup("group");
  identityService.saveGroup(group);
  
  Group group1 = identityService.createGroupQuery().singleResult();
  Group group2 = identityService.createGroupQuery().singleResult();
  
  group1.setName("name one");
  identityService.saveGroup(group1);

  try {
    
    group2.setName("name two");
    identityService.saveGroup(group2);
    
    fail("Expected an exception");
  } catch (ActivitiOptimisticLockingException e) {
    // Expected an exception
  }
  
  identityService.deleteGroup(group.getId());
}
 
Example 6
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存Group
 *
 * @return
 */
@RequestMapping(value = "group/save", method = RequestMethod.POST)
public String saveGroup(@RequestParam("groupId") String groupId,
                        @RequestParam("groupName") String groupName,
                        @RequestParam("type") String type,
                        RedirectAttributes redirectAttributes) {
    Group group = identityService.createGroupQuery().groupId(groupId).singleResult();
    if (group == null) {
        group = identityService.newGroup(groupId);
    }
    group.setName(groupName);
    group.setType(type);
    identityService.saveGroup(group);
    redirectAttributes.addFlashAttribute("message", "成功添加组[" + groupName + "]");
    return "redirect:/chapter14/identity/group/list";
}
 
Example 7
Source File: IdentityController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存Group
 *
 * @return
 */
@RequestMapping(value = "group/save", method = RequestMethod.POST)
public String saveGroup(@RequestParam("groupId") String groupId,
                        @RequestParam("groupName") String groupName,
                        @RequestParam("type") String type,
                        RedirectAttributes redirectAttributes) {
    Group group = identityService.createGroupQuery().groupId(groupId).singleResult();
    if (group == null) {
        group = identityService.newGroup(groupId);
    }
    group.setName(groupName);
    group.setType(type);
    identityService.saveGroup(group);
    redirectAttributes.addFlashAttribute("message", "成功添加组[" + groupName + "]");
    return "redirect:/chapter14/identity/group/list";
}
 
Example 8
Source File: GroupResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting a single group.
 */
public void testGetGroup() throws Exception {
  try {
    Group testGroup = identityService.newGroup("testgroup");
    testGroup.setName("Test group");
    testGroup.setType("Test type");
    identityService.saveGroup(testGroup);

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("testgroup", responseNode.get("id").textValue());
    assertEquals("Test group", responseNode.get("name").textValue());
    assertEquals("Test type", responseNode.get("type").textValue());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));

    Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
    assertNotNull(createdGroup);
    assertEquals("Test group", createdGroup.getName());
    assertEquals("Test type", createdGroup.getType());

  } finally {
    try {
      identityService.deleteGroup("testgroup");
    } catch (Throwable ignore) {
      // Ignore, since the group may not have been created in the test
      // or already deleted
    }
  }
}
 
Example 9
Source File: SerializableVariablesDiabledTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupServer() {
	if (serverUrlPrefix == null) {
		TestServer testServer = TestServerUtil.createAndStartServer(ObjectVariableSerializationDisabledApplicationConfiguration.class);
		serverUrlPrefix = testServer.getServerUrlPrefix();
		
		this.repositoryService = testServer.getApplicationContext().getBean(RepositoryService.class);
		this.runtimeService = testServer.getApplicationContext().getBean(RuntimeService.class);
		this.identityService = testServer.getApplicationContext().getBean(IdentityService.class);
		this.taskService = testServer.getApplicationContext().getBean(TaskService.class);
		
    User user = identityService.newUser("kermit");
    user.setFirstName("Kermit");
    user.setLastName("the Frog");
    user.setPassword("kermit");
    identityService.saveUser(user);
    
    Group group = identityService.newGroup("admin");
    group.setName("Administrators");
    identityService.saveGroup(group);
    
    identityService.createMembership(user.getId(), group.getId());
    
    this.testUserId = user.getId();
    this.testGroupId = group.getId();
	}
}
 
Example 10
Source File: DemoDataConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void createGroup(String groupId, String type) {
  if (identityService.createGroupQuery().groupId(groupId).count() == 0) {
    Group newGroup = identityService.newGroup(groupId);
    newGroup.setName(groupId.substring(0, 1).toUpperCase() + groupId.substring(1));
    newGroup.setType(type);
    identityService.saveGroup(newGroup);
  }
}
 
Example 11
Source File: GroupResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test updating a single group passing in no fields in the json, user should remain unchanged.
 */
public void testUpdateGroupNoFields() throws Exception {
  try {
    Group testGroup = identityService.newGroup("testgroup");
    testGroup.setName("Test group");
    testGroup.setType("Test type");
    identityService.saveGroup(testGroup);

    ObjectNode requestNode = objectMapper.createObjectNode();

    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup"));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("testgroup", responseNode.get("id").textValue());
    assertEquals("Test group", responseNode.get("name").textValue());
    assertEquals("Test type", responseNode.get("type").textValue());
    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));

    Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
    assertNotNull(createdGroup);
    assertEquals("Test group", createdGroup.getName());
    assertEquals("Test type", createdGroup.getType());

  } finally {
    try {
      identityService.deleteGroup("testgroup");
    } catch (Throwable ignore) {
      // Ignore, since the group may not have been created in the test
      // or already deleted
    }
  }
}
 
Example 12
Source File: DemoDataGenerator.java    From maven-framework-project with MIT License 5 votes vote down vote up
protected void createGroup(String groupId, String type) {
    if (identityService.createGroupQuery().groupId(groupId).count() == 0) {
        Group newGroup = identityService.newGroup(groupId);
        newGroup.setName(groupId.substring(0, 1).toUpperCase() + groupId.substring(1));
        newGroup.setType(type);
        identityService.saveGroup(newGroup);
    }
}
 
Example 13
Source File: GroupCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Create a group", tags = {"Groups"})
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the group was created."),
    @ApiResponse(code = 400, message = "Indicates the id of the group was missing.")
})
@RequestMapping(value = "/identity/groups", method = RequestMethod.POST, produces = "application/json")
public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) {
  if (groupRequest.getId() == null) {
    throw new ActivitiIllegalArgumentException("Id cannot be null.");
  }

  // Check if a user with the given ID already exists so we return a
  // CONFLICT
  if (identityService.createGroupQuery().groupId(groupRequest.getId()).count() > 0) {
    throw new ActivitiConflictException("A group with id '" + groupRequest.getId() + "' already exists.");
  }

  Group created = identityService.newGroup(groupRequest.getId());
  created.setId(groupRequest.getId());
  created.setName(groupRequest.getName());
  created.setType(groupRequest.getType());
  identityService.saveGroup(created);

  response.setStatus(HttpStatus.CREATED.value());

  return restResponseFactory.createGroupResponse(created);
}
 
Example 14
Source File: GroupQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
  Group group = identityService.newGroup(id);
  group.setName(name);
  group.setType(type);
  identityService.saveGroup(group);
  return group;
}
 
Example 15
Source File: IdentityServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testUpdateGroup() {
  Group group = identityService.newGroup("sales");
  group.setName("Sales");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  group.setName("Updated");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  assertEquals("Updated", group.getName());

  identityService.deleteGroup(group.getId());
}
 
Example 16
Source File: GroupQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
  Group group = identityService.newGroup(id);
  group.setName(name);
  group.setType(type);
  identityService.saveGroup(group);
  return group;
}
 
Example 17
Source File: IdentityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testGroup() {
  Group group = identityService.newGroup("sales");
  group.setName("Sales division");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  assertEquals("sales", group.getId());
  assertEquals("Sales division", group.getName());

  identityService.deleteGroup("sales");
}
 
Example 18
Source File: GroupQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Group createGroup(String id, String name, String type) {
  Group group = identityService.newGroup(id);
  group.setName(name);
  group.setType(type);
  identityService.saveGroup(group);
  return group;
}
 
Example 19
Source File: IdentityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testGroup() {
  Group group = identityService.newGroup("sales");
  group.setName("Sales division");
  identityService.saveGroup(group);

  group = identityService.createGroupQuery().groupId("sales").singleResult();
  assertEquals("sales", group.getId());
  assertEquals("Sales division", group.getName());

  identityService.deleteGroup("sales");
}
 
Example 20
Source File: Application.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Bean
CommandLineRunner seedUsersAndGroups(final IdentityService identityService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {

            // install groups & users
            Group group = identityService.newGroup("user");
            group.setName("users");
            group.setType("security-role");
            identityService.saveGroup(group);

            User joram = identityService.newUser("jbarrez");
            joram.setFirstName("Joram");
            joram.setLastName("Barrez");
            joram.setPassword("password");
            identityService.saveUser(joram);

            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);

            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}