Action configuration now contains all the configurations. The global and mustache configurations now exist under the same object. Data template object has been removed. This is inline with the design discussion.
This commit is contained in:
parent
3df8d70652
commit
43780a6550
|
|
@ -9,4 +9,5 @@ public interface Url {
|
|||
String PLUGIN_URL = BASE_URL + VERSION + "/plugins";
|
||||
String QUERY_URL = BASE_URL + VERSION + "/queries";
|
||||
String SETTING_URL = BASE_URL + VERSION + "/settings";
|
||||
String RESOURCE_URL = BASE_URL + VERSION + "/resources";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.mobtools.server.controllers;
|
||||
|
||||
import com.mobtools.server.constants.Url;
|
||||
import com.mobtools.server.domains.Resource;
|
||||
import com.mobtools.server.services.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Url.RESOURCE_URL)
|
||||
public class ResourceController extends BaseController<ResourceService, Resource, String> {
|
||||
|
||||
@Autowired
|
||||
public ResourceController(ResourceService service) {
|
||||
super(service);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Action extends BaseDomain {
|
||||
@Indexed(unique = true)
|
||||
String name;
|
||||
|
||||
@DBRef
|
||||
Resource resource;
|
||||
|
||||
ActionConfiguration actionConfiguration;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.mobtools.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class ActionConfiguration extends BaseDomain {
|
||||
/*
|
||||
* Any of the fields mentioned below could be represented in mustache
|
||||
* template. If the mustache template is found, it would be replaced
|
||||
* realtime every time the action needs to be executed. If no {{}} braces
|
||||
* are found, that implies the configuration is global for this action.
|
||||
* Global signifies that the configuration remains constant for each
|
||||
* action execution.
|
||||
*/
|
||||
|
||||
// API fields
|
||||
String resourceEndPoint;
|
||||
List<Property> headers;
|
||||
List<Property> queryParameters;
|
||||
String body;
|
||||
|
||||
// DB action fields
|
||||
String query;
|
||||
|
||||
/*
|
||||
* Future plugins could require more fields that are not covered above.
|
||||
* They will have to represented in a key-value format where the plugin
|
||||
* understands what the keys stand for.
|
||||
*/
|
||||
List<Property> pluginSpecifiedTemplates;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
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.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Resource extends BaseDomain {
|
||||
@Indexed(unique = true)
|
||||
String name;
|
||||
|
||||
@DBRef
|
||||
Plugin plugin;
|
||||
|
||||
@DBRef
|
||||
Tenant tenant;
|
||||
|
||||
ResourceConfiguration resourceConfiguration;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.mobtools.server.domains;
|
||||
|
||||
import com.mobtools.server.dtos.AuthenticationDTO;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class ResourceConfiguration extends BaseDomain {
|
||||
|
||||
String url;
|
||||
|
||||
AuthenticationDTO authentication;
|
||||
|
||||
List<Property> properties;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.mobtools.server.repositories;
|
||||
|
||||
import com.mobtools.server.domains.Resource;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResourceRepository extends BaseRepository<Resource, String>{
|
||||
}
|
||||
|
|
@ -25,4 +25,6 @@ public interface PluginService extends CrudService<Plugin, String> {
|
|||
|
||||
public Mono<Tenant> uninstallPlugin(PluginTenantDTO plugin);
|
||||
|
||||
public Mono<Plugin> findByName(String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.mobtools.server.repositories.UserRepository;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
|
|
@ -36,6 +37,9 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
private final ClientUserRepository clientUserRepository;
|
||||
private final TenantService tenantService;
|
||||
|
||||
@Value("${tenant.id}")
|
||||
private String tenantId;
|
||||
|
||||
@Autowired
|
||||
public PluginServiceImpl(Scheduler scheduler,
|
||||
MongoConverter mongoConverter,
|
||||
|
|
@ -97,7 +101,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
* be stored as part of user and this tenant should be used to store
|
||||
* the installed plugin or to delete plugin during uninstallation.
|
||||
*/
|
||||
Mono<Tenant> tenantMono = tenantService.findById("5d3e90a2dfec7c00047a81ea");
|
||||
Mono<Tenant> tenantMono = tenantService.findById(tenantId);
|
||||
|
||||
return tenantMono
|
||||
.map(tenant -> {
|
||||
|
|
@ -141,7 +145,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
* be stored as part of user and this tenant should be used to store
|
||||
* the installed plugin or to delete plugin during uninstallation.
|
||||
*/
|
||||
Mono<Tenant> tenantMono = tenantService.findById("5d3e90a2dfec7c00047a81ea");
|
||||
Mono<Tenant> tenantMono = tenantService.findById(tenantId);
|
||||
|
||||
Mono<Object> userObjectMono = ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
|
|
@ -156,7 +160,7 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
for (TenantPlugin listPlugin : tenantPluginList) {
|
||||
if (listPlugin.getPlugin().getName().equals(plugin.getName())) {
|
||||
log.debug("Plugin {} is already installed for Tenant {}. Don't add again.",
|
||||
plugin.getName(), tenant.getName());
|
||||
plugin.getName(), tenant.getName());
|
||||
return tenant;
|
||||
}
|
||||
}
|
||||
|
|
@ -171,4 +175,8 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
|
|||
return tenant;
|
||||
}).flatMap(tenantService::save);
|
||||
}
|
||||
|
||||
public Mono<Plugin> findByName(String name) {
|
||||
return repository.findByName(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.mobtools.server.services;
|
||||
|
||||
import com.mobtools.server.domains.Resource;
|
||||
|
||||
public interface ResourceService extends CrudService<Resource, String> {
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.mobtools.server.services;
|
||||
|
||||
import com.mobtools.server.domains.Plugin;
|
||||
import com.mobtools.server.domains.Resource;
|
||||
import com.mobtools.server.domains.Tenant;
|
||||
import com.mobtools.server.domains.TenantPlugin;
|
||||
import com.mobtools.server.exceptions.MobtoolsException;
|
||||
import com.mobtools.server.repositories.ResourceRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ResourceServiceImpl extends BaseService<ResourceRepository, Resource, String> implements ResourceService {
|
||||
|
||||
@Value("${tenant.id}")
|
||||
private String tenantId;
|
||||
|
||||
private final ResourceRepository repository;
|
||||
private final TenantService tenantService;
|
||||
private final PluginService pluginService;
|
||||
|
||||
@Autowired
|
||||
public ResourceServiceImpl(Scheduler scheduler, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ResourceRepository repository, TenantService tenantService, PluginService pluginService) {
|
||||
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
|
||||
this.repository = repository;
|
||||
this.tenantService = tenantService;
|
||||
this.pluginService = pluginService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Resource> create(@NotNull Resource resource) throws MobtoolsException {
|
||||
if (resource.getId() != null) {
|
||||
throw new MobtoolsException("During create resource, Id is not null. Can't create new resource.");
|
||||
}
|
||||
|
||||
Mono<Tenant> tenantMono = tenantService.findById(tenantId);
|
||||
Mono<Plugin> pluginMono = pluginService.findByName(resource.getPlugin().getName());
|
||||
Mono<Resource> updatedResourceMono = Mono.zip(tenantMono, pluginMono, (tenant, plugin) -> {
|
||||
resource.setTenant(tenant);
|
||||
resource.setPlugin(plugin);
|
||||
return resource;
|
||||
});
|
||||
|
||||
return updatedResourceMono
|
||||
.filter(updatedResource -> {
|
||||
AtomicReference<Boolean> temp = new AtomicReference<>(false);
|
||||
tenantMono.map(tenant -> {
|
||||
List<TenantPlugin> tenantPlugins = tenant.getPlugins();
|
||||
if (tenantPlugins == null || tenantPlugins.isEmpty()) {
|
||||
temp.set(false);
|
||||
return temp;
|
||||
}
|
||||
for (TenantPlugin tenantPlugin : tenantPlugins) {
|
||||
if (tenantPlugin.getPlugin().getName().equals(resource.getPlugin().getName())) {
|
||||
temp.set(true);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
temp.set(false);
|
||||
return temp;
|
||||
}).block();
|
||||
return temp.get();
|
||||
})
|
||||
.flatMap(repository::save);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,5 +11,5 @@ public interface TenantService extends CrudService<Tenant, String> {
|
|||
|
||||
Mono<Tenant> findById(String id);
|
||||
|
||||
Mono<Tenant> save (Tenant tenant);
|
||||
Mono<Tenant> save(Tenant tenant);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,4 +90,6 @@ public class TenantServiceImpl extends BaseService<TenantRepository, Tenant, Str
|
|||
public Mono<Tenant> save(Tenant tenant) {
|
||||
return repository.save(tenant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ spring.jpa.show-sql=true
|
|||
# Jackson Properties
|
||||
spring.jackson.default-property-inclusion=non_null
|
||||
|
||||
#Hard coded tenant properties
|
||||
tenant.id=5d5e7c29006cb4e82ea75075
|
||||
Loading…
Reference in New Issue
Block a user