use of org.activiti.engine.identity.Picture 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.Picture in project Activiti by Activiti.
the class UserDetailPanel method loadPicture.
protected void loadPicture() {
Component pictureComponent = null;
final Picture userPicture = identityService.getUserPicture(user.getId());
if (userPicture != null) {
StreamResource imageresource = new StreamResource(new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
return userPicture.getInputStream();
}
}, user.getId() + "." + Constants.MIMETYPE_EXTENSION_MAPPING.get(userPicture.getMimeType()), ExplorerApp.get());
pictureComponent = new Embedded(null, imageresource);
} else {
pictureComponent = new Label("");
}
pictureComponent.setHeight("200px");
pictureComponent.setWidth("200px");
pictureComponent.addStyleName(ExplorerLayout.STYLE_PROFILE_PICTURE);
userDetailsLayout.addComponent(pictureComponent);
userDetailsLayout.setComponentAlignment(pictureComponent, Alignment.MIDDLE_CENTER);
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class UserPictureResourceTest method testUpdatePictureWithCustomMimeType.
public void testUpdatePictureWithCustomMimeType() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
Map<String, String> additionalFields = new HashMap<String, String>();
additionalFields.put("mimeType", MediaType.IMAGE_PNG.toString());
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), additionalFields));
closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
Picture picture = identityService.getUserPicture(newUser.getId());
assertNotNull(picture);
assertEquals("image/png", picture.getMimeType());
assertEquals("this is the picture raw byte stream", new String(picture.getBytes()));
} finally {
// Delete user after test passes or fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class UserPictureResourceTest method testUpdatePicture.
public void testUpdatePicture() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), null));
closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
Picture picture = identityService.getUserPicture(newUser.getId());
assertNotNull(picture);
assertEquals("image/png", picture.getMimeType());
assertEquals("this is the picture raw byte stream", new String(picture.getBytes()));
} finally {
// Delete user after test passes or fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class UserPictureResourceTest method testGetUserPicture.
/**
* Test getting the picture for a user.
*/
public void testGetUserPicture() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
// Create picture for user
Picture thePicture = new Picture("this is the picture raw byte stream".getBytes(), "image/png");
identityService.setUserPicture(newUser.getId(), thePicture);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId())), HttpStatus.SC_OK);
assertEquals("this is the picture raw byte stream", IOUtils.toString(response.getEntity().getContent()));
// Check if media-type is correct
assertEquals("image/png", response.getEntity().getContentType().getValue());
closeResponse(response);
} finally {
// Delete user after test passes or fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
Aggregations