Search in sources :

Example 1 with Picture

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);
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) Picture(org.activiti.engine.identity.Picture) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) Embedded(com.vaadin.ui.Embedded)

Example 2 with Picture

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());
            }
        });
    }
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) Picture(org.activiti.engine.identity.Picture) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) ClickEvent(com.vaadin.event.MouseEvents.ClickEvent) StreamResource(com.vaadin.terminal.StreamResource) Resource(com.vaadin.terminal.Resource) Embedded(com.vaadin.ui.Embedded)

Example 3 with Picture

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;
}
Also used : InMemoryUploadReceiver(org.activiti.explorer.ui.custom.InMemoryUploadReceiver) FinishedEvent(com.vaadin.ui.Upload.FinishedEvent) Picture(org.activiti.engine.identity.Picture) Upload(com.vaadin.ui.Upload) FinishedListener(com.vaadin.ui.Upload.FinishedListener)

Example 4 with Picture

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));
        }
    }
}
Also used : User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture)

Example 5 with Picture

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

Aggregations

Picture (org.activiti.engine.identity.Picture)15 User (org.activiti.engine.identity.User)9 StreamResource (com.vaadin.terminal.StreamResource)4 Embedded (com.vaadin.ui.Embedded)4 StreamSource (com.vaadin.terminal.StreamResource.StreamSource)3 Resource (com.vaadin.terminal.Resource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ActivitiException (org.activiti.engine.ActivitiException)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 HttpPut (org.apache.http.client.methods.HttpPut)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 MouseEvents (com.vaadin.event.MouseEvents)1 ClickEvent (com.vaadin.event.MouseEvents.ClickEvent)1 Component (com.vaadin.ui.Component)1 Label (com.vaadin.ui.Label)1 Upload (com.vaadin.ui.Upload)1 FinishedEvent (com.vaadin.ui.Upload.FinishedEvent)1 FinishedListener (com.vaadin.ui.Upload.FinishedListener)1