Search in sources :

Example 36 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class BaseJPARestTestCase method createUsers.

protected void createUsers() {
    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());
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User)

Example 37 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoCollectionResource method setUserInfo.

@RequestMapping(value = "/identity/users/{userId}/info", method = RequestMethod.POST, produces = "application/json")
public UserInfoResponse setUserInfo(@PathVariable String userId, @RequestBody UserInfoRequest userRequest, HttpServletRequest request, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    if (userRequest.getKey() == null) {
        throw new ActivitiIllegalArgumentException("The key cannot be null.");
    }
    if (userRequest.getValue() == null) {
        throw new ActivitiIllegalArgumentException("The value cannot be null.");
    }
    String existingValue = identityService.getUserInfo(user.getId(), userRequest.getKey());
    if (existingValue != null) {
        throw new ActivitiConflictException("User info with key '" + userRequest.getKey() + "' already exists for this user.");
    }
    identityService.setUserInfo(user.getId(), userRequest.getKey(), userRequest.getValue());
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createUserInfoResponse(userRequest.getKey(), userRequest.getValue(), user.getId());
}
Also used : User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiConflictException(org.activiti.rest.exception.ActivitiConflictException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResource method setUserInfo.

@RequestMapping(value = "/identity/users/{userId}/info/{key}", method = RequestMethod.PUT, produces = "application/json")
public UserInfoResponse setUserInfo(@PathVariable("userId") String userId, @PathVariable("key") String key, @RequestBody UserInfoRequest userRequest, HttpServletRequest request) {
    User user = getUserFromRequest(userId);
    String validKey = getValidKeyFromRequest(user, key);
    if (userRequest.getValue() == null) {
        throw new ActivitiIllegalArgumentException("The value cannot be null.");
    }
    if (userRequest.getKey() == null || validKey.equals(userRequest.getKey())) {
        identityService.setUserInfo(user.getId(), key, userRequest.getValue());
    } else {
        throw new ActivitiIllegalArgumentException("Key provided in request body doesn't match the key in the resource URL.");
    }
    return restResponseFactory.createUserInfoResponse(key, userRequest.getValue(), user.getId());
}
Also used : User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResource method deleteUserInfo.

@RequestMapping(value = "/identity/users/{userId}/info/{key}", method = RequestMethod.DELETE)
public void deleteUserInfo(@PathVariable("userId") String userId, @PathVariable("key") String key, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    String validKey = getValidKeyFromRequest(user, key);
    identityService.setUserInfo(user.getId(), validKey, null);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : User(org.activiti.engine.identity.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with User

use of org.activiti.engine.identity.User in project Activiti by Activiti.

the class UserInfoResource method getUserInfo.

@RequestMapping(value = "/identity/users/{userId}/info/{key}", method = RequestMethod.GET, produces = "application/json")
public UserInfoResponse getUserInfo(@PathVariable("userId") String userId, @PathVariable("key") String key, HttpServletRequest request) {
    User user = getUserFromRequest(userId);
    String existingValue = identityService.getUserInfo(user.getId(), key);
    if (existingValue == null) {
        throw new ActivitiObjectNotFoundException("User info with key '" + key + "' does not exists for user '" + user.getId() + "'.", null);
    }
    return restResponseFactory.createUserInfoResponse(key, existingValue, user.getId());
}
Also used : User(org.activiti.engine.identity.User) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3