Skip to content

Commit

Permalink
wip register formbackend
Browse files Browse the repository at this point in the history
  • Loading branch information
thoniTUB committed Nov 8, 2024
1 parent 48d11e9 commit 1fe2398
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 115 deletions.
6 changes: 5 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@
<version>${openapi-generator.version}</version>
<executions>
<execution>
<id>openapi-admin</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/admin-openapi.json</inputSpec>
<!-- Don't use jaxrs-jersey here because it does not allow dependency injection -->
<generatorName>jaxrs-spec</generatorName>
<modelsToGenerate>ApiResponse</modelsToGenerate>
<packageName>com.bakdata.conquery</packageName>
<!-- This package name is used by EndpointTestHelper to filter out openapi specs -->
<apiPackage>com.bakdata.conquery.models.api.openapi</apiPackage>
<modelPackage>com.bakdata.conquery.models.config</modelPackage>
<configOptions>
<!-- <library>jersey3</library>-->
<!-- The implementation of these interfaces actually allows us to use DI (not possible with jaxrs-jersey) -->
<interfaceOnly>true</interfaceOnly>
<sourceFolder>src/main/java</sourceFolder>
<generateSupportingFiles>false</generateSupportingFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;

import com.bakdata.conquery.apiv1.forms.Form;
Expand Down Expand Up @@ -42,19 +43,18 @@ public class FormScanner extends Task {
* task accounts the change.
*/
private final ConqueryConfig config;
private final List<FormConfigProvider> formConfigProviders = new ArrayList<>();
private final Map<String, FormConfigProvider> formConfigProviders = new ConcurrentHashMap<>();

public FormScanner(ConqueryConfig config) {
super("form-scanner");
this.config = config;
registerFrontendFormConfigProvider(new FormConfigProvider("internal", ResourceFormConfigProvider::accept));
}

public synchronized void registerFrontendFormConfigProvider(FormConfigProvider provider) {
formConfigProviders.add(provider);
public void registerFrontendFormConfigProvider(FormConfigProvider provider) {
formConfigProviders.put(provider.getProviderName(), provider);
}


@Nullable
public static FormType resolveFormType(String formType) {
return FRONTEND_FORM_CONFIGS.get(formType);
Expand All @@ -64,6 +64,14 @@ public static Set<FormType> getAllFormTypes() {
return Set.copyOf(FRONTEND_FORM_CONFIGS.values());
}

public FormConfigProvider unregisterFrontendFormConfigProvider(String providerName) {
return formConfigProviders.remove(providerName);
}

public Collection<String> listFrontendFormConfigProviders() {
return formConfigProviders.keySet();
}

@Override
public void execute(Map<String, List<String>> parameters, PrintWriter output) throws Exception {
FRONTEND_FORM_CONFIGS = generateFEFormConfigMap();
Expand Down Expand Up @@ -188,7 +196,7 @@ private List<FormFrontendConfigInformation> findFrontendFormConfigs() {

log.trace("Begin collecting form frontend configurations");

for (FormConfigProvider formConfigProvider : formConfigProviders) {
for (FormConfigProvider formConfigProvider : formConfigProviders.values()) {

try {
formConfigProvider.addFormConfigs(frontendConfigs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.bakdata.conquery.resources.admin.rest.AdminResource;
import com.bakdata.conquery.resources.admin.rest.AdminTablesResource;
import com.bakdata.conquery.resources.admin.rest.AuthOverviewResource;
import com.bakdata.conquery.resources.admin.rest.ConfigApiProcessor;
import com.bakdata.conquery.resources.admin.rest.ConfigApiResource;
import com.bakdata.conquery.resources.admin.rest.GroupResource;
import com.bakdata.conquery.resources.admin.rest.PermissionResource;
import com.bakdata.conquery.resources.admin.rest.RoleResource;
Expand Down Expand Up @@ -164,7 +164,7 @@ public void register() {
.register(PermissionResource.class)
.register(AuthOverviewResource.class)
.register(AdminResource.class)
.register(ConfigApiProcessor.class);
.register(ConfigApiResource.class);

jerseyConfigUI
.register(AdminUIResource.class)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.bakdata.conquery.resources.admin.rest;

import java.util.List;
import jakarta.inject.Inject;

import com.bakdata.conquery.commands.ManagerNode;
import com.bakdata.conquery.models.api.openapi.ConfigApi;
import com.bakdata.conquery.models.config.FormBackendConfig;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(onConstructor_ = @Inject)
public class ConfigApiResource implements ConfigApi {

private final ManagerNode managerNode;

@Override
public String deleteFormBackend(String configId) {
String providerName = managerNode.getFormScanner().unregisterFrontendFormConfigProvider(configId).getProviderName();
try {
managerNode.getFormScanner().execute(null, null);
}
catch (Exception e) {
throw new RuntimeException(e);
}
return providerName;
}

@Override
public List<String> listFormBackends() {
return List.copyOf(managerNode.getFormScanner().listFrontendFormConfigProviders());
}

@Override
public String registerFormBackend(FormBackendConfig pluginConfig) {
pluginConfig.initialize(managerNode);
try {
managerNode.getFormScanner().execute(null, null);
}
catch (Exception e) {
throw new RuntimeException(e);
}
return pluginConfig.getId();
}
}
158 changes: 100 additions & 58 deletions backend/src/main/resources/openapi/admin-openapi.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"version": "1.0.7",
"title": "Swagger Petstore",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
"description": "Partial description of the conquery admin REST api",
"version": "1.0.0",
"title": "Conquery Admin"
},
"host": "petstore.swagger.io",
"basePath": "/admin",
"tags": [
{
Expand All @@ -29,11 +20,10 @@
"/config/plugins/form-backend": {
"post": {
"tags": [
"plugin"
"config"
],
"summary": "adds a form backend config",
"description": "",
"operationId": "addPlugin",
"summary": "adds a form backend configurations",
"operationId": "registerFormBackend",
"consumes": [
"application/json"
],
Expand All @@ -46,73 +36,125 @@
"name": "pluginConfig",
"schema": {
"$ref": "#/definitions/FormBackendConfig"
},
"required": true
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "string",
"description": "Id of the registered form backend configuration"
}
}
}
},
"get": {
"tags": [
"config"
],
"summary": "lists all registered form backend configurations",
"operationId": "listFormBackends",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/ApiResponse"
"description": "Ids of the registered form providers",
"type":"array",
"items": {
"type": "string"
}
}
}
},
"security": [
}
}
},
"/config/plugins/form-backend/{configId}":{
"delete": {
"tags": [
"config"
],
"summary": "unegister form backend configuration",
"operationId": "deleteFormBackend",
"parameters": [
{
"api_key": [
"write:pets",
"read:pets"
]
"in": "path",
"name": "configId",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "string",
"description": "Id of the deleted form backend configuration"
}
}
]
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
},
"definitions": {
"ApiResponse": {
"FormBackendConfig": {
"type": "object",
"x-discriminator-value": "type",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"type": {
"type": "string"
},
"message": {
"type": "string"
}
}
},
"Test": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
},
"FormBackendConfig": {
"type": "object",
"x-discriminator-value": "type",
"properties": {
"type": {
"type": "string"
},
"baseURI": {
"type":"string",
"format": "uri"
},
"conqueryApiUrl": {
"type":"string",
"format": "uri"
},
"formConfigPath":{
"type": "string",
"format": "uri",
"default": "form-config"
},
"postFormPath":{
"type": "string",
"format": "uri",
"default": "task"
},
"statusTemplatePath":{
"type": "string",
"format": "uri",
"default": "task/{task-id}"
},
"cancelTaskPath":{
"type": "string",
"format": "uri",
"default": "task/{task-id}/cancel"
},
"healthCheckPath":{
"type": "string",
"format": "uri",
"default": "health"
},
"versionPath":{
"type": "string",
"format": "uri",
"default": "version"
}
},
"required": [
"type"
"type",
"id",
"baseURI",
"conqueryApiUrl"
]
}
}
Expand Down
Loading

0 comments on commit 1fe2398

Please sign in to comment.