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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations