Skip to content

Commit

Permalink
Feature/editor simplify - API to work with mock data sets (#5421)
Browse files Browse the repository at this point in the history
* Added an API to get list of mock datsets
Removed the flow of

* Removed the auto populate of mock datasets flow when the user sign up first time

* Fixed indentation issues

* Instead of sending empty datasource, change template value to empty

* Add only the configs to response instead of entire mongo doc

* Add API to create mock data set
  • Loading branch information
AnaghHegde authored and rishabhsaxena committed Jul 2, 2021
1 parent 8475fa3 commit 409c2fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.appsmith.server.services.DatasourceService;
import com.appsmith.server.solutions.AuthenticationService;
import com.appsmith.server.solutions.DatasourceStructureSolution;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.solutions.ExamplesOrganizationCloner;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,6 +25,8 @@
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import net.minidev.json.JSONObject;

import java.net.URI;

@Slf4j
Expand All @@ -32,14 +36,20 @@ public class DatasourceController extends BaseController<DatasourceService, Data

private final DatasourceStructureSolution datasourceStructureSolution;
private final AuthenticationService authenticationService;
private final ConfigService configService;
private final ExamplesOrganizationCloner examplesOrganizationCloner;

private static final String TEMPLATE_ORGANIZATION_CONFIG_NAME = "template-mockdb";

@Autowired
public DatasourceController(DatasourceService service,
DatasourceStructureSolution datasourceStructureSolution,
AuthenticationService authenticationService) {
AuthenticationService authenticationService, ConfigService configService, ExamplesOrganizationCloner examplesOrganizationCloner) {
super(service);
this.datasourceStructureSolution = datasourceStructureSolution;
this.authenticationService = authenticationService;
this.configService = configService;
this.examplesOrganizationCloner = examplesOrganizationCloner;
}

@PostMapping("/test")
Expand Down Expand Up @@ -79,5 +89,16 @@ public Mono<Void> getAccessToken(AuthorizationCodeCallbackDTO callbackDTO, Serve
});
}

@GetMapping("/mocks")
public Mono<ResponseDTO<JSONObject>> getMockDataSets() {
return configService.getByName(TEMPLATE_ORGANIZATION_CONFIG_NAME)
.map(config -> new ResponseDTO<>(HttpStatus.OK.value(), config.getConfig(), null));
}

@PostMapping("/mocks")
public Mono<ResponseDTO<Datasource>> createMockDataSet(@RequestParam String datasourceId, @RequestParam String organizationId) {
return examplesOrganizationCloner.cloneDatasource(datasourceId, organizationId)
.map(datasource -> new ResponseDTO<>(HttpStatus.OK.value(), datasource, null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private Mono<Application> cloneApplicationDocument(Application application) {
);
}

private Mono<Datasource> cloneDatasource(String datasourceId, String toOrganizationId) {
public Mono<Datasource> cloneDatasource(String datasourceId, String toOrganizationId) {
final Mono<List<Datasource>> existingDatasourcesMono = datasourceRepository.findAllByOrganizationId(toOrganizationId)
.collectList();

Expand Down

0 comments on commit 409c2fb

Please sign in to comment.