Skip to content

Commit 9141557

Browse files
authored
Merge pull request #2455 from digma-ai/user-activation-status
user activation from backend Closes #2290 Closes #2439
2 parents 56127dd + adb4946 commit 9141557

File tree

28 files changed

+1332
-42
lines changed

28 files changed

+1332
-42
lines changed

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.digma.intellij.plugin.analytics;
22

33
import org.digma.intellij.plugin.model.rest.AboutResult;
4+
import org.digma.intellij.plugin.model.rest.activation.DiscoveredDataResponse;
45
import org.digma.intellij.plugin.model.rest.assets.AssetDisplayInfo;
56
import org.digma.intellij.plugin.model.rest.codelens.*;
67
import org.digma.intellij.plugin.model.rest.codespans.CodeContextSpans;
@@ -147,4 +148,6 @@ public interface AnalyticsProvider extends Closeable {
147148
String getHighlightsImpact(HighlightsRequest request);
148149

149150
List<SpanEnvironment> getSpanEnvironmentsStats(String spanCodeObjectId);
151+
152+
DiscoveredDataResponse getDiscoveredData();
150153
}

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/RestAnalyticsProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import okhttp3.logging.HttpLoggingInterceptor;
88
import org.apache.commons.lang3.time.StopWatch;
99
import org.digma.intellij.plugin.model.rest.AboutResult;
10+
import org.digma.intellij.plugin.model.rest.activation.DiscoveredDataResponse;
1011
import org.digma.intellij.plugin.model.rest.assets.AssetDisplayInfo;
1112
import org.digma.intellij.plugin.model.rest.codelens.*;
1213
import org.digma.intellij.plugin.model.rest.codespans.CodeContextSpans;
@@ -427,6 +428,11 @@ public void resetThrottlingStatus() {
427428
execute(client.analyticsProvider::resetThrottlingStatus);
428429
}
429430

431+
@Override
432+
public DiscoveredDataResponse getDiscoveredData() {
433+
return execute(client.analyticsProvider::getDiscoveredData);
434+
}
435+
430436
@Override
431437
public HttpResponse lowLevelCall(HttpRequest request) {
432438

@@ -1141,5 +1147,11 @@ Call<Void> setInsightCustomStartTime(
11411147

11421148
@GET("spans/environments")
11431149
Call<List<SpanEnvironment>> getSpanEnvironmentsStats(@Query("SpanCodeObjectId") String spanCodeObjectId);
1150+
1151+
@Headers({
1152+
"Content-Type:application/json"
1153+
})
1154+
@GET("CodeAnalytics/discovered-data")
1155+
Call<DiscoveredDataResponse> getDiscoveredData();
11441156
}
11451157
}

ide-common/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.digma.intellij.plugin.errorreporting.ErrorReporter;
1111
import org.digma.intellij.plugin.log.Log;
1212
import org.digma.intellij.plugin.model.rest.AboutResult;
13+
import org.digma.intellij.plugin.model.rest.activation.DiscoveredDataResponse;
1314
import org.digma.intellij.plugin.model.rest.assets.AssetDisplayInfo;
1415
import org.digma.intellij.plugin.model.rest.codelens.*;
1516
import org.digma.intellij.plugin.model.rest.codespans.CodeContextSpans;
@@ -488,10 +489,15 @@ public InsightsStatsResult getInsightsStats(String spanCodeObjectId, String insi
488489
}
489490

