Search in sources :

Example 11 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 12 with Picture

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

the class IdentityServiceTest method testUserPicture.

public void testUserPicture() {
    // First, create a new user
    User user = identityService.newUser("johndoe");
    identityService.saveUser(user);
    String userId = user.getId();
    Picture picture = new Picture("niceface".getBytes(), "image/string");
    identityService.setUserPicture(userId, picture);
    picture = identityService.getUserPicture(userId);
    // Fetch and update the user
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertTrue("byte arrays differ", Arrays.equals("niceface".getBytes(), picture.getBytes()));
    assertEquals("image/string", picture.getMimeType());
    //interface defintion states that setting picture to null should delete it
    identityService.setUserPicture(userId, null);
    assertNull("it should be possible to nullify user picture", identityService.getUserPicture(userId));
    user = identityService.createUserQuery().userId("johndoe").singleResult();
    assertNull("it should be possible to delete user picture", identityService.getUserPicture(userId));
    identityService.deleteUser(user.getId());
}
Also used : User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture)

Example 13 with Picture

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

the class UserEntityTest method testSetPicture_pictureShouldBeSavedWhenNotNull.

@Test
public void testSetPicture_pictureShouldBeSavedWhenNotNull() {
    TestableUserEntity userEntity = new TestableUserEntity();
    Picture picture = new Picture(null, null);
    // even though parameters were null, picture object is not null
    userEntity.setPicture(picture);
    assertTrue(userEntity.getHasSavePictureBeenCalled());
    assertFalse(userEntity.getHasDeletePictureBeenCalled());
}
Also used : Picture(org.activiti.engine.identity.Picture) Test(org.junit.Test)

Example 14 with Picture

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

the class UserProfileLink method initPicture.

protected void initPicture(IdentityService identityService, boolean renderPicture, final String userName) {
    if (renderPicture) {
        Picture picture = identityService.getUserPicture(userName);
        if (picture != null) {
            Resource imageResource = new StreamResource(new InputStreamStreamSource(picture.getInputStream()), userName + picture.getMimeType(), ExplorerApp.get());
            Embedded image = new Embedded(null, imageResource);
            image.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
            image.setType(Embedded.TYPE_IMAGE);
            image.setHeight(30, Embedded.UNITS_PIXELS);
            image.setWidth(30, Embedded.UNITS_PIXELS);
            image.addListener(new MouseEvents.ClickListener() {

                private static final long serialVersionUID = 7341560240277898495L;

                public void click(MouseEvents.ClickEvent event) {
                    viewManager.showProfilePopup(userName);
                }
            });
            addComponent(image);
            setComponentAlignment(image, Alignment.MIDDLE_LEFT);
        } else {
        // TODO: what when no image is available?
        }
    }
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) Picture(org.activiti.engine.identity.Picture) StreamResource(com.vaadin.terminal.StreamResource) Resource(com.vaadin.terminal.Resource) Embedded(com.vaadin.ui.Embedded) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) MouseEvents(com.vaadin.event.MouseEvents)

Example 15 with Picture

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

the class DemoDataGenerator 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)

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