Search in sources :

Example 1 with Picture

use of org.camunda.bpm.engine.identity.Picture in project camunda-bpm-platform by camunda.

the class GetUserPictureCmd method execute.

public Picture execute(CommandContext commandContext) {
    ensureNotNull("userId", userId);
    IdentityInfoEntity pictureInfo = commandContext.getIdentityInfoManager().findUserInfoByUserIdAndKey(userId, "picture");
    if (pictureInfo != null) {
        String pictureByteArrayId = pictureInfo.getValue();
        if (pictureByteArrayId != null) {
            ByteArrayEntity byteArray = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, pictureByteArrayId);
            return new Picture(byteArray.getBytes(), byteArray.getName());
        }
    }
    return null;
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) Picture(org.camunda.bpm.engine.identity.Picture) IdentityInfoEntity(org.camunda.bpm.engine.impl.persistence.entity.IdentityInfoEntity)

Example 2 with Picture

use of org.camunda.bpm.engine.identity.Picture in project camunda-bpm-platform by camunda.

the class IdentityServiceTest method testUserPicture.

@Test
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());
    identityService.deleteUserPicture("johndoe");
    // this is ignored
    identityService.deleteUserPicture("someone-else-we-dont-know");
    // picture does not exist
    picture = identityService.getUserPicture("johndoe");
    assertNull(picture);
    // add new picture
    picture = new Picture("niceface".getBytes(), "image/string");
    identityService.setUserPicture(userId, picture);
    // makes the picture go away
    identityService.deleteUser(user.getId());
}
Also used : User(org.camunda.bpm.engine.identity.User) Picture(org.camunda.bpm.engine.identity.Picture) Test(org.junit.Test)

Aggregations

Picture (org.camunda.bpm.engine.identity.Picture)2 User (org.camunda.bpm.engine.identity.User)1 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)1 IdentityInfoEntity (org.camunda.bpm.engine.impl.persistence.entity.IdentityInfoEntity)1 Test (org.junit.Test)1