Search in sources :

Example 41 with User

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

the class UserPictureResource method updateUserPicture.

@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.PUT)
public void updateUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
    }
    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
    try {
        String mimeType = file.getContentType();
        int size = ((Long) file.getSize()).intValue();
        // Copy file-body in a bytearray as the engine requires this
        ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(size);
        IOUtils.copy(file.getInputStream(), bytesOutput);
        Picture newPicture = new Picture(bytesOutput.toByteArray(), mimeType);
        identityService.setUserPicture(user.getId(), newPicture);
        response.setStatus(HttpStatus.NO_CONTENT.value());
    } catch (Exception e) {
        throw new ActivitiException("Error while reading uploaded file: " + e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Picture(org.activiti.engine.identity.Picture) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with User

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

the class UserPictureResource method getUserPicture.

@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET)
public ResponseEntity<byte[]> getUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    Picture userPicture = identityService.getUserPicture(user.getId());
    if (userPicture == null) {
        throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
    }
    HttpHeaders responseHeaders = new HttpHeaders();
    if (userPicture.getMimeType() != null) {
        responseHeaders.set("Content-Type", userPicture.getMimeType());
    } else {
        responseHeaders.set("Content-Type", "image/jpeg");
    }
    try {
        return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ActivitiException(org.activiti.engine.ActivitiException) User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with User

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

the class UserResource method updateUser.

@RequestMapping(value = "/identity/users/{userId}", method = RequestMethod.PUT, produces = "application/json")
public UserResponse updateUser(@PathVariable String userId, @RequestBody UserRequest userRequest, HttpServletRequest request) {
    User user = getUserFromRequest(userId);
    if (userRequest.isEmailChanged()) {
        user.setEmail(userRequest.getEmail());
    }
    if (userRequest.isFirstNameChanged()) {
        user.setFirstName(userRequest.getFirstName());
    }
    if (userRequest.isLastNameChanged()) {
        user.setLastName(userRequest.getLastName());
    }
    if (userRequest.isPasswordChanged()) {
        user.setPassword(userRequest.getPassword());
    }
    identityService.saveUser(user);
    return restResponseFactory.createUserResponse(user, false);
}
Also used : User(org.activiti.engine.identity.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with User

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

the class TaskServiceTest method testAddCandidateUserDuplicate.

public void testAddCandidateUserDuplicate() {
    // Check behavior when adding the same user twice as candidate
    User user = identityService.newUser("user");
    identityService.saveUser(user);
    Task task = taskService.newTask();
    taskService.saveTask(task);
    taskService.addCandidateUser(task.getId(), user.getId());
    // Add as candidate the second time
    taskService.addCandidateUser(task.getId(), user.getId());
    identityService.deleteUser(user.getId());
    taskService.deleteTask(task.getId(), true);
}
Also used : Task(org.activiti.engine.task.Task) User(org.activiti.engine.identity.User)

Example 45 with User

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

the class TaskServiceTest method testSetAssignee.

public void testSetAssignee() {
    User user = identityService.newUser("user");
    identityService.saveUser(user);
    Task task = taskService.newTask();
    assertNull(task.getAssignee());
    taskService.saveTask(task);
    // Set assignee
    taskService.setAssignee(task.getId(), user.getId());
    // Fetch task again
    task = taskService.createTaskQuery().taskId(task.getId()).singleResult();
    assertEquals(user.getId(), task.getAssignee());
    // Set assignee to null
    taskService.setAssignee(task.getId(), null);
    identityService.deleteUser(user.getId());
    taskService.deleteTask(task.getId(), true);
}
Also used : Task(org.activiti.engine.task.Task) User(org.activiti.engine.identity.User)

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