Skip to content

Commit 2b10aba

Browse files
committed
Move updateLayout analytics event to ContextLayoutRefactoringService
1 parent f7e8aad commit 2b10aba

File tree

4 files changed

+58
-23
lines changed

4 files changed

+58
-23
lines changed

app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import com.appsmith.server.constants.FieldName;
1111
import com.appsmith.server.domains.ExecutableDependencyEdge;
1212
import com.appsmith.server.domains.Layout;
13-
import com.appsmith.server.domains.NewPage;
14-
import com.appsmith.server.domains.User;
1513
import com.appsmith.server.dtos.LayoutDTO;
1614
import com.appsmith.server.dtos.UpdateMultiplePageLayoutDTO;
1715
import com.appsmith.server.exceptions.AppsmithError;
@@ -87,29 +85,22 @@ private Mono<Boolean> sendUpdateLayoutAnalyticsEvent(
8785
boolean isSuccess,
8886
Throwable error,
8987
CreatorContextType creatorType) {
90-
return Mono.zip(sessionUserService.getCurrentUser(), newPageService.getByIdWithoutPermissionCheck(creatorId))
91-
.flatMap(tuple -> {
92-
User t1 = tuple.getT1();
93-
NewPage t2 = tuple.getT2();
94-
95-
final Map<String, Object> data = Map.of(
96-
"username",
97-
t1.getUsername(),
98-
"appId",
99-
t2.getApplicationId(),
100-
"creatorId",
101-
creatorId,
102-
"creatorType",
103-
creatorType,
104-
"layoutId",
105-
layoutId,
106-
"isSuccessfulExecution",
107-
isSuccess,
108-
"error",
109-
error == null ? "" : error.getMessage());
88+
return contextLayoutRefactorResolver
89+
.getContextLayoutRefactorHelper(creatorType)
90+
.getContextForAnalytics(creatorId)
91+
.flatMap(contextInfo -> {
92+
final Map<String, Object> data = Map.ofEntries(
93+
Map.entry("username", contextInfo.getUsername()),
94+
Map.entry("artifactType", contextInfo.getArtifactType()),
95+
Map.entry("artifactId", contextInfo.getArtifactId()),
96+
Map.entry("creatorId", creatorId),
97+
Map.entry("creatorType", creatorType),
98+
Map.entry("layoutId", layoutId),
99+
Map.entry("isSuccessfulExecution", isSuccess),
100+
Map.entry("error", error == null ? "" : error.getMessage()));
110101

111102
return analyticsService
112-
.sendObjectEvent(AnalyticsEvents.UPDATE_LAYOUT, t2, data)
103+
.sendObjectEvent(AnalyticsEvents.UPDATE_LAYOUT, contextInfo.getDomain(), data)
113104
.thenReturn(isSuccess);
114105
})
115106
.onErrorResume(e -> {

app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/refactors/PageLayoutRefactoringServiceImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.appsmith.server.newpages.refactors;
22

33
import com.appsmith.server.applications.base.ApplicationService;
4+
import com.appsmith.server.constants.ArtifactType;
45
import com.appsmith.server.constants.FieldName;
56
import com.appsmith.server.domains.Layout;
67
import com.appsmith.server.domains.NewPage;
@@ -11,7 +12,9 @@
1112
import com.appsmith.server.exceptions.AppsmithError;
1213
import com.appsmith.server.exceptions.AppsmithException;
1314
import com.appsmith.server.newpages.base.NewPageService;
15+
import com.appsmith.server.refactors.AnalyticsContextDTO;
1416
import com.appsmith.server.refactors.ContextLayoutRefactoringService;
17+
import com.appsmith.server.services.SessionUserService;
1518
import lombok.RequiredArgsConstructor;
1619
import lombok.extern.slf4j.Slf4j;
1720
import org.springframework.stereotype.Component;
@@ -27,6 +30,7 @@
2730
public class PageLayoutRefactoringServiceImpl implements ContextLayoutRefactoringService<NewPage, PageDTO> {
2831
private final NewPageService newPageService;
2932
private final ApplicationService applicationService;
33+
private final SessionUserService sessionUserService;
3034

3135
@Override
3236
public Mono<PageDTO> updateContext(String contextId, LayoutContainer dto) {
@@ -106,4 +110,17 @@ public String getArtifactId(RefactoringMetaDTO refactoringMetaDTO) {
106110
public void setUpdatedContext(RefactoringMetaDTO refactoringMetaDTO, LayoutContainer updatedContext) {
107111
refactoringMetaDTO.setUpdatedPage((PageDTO) updatedContext);
108112
}
113+
114+
@Override
115+
public Mono<AnalyticsContextDTO> getContextForAnalytics(String contextId) {
116+
return Mono.zip(sessionUserService.getCurrentUser(), newPageService.getByIdWithoutPermissionCheck(contextId))
117+
.map(tuple -> {
118+
return AnalyticsContextDTO.builder()
119+
.username(tuple.getT1().getUsername())
120+
.artifactType(ArtifactType.APPLICATION)
121+
.artifactId(tuple.getT2().getApplicationId())
122+
.domain(tuple.getT2())
123+
.build();
124+
});
125+
}
109126
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.appsmith.server.refactors;
2+
3+
import com.appsmith.external.models.BaseDomain;
4+
import com.appsmith.server.constants.ArtifactType;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
8+
/**
9+
* DTO class that holds context information used for analytics
10+
*/
11+
@Data
12+
@Builder
13+
public class AnalyticsContextDTO {
14+
private String username;
15+
private ArtifactType artifactType;
16+
private String artifactId;
17+
private BaseDomain domain;
18+
}

app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/ContextLayoutRefactoringService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ Mono<Integer> getEvaluationVersionMono(
104104
* @param updatedContext The updated layout container to persist in metadata
105105
*/
106106
void setUpdatedContext(RefactoringMetaDTO refactoringMetaDTO, LayoutContainer updatedContext);
107+
108+
/**
109+
* Retrieves context information needed for analytics based on the context ID.
110+
* This includes the username of the current user, the artifact ID, and the domain object.
111+
*
112+
* @param contextId The unique identifier of the context
113+
* @return A Mono emitting the analytics context information
114+
*/
115+
Mono<AnalyticsContextDTO> getContextForAnalytics(String contextId);
107116
}

0 commit comments

Comments
 (0)