chore: Add analytics for partial export (#28934)
This commit is contained in:
parent
97a8a40df4
commit
2fc028ab2f
|
|
@ -86,7 +86,9 @@ public enum AnalyticsEvents {
|
|||
GIT_STALE_FILE_LOCK_DELETED,
|
||||
SERVER_SETUP_COMPLETE("server_setup_complete"),
|
||||
|
||||
PARTIAL_IMPORT;
|
||||
PARTIAL_IMPORT,
|
||||
|
||||
PARTIAL_EXPORT;
|
||||
|
||||
private final String eventName;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.appsmith.server.exports.internal;
|
||||
|
||||
import com.appsmith.external.constants.AnalyticsEvents;
|
||||
import com.appsmith.external.models.Datasource;
|
||||
import com.appsmith.external.models.DatasourceStorage;
|
||||
import com.appsmith.server.acl.AclPermission;
|
||||
|
|
@ -11,6 +12,7 @@ import com.appsmith.server.domains.Application;
|
|||
import com.appsmith.server.domains.CustomJSLib;
|
||||
import com.appsmith.server.domains.NewAction;
|
||||
import com.appsmith.server.domains.Plugin;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.dtos.ApplicationJson;
|
||||
import com.appsmith.server.dtos.ExportingMetaDTO;
|
||||
import com.appsmith.server.dtos.MappedExportableResourcesDTO;
|
||||
|
|
@ -22,15 +24,17 @@ import com.appsmith.server.jslibs.base.CustomJSLibService;
|
|||
import com.appsmith.server.migrations.JsonSchemaVersions;
|
||||
import com.appsmith.server.newactions.base.NewActionService;
|
||||
import com.appsmith.server.newpages.base.NewPageService;
|
||||
import com.appsmith.server.services.AnalyticsService;
|
||||
import com.appsmith.server.services.ApplicationService;
|
||||
import com.appsmith.server.services.SessionUserService;
|
||||
import com.appsmith.server.solutions.ApplicationPermission;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.appsmith.server.constants.ResourceModes.EDIT;
|
||||
|
|
@ -50,7 +54,8 @@ public class PartialExportServiceCEImpl implements PartialExportServiceCE {
|
|||
private final ExportableService<Plugin> pluginExportableService;
|
||||
private final ExportableService<NewAction> newActionExportableService;
|
||||
private final ExportableService<ActionCollection> actionCollectionExportableService;
|
||||
private final Gson gson;
|
||||
private final SessionUserService sessionUserService;
|
||||
private final AnalyticsService analyticsService;
|
||||
|
||||
@Override
|
||||
public Mono<ApplicationJson> getPartialExportResources(
|
||||
|
|
@ -158,12 +163,26 @@ public class PartialExportServiceCEImpl implements PartialExportServiceCE {
|
|||
applicationJson,
|
||||
SerialiseApplicationObjective.SHARE);
|
||||
}
|
||||
return Mono.just(applicationJson);
|
||||
return Mono.just(applicationJson).zipWith(sessionUserService.getCurrentUser());
|
||||
})
|
||||
.map(exportedJson -> {
|
||||
.flatMap(tuple -> {
|
||||
ApplicationJson applicationJson1 = tuple.getT1();
|
||||
Application application = applicationJson1.getExportedApplication();
|
||||
|
||||
applicationJson.setWidgets(partialExportFileDTO.getWidget());
|
||||
applicationJson.setExportedApplication(null);
|
||||
return applicationJson;
|
||||
|
||||
User user = tuple.getT2();
|
||||
final Map<String, Object> eventData = Map.of(FieldName.APPLICATION, application);
|
||||
|
||||
final Map<String, Object> data = Map.of(
|
||||
FieldName.APPLICATION_ID, application.getId(),
|
||||
FieldName.WORKSPACE_ID, application.getWorkspaceId(),
|
||||
FieldName.EVENT_DATA, eventData);
|
||||
|
||||
return analyticsService
|
||||
.sendEvent(AnalyticsEvents.PARTIAL_EXPORT.getEventName(), user.getUsername(), data)
|
||||
.thenReturn(applicationJson);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ import com.appsmith.server.exports.exportable.ExportableService;
|
|||
import com.appsmith.server.jslibs.base.CustomJSLibService;
|
||||
import com.appsmith.server.newactions.base.NewActionService;
|
||||
import com.appsmith.server.newpages.base.NewPageService;
|
||||
import com.appsmith.server.services.AnalyticsService;
|
||||
import com.appsmith.server.services.ApplicationService;
|
||||
import com.appsmith.server.services.SessionUserService;
|
||||
import com.appsmith.server.solutions.ApplicationPermission;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -29,7 +30,8 @@ public class PartialExportServiceImpl extends PartialExportServiceCEImpl impleme
|
|||
ExportableService<Plugin> pluginExportableService,
|
||||
ExportableService<NewAction> newActionExportableService,
|
||||
ExportableService<ActionCollection> actionCollectionExportableService,
|
||||
Gson gson) {
|
||||
SessionUserService sessionUserService,
|
||||
AnalyticsService analyticsService) {
|
||||
super(
|
||||
applicationService,
|
||||
applicationPermission,
|
||||
|
|
@ -41,6 +43,7 @@ public class PartialExportServiceImpl extends PartialExportServiceCEImpl impleme
|
|||
pluginExportableService,
|
||||
newActionExportableService,
|
||||
actionCollectionExportableService,
|
||||
gson);
|
||||
sessionUserService,
|
||||
analyticsService);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,10 +338,10 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC
|
|||
*/
|
||||
private String validateApplicationJson(ApplicationJson importedDoc) {
|
||||
String errorField = "";
|
||||
if (CollectionUtils.isEmpty(importedDoc.getPageList())) {
|
||||
errorField = FieldName.PAGE_LIST;
|
||||
} else if (importedDoc.getExportedApplication() == null) {
|
||||
if (importedDoc.getExportedApplication() == null) {
|
||||
errorField = FieldName.APPLICATION;
|
||||
} else if (CollectionUtils.isEmpty(importedDoc.getPageList())) {
|
||||
errorField = FieldName.PAGE_LIST;
|
||||
} else if (importedDoc.getActionList() == null) {
|
||||
errorField = FieldName.ACTIONS;
|
||||
} else if (importedDoc.getDatasourceList() == null) {
|
||||
|
|
@ -493,6 +493,13 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC
|
|||
String errorField = validateApplicationJson(importedDoc);
|
||||
if (!errorField.isEmpty()) {
|
||||
log.error("Error in importing application. Field {} is missing", errorField);
|
||||
if (errorField.equals(FieldName.APPLICATION)) {
|
||||
return Mono.error(
|
||||
new AppsmithException(
|
||||
AppsmithError.VALIDATION_FAILURE,
|
||||
"Field '" + errorField
|
||||
+ "' Sorry! Seems like you've imported a page-level json instead of an application. Please use the import within the page."));
|
||||
}
|
||||
return Mono.error(new AppsmithException(
|
||||
AppsmithError.VALIDATION_FAILURE, "Field '" + errorField + "' is missing in the JSON."));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -899,11 +899,14 @@ public class ImportApplicationServiceTests {
|
|||
importApplicationService.extractFileAndSaveApplication(workspaceId, filePart);
|
||||
|
||||
StepVerifier.create(resultMono)
|
||||
.expectErrorMatches(throwable -> throwable instanceof AppsmithException
|
||||
&& throwable
|
||||
.getMessage()
|
||||
.equals(AppsmithError.VALIDATION_FAILURE.getMessage(
|
||||
"Field '" + FieldName.APPLICATION + "' is missing in the JSON.")))
|
||||
.expectErrorMatches(
|
||||
throwable -> throwable instanceof AppsmithException
|
||||
&& throwable
|
||||
.getMessage()
|
||||
.equals(
|
||||
AppsmithError.VALIDATION_FAILURE.getMessage(
|
||||
"Field '" + FieldName.APPLICATION
|
||||
+ "' Sorry! Seems like you've imported a page-level json instead of an application. Please use the import within the page.")))
|
||||
.verify();
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user