Java Code Examples for org.flowable.idm.api.Group#setName()

The following examples show how to use org.flowable.idm.api.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: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testGroupOptimisticLockingException() {
    Group group = idmIdentityService.newGroup("group");
    idmIdentityService.saveGroup(group);

    Group group1 = idmIdentityService.createGroupQuery().singleResult();
    Group group2 = idmIdentityService.createGroupQuery().singleResult();

    group1.setName("name one");
    idmIdentityService.saveGroup(group1);

    assertThatThrownBy(() -> {
        group2.setName("name two");
        idmIdentityService.saveGroup(group2);
    })
            .isExactlyInstanceOf(FlowableOptimisticLockingException.class);

    idmIdentityService.deleteGroup(group.getId());
}
 
Example 2
Source File: GroupResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Update a group", tags = {
        "Groups" }, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the group, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the group-value will be updated to null.")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the group was updated."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found."),
        @ApiResponse(code = 409, message = "Indicates the requested group was updated simultaneously.")
})
@PutMapping(value = "/groups/{groupId}", produces = "application/json")
public GroupResponse updateGroup(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody GroupRequest groupRequest, HttpServletRequest request) {
    Group group = getGroupFromRequest(groupId);

    if (groupRequest.getId() == null || groupRequest.getId().equals(group.getId())) {
        if (groupRequest.isNameChanged()) {
            group.setName(groupRequest.getName());
        }
        if (groupRequest.isTypeChanged()) {
            group.setType(groupRequest.getType());
        }
        identityService.saveGroup(group);
    } else {
        throw new FlowableIllegalArgumentException("Key provided in request body doesn't match the key in the resource URL.");
    }

    return restResponseFactory.createGroupResponse(group);
}
 
Example 3
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test deleting a single group.
 */
@Test
public void testDeleteGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_NO_CONTENT));

        assertThat(identityService.createGroupQuery().groupId("testgroup").singleResult()).isNull();

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 4
Source File: GroupServiceImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public Group createNewGroup(String id, String name, String type) {
    if (StringUtils.isBlank(name)) {
        throw new BadRequestException("Group name required");
    }

    Group newGroup = identityService.newGroup(id);
    newGroup.setName(name);

    if (type == null) {
        newGroup.setType(GroupTypes.TYPE_ASSIGNMENT);
    } else {
        newGroup.setType(type);
    }

    identityService.saveGroup(newGroup);
    return newGroup;
}
 
Example 5
Source File: IdentityServiceTest.java    From flowable-engine 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 (FlowableOptimisticLockingException e) {
        // Expected an exception
    }

    identityService.deleteGroup(group.getId());
}
 
Example 6
Source File: IdentityServiceTest.java    From flowable-engine 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 7
Source File: SerializableVariablesDiabledTest.java    From flowable-engine 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 8
Source File: GroupCollectionResource.java    From flowable-engine 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.")
})
@PostMapping(value = "/groups", produces = "application/json")
public GroupResponse createGroup(@RequestBody GroupRequest groupRequest, HttpServletRequest httpRequest, HttpServletResponse response) {
    if (groupRequest.getId() == null) {
        throw new FlowableIllegalArgumentException("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 FlowableConflictException("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());
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createNewGroup(created);
    }
    
    identityService.saveGroup(created);

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

    return restResponseFactory.createGroupResponse(created);
}
 
Example 9
Source File: Sample15RestApplication.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public CommandLineRunner usersAndGroupsInitializer(final IdentityService identityService) {
    return args -> {
        // 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 filip = identityService.newUser("filiphr");
        filip.setFirstName("Filip");
        filip.setLastName("Hrisafov");
        filip.setPassword("password");
        identityService.saveUser(filip);

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

        identityService.createMembership("jbarrez", "user");
        identityService.createMembership("filiphr", "user");
        identityService.createMembership("jlong", "user");
    };
}
 
Example 10
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting a single group.
 */
