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