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

The following examples show how to use org.flowable.idm.api.Group#getId() . 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: GroupMembershipCollectionResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Add a member to a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the group was found and the member has been added."),
        @ApiResponse(code = 400, message = "Indicates the userId was not included in the request body."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found."),
        @ApiResponse(code = 409, message = "Indicates the requested user is already a member of the group.")
})
@PostMapping(value = "/identity/groups/{groupId}/members", produces = "application/json")
public MembershipResponse createMembership(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody MembershipRequest memberShip, HttpServletRequest request, HttpServletResponse response) {

    Group group = getGroupFromRequest(groupId);

    if (memberShip.getUserId() == null) {
        throw new FlowableIllegalArgumentException("UserId cannot be null.");
    }

    // Check if user is member of group since API does not return typed exception
    if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(memberShip.getUserId()).count() > 0) {
        throw new FlowableConflictException("User '" + memberShip.getUserId() + "' is already part of group '" + group.getId() + "'.");
    }

    identityService.createMembership(memberShip.getUserId(), group.getId());
    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createMembershipResponse(memberShip.getUserId(), group.getId());
}
 
Example 2
Source File: GroupMembershipResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a member from a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 204, message = "Indicates the group was found and the member has been deleted. The response body is left empty intentionally."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found or that the user is not a member of the group. The status description contains additional information about the error.")
})
@DeleteMapping("/identity/groups/{groupId}/members/{userId}")
public void deleteMembership(@ApiParam(name = "groupId") @PathVariable("groupId") String groupId, @ApiParam(name = "userId") @PathVariable("userId") String userId, HttpServletRequest request, HttpServletResponse response) {

    Group group = getGroupFromRequest(groupId);

    // Check if user is not a member of group since API does not return typed exception
    if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) {
        throw new FlowableObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null);
    }

    identityService.deleteMembership(userId, group.getId());
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example 3
Source File: GroupMembershipResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a member from a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 204, message = "Indicates the group was found and the member has been deleted. The response body is left empty intentionally."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found or that the user is not a member of the group. The status description contains additional information about the error.")
})
@DeleteMapping("/groups/{groupId}/members/{userId}")
public void deleteMembership(@ApiParam(name = "groupId") @PathVariable("groupId") String groupId, @ApiParam(name = "userId") @PathVariable("userId") String userId, HttpServletRequest request, HttpServletResponse response) {

    Group group = getGroupFromRequest(groupId);

    // Check if user is not a member of group since API doesn't return typed exception
    if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(userId).count() != 1) {
        throw new FlowableObjectNotFoundException("User '" + userId + "' is not part of group '" + group.getId() + "'.", null);
    }

    identityService.deleteMembership(userId, group.getId());
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example 4
Source File: SerializableVariablesDisabledTest.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(CmmnRepositoryService.class);
        this.runtimeService = testServer.getApplicationContext().getBean(CmmnRuntimeService.class);
        this.identityService = testServer.getApplicationContext().getBean(IdmIdentityService.class);
        this.taskService = testServer.getApplicationContext().getBean(CmmnTaskService.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 5
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 6
Source File: GroupMembershipCollectionResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Add a member to a group", tags = { "Groups" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the group was found and the member has been added."),
        @ApiResponse(code = 400, message = "Indicates the userId was not included in the request body."),
        @ApiResponse(code = 404, message = "Indicates the requested group was not found."),
        @ApiResponse(code = 409, message = "Indicates the requested user is already a member of the group.")
})
@PostMapping(value = "/groups/{groupId}/members", produces = "application/json")
public MembershipResponse createMembership(@ApiParam(name = "groupId") @PathVariable String groupId, @RequestBody MembershipRequest memberShip, HttpServletRequest request, HttpServletResponse response) {

    Group group = getGroupFromRequest(groupId);

    if (memberShip.getUserId() == null) {
        throw new FlowableIllegalArgumentException("UserId cannot be null.");
    }

    // Check if user is member of group since API doesn't return typed exception
    if (identityService.createUserQuery().memberOfGroup(group.getId()).userId(memberShip.getUserId()).count() > 0) {

        throw new FlowableConflictException("User '" + memberShip.getUserId() + "' is already part of group '" + group.getId() + "'.");
    }

    identityService.createMembership(memberShip.getUserId(), group.getId());
    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createMembershipResponse(memberShip.getUserId(), group.getId());
}
 
Example 7
Source File: GroupDetails.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public static GroupDetails create(Group group) {
    return new GroupDetails(group.getId(), group.getName(), group.getType());
}