Merge branch 'trisha-dev' into 'master'
Added Tenant Settings See merge request theappsmith/internal-tools-server!1
This commit is contained in:
commit
00a588cbc5
|
|
@ -8,4 +8,5 @@ public interface Url {
|
||||||
String LAYOUT_URL = BASE_URL + VERSION + "/layouts";
|
String LAYOUT_URL = BASE_URL + VERSION + "/layouts";
|
||||||
String PLUGIN_URL = BASE_URL + VERSION + "/plugins";
|
String PLUGIN_URL = BASE_URL + VERSION + "/plugins";
|
||||||
String QUERY_URL = BASE_URL + VERSION + "/queries";
|
String QUERY_URL = BASE_URL + VERSION + "/queries";
|
||||||
|
String SETTING_URL = BASE_URL + VERSION + "/settings";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mobtools.server.controllers;
|
||||||
|
|
||||||
|
import com.mobtools.server.constants.Url;
|
||||||
|
import com.mobtools.server.domains.Setting;
|
||||||
|
import com.mobtools.server.services.SettingService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Url.SETTING_URL)
|
||||||
|
public class SettingController extends BaseController<SettingService, Setting, String> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SettingController(SettingService settingService) {
|
||||||
|
super(settingService);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.mobtools.server.domains;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.data.mongodb.core.index.Indexed;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Document
|
||||||
|
public class Setting extends BaseDomain {
|
||||||
|
|
||||||
|
@Indexed(unique = true)
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
private Boolean isTenantSetting;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,8 @@ import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
@ -20,4 +22,6 @@ public class Tenant extends BaseDomain {
|
||||||
|
|
||||||
private String website;
|
private String website;
|
||||||
|
|
||||||
|
private List<TenantSetting> tenantSettings;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.mobtools.server.domains;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only used to store the settings that are different from the default values already set in setting collection
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TenantSetting extends BaseDomain {
|
||||||
|
|
||||||
|
@DBRef
|
||||||
|
private Setting setting;
|
||||||
|
|
||||||
|
private String settingValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.mobtools.server.repositories;
|
||||||
|
|
||||||
|
import com.mobtools.server.domains.Setting;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface SettingRepository extends BaseRepository<Setting, String> {
|
||||||
|
|
||||||
|
Mono<Setting> findByKey(String key);
|
||||||
|
}
|
||||||
|
|
@ -65,8 +65,8 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<T> create(T widget) {
|
public Mono<T> create(T object) {
|
||||||
return repository.save(widget);
|
return repository.save(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DBObject getDbObject(Object o) {
|
private DBObject getDbObject(Object o) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ public interface PluginService extends CrudService<Plugin, String> {
|
||||||
/**
|
/**
|
||||||
* Return an instance of PluginExecutor based on the classname available.
|
* Return an instance of PluginExecutor based on the classname available.
|
||||||
* If the classname is not available, null is returned.
|
* If the classname is not available, null is returned.
|
||||||
|
*
|
||||||
* @param pluginType
|
* @param pluginType
|
||||||
* @param className
|
* @param className
|
||||||
* @return PluginExecutor
|
* @return PluginExecutor
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.mobtools.server.services;
|
||||||
|
|
||||||
|
import com.mobtools.server.domains.Setting;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
public interface SettingService extends CrudService<Setting, String> {
|
||||||
|
|
||||||
|
Mono<Setting> getByKey(String key);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.mobtools.server.services;
|
||||||
|
|
||||||
|
import com.mobtools.server.domains.Setting;
|
||||||
|
import com.mobtools.server.repositories.SettingRepository;
|
||||||
|
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;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.core.scheduler.Scheduler;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SettingServiceImpl extends BaseService<SettingRepository, Setting, String> implements SettingService {
|
||||||
|
|
||||||
|
private final SettingRepository repository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SettingServiceImpl(Scheduler scheduler,
|
||||||
|
MongoConverter mongoConverter,
|
||||||
|
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||||
|
SettingRepository repository) {
|
||||||
|
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Setting> getByKey(String key) {
|
||||||
|
return repository.findByKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,4 +6,6 @@ import reactor.core.publisher.Mono;
|
||||||
public interface TenantService extends CrudService<Tenant, String> {
|
public interface TenantService extends CrudService<Tenant, String> {
|
||||||
|
|
||||||
Mono<Tenant> getByName(String name);
|
Mono<Tenant> getByName(String name);
|
||||||
|
|
||||||
|
Mono<Tenant> create(Tenant object);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,67 @@
|
||||||
package com.mobtools.server.services;
|
package com.mobtools.server.services;
|
||||||
|
|
||||||
|
import com.mobtools.server.domains.Setting;
|
||||||
import com.mobtools.server.domains.Tenant;
|
import com.mobtools.server.domains.Tenant;
|
||||||
|
import com.mobtools.server.domains.TenantSetting;
|
||||||
import com.mobtools.server.repositories.TenantRepository;
|
import com.mobtools.server.repositories.TenantRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.core.scheduler.Scheduler;
|
import reactor.core.scheduler.Scheduler;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class TenantServiceImpl extends BaseService<TenantRepository, Tenant, String> implements TenantService {
|
public class TenantServiceImpl extends BaseService<TenantRepository, Tenant, String> implements TenantService {
|
||||||
|
|
||||||
private final TenantRepository repository;
|
private final TenantRepository repository;
|
||||||
|
private final SettingService settingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TenantServiceImpl(Scheduler scheduler,
|
public TenantServiceImpl(Scheduler scheduler,
|
||||||
MongoConverter mongoConverter,
|
MongoConverter mongoConverter,
|
||||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||||
TenantRepository repository) {
|
TenantRepository repository,
|
||||||
|
SettingService settingService) {
|
||||||
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
|
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
this.settingService = settingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Tenant> getByName(String name) {
|
public Mono<Tenant> getByName(String name) {
|
||||||
return repository.findByName(name);
|
return repository.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Tenant> create(@NotNull Tenant tenant) {
|
||||||
|
|
||||||
|
//Embed the setting object into tenantSetting. This is done only for settings for which the values deviate from the default.
|
||||||
|
//It is assumed that the tenant create API body would only contain the settings for which the default value and
|
||||||
|
//true value are different.
|
||||||
|
if (tenant.getTenantSettings() != null) {
|
||||||
|
|
||||||
|
try (Stream<TenantSetting> stream = tenant.getTenantSettings().stream()) {
|
||||||
|
Flux<TenantSetting> tenantSettingFlux = Flux.fromStream(stream);
|
||||||
|
tenantSettingFlux.map(this::getAndStoreSettingObjectInTenantSetting).subscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository.save(tenant);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getAndStoreSettingObjectInTenantSetting(TenantSetting tenantSetting) {
|
||||||
|
String key = tenantSetting.getSetting().getKey();
|
||||||
|
Mono<Setting> setting = settingService.getByKey(key);
|
||||||
|
return setting.doOnNext(set -> tenantSetting.setSetting(set))
|
||||||
|
.thenReturn(tenantSetting)
|
||||||
|
.subscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user