490491
@NotNull
491-
public List<SpanEnvironment> getSpanEnvironmentsStats(String spanCodeObjectId) throws AnalyticsServiceException {
492+
public List<SpanEnvironment> getSpanEnvironmentsStats(String spanCodeObjectId) throws AnalyticsServiceException {
492493
return executeCatching(() -> analyticsProviderProxy.getSpanEnvironmentsStats(spanCodeObjectId));
493494
}
494495

496+
@NotNull
497+
public DiscoveredDataResponse getDiscoveredData() throws AnalyticsServiceException {
498+
return executeCatching(() -> analyticsProviderProxy.getDiscoveredData());
499+
}
500+
495501
public HttpResponse lowLevelCall(HttpRequest request) throws AnalyticsServiceException {
496502
return executeCatching(() -> analyticsProviderProxy.lowLevelCall(request));
497503
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package org.digma.intellij.plugin.activation
2+
3+
import com.intellij.notification.Notification
4+
import com.intellij.notification.NotificationGroupManager
5+
import com.intellij.notification.NotificationType
6+
import com.intellij.openapi.actionSystem.AnAction
7+
import com.intellij.openapi.actionSystem.AnActionEvent
8+
import com.intellij.openapi.project.Project
9+
import org.digma.intellij.plugin.PluginId
10+
import org.digma.intellij.plugin.common.findActiveProject
11+
import org.digma.intellij.plugin.errorreporting.ErrorReporter
12+
import org.digma.intellij.plugin.notifications.NotificationUtil.DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP
13+
import org.digma.intellij.plugin.posthog.ActivityMonitor
14+
import org.digma.intellij.plugin.recentactivity.RecentActivityToolWindowShower
15+
import org.digma.intellij.plugin.ui.ToolWindowShower
16+
17+
18+
fun showNewIssueNotification(title: String, uiMessage: String) {
19+
20+
findActiveProject()?.let { project ->
21+
val notificationName = "NewIssueFoundNotification"
22+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf())
23+
val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP)
24+
.createNotification(
25+
title,
26+
"Digma has some initial findings! Click the link bellow to view the issues and get more information.",
27+
NotificationType.INFORMATION
28+
)
29+
notification.addAction(ShowIssuesAction(project, notification, notificationName, uiMessage))
30+
notification.whenExpired {
31+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf())
32+
}
33+
notification.setImportant(true)
34+
notification.setToolWindowId(PluginId.TOOL_WINDOW_ID)
35+
notification.notify(project)
36+
}
37+
}
38+
39+
fun showNewInsightNotification(title: String, uiMessage: String) {
40+
findActiveProject()?.let { project ->
41+
val notificationName = "NewInsightFoundNotification"
42+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf())
43+
val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP)
44+
.createNotification(
45+
title,
46+
"Digma has some initial analytics results. Click the link bellow to see the list of assets and drill into any specific one to see more data.",
47+
NotificationType.INFORMATION
48+
)
49+
notification.addAction(ShowAssetAction(project, notification, notificationName, uiMessage))
50+
notification.whenExpired {
51+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf())
52+
}
53+
notification.setImportant(true)
54+
notification.setToolWindowId(PluginId.TOOL_WINDOW_ID)
55+
notification.notify(project)
56+
}
57+
}
58+
59+
fun showNewAssetNotification(title: String, uiMessage: String) {
60+
findActiveProject()?.let { project ->
61+
val notificationName = "NewAssetFoundNotification"
62+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf())
63+
val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP)
64+
.createNotification(
65+
title,
66+
"First assets discovered! Digma has received some data about your code. Click the link bellow to see the assets view.",
67+
NotificationType.INFORMATION
68+
)
69+
notification.addAction(ShowAssetAction(project, notification, notificationName, uiMessage))
70+
notification.whenExpired {
71+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf())
72+
}
73+
notification.setImportant(true)
74+
notification.setToolWindowId(PluginId.TOOL_WINDOW_ID)
75+
notification.notify(project)
76+
}
77+
}
78+
79+
fun showNewRecentActivityNotification(title: String, uiMessage: String) {
80+
findActiveProject()?.let { project ->
81+
val notificationName = "NewRecentActivityFoundNotification"
82+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf())
83+
val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP)
84+
.createNotification(
85+
title,
86+
"Digma has some initial analytics results. Click here to see the list of activities and drill into any specific one to see more data.",
87+
NotificationType.INFORMATION
88+
)
89+
notification.addAction(ShowRecentActivityAction(project, notification, notificationName, uiMessage))
90+
notification.whenExpired {
91+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf())
92+
}
93+
notification.setImportant(true)
94+
notification.setToolWindowId(PluginId.TOOL_WINDOW_ID)
95+
notification.notify(project)
96+
}
97+
}
98+
99+
100+
private class ShowIssuesAction(
101+
private val project: Project,
102+
private val notification: Notification,
103+
private val notificationName: String,
104+
private val uiMessage: String,
105+
) : AnAction("Show Issues") {
106+
override fun actionPerformed(e: AnActionEvent) {
107+
108+
try {
109+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf())
110+
ToolWindowShower.getInstance(project).showToolWindow()
111+
project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage)
112+
notification.expire()
113+
} catch (e: Throwable) {
114+
ErrorReporter.getInstance().reportError(project, "ShowIssuesAction.actionPerformed", e)
115+
}
116+
}
117+
}
118+
119+
//we can't show the analytics tab because there is no home for analytics
120+
private class ShowInsightAction(
121+
private val project: Project,
122+
private val notification: Notification,
123+
private val notificationName: String,
124+
private val uiMessage: String,
125+
) : AnAction("Show Insights") {
126+
override fun actionPerformed(e: AnActionEvent) {
127+
128+
try {
129+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf())
130+
ToolWindowShower.getInstance(project).showToolWindow()
131+
project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage)
132+
notification.expire()
133+
} catch (e: Throwable) {
134+
ErrorReporter.getInstance().reportError(project, "ShowInsightAction.actionPerformed", e)
135+
}
136+
}
137+
}
138+
139+
private class ShowAssetAction(
140+
private val project: Project,
141+
private val notification: Notification,
142+
private val notificationName: String,
143+
private val uiMessage: String,
144+
) : AnAction("Show Assets") {
145+
override fun actionPerformed(e: AnActionEvent) {
146+
147+
try {
148+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf())
149+
ToolWindowShower.getInstance(project).showToolWindow()
150+
project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage)
151+
notification.expire()
152+
} catch (e: Throwable) {
153+
ErrorReporter.getInstance().reportError(project, "ShowAssetAction.actionPerformed", e)
154+
}
155+
}
156+
}
157+
158+
private class ShowRecentActivityAction(
159+
private val project: Project,
160+
private val notification: Notification,
161+
private val notificationName: String,
162+
private val uiMessage: String,
163+
) : AnAction("Show Recent Activity") {
164+
override fun actionPerformed(e: AnActionEvent) {
165+
166+
try {
167+
ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf())
168+
RecentActivityToolWindowShower.getInstance(project).showToolWindow()
169+
project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage)
170+
notification.expire()
171+
} catch (e: Throwable) {
172+
ErrorReporter.getInstance().reportError(project, "ShowRecentActivityAction.actionPerformed", e)
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)