Skip to content
Snippets Groups Projects
Commit 8865dea1 authored by Martin Vogel's avatar Martin Vogel
Browse files

feat: add basic repo access setup and bpmn client (planning#2411)

parent ccc507bb
No related branches found
No related tags found
No related merge requests found
package dev.fitko.fitconnect.api.config.defaults;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class ProcessEnvironment {
public static final ProcessEnvironment DEV = new ProcessEnvironment("DEV", "https://repository.iw24.fit-connect.dev");
public static final ProcessEnvironment LOCAL = new ProcessEnvironment("LOCAL", " http://localhost:7415");
private String name;
private String repoServerUrl;
}
\ No newline at end of file
package dev.fitko.fitconnect.client;
import dev.fitko.fitconnect.api.exceptions.FitConnectException;
import dev.fitko.fitconnect.core.bpmn.ProcessRepoService;
import java.util.function.Supplier;
import static java.util.Optional.ofNullable;
/**
* BPMN Client to execute business workflows
*/
public class BusinessProcessClient {
private final ProcessRepoService repoService;
public BusinessProcessClient(ProcessRepoService repoService) {
this.repoService = repoService;
}
/**
* Get all BPMN definitions from repo.
*
* @return all definitions
*/
public String getAllDefinitions() {
return wrapExceptions(repoService::getAllDefinitions);
}
/**
* Get a specific definition by id.
*
* @param definitionId unique identifier of a definition
* @return the definition
*/
public String getDefinitionById(String definitionId) {
return wrapExceptions(() -> repoService.getDefinitionById(definitionId));
}
/**
* Get a sub-process for a definition by id.
*
* @param definitionId unique identifier of a definition
* @param processId unique identifier of the process
* @return the process model
*/
public String getProcessForDefinition(String definitionId, String processId) {
return wrapExceptions(() -> repoService.getProcessById(definitionId, processId));
}
public String getMessageFlowForParticipant(String definitionId, String participantId) {
return wrapExceptions(() -> repoService.getMessageFlowForParticipant(definitionId, participantId));
}
public String getFullMessageFlow(String definitionId, String messageFlowId) {
return wrapExceptions(() -> repoService.getFullMessageFlow(definitionId, messageFlowId));
}
private <T> T wrapExceptions(final Supplier<T> supplier) {
try {
return supplier.get();
} catch (final Exception e) {
throw new FitConnectException(ofNullable(e.getMessage()).orElse("Failed repo request"), ofNullable(e.getCause()).orElse(e));
}
}
}
...@@ -8,6 +8,7 @@ import dev.fitko.fitconnect.api.config.SenderConfig; ...@@ -8,6 +8,7 @@ import dev.fitko.fitconnect.api.config.SenderConfig;
import dev.fitko.fitconnect.api.config.SubscriberConfig; import dev.fitko.fitconnect.api.config.SubscriberConfig;
import dev.fitko.fitconnect.api.config.ZBPCertConfig; import dev.fitko.fitconnect.api.config.ZBPCertConfig;
import dev.fitko.fitconnect.api.config.chunking.AttachmentChunkingConfig; import dev.fitko.fitconnect.api.config.chunking.AttachmentChunkingConfig;
import dev.fitko.fitconnect.api.config.defaults.ProcessEnvironment;
import dev.fitko.fitconnect.api.config.defaults.ZBPEnvironment; import dev.fitko.fitconnect.api.config.defaults.ZBPEnvironment;
import dev.fitko.fitconnect.api.config.http.HttpConfig; import dev.fitko.fitconnect.api.config.http.HttpConfig;
import dev.fitko.fitconnect.api.config.http.ProxyConfig; import dev.fitko.fitconnect.api.config.http.ProxyConfig;
...@@ -32,6 +33,7 @@ import dev.fitko.fitconnect.api.services.routing.RoutingService; ...@@ -32,6 +33,7 @@ import dev.fitko.fitconnect.api.services.routing.RoutingService;
import dev.fitko.fitconnect.api.services.schema.SchemaProvider; import dev.fitko.fitconnect.api.services.schema.SchemaProvider;
import dev.fitko.fitconnect.api.services.submission.SubmissionService; import dev.fitko.fitconnect.api.services.submission.SubmissionService;
import dev.fitko.fitconnect.api.services.validation.ValidationService; import dev.fitko.fitconnect.api.services.validation.ValidationService;
import dev.fitko.fitconnect.client.BusinessProcessClient;
import dev.fitko.fitconnect.client.DestinationClient; import dev.fitko.fitconnect.client.DestinationClient;
import dev.fitko.fitconnect.client.RouterClient; import dev.fitko.fitconnect.client.RouterClient;
import dev.fitko.fitconnect.client.SenderClient; import dev.fitko.fitconnect.client.SenderClient;
...@@ -54,6 +56,7 @@ import dev.fitko.fitconnect.client.util.SubmissionValidator; ...@@ -54,6 +56,7 @@ import dev.fitko.fitconnect.client.util.SubmissionValidator;
import dev.fitko.fitconnect.client.zbp.ZBPServiceAdapter; import dev.fitko.fitconnect.client.zbp.ZBPServiceAdapter;
import dev.fitko.fitconnect.core.FitConnectDefaultService; import dev.fitko.fitconnect.core.FitConnectDefaultService;
import dev.fitko.fitconnect.core.auth.DefaultOAuthApiService; import dev.fitko.fitconnect.core.auth.DefaultOAuthApiService;
import dev.fitko.fitconnect.core.bpmn.ProcessRepoService;
import dev.fitko.fitconnect.core.cases.CaseApiService; import dev.fitko.fitconnect.core.cases.CaseApiService;
import dev.fitko.fitconnect.core.cases.EventLogVerifier; import dev.fitko.fitconnect.core.cases.EventLogVerifier;
import dev.fitko.fitconnect.core.cases.SecurityEventTokenService; import dev.fitko.fitconnect.core.cases.SecurityEventTokenService;
...@@ -248,6 +251,19 @@ public final class ClientFactory { ...@@ -248,6 +251,19 @@ public final class ClientFactory {
return new ZBPClient(new ZBPServiceAdapter(apiService, certConfig)); return new ZBPClient(new ZBPServiceAdapter(apiService, certConfig));
} }
/**
* Create a new BPMN processing client.
*
* @param processEnvironment the {@link ProcessEnvironment} the client should be configured for
* @return the client
*/
public static BusinessProcessClient createProcessClient(ProcessEnvironment processEnvironment) {
LOGGER.info("Initializing BPMN client ...");
final HttpClient httpClient = createHttpClient(ApplicationConfig.builder().build());
final ProcessRepoService bpmnRepoService = new ProcessRepoService(httpClient, processEnvironment.getRepoServerUrl());
return new BusinessProcessClient(bpmnRepoService);
}
private static FitConnectService createFitConnectService(final ApplicationConfig config, final String clientId, final String clientSecret) { private static FitConnectService createFitConnectService(final ApplicationConfig config, final String clientId, final String clientSecret) {
return createFitConnectService(config, clientId, clientSecret, null); return createFitConnectService(config, clientId, clientSecret, null);
} }
......
package dev.fitko.fitconnect.core.bpmn;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.fitko.fitconnect.api.exceptions.internal.RestApiException;
import dev.fitko.fitconnect.api.services.http.HttpClient;
import dev.fitko.fitconnect.core.http.HttpHeaders;
import dev.fitko.fitconnect.core.http.MimeTypes;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public class ProcessRepoService {
public static final String DEFINITIONS_PATH = "/api/definitions";
public static final String DEFINITION_PATH = "api/definitions/%s";
public static final String PROCESS_PATH = "/api/definitions/%s/processes/%s";
public static final String MESSAGE_TARGET_PATH = "/api/definitions/%s/messageTargets/%s";
public static final String MESSAGE_FLOW_PATH = "/api/definitions/%s/messageFlows/%s";
public static final String MESSAGE_FULL_FLOW_PATH = "/api/definitions/%s/message-flow-full/%s";
public static final String MESSAGE_PARTICIPANT_PATH = "/api/definitions/%s/participants/%s/messageFlows";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private final HttpClient httpClient;
private final String baseUrl;
public ProcessRepoService(HttpClient httpClient, String baseUrl) {
this.httpClient = httpClient;
this.baseUrl = baseUrl;
}
public String getAllDefinitions() throws RestApiException {
final String url = baseUrl + DEFINITIONS_PATH;
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get definitions", e);
}
}
public String getDefinitionById(String definitionId) throws RestApiException {
final String url = String.format(baseUrl + DEFINITION_PATH, definitionId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get definition " + definitionId, e);
}
}
public String getProcessById(String definitionId, String processId) throws RestApiException {
final String url = String.format(baseUrl + PROCESS_PATH, definitionId, processId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get process " + processId + " for definition " + definitionId, e);
}
}
public String getMessageTarget(String definitionId, String targetId) throws RestApiException {
final String url = String.format(baseUrl + MESSAGE_TARGET_PATH, definitionId, targetId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get target " + targetId + " for definition " + definitionId, e);
}
}
public String getMessageFlow(String definitionId, String messageFlowId) throws RestApiException {
final String url = String.format(baseUrl + MESSAGE_FLOW_PATH, definitionId, messageFlowId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get messageFlow " + messageFlowId + " for definition " + definitionId, e);
}
}
public String getFullMessageFlow(String definitionId, String messageFlowId) throws RestApiException {
final String url = String.format(baseUrl + MESSAGE_FULL_FLOW_PATH, definitionId, messageFlowId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get full messageFlow " + messageFlowId + " for definition " + definitionId, e);
}
}
public String getMessageFlowForParticipant(String definitionId, String participantId) throws RestApiException {
final String url = String.format(baseUrl + MESSAGE_PARTICIPANT_PATH, definitionId, participantId);
try {
return httpClient.get(url, getHeaders(MimeTypes.APPLICATION_JSON), String.class).getBody();
} catch (final RestApiException e) {
throw new RestApiException("Could not get messageFlow for participant " + participantId, e);
}
}
private Map<String, String> getHeaders(final String contentType) {
return Map.of(
HttpHeaders.CONTENT_TYPE, contentType,
HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.toString()
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment