use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class TaskEventsPanel method addTaskEventPicture.
protected void addTaskEventPicture(final org.activiti.engine.task.Event taskEvent, GridLayout eventGrid) {
final Picture userPicture = identityService.getUserPicture(taskEvent.getUserId());
Embedded authorPicture = null;
if (userPicture != null) {
StreamResource imageresource = new StreamResource(new StreamSource() {
private static final long serialVersionUID = 1L;
public InputStream getStream() {
return userPicture.getInputStream();
}
}, "event_" + taskEvent.getUserId() + "." + Constants.MIMETYPE_EXTENSION_MAPPING.get(userPicture.getMimeType()), ExplorerApp.get());
authorPicture = new Embedded(null, imageresource);
} else {
authorPicture = new Embedded(null, Images.USER_50);
}
authorPicture.setType(Embedded.TYPE_IMAGE);
authorPicture.setHeight("48px");
authorPicture.setWidth("48px");
authorPicture.addStyleName(ExplorerLayout.STYLE_TASK_EVENT_PICTURE);
eventGrid.addComponent(authorPicture);
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class UserDetailsComponent method addUserPicture.
protected void addUserPicture() {
// default icon
Resource pictureResource = Images.USER_32;
if (user != null) {
final Picture userPicture = identityService.getUserPicture(user.getId());
if (userPicture != null) {
pictureResource = new StreamResource(new StreamSource() {
public InputStream getStream() {
return userPicture.getInputStream();
}
}, user.getId(), ExplorerApp.get());
}
}
Embedded picture = new Embedded(null, pictureResource);
picture.setType(Embedded.TYPE_IMAGE);
picture.addStyleName(ExplorerLayout.STYLE_TASK_EVENT_PICTURE);
if (user != null) {
// Only set fixed height and width when user has image, otherwise icon's dimensions will be used
picture.setHeight("32px");
picture.setWidth("32px");
}
addComponent(picture);
// Add profile popup listener
if (user != null) {
picture.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
picture.addListener(new com.vaadin.event.MouseEvents.ClickListener() {
public void click(ClickEvent event) {
viewManager.showProfilePopup(user.getId());
}
});
}
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class ProfilePanel method initChangePictureButton.
protected Upload initChangePictureButton() {
final Upload changePictureUpload = new Upload();
changePictureUpload.setImmediate(true);
changePictureUpload.setButtonCaption(i18nManager.getMessage(Messages.PROFILE_CHANGE_PICTURE));
final InMemoryUploadReceiver receiver = initPictureReceiver(changePictureUpload);
changePictureUpload.addListener(new FinishedListener() {
private static final long serialVersionUID = 1L;
public void uploadFinished(FinishedEvent event) {
if (!receiver.isInterruped()) {
picture = new Picture(receiver.getBytes(), receiver.getMimeType());
identityService.setUserPicture(userId, picture);
// reset picture
imageLayout.removeAllComponents();
initPicture();
} else {
receiver.reset();
}
}
});
return changePictureUpload;
}
use of org.activiti.engine.identity.Picture in project Activiti by Activiti.
the class DemoDataConfiguration method createUser.
protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) {
if (identityService.createUserQuery().userId(userId).count() == 0) {
// Following data can already be set by demo setup script
User user = identityService.newUser(userId);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setPassword(password);
user.setEmail(email);
identityService.saveUser(user);
if (groups != null) {
for (String group : groups) {
identityService.createMembership(userId, group);
}
}
}
// image
if (imageResource != null) {
byte[] pictureBytes = IoUtil.readInputStream(this.getClass().getClassLoader().getResourceAsStream(imageResource), null);
Picture picture = new Picture(pictureBytes, "image/jpeg");
identityService.setUserPicture(userId, picture);
}
// user info
if (userInfo != null) {
for (int i = 0; i < userInfo.size(); i += 2) {
identityService.setUserInfo(userId, userInfo.get(i), userInfo.get(i + 1));
}
}
}
use of org.activiti.engine.identity.Picture 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);
}
}
Aggregations