Analytics Service now caters to all the events that need to be published. Every service should now call the analytics service's sendEvent function for tracking events.
This commit is contained in:
parent
84837fe57f
commit
74a8466528
|
|
@ -0,0 +1,6 @@
|
|||
package com.appsmith.server.constants;
|
||||
|
||||
public interface AnalyticsEvents {
|
||||
String CREATE = "create";
|
||||
String UPDATE = "update";
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.appsmith.external.models.ActionExecutionResult;
|
|||
import com.appsmith.external.models.Param;
|
||||
import com.appsmith.external.models.ResourceConfiguration;
|
||||
import com.appsmith.external.plugins.PluginExecutor;
|
||||
import com.appsmith.server.constants.AnalyticsEvents;
|
||||
import com.appsmith.server.domains.Action;
|
||||
import com.appsmith.server.domains.Page;
|
||||
import com.appsmith.server.domains.PageAction;
|
||||
|
|
@ -61,10 +62,10 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
PluginService pluginService,
|
||||
PageService pageService,
|
||||
PluginManager pluginManager,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService,
|
||||
ObjectMapper objectMapper, ResourceContextService resourceContextService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService,
|
||||
ObjectMapper objectMapper,
|
||||
ResourceContextService resourceContextService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
this.resourceService = resourceService;
|
||||
this.pluginService = pluginService;
|
||||
|
|
@ -84,7 +85,6 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
return Mono.error(new AppsmithException(AppsmithError.PAGE_ID_NOT_GIVEN));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<Resource> resourceMono = resourceService.findById(action.getResourceId());
|
||||
Mono<Plugin> pluginMono = resourceMono.flatMap(resource -> pluginService.findById(resource.getPluginId()));
|
||||
Mono<Page> pageMono = pageService.findById(action.getPageId());
|
||||
|
|
@ -94,34 +94,32 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
action.setPluginId(plugin.getId());
|
||||
return action;
|
||||
})
|
||||
.flatMap(repository::save)
|
||||
.flatMap(super::create)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.REPOSITORY_SAVE_FAILED)));
|
||||
|
||||
return savedActionMono
|
||||
//Now that the action has been stored, add it to the page
|
||||
.flatMap(action1 -> {
|
||||
return pageMono
|
||||
.map(page -> {
|
||||
PageAction pageAction = new PageAction();
|
||||
pageAction.setId(action1.getId());
|
||||
pageAction.setName(action1.getName());
|
||||
pageAction.setJsonPathKeys(new ArrayList<>());
|
||||
.flatMap(action1 -> pageMono
|
||||
.map(page -> {
|
||||
PageAction pageAction = new PageAction();
|
||||
pageAction.setId(action1.getId());
|
||||
pageAction.setName(action1.getName());
|
||||
pageAction.setJsonPathKeys(new ArrayList<>());
|
||||
|
||||
List<PageAction> actions = page.getActions();
|
||||
List<PageAction> actions = page.getActions();
|
||||
|
||||
if (actions == null) {
|
||||
actions = new ArrayList<>();
|
||||
}
|
||||
if (actions == null) {
|
||||
actions = new ArrayList<>();
|
||||
}
|
||||
|
||||
actions.add(pageAction);
|
||||
page.setActions(actions);
|
||||
return page;
|
||||
})
|
||||
.flatMap(pageService::save)
|
||||
.then(Mono.just(action1))
|
||||
//Now publish this event
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
});
|
||||
actions.add(pageAction);
|
||||
page.setActions(actions);
|
||||
return page;
|
||||
})
|
||||
.flatMap(pageService::save)
|
||||
//Finally return the saved action
|
||||
.then(Mono.just(action1))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.BaseDomain;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.segment.analytics.Analytics;
|
||||
import com.segment.analytics.messages.IdentifyMessage;
|
||||
import com.segment.analytics.messages.TrackMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AnalyticsService<T extends BaseDomain> {
|
||||
|
||||
private final Analytics analytics;
|
||||
private final SessionUserService sessionUserService;
|
||||
|
||||
@Autowired
|
||||
public AnalyticsService(Analytics analytics, SessionUserService sessionUserService) {
|
||||
this.analytics = analytics;
|
||||
this.sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
public Mono<User> trackNewUser(User user) {
|
||||
return Mono.just(user)
|
||||
.map(savedUser -> {
|
||||
Map<String, String> traitsMap = new HashMap<>();
|
||||
traitsMap.put("name", savedUser.getName());
|
||||
traitsMap.put("email", savedUser.getEmail());
|
||||
analytics.enqueue(IdentifyMessage.builder()
|
||||
.userId(savedUser.getId())
|
||||
.traits(traitsMap)
|
||||
);
|
||||
analytics.flush();
|
||||
return savedUser;
|
||||
});
|
||||
}
|
||||
|
||||
public Mono<T> sendEvent(String eventTag, T object) {
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
return userMono
|
||||
.map(user -> {
|
||||
HashMap<String, String> analyticsProperties = new HashMap<>();
|
||||
analyticsProperties.put("id", ((BaseDomain) object).getId());
|
||||
analyticsProperties.put("object", object.toString());
|
||||
if(user.getOrganizationId() != null) {
|
||||
analyticsProperties.put("organizationId", user.getOrganizationId());
|
||||
}
|
||||
|
||||
analytics.enqueue(
|
||||
TrackMessage.builder(eventTag)
|
||||
.userId(user.getId())
|
||||
.properties(analyticsProperties)
|
||||
);
|
||||
return (T) object;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.constants.AnalyticsEvents;
|
||||
import com.appsmith.server.constants.FieldName;
|
||||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.ApplicationRepository;
|
||||
import com.segment.analytics.Analytics;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
|
|
@ -23,12 +23,18 @@ import javax.validation.Validator;
|
|||
@Service
|
||||
public class ApplicationServiceImpl extends BaseService<ApplicationRepository, Application, String> implements ApplicationService {
|
||||
|
||||
private final Analytics analytics;
|
||||
private final SessionUserService sessionUserService;
|
||||
|
||||
@Autowired
|
||||
public ApplicationServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ApplicationRepository repository, SessionUserService sessionUserService, Analytics analytics) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
this.analytics = analytics;
|
||||
public ApplicationServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
ApplicationRepository repository,
|
||||
AnalyticsService analyticsService,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -37,7 +43,7 @@ public class ApplicationServiceImpl extends BaseService<ApplicationRepository, A
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.NAME));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
|
||||
return userMono
|
||||
.map(user -> user.getOrganizationId())
|
||||
|
|
@ -45,14 +51,12 @@ public class ApplicationServiceImpl extends BaseService<ApplicationRepository, A
|
|||
application.setOrganizationId(orgId);
|
||||
return application;
|
||||
})
|
||||
.flatMap(repository::save)
|
||||
//Log the event to Segment
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
.flatMap(super::create);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Application> get() {
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
|
||||
return userMono
|
||||
.map(user -> user.getOrganizationId())
|
||||
|
|
@ -65,7 +69,7 @@ public class ApplicationServiceImpl extends BaseService<ApplicationRepository, A
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
|
||||
return userMono
|
||||
.map(user -> user.getOrganizationId())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.constants.AnalyticsEvents;
|
||||
import com.appsmith.server.constants.FieldName;
|
||||
import com.appsmith.server.domains.BaseDomain;
|
||||
import com.appsmith.server.domains.User;
|
||||
|
|
@ -35,22 +36,19 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
|
|||
|
||||
protected final Validator validator;
|
||||
|
||||
protected final Analytics analytics;
|
||||
|
||||
protected final SessionUserService sessionUserService;
|
||||
protected final AnalyticsService analyticsService;
|
||||
|
||||
public BaseService(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
R repository, Analytics analytics, SessionUserService sessionUserService) {
|
||||
R repository, AnalyticsService analyticsService) {
|
||||
this.scheduler = scheduler;
|
||||
this.validator = validator;
|
||||
this.mongoConverter = mongoConverter;
|
||||
this.mongoTemplate = reactiveMongoTemplate;
|
||||
this.repository = repository;
|
||||
this.analytics = analytics;
|
||||
this.sessionUserService = sessionUserService;
|
||||
this.analyticsService = analyticsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,7 +66,8 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
|
|||
updateMap.entrySet().stream().forEach(entry -> updateObj.set(entry.getKey(), entry.getValue()));
|
||||
|
||||
return mongoTemplate.updateFirst(query, updateObj, resource.getClass())
|
||||
.flatMap(obj -> repository.findById(id));
|
||||
.flatMap(obj -> repository.findById(id))
|
||||
.flatMap(updatedObj -> analyticsService.sendEvent(AnalyticsEvents.UPDATE+"_"+updatedObj.getClass().getSimpleName().toUpperCase(), (T) updatedObj));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -88,11 +87,10 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
|
|||
|
||||
@Override
|
||||
public Mono<T> create(T object) {
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
return Mono.just(object)
|
||||
.flatMap(this::validateObject)
|
||||
.flatMap(repository::save)
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
.flatMap(savedObj -> analyticsService.sendEvent(AnalyticsEvents.CREATE+"_"+savedObj.getClass().getSimpleName().toUpperCase(), (T) savedObj));
|
||||
}
|
||||
|
||||
private DBObject getDbObject(Object o) {
|
||||
|
|
@ -118,24 +116,4 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, constraint.stream().findFirst().get().getPropertyPath()));
|
||||
});
|
||||
}
|
||||
|
||||
protected Mono<T> segmentTrackCreate(Object savedObject) {
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
return userMono
|
||||
.map(user -> {
|
||||
HashMap<String, String> analyticsProperties = new HashMap<>();
|
||||
analyticsProperties.put("id", ((BaseDomain) savedObject).getId());
|
||||
if(user.getOrganizationId() != null) {
|
||||
analyticsProperties.put("organizationId", user.getOrganizationId());
|
||||
}
|
||||
|
||||
analytics.enqueue(
|
||||
TrackMessage.builder("MONGO_DB_CREATE_" + savedObject.getClass().getSimpleName().toUpperCase())
|
||||
.userId(user.getId())
|
||||
.properties(analyticsProperties)
|
||||
);
|
||||
return (T) savedObject;
|
||||
})
|
||||
.switchIfEmpty(Mono.just((T) savedObject));
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,8 @@ public class GroupServiceImpl extends BaseService<GroupRepository, Group, String
|
|||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
GroupRepository repository,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.constants.AnalyticsEvents;
|
||||
import com.appsmith.server.constants.FieldName;
|
||||
import com.appsmith.server.domains.Group;
|
||||
import com.appsmith.server.domains.Organization;
|
||||
import com.appsmith.server.domains.OrganizationSetting;
|
||||
import com.appsmith.server.domains.Setting;
|
||||
|
|
@ -20,7 +20,6 @@ import reactor.core.scheduler.Scheduler;
|
|||
|
||||
import javax.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -38,10 +37,9 @@ public class OrganizationServiceImpl extends BaseService<OrganizationRepository,
|
|||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
OrganizationRepository repository,
|
||||
SettingService settingService,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService,
|
||||
AnalyticsService analyticsService,
|
||||
GroupService groupService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
this.settingService = settingService;
|
||||
this.groupService = groupService;
|
||||
|
|
@ -68,10 +66,8 @@ public class OrganizationServiceImpl extends BaseService<OrganizationRepository,
|
|||
.flatMap(this::validateObject)
|
||||
//transform the organization data to embed setting object in each object in organizationSetting list.
|
||||
.flatMap(this::enhanceOrganizationSettingList)
|
||||
//Call the library function to save the updated organization
|
||||
.flatMap(repository::save)
|
||||
//push the org create to analytics
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
//Call the BaseService function to save the updated organization
|
||||
.flatMap(super::create);
|
||||
}
|
||||
|
||||
private Mono<Organization> enhanceOrganizationSettingList(Organization organization) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.appsmith.server.domains.User;
|
|||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.PageRepository;
|
||||
import com.segment.analytics.Analytics;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -26,12 +25,20 @@ import java.util.List;
|
|||
public class PageServiceImpl extends BaseService<PageRepository, Page, String> implements PageService {
|
||||
|
||||
private final ApplicationService applicationService;
|
||||
private final SessionUserService sessionUserService;
|
||||
|
||||
@Autowired
|
||||
public PageServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, PageRepository repository, ApplicationService applicationService,
|
||||
Analytics analytics, SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
public PageServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
PageRepository repository,
|
||||
ApplicationService applicationService,
|
||||
AnalyticsService analyticsService,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.applicationService = applicationService;
|
||||
this.sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -44,8 +51,6 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.APPLICATIONID));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
|
||||
List<Layout> layoutList = page.getLayouts();
|
||||
if (layoutList == null) {
|
||||
layoutList = new ArrayList<>();
|
||||
|
|
@ -54,9 +59,7 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
|
|||
layoutList.add(createDefaultLayout());
|
||||
page.setLayouts(layoutList);
|
||||
}
|
||||
return repository
|
||||
.save(page)
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
return super.create(page);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -77,7 +80,7 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
|
|||
|
||||
@Override
|
||||
public Mono<Page> doesPageIdBelongToCurrentUserOrganization(Page page) {
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
final String[] username = {null};
|
||||
|
||||
return userMono
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ public class PermissionServiceImpl extends BaseService<PermissionRepository, Per
|
|||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
PermissionRepository repository,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.appsmith.server.exceptions.AppsmithException;
|
|||
import com.appsmith.server.repositories.PluginRepository;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.segment.analytics.Analytics;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.pf4j.PluginManager;
|
||||
|
|
@ -44,6 +43,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
private final ReactiveRedisTemplate<String, String> reactiveTemplate;
|
||||
private final ChannelTopic topic;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final SessionUserService sessionUserService;
|
||||
|
||||
private static final int CONNECTION_TIMEOUT = 10000;
|
||||
private static final int READ_TIMEOUT = 10000;
|
||||
|
|
@ -54,19 +54,22 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
PluginRepository repository,
|
||||
AnalyticsService analyticsService,
|
||||
ApplicationContext applicationContext,
|
||||
OrganizationService organizationService,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService, PluginManager pluginManager,
|
||||
PluginManager pluginManager,
|
||||
ReactiveRedisTemplate<String, String> reactiveTemplate,
|
||||
ChannelTopic topic, ObjectMapper objectMapper) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
ChannelTopic topic,
|
||||
ObjectMapper objectMapper,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.applicationContext = applicationContext;
|
||||
this.organizationService = organizationService;
|
||||
this.pluginManager = pluginManager;
|
||||
this.reactiveTemplate = reactiveTemplate;
|
||||
this.topic = topic;
|
||||
this.objectMapper = objectMapper;
|
||||
this.sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
public OldPluginExecutor getPluginExecutor(PluginType pluginType, String className) {
|
||||
|
|
@ -86,12 +89,8 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id"));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
|
||||
plugin.setDeleted(false);
|
||||
return repository
|
||||
.save(plugin)
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
return super.create(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -112,7 +111,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
}
|
||||
|
||||
//Find the organization using id and plugin id -> This is to find if the organization has the plugin installed
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
Mono<Organization> organizationMono = userMono.flatMap(user ->
|
||||
organizationService.findByIdAndPluginsPluginId(user.getOrganizationId(), pluginDTO.getPluginId()));
|
||||
|
||||
|
|
@ -133,7 +132,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
private Mono<Organization> storeOrganizationPlugin(PluginOrgDTO pluginDTO, OrganizationPluginStatus status) {
|
||||
|
||||
//Find the organization using id and plugin id -> This is to find if the organization already has the plugin installed
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
Mono<Organization> pluginInOrganizationMono = userMono.flatMap(user ->
|
||||
organizationService.findByIdAndPluginsPluginId(user.getOrganizationId(), pluginDTO.getPluginId()));
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.appsmith.server.repositories.PropertyPaneRepository;
|
|||
import com.segment.analytics.Analytics;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -22,8 +23,15 @@ import java.util.Map;
|
|||
@Slf4j
|
||||
@Service
|
||||
public class PropertyPaneServiceImpl extends BaseService<PropertyPaneRepository, PropertyPane, String> implements PropertyPaneService {
|
||||
public PropertyPaneServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, PropertyPaneRepository repository, Analytics analytics, SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
|
||||
@Autowired
|
||||
public PropertyPaneServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
PropertyPaneRepository repository,
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -47,8 +55,6 @@ public class PropertyPaneServiceImpl extends BaseService<PropertyPaneRepository,
|
|||
});
|
||||
propertyPane.setConfig(configMap);
|
||||
}
|
||||
return repository
|
||||
.save(propertyPane)
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
return super.create(propertyPane);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.appsmith.server.domains.User;
|
|||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.ResourceRepository;
|
||||
import com.segment.analytics.Analytics;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
|
|
@ -24,13 +23,21 @@ public class ResourceServiceImpl extends BaseService<ResourceRepository, Resourc
|
|||
|
||||
private final ResourceRepository repository;
|
||||
private final OrganizationService organizationService;
|
||||
private final SessionUserService sessionUserService;
|
||||
|
||||
@Autowired
|
||||
public ResourceServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ResourceRepository repository, OrganizationService organizationService, PluginService pluginService, Analytics analytics,
|
||||
public ResourceServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
ResourceRepository repository,
|
||||
OrganizationService organizationService,
|
||||
AnalyticsService analyticsService,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
this.organizationService = organizationService;
|
||||
this.sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -41,7 +48,7 @@ public class ResourceServiceImpl extends BaseService<ResourceRepository, Resourc
|
|||
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_ID_NOT_GIVEN));
|
||||
}
|
||||
|
||||
Mono<User> userMono = super.sessionUserService.getCurrentUser();
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser();
|
||||
|
||||
Mono<Organization> organizationMono = userMono.flatMap(user -> organizationService.findByIdAndPluginsPluginId(user.getOrganizationId(), resource.getPluginId()));
|
||||
|
||||
|
|
@ -55,8 +62,7 @@ public class ResourceServiceImpl extends BaseService<ResourceRepository, Resourc
|
|||
return organizationMono
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.PLUGIN_NOT_INSTALLED, resource.getPluginId())))
|
||||
.then(updatedResourceMono)
|
||||
.flatMap(repository::save)
|
||||
.flatMap(this::segmentTrackCreate);
|
||||
.flatMap(super::create);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ public class SettingServiceImpl extends BaseService<SettingRepository, Setting,
|
|||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
SettingRepository repository,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
|
||||
private UserRepository repository;
|
||||
private final OrganizationService organizationService;
|
||||
private final Analytics analytics;
|
||||
|
||||
private final AnalyticsService analyticsService;
|
||||
@Autowired
|
||||
public UserServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
|
|
@ -37,12 +36,11 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
UserRepository repository,
|
||||
OrganizationService organizationService,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
this.repository = repository;
|
||||
this.organizationService = organizationService;
|
||||
this.analytics = analytics;
|
||||
this.analyticsService = analyticsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -58,19 +56,9 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
@Override
|
||||
public Mono<User> create(User user) {
|
||||
|
||||
Mono<User> savedUserMono = repository.save(user);
|
||||
Mono<User> savedUserMono = super.create(user);
|
||||
return savedUserMono
|
||||
.map(savedUser -> {
|
||||
Map<String, String> traitsMap = new HashMap<>();
|
||||
traitsMap.put("name", savedUser.getName());
|
||||
traitsMap.put("email", savedUser.getEmail());
|
||||
analytics.enqueue(IdentifyMessage.builder()
|
||||
.userId(savedUser.getId())
|
||||
.traits(traitsMap)
|
||||
);
|
||||
analytics.flush();
|
||||
return savedUser;
|
||||
});
|
||||
.flatMap(analyticsService::trackNewUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -25,9 +25,8 @@ public class WidgetServiceImpl extends BaseService<WidgetRepository, Widget, Str
|
|||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate mongoTemplate,
|
||||
WidgetRepository widgetRepository,
|
||||
Analytics analytics,
|
||||
SessionUserService sessionUserService) {
|
||||
super(scheduler, validator, mongoConverter, mongoTemplate, widgetRepository, analytics, sessionUserService);
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, mongoTemplate, widgetRepository, analyticsService);
|
||||
this.widgetRepository = widgetRepository;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user