@ApiOperation(value = "Get a user’s picture", tags = {"Users"}, notes = "The response body contains the raw picture data, representing the user’s picture. The Content-type of the response corresponds to the mimeType that was set when creating the picture.") @ApiResponses(value = { @ApiResponse(code = 200, message = "Indicates the user was found and has a picture, which is returned in the body."), @ApiResponse(code = 404, message = "Indicates the requested user was not found or the user does not have a profile picture. Status-description contains additional information about the error.") }) @RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET) public ResponseEntity<byte[]> getUserPicture(@ApiParam(name = "userId", value="The id of the user to get the picture for.") @PathVariable String userId, HttpServletRequest request, HttpServletResponse response) { User user = getUserFromRequest(userId); Picture userPicture = identityService.getUserPicture(user.getId()); if (userPicture == null) { throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class); } HttpHeaders responseHeaders = new HttpHeaders(); if (userPicture.getMimeType() != null) { responseHeaders.set("Content-Type", userPicture.getMimeType()); } else { responseHeaders.set("Content-Type", "image/jpeg"); } try { return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK); } catch (Exception e) { throw new ActivitiException("Error exporting picture: " + e.getMessage(), e); } }
protected void savePicture(Picture picture) { if (pictureByteArrayRef != null) { pictureByteArrayRef = new ByteArrayRef(); } pictureByteArrayRef.setValue(picture.getMimeType(), picture.getBytes()); }
protected void loadPicture() { Component pictureComponent = null; final Picture userPicture = identityService.getUserPicture(user.getId()); if (userPicture != null) { StreamResource imageresource = new StreamResource(new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { return userPicture.getInputStream(); } }, user.getId() + "." + Constants.MIMETYPE_EXTENSION_MAPPING.get(userPicture.getMimeType()), ExplorerApp.get()); pictureComponent = new Embedded(null, imageresource); } else { pictureComponent = new Label(""); } pictureComponent.setHeight("200px"); pictureComponent.setWidth("200px"); pictureComponent.addStyleName(ExplorerLayout.STYLE_PROFILE_PICTURE); userDetailsLayout.addComponent(pictureComponent); userDetailsLayout.setComponentAlignment(pictureComponent, Alignment.MIDDLE_CENTER); }
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); }
public void setPicture(Picture picture) { if (pictureByteArrayId!=null) { Context .getCommandContext() .getByteArrayEntityManager() .deleteByteArrayById(pictureByteArrayId); } if (picture!=null) { pictureByteArray = new ByteArrayEntity(picture.getMimeType(), picture.getBytes()); Context .getCommandContext() .getDbSqlSession() .insert(pictureByteArray); pictureByteArrayId = pictureByteArray.getId(); } else { pictureByteArrayId = null; pictureByteArray = null; } }
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? } } }