Merge branch 'feature/property-pane-jsonobject' into 'release'
Moving the propertyPane config to generic JSONObject See merge request theappsmith/internal-tools-server!234
This commit is contained in:
commit
d009e91e9d
|
|
@ -7,6 +7,8 @@ import com.appsmith.server.services.ConfigService;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
|
@ -25,4 +27,9 @@ public class ConfigController extends BaseController<ConfigService, Config, Stri
|
|||
.map(resource -> new ResponseDTO<>(HttpStatus.OK.value(), resource, null));
|
||||
}
|
||||
|
||||
@PutMapping("/name/{name}")
|
||||
public Mono<ResponseDTO<Config>> updateByName(@PathVariable String name, @RequestBody Config config) {
|
||||
return service.updateByName(name, config)
|
||||
.map(resource -> new ResponseDTO<>(HttpStatus.OK.value(), resource, null));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
package com.appsmith.server.controllers;
|
||||
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.PropertyPane;
|
||||
import com.appsmith.server.services.PropertyPaneService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Url.PROPERTY_URL)
|
||||
public class PropertyPaneController extends BaseController<PropertyPaneService, PropertyPane, String> {
|
||||
public PropertyPaneController(PropertyPaneService service) {
|
||||
super(service);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.appsmith.server.controllers;
|
||||
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.Widget;
|
||||
import com.appsmith.server.dtos.ResponseDTO;
|
||||
import com.appsmith.server.services.WidgetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Url.WIDGET_URL)
|
||||
public class WidgetController extends BaseController<WidgetService, Widget, String> {
|
||||
|
||||
@Autowired
|
||||
public WidgetController(WidgetService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
@GetMapping("/name/{name}")
|
||||
public Mono<ResponseDTO<Widget>> getByName(@PathVariable String name) {
|
||||
return service.getByName(name)
|
||||
.map(widget -> new ResponseDTO<>(HttpStatus.OK.value(), widget, null));
|
||||
}
|
||||
}
|
||||
|
|
@ -5,19 +5,17 @@ import lombok.Getter;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.minidev.json.JSONObject;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Config extends BaseDomain {
|
||||
Map<String, List<WidgetSectionProperty>> config;
|
||||
JSONObject config;
|
||||
|
||||
@Indexed(unique = true)
|
||||
String name;
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import com.appsmith.external.models.BaseDomain;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class PropertyPane extends BaseDomain {
|
||||
|
||||
Map<String, List<WidgetSectionProperty>> config;
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import com.appsmith.external.models.BaseDomain;
|
||||
import com.appsmith.external.models.Property;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Widget extends BaseDomain {
|
||||
|
||||
@Indexed(unique = true)
|
||||
private String name;
|
||||
|
||||
private WidgetType type;
|
||||
|
||||
private PricingPlan pricingPlan;
|
||||
|
||||
private List<Property> properties;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class WidgetChildProperty {
|
||||
String id;
|
||||
String propertyName;
|
||||
String label;
|
||||
String controlType;
|
||||
String placeholderText;
|
||||
List<WidgetOption> options;
|
||||
String inputType;
|
||||
Boolean isJSConvertible;
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class WidgetOption {
|
||||
String label;
|
||||
String value;
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class WidgetSectionProperty {
|
||||
String sectionName;
|
||||
String id;
|
||||
List<WidgetChildProperty> children;
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
public enum WidgetType {
|
||||
DB, DISPLAY
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package com.appsmith.server.repositories;
|
||||
|
||||
import com.appsmith.server.domains.PropertyPane;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PropertyPaneRepository extends BaseRepository<PropertyPane, String> {
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.appsmith.server.repositories;
|
||||
|
||||
import com.appsmith.server.domains.Widget;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Repository
|
||||
public interface WidgetRepository extends BaseRepository<Widget, String> {
|
||||
|
||||
Mono<Widget> findByName(String name);
|
||||
}
|
||||
|
|
@ -5,4 +5,6 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
public interface ConfigService extends CrudService<Config, String> {
|
||||
Mono<Config> getByName(String name);
|
||||
|
||||
Mono<Config> updateByName(String name, Config config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.appsmith.server.domains.Config;
|
|||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.ConfigRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -13,6 +14,7 @@ import reactor.core.scheduler.Scheduler;
|
|||
|
||||
import javax.validation.Validator;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConfigServiceImpl extends BaseService<ConfigRepository, Config, String> implements ConfigService {
|
||||
|
||||
|
|
@ -30,4 +32,15 @@ public class ConfigServiceImpl extends BaseService<ConfigRepository, Config, Str
|
|||
return repository.findByName(name)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.CONFIG, name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Config> updateByName(String name, Config config) {
|
||||
return repository.findByName(name)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.CONFIG, name)))
|
||||
.flatMap(dbConfig -> {
|
||||
log.debug("Found config with name: {} and id: {}", name, dbConfig.getId());
|
||||
dbConfig.setConfig(config.getConfig());
|
||||
return repository.save(dbConfig);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.PropertyPane;
|
||||
|
||||
public interface PropertyPaneService extends CrudService<PropertyPane, String> {
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.PropertyPane;
|
||||
import com.appsmith.server.domains.WidgetChildProperty;
|
||||
import com.appsmith.server.domains.WidgetSectionProperty;
|
||||
import com.appsmith.server.exceptions.AppsmithError;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.PropertyPaneRepository;
|
||||
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;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
|
||||
import javax.validation.Validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PropertyPaneServiceImpl extends BaseService<PropertyPaneRepository, PropertyPane, String> implements PropertyPaneService {
|
||||
|
||||
@Autowired
|
||||
public PropertyPaneServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
PropertyPaneRepository repository,
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PropertyPane> create(PropertyPane propertyPane) {
|
||||
if (propertyPane.getId() != null) {
|
||||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id"));
|
||||
}
|
||||
if (propertyPane.getConfig() != null) {
|
||||
Map<String, List<WidgetSectionProperty>> configMap = propertyPane.getConfig();
|
||||
configMap.forEach((key, sectionProperty) -> {
|
||||
List<WidgetSectionProperty> widgetSectionProperties = sectionProperty;
|
||||
for (WidgetSectionProperty widgetSectionProperty : widgetSectionProperties) {
|
||||
widgetSectionProperty.setId(new ObjectId().toString());
|
||||
List<WidgetChildProperty> widgetChildProperties = widgetSectionProperty.getChildren();
|
||||
for (WidgetChildProperty widgetChildProperty : widgetChildProperties) {
|
||||
widgetChildProperty.setId(new ObjectId().toString());
|
||||
}
|
||||
widgetSectionProperty.setChildren(widgetChildProperties);
|
||||
}
|
||||
configMap.put(key, widgetSectionProperties);
|
||||
});
|
||||
propertyPane.setConfig(configMap);
|
||||
}
|
||||
return super.create(propertyPane);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Widget;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface WidgetService extends CrudService<Widget, String> {
|
||||
|
||||
Mono<Widget> getByName(String name);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Widget;
|
||||
import com.appsmith.server.repositories.WidgetRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
import javax.validation.Validator;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WidgetServiceImpl extends BaseService<WidgetRepository, Widget, String> implements WidgetService {
|
||||
|
||||
private WidgetRepository widgetRepository;
|
||||
|
||||
@Autowired
|
||||
public WidgetServiceImpl(Scheduler scheduler,
|
||||
Validator validator,
|
||||
MongoConverter mongoConverter,
|
||||
ReactiveMongoTemplate mongoTemplate,
|
||||
WidgetRepository widgetRepository,
|
||||
AnalyticsService analyticsService) {
|
||||
super(scheduler, validator, mongoConverter, mongoTemplate, widgetRepository, analyticsService);
|
||||
this.widgetRepository = widgetRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Widget> getByName(String name) {
|
||||
return widgetRepository.findByName(name);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user