@Test
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);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Test group',"
                        + " type: 'Test type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Test group");
        assertThat(createdGroup.getType()).isEqualTo("Test type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 11
Source File: AiaGroupEntityManager.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@Override
public List<Group> findGroupByQueryCriteria(GroupQueryImpl query) {
    List<Group> groups = new ArrayList<>();
    ObjectMap response = restClient.getForIdentityService("/groups", queryToParams(query), ObjectMap.class);
    List<ObjectMap> dataMap = response.getAsList("data");
    for (ObjectMap groupMap : dataMap) {
        Group group = new GroupEntityImpl();
        group.setId(groupMap.getAsString("id"));
        group.setName(groupMap.getAsString("name"));
        group.setType(groupMap.getAsString("type"));
        groups.add(group);
    }
    return groups;
}
 
Example 12
Source File: BaseSpringRestTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void createUsers() {
    User user = idmIdentityService.newUser("kermit");
    user.setFirstName("Kermit");
    user.setLastName("the Frog");
    user.setPassword("kermit");
    idmIdentityService.saveUser(user);

    Group group = idmIdentityService.newGroup("admin");
    group.setName("Administrators");
    idmIdentityService.saveGroup(group);

    idmIdentityService.createMembership(user.getId(), group.getId());
}
 
Example 13
Source File: IdentityTest.java    From flowable-engine 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 14
Source File: GroupServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public Group updateGroupName(String groupId, String name) {
    if (StringUtils.isBlank(name)) {
        throw new BadRequestException("Group name required");
    }

    Group group = identityService.createGroupQuery().groupId(groupId).singleResult();
    if (group == null) {
        throw new NotFoundException();
    }

    group.setName(name);
    identityService.saveGroup(group);

    return group;
}
 
Example 15
Source File: IdentityServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateGroup() {
    Group group = idmIdentityService.newGroup("sales");
    group.setName("Sales");
    idmIdentityService.saveGroup(group);

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

    group = idmIdentityService.createGroupQuery().groupId("sales").singleResult();
    assertThat(group.getName()).isEqualTo("Updated");

    idmIdentityService.deleteGroup(group.getId());
}
 
Example 16
Source File: PluggableFlowableIdmTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Group createGroup(String id, String name, String type) {
    Group group = idmIdentityService.newGroup(id);
    group.setName(name);
    group.setType(type);
    idmIdentityService.saveGroup(group);
    return group;
}
 
Example 17
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single group passing in no fields in the json, user should remain unchanged.
 */
@Test
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);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Test group',"
                        + " type: 'Test type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Test group");
        assertThat(createdGroup.getType()).isEqualTo("Test type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 18
Source File: GroupResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test updating a single group.
 */
@Test
public void testUpdateGroup() throws Exception {
    try {
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("name", "Updated group");
        requestNode.put("type", "Updated type");

        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);
        assertThat(responseNode).isNotNull();
        assertThatJson(responseNode)
                .when(Option.IGNORING_EXTRA_FIELDS)
                .isEqualTo("{"
                        + " id: 'testgroup',"
                        + " name: 'Updated group',"
                        + " type: 'Updated type',"
                        + " url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId()) + "'"
                        + "}");

        Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
        assertThat(createdGroup).isNotNull();
        assertThat(createdGroup.getName()).isEqualTo("Updated group");
        assertThat(createdGroup.getType()).isEqualTo("Updated type");

    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}
 
Example 19
Source File: Application.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
CommandLineRunner seedUsersAndGroups(final IdmIdentityService identityService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {

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

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

            Privilege userPrivilege = identityService.createPrivilege("user-privilege");
            identityService.addGroupPrivilegeMapping(userPrivilege.getId(), group.getId());

            Privilege adminPrivilege = identityService.createPrivilege("admin-privilege");

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

            User filip = identityService.newUser("filiphr");
            filip.setFirstName("Filip");
            filip.setLastName("Hrisafov");
            filip.setPassword("password");
            identityService.saveUser(filip);

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

            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jbarrez", "admin");
            identityService.createMembership("filiphr", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}
 
Example 20
Source File: GroupCollectionResourceTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting all groups.
 */
@Test
@Deployment
public void testGetGroups() throws Exception {
    List<Group> savedGroups = new ArrayList<>();
    try {
        Group group1 = identityService.newGroup("testgroup1");
        group1.setName("Test group");
        group1.setType("Test type");
        identityService.saveGroup(group1);
        savedGroups.add(group1);

        Group group2 = identityService.newGroup("testgroup2");
        group2.setName("Another group");
        group2.setType("Another type");
        identityService.saveGroup(group2);
        savedGroups.add(group2);

        Group group3 = identityService.createGroupQuery().groupId("admin").singleResult();
        assertThat(group3).isNotNull();
        
        Group group4 = identityService.createGroupQuery().groupId("sales").singleResult();
        assertThat(group4).isNotNull();

        // Test filter-less
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION);
        assertResultsPresentInDataResponse(url, group1.getId(), group2.getId(), group3.getId(), group4.getId());

        // Test based on name
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?name=" + encode("Test group");
        assertResultsPresentInDataResponse(url, group1.getId());

        // Test based on name like
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?nameLike=" + encode("% group");
        assertResultsPresentInDataResponse(url, group2.getId(), group1.getId());

        // Test based on type
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?type=" + encode("Another type");
        assertResultsPresentInDataResponse(url, group2.getId());

        // Test based on group member
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?member=kermit";
        assertResultsPresentInDataResponse(url, group3.getId());

    } finally {

        // Delete groups after test passes or fails
        if (!savedGroups.isEmpty()) {
            for (Group group : savedGroups) {
                identityService.deleteGroup(group.getId());
            }
        }
    }
}