From e1e05a8ed94644e9f079caac7a1492cfd9ab617d Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Fri, 25 Jul 2025 14:03:34 +0300 Subject: [PATCH] Remove deprecated StreamResource references --- .../CollaborationAvatarGroup.java | 87 ------------------ .../CollaborationMessageList.java | 58 ------------ .../vaadin/collaborationengine/UserInfo.java | 6 +- .../CollaborationAvatarGroupTest.java | 72 --------------- .../CollaborationMessageListTest.java | 89 ------------------- .../util/TestStreamResource.java | 24 ----- 6 files changed, 3 insertions(+), 333 deletions(-) delete mode 100644 collaboration-engine/src/test/java/com/vaadin/collaborationengine/util/TestStreamResource.java diff --git a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationAvatarGroup.java b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationAvatarGroup.java index fa37daed..ef731834 100644 --- a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationAvatarGroup.java +++ b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationAvatarGroup.java @@ -33,8 +33,6 @@ import com.vaadin.flow.component.shared.HasOverlayClassName; import com.vaadin.flow.function.SerializableSupplier; import com.vaadin.flow.internal.UsageStatistics; -import com.vaadin.flow.server.AbstractStreamResource; -import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.server.streams.DownloadHandler; /** @@ -48,33 +46,6 @@ public class CollaborationAvatarGroup extends Composite implements HasSize, HasStyle, HasTheme, HasOverlayClassName { - /** - * Callback for creating a stream resource with the image for a specific - * user. This allows loading the user image from a dynamic location such as - * a database. - * - * @see StreamResource - * @see CollaborationAvatarGroup#setImageProvider(ImageProvider) - * @since 1.0 - * @deprecated Use {@link #setImageHandler(ImageHandler)} instead. - */ - @FunctionalInterface - @Deprecated(since = "6.5", forRemoval = true) - public interface ImageProvider { - /** - * Gets a stream resource that provides the avatar image for the given - * user. - * - * @param user - * the user for which to get a stream resource with the - * image, not null - * @return the stream resource to use for the image, or - * null to not show use any avatar image for the - * given user - */ - AbstractStreamResource getImageResource(UserInfo user); - } - /** * Callback for creating a download handler for the avatar image for a * specific user. This allows loading the user image from a dynamic location @@ -109,8 +80,6 @@ public interface ImageHandler { private String topicId; - private ImageProvider imageProvider; - private ImageHandler imageHandler; private boolean ownAvatarVisible; @@ -292,8 +261,6 @@ private AvatarGroupItem userToAvatarGroupItem(UserInfo user) { if (imageHandler != null) { item.setImageHandler(imageHandler.getDownloadHandler(user)); - } else if (imageProvider != null) { - item.setImageResource(imageProvider.getImageResource(user)); } else { item.setImage(user.getImage()); } @@ -310,60 +277,6 @@ private boolean isNotLocalUser(UserInfo user) { return !localUser.equals(user); } - /** - * Sets an image provider callback for dynamically loading avatar images for - * a given user. The image can be loaded on-demand from a database or using - * any other source of IO streams. - *

- * If no image callback is defined, then the image URL defined by - * {@link UserInfo#getImage()} is directly passed to the browser. This means - * that avatar images need to be available as static files or served - * dynamically from a custom servlet. This is the default. - *

- * - * Usage example: - * - *

-     * collaborationAvatarGroup.setImageProvider(userInfo -> {
-     *     StreamResource streamResource = new StreamResource(
-     *             "avatar_" + userInfo.getId(), () -> {
-     *                 User userEntity = userRepository
-     *                         .findById(userInfo.getId());
-     *                 byte[] profilePicture = userEntity.getProfilePicture();
-     *                 return new ByteArrayInputStream(profilePicture);
-     *             });
-     *     streamResource.setContentType("image/png");
-     *     return streamResource;
-     * });
-     * 
- * - * @param imageProvider - * the image provider to use, or null to use image - * URLs directly from the user info object - * @since 1.0 - * @deprecated Use {@link #setImageHandler(ImageHandler)} instead. - */ - @Deprecated(since = "6.5", forRemoval = true) - public void setImageProvider(ImageProvider imageProvider) { - this.imageProvider = imageProvider; - refreshItems(); - } - - /** - * Gets the currently used image provider callback. - * - * @see #setImageProvider(ImageProvider) - * - * @return the current image provider callback, or null if no - * callback is set - * @since 1.0 - * @deprecated Use {@link #setImageHandler(ImageHandler)} instead. - */ - @Deprecated(since = "6.5", forRemoval = true) - public ImageProvider getImageProvider() { - return imageProvider; - } - /** * Sets an image handler callback for dynamically loading avatar images for * a given user. The image can be loaded on-demand from a database or using diff --git a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationMessageList.java b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationMessageList.java index 8b20279a..a90cf19f 100644 --- a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationMessageList.java +++ b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/CollaborationMessageList.java @@ -21,7 +21,6 @@ import java.util.stream.Collectors; import com.vaadin.collaborationengine.CollaborationAvatarGroup.ImageHandler; -import com.vaadin.collaborationengine.CollaborationAvatarGroup.ImageProvider; import com.vaadin.flow.component.Composite; import com.vaadin.flow.component.HasSize; import com.vaadin.flow.component.HasStyle; @@ -69,8 +68,6 @@ public interface MessageConfigurator { private final SerializableSupplier ceSupplier; - private ImageProvider imageProvider; - private ImageHandler imageHandler; private final UserInfo localUser; @@ -251,58 +248,6 @@ void appendMessage(String text) { messageManager.submit(message); } - /** - * Sets an image provider callback for dynamically loading avatar images for - * a given user. The image can be loaded on-demand from a database or using - * any other source of IO streams. - *

- * If no image callback is defined, then the image URL defined by - * {@link UserInfo#getImage()} is directly passed to the browser. This means - * that avatar images need to be available as static files or served - * dynamically from a custom servlet. This is the default. - *

- * - * Usage example: - * - *

-     * collaborationMessageList.setImageProvider(userInfo -> {
-     *     StreamResource streamResource = new StreamResource(
-     *             "avatar_" + userInfo.getId(), () -> {
-     *                 User userEntity = userRepository
-     *                         .findById(userInfo.getId());
-     *                 byte[] profilePicture = userEntity.getProfilePicture();
-     *                 return new ByteArrayInputStream(profilePicture);
-     *             });
-     *     streamResource.setContentType("image/png");
-     *     return streamResource;
-     * });
-     * 
- * - * @param imageProvider - * the image provider to use, or null to use image - * URLs directly from the user info object - * @deprecated Use {@link #setImageHandler(ImageHandler)} instead. - */ - @Deprecated(since = "6.5", forRemoval = true) - public void setImageProvider(ImageProvider imageProvider) { - this.imageProvider = imageProvider; - refreshMessages(); - } - - /** - * Gets the currently used image provider callback. - * - * @see #setImageProvider(ImageProvider) - * - * @return the current image provider callback, or null if no - * callback is set - * @deprecated Use {@link #setImageHandler(ImageHandler)} instead. - */ - @Deprecated(since = "6.5", forRemoval = true) - public ImageProvider getImageProvider() { - return imageProvider; - } - /** * Sets an image handler callback for dynamically loading avatar images for * a given user. The image can be loaded on-demand from a database or using @@ -450,9 +395,6 @@ private MessageListItem convertToMessageListItem( if (imageHandler != null) { messageListItem.setUserImageHandler( imageHandler.getDownloadHandler(message.getUser())); - } else if (imageProvider != null) { - messageListItem.setUserImageResource( - imageProvider.getImageResource(message.getUser())); } else { messageListItem.setUserImage(message.getUser().getImage()); } diff --git a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/UserInfo.java b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/UserInfo.java index 72b81ca2..465fd8ad 100644 --- a/collaboration-engine/src/main/java/com/vaadin/collaborationengine/UserInfo.java +++ b/collaboration-engine/src/main/java/com/vaadin/collaborationengine/UserInfo.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.vaadin.collaborationengine.CollaborationAvatarGroup.ImageProvider; +import com.vaadin.collaborationengine.CollaborationAvatarGroup.ImageHandler; /** * User information of a collaborating user, used with various features of the @@ -73,7 +73,7 @@ public UserInfo(String userId, String name) { * If this user info is given to a {@link CollaborationAvatarGroup}, the * image URL is used to load the user's avatar. Alternatively, the user * images can be loaded from a backend to the avatar group with - * {@link CollaborationAvatarGroup#setImageProvider(ImageProvider)}. + * {@link CollaborationAvatarGroup#setImageHandler(ImageHandler)}. * * * @param userId @@ -177,7 +177,7 @@ public String getImage() { * If this user info is given to a {@link CollaborationAvatarGroup}, the * image URL is used to load the user's avatar. Alternatively, the user * images can be loaded from a backend to the avatar group with - * {@link CollaborationAvatarGroup#setImageProvider(ImageProvider)}. + * {@link CollaborationAvatarGroup#setImageHandler(ImageHandler)}. * * @param imageUrl * the image URL to set diff --git a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationAvatarGroupTest.java b/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationAvatarGroupTest.java index 23b7bce4..a09a38e9 100644 --- a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationAvatarGroupTest.java +++ b/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationAvatarGroupTest.java @@ -33,7 +33,6 @@ import com.vaadin.collaborationengine.util.MockService; import com.vaadin.collaborationengine.util.MockUI; import com.vaadin.collaborationengine.util.ReflectionUtils; -import com.vaadin.collaborationengine.util.TestStreamResource; import com.vaadin.collaborationengine.util.TestUtils; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.avatar.Avatar; @@ -358,77 +357,6 @@ public void avatarGroup_replicateRelevantAPIs() { } } - @Test - public void imageProvider_beforeAttach_streamResourceIsUsed() { - UI.setCurrent(client1.ui); - client1.group.setImageProvider( - user -> new TestStreamResource(user.getName())); - client1.attach(); - client2.attach(); - - List items = client1.getItems(); - assertEquals(2, items.size()); - AvatarGroupItem item = items.get(1); - - Assert.assertThat(item.getImage(), - CoreMatchers.startsWith("VAADIN/dynamic")); - assertEquals("name2", item.getImageResource().getName()); - } - - @Test - public void imageProvider_afterAttach_streamResourceIsUsed() { - UI.setCurrent(client1.ui); - client1.attach(); - client2.attach(); - - client1.group.setImageProvider( - user -> new TestStreamResource(user.getName())); - - List items = client1.getItems(); - assertEquals(2, items.size()); - - AvatarGroupItem item = items.get(1); - - Assert.assertThat(item.getImage(), - CoreMatchers.startsWith("VAADIN/dynamic")); - assertEquals("name2", item.getImageResource().getName()); - } - - @Test - public void imageProvider_nullStream_noImage() { - UI.setCurrent(client1.ui); - client1.attach(); - client2.attach(); - - client1.group.setImageProvider(user -> null); - - List items = client1.getItems(); - assertEquals(2, items.size()); - - AvatarGroupItem item = items.get(1); - - Assert.assertNull(item.getImage()); - Assert.assertNull(item.getImageResource()); - } - - @Test - public void imageProvider_clearProvider_imageIsSetFromUserInfo() { - UI.setCurrent(client1.ui); - client1.group.setImageProvider( - user -> new TestStreamResource(user.getName())); - client1.attach(); - client2.attach(); - - client1.group.setImageProvider(null); - - List items = client1.getItems(); - assertEquals(2, items.size()); - AvatarGroupItem item = items.get(1); - - Assert.assertNull(item.getImageResource()); - assertEquals("image2", item.getImage()); - } - @Test public void imageHandler_beforeAttach_downloadHandlerIsUsed() { UI.setCurrent(client1.ui); diff --git a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationMessageListTest.java b/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationMessageListTest.java index dbc128f3..fab4df85 100644 --- a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationMessageListTest.java +++ b/collaboration-engine/src/test/java/com/vaadin/collaborationengine/CollaborationMessageListTest.java @@ -37,7 +37,6 @@ import com.vaadin.collaborationengine.util.MockService; import com.vaadin.collaborationengine.util.MockUI; import com.vaadin.collaborationengine.util.ReflectionUtils; -import com.vaadin.collaborationengine.util.TestStreamResource; import com.vaadin.collaborationengine.util.TestUtils; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.messages.MessageList; @@ -436,94 +435,6 @@ private void addMessageToBackend(String topicId, UserInfo user, String text, .add(new CollaborationMessage(user, text, time)); } - @Test - public void imageProvider_beforeAttach_streamResourceIsUsed() { - UI.setCurrent(client1.ui); - client1.messageList.setImageProvider( - user -> new TestStreamResource(user.getName())); - client1.setTopic(TOPIC_ID); - client2.setTopic(TOPIC_ID); - client1.attach(); - client2.attach(); - - client2.sendMessage("foo"); - - List items = client1.getMessages(); - - Assert.assertEquals(1, items.size()); - MessageListItem item = items.get(0); - - Assert.assertThat(item.getUserImage(), - CoreMatchers.startsWith("VAADIN/dynamic")); - Assert.assertEquals("name2", item.getUserImageResource().getName()); - } - - @Test - public void imageProvider_afterAttach_streamResourceIsUsed() { - UI.setCurrent(client1.ui); - client1.setTopic(TOPIC_ID); - client2.setTopic(TOPIC_ID); - client1.attach(); - client2.attach(); - - client1.messageList.setImageProvider( - user -> new TestStreamResource(user.getName())); - - client2.sendMessage("foo"); - - List items = client1.getMessages(); - - Assert.assertEquals(1, items.size()); - MessageListItem item = items.get(0); - - Assert.assertThat(item.getUserImage(), - CoreMatchers.startsWith("VAADIN/dynamic")); - Assert.assertEquals("name2", item.getUserImageResource().getName()); - } - - @Test - public void imageProvider_nullStream_noImage() { - UI.setCurrent(client1.ui); - client1.setTopic(TOPIC_ID); - client2.setTopic(TOPIC_ID); - client1.attach(); - client2.attach(); - - client1.messageList.setImageProvider(user -> null); - - client2.sendMessage("foo"); - - List items = client1.getMessages(); - Assert.assertEquals(1, items.size()); - - MessageListItem item = items.get(0); - - Assert.assertNull(item.getUserImage()); - Assert.assertNull(item.getUserImageResource()); - } - - @Test - public void imageProvider_clearProvider_imageIsSetFromUserInfo() { - UI.setCurrent(client1.ui); - client1.messageList.setImageProvider( - user -> new TestStreamResource(user.getName())); - client1.setTopic(TOPIC_ID); - client2.setTopic(TOPIC_ID); - client1.attach(); - client2.attach(); - - client2.sendMessage("foo"); - - client1.messageList.setImageProvider(null); - - List items = client1.getMessages(); - Assert.assertEquals(1, items.size()); - MessageListItem item = items.get(0); - - Assert.assertNull(item.getUserImageResource()); - Assert.assertEquals("image2", item.getUserImage()); - } - @Test public void imageHandler_beforeAttach_downloadHandlerIsUsed() { UI.setCurrent(client1.ui); diff --git a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/util/TestStreamResource.java b/collaboration-engine/src/test/java/com/vaadin/collaborationengine/util/TestStreamResource.java deleted file mode 100644 index 01d75152..00000000 --- a/collaboration-engine/src/test/java/com/vaadin/collaborationengine/util/TestStreamResource.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2000-2024 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.collaborationengine.util; - -import com.vaadin.flow.server.StreamResource; - -public class TestStreamResource extends StreamResource { - public TestStreamResource(String name) { - super(name, () -> null); - } -}