diff --git a/sticker-award/src/main/java/com/datadoghq/stickerlandia/stickeraward/sticker/StickerImageSeeder.java b/sticker-award/src/main/java/com/datadoghq/stickerlandia/stickeraward/sticker/StickerImageSeeder.java new file mode 100644 index 00000000..f61a2739 --- /dev/null +++ b/sticker-award/src/main/java/com/datadoghq/stickerlandia/stickeraward/sticker/StickerImageSeeder.java @@ -0,0 +1,78 @@ +package com.datadoghq.stickerlandia.stickeraward.sticker; + +import com.datadoghq.stickerlandia.stickeraward.sticker.entity.Sticker; +import io.quarkus.runtime.StartupEvent; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.event.Observes; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; +import org.jboss.logging.Logger; + +import java.io.InputStream; + +@ApplicationScoped +public class StickerImageSeeder { + + private static final Logger LOG = Logger.getLogger(StickerImageSeeder.class); + + @Inject + StickerImageService stickerImageService; + + @Inject + StickerRepository stickerRepository; + + @Transactional + public void onStartup(@Observes StartupEvent ev) { + LOG.info("Starting sticker image seeding..."); + + try { + seedStickerImage("sticker-001", "/stickers/dd_icon_rgb.png", "Datadog Purple Logo"); + seedStickerImage("sticker-002", "/stickers/dd_icon_white.png", "Datadog White Logo"); + + LOG.info("Sticker image seeding completed successfully"); + } catch (Exception e) { + LOG.error("Failed to seed sticker images", e); + } + } + + private void seedStickerImage(String stickerId, String resourcePath, String description) { + // Check if sticker exists and doesn't already have an image + Sticker sticker = Sticker.findById(stickerId); + if (sticker == null) { + LOG.warnf("Sticker %s not found, skipping image seeding", stickerId); + return; + } + + if (sticker.getImageKey() != null && !sticker.getImageKey().isEmpty()) { + LOG.infof("Sticker %s already has image key %s, skipping", stickerId, sticker.getImageKey()); + return; + } + + try { + // Load image from resources + InputStream imageStream = getClass().getResourceAsStream(resourcePath); + if (imageStream == null) { + LOG.errorf("Could not find image resource: %s", resourcePath); + return; + } + + // Get file size for upload + byte[] imageData = imageStream.readAllBytes(); + imageStream.close(); + + // Upload image to our storage service + InputStream uploadStream = getClass().getResourceAsStream(resourcePath); + String imageKey = stickerImageService.uploadImage(uploadStream, "image/png", imageData.length); + uploadStream.close(); + + // Update sticker with image key + stickerRepository.updateStickerImageKey(stickerId, imageKey); + + LOG.infof("Successfully seeded image for sticker %s with key %s (%s)", + stickerId, imageKey, description); + + } catch (Exception e) { + LOG.errorf(e, "Failed to seed image for sticker %s from %s", stickerId, resourcePath); + } + } +} \ No newline at end of file diff --git a/sticker-award/src/main/resources/stickers/dd_icon_rgb.png b/sticker-award/src/main/resources/stickers/dd_icon_rgb.png new file mode 100644 index 00000000..59877115 Binary files /dev/null and b/sticker-award/src/main/resources/stickers/dd_icon_rgb.png differ diff --git a/sticker-award/src/main/resources/stickers/dd_icon_white.png b/sticker-award/src/main/resources/stickers/dd_icon_white.png new file mode 100644 index 00000000..32e7136c Binary files /dev/null and b/sticker-award/src/main/resources/stickers/dd_icon_white.png differ