From 5738280c786ef46ca63eb34e8a4d27106b1f35c8 Mon Sep 17 00:00:00 2001 From: Thomasr Date: Thu, 16 Jan 2025 14:04:55 -0500 Subject: [PATCH] add deploymentid into events published --- .../java/org/lowcoder/infra/event/AbstractEvent.java | 5 +++++ .../lowcoder/runner/eventlistener/AppEventListener.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java b/server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java index 44b1ded98..a42651fa8 100644 --- a/server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java +++ b/server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java @@ -1,6 +1,7 @@ package org.lowcoder.infra.event; import lombok.Getter; +import lombok.Setter; import lombok.experimental.SuperBuilder; import org.lowcoder.plugin.api.event.LowcoderEvent; @@ -18,6 +19,8 @@ public abstract class AbstractEvent implements LowcoderEvent protected final Boolean isAnonymous; private final String ipAddress; protected Map details; + @Setter + private static String deploymentID; public Map details() { @@ -33,6 +36,7 @@ public B detail(String name, String value) details = new HashMap<>(); } this.details.put(name, value); + this.details.put("deploymentID", deploymentID); return self(); } } @@ -51,5 +55,6 @@ public void populateDetails() { } } + details.put("deploymentID", deploymentID); } } diff --git a/server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/eventlistener/AppEventListener.java b/server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/eventlistener/AppEventListener.java index 5b0b944ef..54c4aca94 100644 --- a/server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/eventlistener/AppEventListener.java +++ b/server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/eventlistener/AppEventListener.java @@ -1,16 +1,23 @@ package org.lowcoder.runner.eventlistener; +import lombok.RequiredArgsConstructor; +import org.lowcoder.infra.config.model.ServerConfig; +import org.lowcoder.infra.config.repository.ServerConfigRepository; +import org.lowcoder.infra.event.AbstractEvent; import org.lowcoder.sdk.exception.BizError; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; +import reactor.core.publisher.Mono; @Slf4j @Component +@RequiredArgsConstructor public class AppEventListener { + private final ServerConfigRepository serverConfigRepository; @EventListener public void onApplicationEvent(ApplicationReadyEvent event) { System.out.println( @@ -23,5 +30,7 @@ public void onApplicationEvent(ApplicationReadyEvent event) { """ ); log.info("check BizError duplicates: {}", BizError.values().length); + String deploymentId = (String)(serverConfigRepository.findByKey("deployment.id").map(ServerConfig::getValue).switchIfEmpty(Mono.just("")).block()); + AbstractEvent.setDeploymentID(deploymentId); } }