Added datasource configuration to the provider to support the provider level configurations in rapid api

This commit is contained in:
Trisha Anand 2020-02-14 06:32:34 +00:00
parent 23641a7e9a
commit 2e11a5c2d5
59 changed files with 236 additions and 180 deletions

View File

@ -1,60 +1,17 @@
package com.appsmith.external.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Persistable;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.Instant;
@Getter
@Setter
@ToString
@NoArgsConstructor
@Document
public class ApiTemplate implements Persistable<String> {
private static final long serialVersionUID = 7459916000501322517L;
@Id
private String id;
@JsonIgnore
@Indexed
@CreatedDate
protected Instant createdAt;
@JsonIgnore
@LastModifiedDate
protected Instant updatedAt;
@CreatedBy
protected String createdBy;
@LastModifiedBy
protected String modifiedBy;
protected Boolean deleted = false;
@JsonIgnore
@Version
protected Long documentVersion;
@JsonIgnore
@Override
public boolean isNew() {
return this.getId() == null;
}
public class ApiTemplate extends BaseDomain {
// ApiTemplate fields below :
String name; //API name here

View File

@ -1,4 +1,4 @@
package com.appsmith.server.domains;
package com.appsmith.external.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
@ -15,7 +15,12 @@ import org.springframework.data.mongodb.core.index.Indexed;
import java.time.Instant;
@Getter
/**
* TODO :
* Move BaseDomain back to appsmith-server.domain. This is done temporarily to create templates and providers in the same database as the server
*/
@Getter
@Setter
@ToString
public abstract class BaseDomain implements Persistable<String> {

View File

@ -0,0 +1,20 @@
package com.appsmith.external.models;
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 Category extends BaseDomain {
@Indexed(unique=true)
String name; //Category name here
}

View File

@ -1,21 +1,12 @@
package com.appsmith.external.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Persistable;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.Instant;
import java.util.List;
@Getter
@ -23,47 +14,24 @@ import java.util.List;
@ToString
@NoArgsConstructor
@Document
public class Provider implements Persistable<String> {
public class Provider extends BaseDomain {
private static final long serialVersionUID = 7459916000501322517L;
@Id
private String id;
@JsonIgnore
@Indexed
@CreatedDate
protected Instant createdAt;
@JsonIgnore
@LastModifiedDate
protected Instant updatedAt;
@CreatedBy
protected String createdBy;
@LastModifiedBy
protected String modifiedBy;
protected Boolean deleted = false;
@JsonIgnore
@Version
protected Long documentVersion;
@JsonIgnore
@Override
public boolean isNew() {
return this.getId() == null;
}
// Provider details here
@Indexed(unique=true)
String name; //Provider name here
String description; //Provider company's description here
String url;
String imageUrl;
String documentationUrl; //URL which points to the homepage of the documentations here
String credentialSteps; //How to generate/get the credentials to run the APIs which belong to this provider
List<String> categories; //Category names here
Statistics statistics; //Cumulative statistics for all the APIs for this provider
DatasourceConfiguration datasourceConfiguration;
}

View File

@ -8,11 +8,12 @@ import reactor.core.publisher.Mono;
public interface PluginExecutor extends ExtensionPoint {
/**
* This function is used to execute the action.
* @param connection : This is the connection that is established to the data source. This connection is according
* to the parameters in Datasource Configuration
* This function is used to execute the action.
*
* @param connection : This is the connection that is established to the data source. This connection is according
* to the parameters in Datasource Configuration
* @param datasourceConfiguration : These are the configurations which have been used to create a Datasource from a Plugin
* @param actionConfiguration : These are the configurations which have been used to create an Action from a Datasource.
* @param actionConfiguration : These are the configurations which have been used to create an Action from a Datasource.
* @return ActionExecutionResult : This object is returned to the user which contains the result values from the execution.
*/
Mono<Object> execute(Object connection, DatasourceConfiguration datasourceConfiguration, ActionConfiguration actionConfiguration);
@ -20,6 +21,7 @@ public interface PluginExecutor extends ExtensionPoint {
/**
* This function is responsible for creating the connection to the data source and returning the connection variable
* on success. For executing actions, this connection object would be passed for each function call.
*
* @param datasourceConfiguration
* @return Connection object
*/
@ -27,6 +29,7 @@ public interface PluginExecutor extends ExtensionPoint {
/**
* This function is used to bring down/destroy the connection to the data source.
*
* @param connection
*/
void datasourceDestroy(Object connection);

View File

@ -38,10 +38,10 @@ public class MongoPlugin extends BasePlugin {
* For reference on creating the json queries for Mongo please head to
* https://docs.huihoo.com/mongodb/3.4/reference/command/index.html
*
* @param connection : This is the connection that is established to the data source. This connection is according
* to the parameters in Datasource Configuration
* @param connection : This is the connection that is established to the data source. This connection is according
* to the parameters in Datasource Configuration
* @param datasourceConfiguration : These are the configurations which have been used to create a Datasource from a Plugin
* @param actionConfiguration : These are the configurations which have been used to create an Action from a Datasource.
* @param actionConfiguration : These are the configurations which have been used to create an Action from a Datasource.
* @return
*/
@Override
@ -55,7 +55,7 @@ public class MongoPlugin extends BasePlugin {
return Mono.error(new Exception("Mongo Client is null."));
}
MongoClientURI mongoClientURI= new MongoClientURI(datasourceConfiguration.getUrl());
MongoClientURI mongoClientURI = new MongoClientURI(datasourceConfiguration.getUrl());
String databaseName = datasourceConfiguration.getDatabaseName();
if (databaseName == null) {
@ -113,7 +113,7 @@ public class MongoPlugin extends BasePlugin {
@Override
public Object datasourceCreate(DatasourceConfiguration datasourceConfiguration) {
MongoClientURI mongoClientURI= new MongoClientURI(datasourceConfiguration.getUrl());
MongoClientURI mongoClientURI = new MongoClientURI(datasourceConfiguration.getUrl());
return new MongoClient(mongoClientURI);
}

View File

@ -7,7 +7,7 @@
<artifactId>integrated</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.appsmith</groupId>
<artifactId>appsmith-plugins</artifactId>
@ -19,5 +19,5 @@
<module>restApiPlugin</module>
<module>mongoPlugin</module>
</modules>
</project>

View File

@ -38,7 +38,7 @@ public class PostgresPlugin extends BasePlugin {
/**
* Postgres plugin receives the query as json of the following format :
* {
* "cmd" : "select * from users;"
* "cmd" : "select * from users;"
* }
*/
@ -87,8 +87,8 @@ public class PostgresPlugin extends BasePlugin {
// Create the connection
conn = DriverManager.getConnection(datasourceConfiguration.getUrl(),
datasourceConfiguration.getAuthentication().getUsername(),
datasourceConfiguration.getAuthentication().getPassword());
datasourceConfiguration.getAuthentication().getUsername(),
datasourceConfiguration.getAuthentication().getPassword());
return conn;
} catch (ClassNotFoundException e) {
log.error("", e);

View File

@ -71,7 +71,7 @@ public class RestApiPlugin extends BasePlugin {
URI uri = null;
try {
uri = createFinalUriWithQueryParams(url, actionConfiguration.getQueryParameters());
System.out.println("Final URL is : "+ uri.toString());
System.out.println("Final URL is : " + uri.toString());
} catch (URISyntaxException e) {
e.printStackTrace();
return Mono.error(new AppsmithPluginException(AppsmithPluginError.PLUGIN_ERROR, e));
@ -153,6 +153,13 @@ public class RestApiPlugin extends BasePlugin {
ClientResponse response = (ClientResponse) res;
if (response.statusCode().is3xxRedirection()) {
String redirectUrl = response.headers().header("Location").get(0);
/**
* TODO
* In case the redirected URL is not absolute (complete), create the new URL using the relative path
* This particular scenario is seen in the URL : https://rickandmortyapi.com/api/character
* It redirects to partial URI : /api/character/
* In this scenario we should convert the partial URI to complete URI
*/
URI redirectUri = null;
try {
redirectUri = new URI(redirectUrl);

View File

@ -9,7 +9,7 @@ import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRep
/**
* This configures the JPA Mongo repositories. The default base implementation is defined in {@link BaseRepositoryImpl}.
* This is required to add default clauses for default JPA queries defined by Spring Data.
*
* <p>
* The factoryBean class is also custom defined in order to add default clauses for soft delete for all custom JPA queries.
* {@link SoftDeleteMongoRepositoryFactoryBean} for details.
*/

View File

@ -22,11 +22,10 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
* This class overrides the default implementation in
* {@link org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory#getQueryLookupStrategy}
* This custom implementation adds the query parameter to filter out any records marked with delete=true in the database
*
* <p>
* Also refer to the custom Factory: {@link SoftDeleteMongoRepositoryFactory} and
* custom FactoryBean: {@link SoftDeleteMongoRepositoryFactoryBean}. The annotation @EnableReactiveMongoRepositories in
* {@link com.appsmith.server.configurations.CommonConfig} sets the Mongo factory bean to our custom bean instead of the default one
*
*/
public class SoftDeleteMongoQueryLookupStrategy implements QueryLookupStrategy {
private final QueryLookupStrategy strategy;

View File

@ -10,6 +10,7 @@ import java.io.Serializable;
/**
* This factory bean class is set in the annotation @EnableReactiveMongoRepositories in {@link com.appsmith.server.configurations.CommonConfig}
* which overrides the default factory bean {@link ReactiveMongoRepositoryFactoryBean}
*
* @param <T>
* @param <S>
* @param <ID>

View File

@ -3,8 +3,8 @@ package com.appsmith.server.constants;
public interface Url {
String BASE_URL = "/api";
String VERSION = "/v1";
String LOGIN_URL= BASE_URL + VERSION + "/login";
String LOGOUT_URL= BASE_URL + VERSION + "/logout";
String LOGIN_URL = BASE_URL + VERSION + "/login";
String LOGOUT_URL = BASE_URL + VERSION + "/logout";
String WIDGET_URL = BASE_URL + VERSION + "/widgets";
String ORGANIZATION_URL = BASE_URL + VERSION + "/organizations";
String LAYOUT_URL = BASE_URL + VERSION + "/layouts";
@ -25,4 +25,5 @@ public interface Url {
String IMPORT_URL = BASE_URL + VERSION + "/import";
String PROVIDER_URL = BASE_URL + VERSION + "/providers";
String MARKETPLACE_URL = BASE_URL + VERSION + "/marketplace";
String API_TEMPLATE_URL = BASE_URL + VERSION + "/templates";
}

View File

@ -0,0 +1,15 @@
package com.appsmith.server.controllers;
import com.appsmith.external.models.ApiTemplate;
import com.appsmith.server.constants.Url;
import com.appsmith.server.services.ApiTemplateService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(Url.API_TEMPLATE_URL)
public class ApiTemplateController extends BaseController<ApiTemplateService, ApiTemplate, String> {
public ApiTemplateController(ApiTemplateService service) {
super(service);
}
}

View File

@ -1,6 +1,6 @@
package com.appsmith.server.controllers;
import com.appsmith.server.domains.BaseDomain;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.CrudService;

View File

@ -1,46 +1,16 @@
package com.appsmith.server.controllers;
import com.appsmith.external.models.Provider;
import com.appsmith.external.models.Statistics;
import com.appsmith.server.constants.Url;
import com.appsmith.server.dtos.ResponseDTO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import com.appsmith.server.services.ProviderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(Url.PROVIDER_URL)
public class ProviderController {
public class ProviderController extends BaseController<ProviderService, Provider, String> {
@GetMapping
Mono<ResponseDTO<List<Provider>>> fetchProviders(@RequestParam(required = false) String categoryName, @RequestParam(required = false) String pageNo) {
Provider provider = new Provider();
List<String> categories = new ArrayList<>();
categories.add("Data");
categories.add("Sports");
provider.setCategories(categories);
provider.setName("New Sports Ltd");
provider.setId("RandomSavedId");
provider.setDescription("Some description here");
provider.setUrl("http://url.com");
provider.setImageUrl("http://image.url.com");
provider.setDocumentationUrl("http://docu.url.com");
Statistics statistics = new Statistics();
statistics.setAverageLatency((long) 230);
statistics.setImports((long) 1000);
statistics.setSuccessRate(99.7);
provider.setStatistics(statistics);
provider.setCredentialSteps("Credential steps here");
List<Provider> providers = new ArrayList<>();
providers.add(provider);
providers.add(provider);
return Mono.just(providers)
.map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null));
public ProviderController(ProviderService service) {
super(service);
}
}

View File

@ -5,7 +5,6 @@ import com.appsmith.server.constants.Url;
import com.appsmith.server.domains.Action;
import com.appsmith.server.domains.RestApiImporterType;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.services.ApiImporter;
import com.appsmith.server.services.CurlImporterService;
import com.appsmith.server.services.PostmanImporterService;
@ -41,7 +40,10 @@ public class RestApiImportController {
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Mono<ResponseDTO<Action>> create(@Valid @RequestBody Object input, @RequestParam RestApiImporterType type) throws AppsmithException {
public Mono<ResponseDTO<Action>> create(@Valid @RequestBody Object input,
@RequestParam RestApiImporterType type,
@RequestParam String pageId,
@RequestParam String name) {
log.debug("Going to import API");
ApiImporter service;
@ -53,13 +55,13 @@ public class RestApiImportController {
throw new IllegalStateException("Unexpected value: " + type);
}
return Mono.just(service.importAction(input))
return service.importAction(input, pageId, name)
.map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null));
}
@PostMapping("/postman")
@ResponseStatus(HttpStatus.CREATED)
public Mono<ResponseDTO<TemplateCollection>> importPostmanCollection(@RequestBody Object input) {
public Mono<ResponseDTO<TemplateCollection>> importPostmanCollection(@RequestBody Object input, @RequestParam String type) {
return Mono.just(postmanImporterService.importPostmanCollection(input))
.map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null));
}

View File

@ -1,6 +1,7 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.BaseDomain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.external.models.DatasourceConfiguration;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.dtos.DslActionDTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.dtos.OrganizationPluginStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,6 +1,7 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

View File

@ -1,5 +1,6 @@
package com.appsmith.server.domains;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.external.models.Property;
import lombok.Getter;
import lombok.NoArgsConstructor;

View File

@ -104,6 +104,7 @@ public class GlobalExceptionHandler {
return Mono.just(new ResponseDTO<>(appsmithError.getHttpErrorCode(), new ErrorDTO(appsmithError.getAppErrorCode(),
appsmithError.getMessage())));
}
/**
* This function catches the generic Exception class and is meant to be a catch all to ensure that we don't leak
* any information to the client. Ideally, the function #catchAppsmithException should be used

View File

@ -5,7 +5,6 @@ import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Set;
@Repository

View File

@ -0,0 +1,6 @@
package com.appsmith.server.repositories;
import com.appsmith.external.models.ApiTemplate;
public interface ApiTemplateRepository extends BaseRepository<ApiTemplate, String> {
}

View File

@ -1,7 +1,7 @@
package com.appsmith.server.repositories;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.BaseDomain;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;

View File

@ -0,0 +1,6 @@
package com.appsmith.server.repositories;
import com.appsmith.external.models.Provider;
public interface ProviderRepository extends BaseRepository<Provider, String> {
}

View File

@ -1,6 +1,6 @@
package com.appsmith.server.services;
import com.appsmith.server.domains.BaseDomain;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.domains.User;
import com.segment.analytics.Analytics;
import com.segment.analytics.messages.IdentifyMessage;

View File

@ -1,9 +1,10 @@
package com.appsmith.server.services;
import com.appsmith.server.domains.Action;
import reactor.core.publisher.Mono;
public interface ApiImporter {
Action importAction(Object input);
Mono<Action> importAction(Object input, String pageId, String name);
}

View File

@ -0,0 +1,6 @@
package com.appsmith.server.services;
import com.appsmith.external.models.ApiTemplate;
public interface ApiTemplateService extends CrudService<ApiTemplate, String> {
}

View File

@ -0,0 +1,23 @@
package com.appsmith.server.services;
import com.appsmith.external.models.ApiTemplate;
import com.appsmith.server.repositories.ApiTemplateRepository;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.stereotype.Service;
import reactor.core.scheduler.Scheduler;
import javax.validation.Validator;
@Service
public class ApiTemplateServiceImpl extends BaseService<ApiTemplateRepository, ApiTemplate, String> implements ApiTemplateService {
public ApiTemplateServiceImpl(Scheduler scheduler,
Validator validator,
MongoConverter mongoConverter,
ReactiveMongoTemplate reactiveMongoTemplate,
ApiTemplateRepository repository,
AnalyticsService analyticsService) {
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
}
}

View File

@ -1,9 +1,10 @@
package com.appsmith.server.services;
import com.appsmith.server.domains.Action;
import reactor.core.publisher.Mono;
public abstract class BaseApiImporter implements ApiImporter {
public abstract Action importAction(Object input);
public abstract Mono<Action> importAction(Object input, String pageId, String name);
}

View File

@ -1,8 +1,8 @@
package com.appsmith.server.services;
import com.appsmith.external.models.BaseDomain;
import com.appsmith.server.constants.AnalyticsEvents;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.BaseDomain;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.repositories.BaseRepository;

View File

@ -1,6 +1,6 @@
package com.appsmith.server.services;
import com.appsmith.server.domains.BaseDomain;
import com.appsmith.external.models.BaseDomain;
import org.springframework.util.MultiValueMap;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@ -10,6 +10,7 @@ import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import java.net.URI;
import java.net.URL;
@ -32,9 +33,14 @@ public class CurlImporterService extends BaseApiImporter {
private static final String headerRegex = "\\-H\\s+\\'(.+?)\\'";
private static final String methodRegex = "\\-X\\s+(.+?)\\b";
private static final String bodyRegex = "\\-d\\s+\\'(.+?)\\'";
private final ActionService actionService;
public CurlImporterService(ActionService actionService) {
this.actionService = actionService;
}
@Override
public Action importAction(Object input) {
public Mono<Action> importAction(Object input, String pageId, String name) {
String command = (String) input;
Action action = new Action();
ActionConfiguration actionConfiguration = new ActionConfiguration();
@ -126,6 +132,8 @@ public class CurlImporterService extends BaseApiImporter {
action.setActionConfiguration(actionConfiguration);
datasource.setDatasourceConfiguration(datasourceConfiguration);
action.setDatasource(datasource);
return action;
action.setName(name);
action.setPageId(pageId);
return actionService.save(action);
}
}

View File

@ -119,18 +119,18 @@ public class OrganizationServiceImpl extends BaseService<OrganizationRepository,
return organizationMono
.flatMap(org -> groupService.createDefaultGroupsForOrg(org.getId())
// Get only the group ids of the default groups to assign them to the user
.map(group -> group.getId())
.collect(Collectors.toSet())
.flatMap(groupIds -> {
// Set the default group Ids for the user
// Append the new organization's default groups to the existing ones belonging to the user
user.getGroupIds().addAll(groupIds);
// At this point the organization have been saved and the user has been added to the org.
// Now add the newly created organization to the newly created user.
return userOrganizationService.saveUser(user);
})
.thenReturn(org)
// Get only the group ids of the default groups to assign them to the user
.map(group -> group.getId())
.collect(Collectors.toSet())
.flatMap(groupIds -> {
// Set the default group Ids for the user
// Append the new organization's default groups to the existing ones belonging to the user
user.getGroupIds().addAll(groupIds);
// At this point the organization have been saved and the user has been added to the org.
// Now add the newly created organization to the newly created user.
return userOrganizationService.saveUser(user);
})
.thenReturn(org)
);
}

View File

@ -111,9 +111,9 @@ public class PageServiceImpl extends BaseService<PageRepository, Page, String> i
});
return pageMono.map(deletedObj -> {
analyticsService.sendEvent(AnalyticsEvents.DELETE + "_" + deletedObj.getClass().getSimpleName().toUpperCase(), (Page) deletedObj);
return (Page) deletedObj;
});
analyticsService.sendEvent(AnalyticsEvents.DELETE + "_" + deletedObj.getClass().getSimpleName().toUpperCase(), (Page) deletedObj);
return (Page) deletedObj;
});
}
@Override

View File

@ -10,15 +10,16 @@ import com.appsmith.server.domains.Datasource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class PostmanImporterService extends BaseApiImporter{
public class PostmanImporterService extends BaseApiImporter {
@Override
public Action importAction(Object input) {
public Mono<Action> importAction(Object input, String pageId, String name) {
Action action = new Action();
ActionConfiguration actionConfiguration = new ActionConfiguration();
Datasource datasource = new Datasource();
@ -26,7 +27,9 @@ public class PostmanImporterService extends BaseApiImporter{
datasource.setDatasourceConfiguration(datasourceConfiguration);
action.setDatasource(datasource);
action.setActionConfiguration(actionConfiguration);
return action;
action.setPageId(pageId);
action.setName(name);
return Mono.just(action);
}
public TemplateCollection importPostmanCollection(Object input) {
@ -79,7 +82,7 @@ public class PostmanImporterService extends BaseApiImporter{
private TemplateCollection createTemplateCollection(String id) {
ApiTemplate apiTemplate = createApiTemplate();
TemplateCollection templateCollection = new TemplateCollection();
List<String> apiTemplateIds ;
List<String> apiTemplateIds;
apiTemplateIds = new ArrayList<>();
List<ApiTemplate> apiTemplateList;
apiTemplateList = new ArrayList<>();

View File

@ -0,0 +1,6 @@
package com.appsmith.server.services;
import com.appsmith.external.models.Provider;
public interface ProviderService extends CrudService<Provider, String> {
}

View File

@ -0,0 +1,23 @@
package com.appsmith.server.services;
import com.appsmith.external.models.Provider;
import com.appsmith.server.repositories.ProviderRepository;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.stereotype.Service;
import reactor.core.scheduler.Scheduler;
import javax.validation.Validator;
@Service
public class ProviderServiceImpl extends BaseService<ProviderRepository, Provider, String> implements ProviderService {
public ProviderServiceImpl(Scheduler scheduler,
Validator validator,
MongoConverter mongoConverter,
ReactiveMongoTemplate reactiveMongoTemplate,
ProviderRepository repository,
AnalyticsService analyticsService) {
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
}
}

View File

@ -99,7 +99,11 @@ authenticated_operations = [
{"method": "GET", "resource": "providers", "permission": "read:providers"},
{"method": "PUT", "resource": "providers", "permission": "update:providers"},
{"method": "GET", "resource": "marketplace", "permission": "read:marketplace"}
{"method": "GET", "resource": "marketplace", "permission": "read:marketplace"},
{"method": "POST", "resource": "templates", "permission": "create:templates"},
{"method": "GET", "resource": "templates", "permission": "read:templates"},
{"method": "PUT", "resource": "templates", "permission": "update:templates"}
]

View File

@ -23,9 +23,9 @@ public class CurlParserServiceTest {
@Test
public void testParser() {
String command = "curl -X GET http://localhost:8080/api/v1/actions?name=something -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Authorization: Basic YXBpX3VzZXI6OHVBQDsmbUI6Y252Tn57Iw==' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'Cookie: SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5,SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5; SESSION=' -H 'Host: localhost:8080' -H 'Postman-Token: 16e4b6bc-2c7a-4ab1-a127-bca382dfc0f0,a6655daa-db07-4c5e-aca3-3fd505bd230d' -H 'User-Agent: PostmanRuntime/7.20.1' -H 'cache-control: no-cache' -d '{someJson}' ";
Action action = curlImporterService.importAction(command);
Mono<Action> action = curlImporterService.importAction(command, "pageId", "actionName");
StepVerifier
.create(Mono.just(action))
.create(action)
.assertNext(action1 -> {
assertThat(action1).isNotNull();
assertThat(action1.getDatasource()).isNotNull();

View File

@ -1,5 +1,6 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>