Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dev.dsf.bpe.v2;

import java.util.Objects;
import java.util.function.Supplier;

import org.springframework.context.ApplicationContext;

import com.fasterxml.jackson.databind.ObjectMapper;

import ca.uhn.fhir.context.FhirContext;
import dev.dsf.bpe.v2.config.ProxyConfig;
import dev.dsf.bpe.v2.service.CryptoService;
import dev.dsf.bpe.v2.service.DataLogger;
import dev.dsf.bpe.v2.service.DsfClientProvider;
import dev.dsf.bpe.v2.service.EndpointProvider;
import dev.dsf.bpe.v2.service.FhirClientConfigProvider;
import dev.dsf.bpe.v2.service.FhirClientProvider;
import dev.dsf.bpe.v2.service.MailService;
import dev.dsf.bpe.v2.service.MimeTypeService;
import dev.dsf.bpe.v2.service.OidcClientProvider;
import dev.dsf.bpe.v2.service.OrganizationProvider;
import dev.dsf.bpe.v2.service.QuestionnaireResponseHelper;
import dev.dsf.bpe.v2.service.ReadAccessHelper;
import dev.dsf.bpe.v2.service.TargetProvider;
import dev.dsf.bpe.v2.service.TaskHelper;
import dev.dsf.bpe.v2.service.process.ProcessAuthorizationHelper;

public class ProcessPluginApiFactory implements Supplier<ProcessPluginApi>
{
private final ApplicationContext parentContext;
private final ProcessPluginDefinition processPluginDefinition;

public ProcessPluginApiFactory(ProcessPluginDefinition processPluginDefinition, ApplicationContext parentContext)
{
this.processPluginDefinition = Objects.requireNonNull(processPluginDefinition, "processPluginDefinition");
this.parentContext = Objects.requireNonNull(parentContext, "parentContext");
}

private <T> T fromParent(Class<T> t)
{
return parentContext.getBean(t);
}

@Override
public ProcessPluginApi get()
{
return new ProcessPluginApiImpl(processPluginDefinition, fromParent(ProxyConfig.class),
fromParent(EndpointProvider.class), fromParent(FhirContext.class), fromParent(DsfClientProvider.class),
fromParent(FhirClientProvider.class), fromParent(FhirClientConfigProvider.class),
fromParent(OidcClientProvider.class), fromParent(MailService.class), fromParent(MimeTypeService.class),
fromParent(ObjectMapper.class), fromParent(OrganizationProvider.class),
fromParent(ProcessAuthorizationHelper.class), fromParent(QuestionnaireResponseHelper.class),
fromParent(ReadAccessHelper.class), fromParent(TaskHelper.class), fromParent(CryptoService.class),
fromParent(TargetProvider.class), fromParent(DataLogger.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

public class ProcessPluginApiImpl implements ProcessPluginApi, InitializingBean
{
private final ProcessPluginDefinition processPluginDefinition;
private final ProxyConfig proxyConfig;
private final EndpointProvider endpointProvider;
private final FhirContext fhirContext;
Expand All @@ -45,14 +46,16 @@ public class ProcessPluginApiImpl implements ProcessPluginApi, InitializingBean
private final TargetProvider targetProvider;
private final DataLogger dataLogger;

public ProcessPluginApiImpl(ProxyConfig proxyConfig, EndpointProvider endpointProvider, FhirContext fhirContext,
DsfClientProvider dsfClientProvider, FhirClientProvider fhirClientProvider,
FhirClientConfigProvider fhirClientConfigProvider, OidcClientProvider oidcClientProvider,
MailService mailService, MimeTypeService mimeTypeService, ObjectMapper objectMapper,
OrganizationProvider organizationProvider, ProcessAuthorizationHelper processAuthorizationHelper,
public ProcessPluginApiImpl(ProcessPluginDefinition processPluginDefinition, ProxyConfig proxyConfig,
EndpointProvider endpointProvider, FhirContext fhirContext, DsfClientProvider dsfClientProvider,
FhirClientProvider fhirClientProvider, FhirClientConfigProvider fhirClientConfigProvider,
OidcClientProvider oidcClientProvider, MailService mailService, MimeTypeService mimeTypeService,
ObjectMapper objectMapper, OrganizationProvider organizationProvider,
ProcessAuthorizationHelper processAuthorizationHelper,
QuestionnaireResponseHelper questionnaireResponseHelper, ReadAccessHelper readAccessHelper,
TaskHelper taskHelper, CryptoService cryptoService, TargetProvider targetProvider, DataLogger dataLogger)
{
this.processPluginDefinition = processPluginDefinition;
this.proxyConfig = proxyConfig;
this.endpointProvider = endpointProvider;
this.fhirContext = fhirContext;
Expand All @@ -76,6 +79,7 @@ public ProcessPluginApiImpl(ProxyConfig proxyConfig, EndpointProvider endpointPr
@Override
public void afterPropertiesSet() throws Exception
{
Objects.requireNonNull(processPluginDefinition, "processPluginDefinition");
Objects.requireNonNull(proxyConfig, "proxyConfig");
Objects.requireNonNull(endpointProvider, "endpointProvider");
Objects.requireNonNull(fhirContext, "fhirContext");
Expand All @@ -96,6 +100,12 @@ public void afterPropertiesSet() throws Exception
Objects.requireNonNull(dataLogger, "dataLogger");
}

@Override
public ProcessPluginDefinition getProcessPluginDefinition()
{
return processPluginDefinition;
}

@Override
public ProxyConfig getProxyConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -61,6 +62,7 @@
import dev.dsf.bpe.api.plugin.ProcessPlugin;
import dev.dsf.bpe.api.plugin.ProcessPluginFhirConfig;
import dev.dsf.bpe.v2.ProcessPluginApi;
import dev.dsf.bpe.v2.ProcessPluginApiFactory;
import dev.dsf.bpe.v2.ProcessPluginDefinition;
import dev.dsf.bpe.v2.ProcessPluginDeploymentListener;
import dev.dsf.bpe.v2.activity.Activity;
Expand Down Expand Up @@ -92,11 +94,12 @@ public class ProcessPluginImpl extends AbstractProcessPlugin<UserTaskListener> i
private static final Logger logger = LoggerFactory.getLogger(ProcessPluginImpl.class);

private final ProcessPluginDefinition processPluginDefinition;
private final ProcessPluginApi processPluginApi;

private final Function<DelegateExecution, Variables> variablesFactory;
private final PluginMdc pluginMdc;

private final AtomicReference<ProcessPluginApi> processPluginApi = new AtomicReference<>();
private final AtomicReference<FhirContext> fhirContext = new AtomicReference<>();
private final AtomicReference<ObjectMapper> objectMapper = new AtomicReference<>();

public ProcessPluginImpl(ProcessPluginDefinition processPluginDefinition, int processPluginApiVersion,
Expand All @@ -109,13 +112,61 @@ public ProcessPluginImpl(ProcessPluginDefinition processPluginDefinition, int pr
MessageEndEvent.class, DefaultUserTaskListener.class);

this.processPluginDefinition = processPluginDefinition;
processPluginApi = apiApplicationContext.getBean(ProcessPluginApi.class);

variablesFactory = delegateExecution -> new VariablesImpl(delegateExecution, getObjectMapper());
pluginMdc = new PluginMdcImpl(processPluginApiVersion, processPluginDefinition.getName(),
processPluginDefinition.getVersion(), jarFile.toString(), serverBaseUrl, variablesFactory);
}

@Override
protected void customizeApplicationContext(AnnotationConfigApplicationContext context,
ApplicationContext parentContext)
{
context.registerBean("processPluginDefinition", ProcessPluginDefinition.class, () -> processPluginDefinition);
context.registerBean("api", ProcessPluginApi.class,
new ProcessPluginApiFactory(processPluginDefinition, parentContext));
}

private ProcessPluginApi getProcessPluginApi()
{
ProcessPluginApi entry = processPluginApi.get();
if (entry == null)
{
ProcessPluginApi o = doGetProcessPluginApi();
if (processPluginApi.compareAndSet(entry, o))
return o;
else
return processPluginApi.get();
}
else
return entry;
}

private ProcessPluginApi doGetProcessPluginApi()
{
return getApplicationContext().getBean(ProcessPluginApi.class);
}

private FhirContext getFhirContext()
{
FhirContext entry = fhirContext.get();
if (entry == null)
{
FhirContext o = doGetFhirContext();
if (fhirContext.compareAndSet(entry, o))
return o;
else
return fhirContext.get();
}
else
return entry;
}

private FhirContext doGetFhirContext()
{
return getApplicationContext().getBean(FhirContext.class);
}

private ObjectMapper getObjectMapper()
{
ObjectMapper entry = objectMapper.get();
Expand Down Expand Up @@ -264,7 +315,7 @@ private IParser newJsonParser()

private IParser newParser(Function<FhirContext, IParser> parserFactor)
{
IParser p = parserFactor.apply(processPluginApi.getFhirContext());
IParser p = parserFactor.apply(getFhirContext());
p.setStripVersionsFromReferences(false);
p.setOverrideResourceIdWithBundleEntryFullUrl(false);

Expand Down Expand Up @@ -383,7 +434,7 @@ public JavaDelegate getMessageSendTask(String className, List<FieldDeclaration>
SendTaskValues sendTaskValues = getSendTaskValues(fieldDeclarations, variableScope)
.orElseThrow(noOrIncompleteFhirTaskFields("MessageSendTask", className));

return new MessageSendTaskDelegate(processPluginApi, variablesFactory, target, sendTaskValues);
return new MessageSendTaskDelegate(getProcessPluginApi(), variablesFactory, target, sendTaskValues);
}

@Override
Expand All @@ -393,7 +444,7 @@ public JavaDelegate getServiceTask(String className, List<FieldDeclaration> fiel
ServiceTask target = get(ServiceTask.class, className);
injectFields(target, fieldDeclarations, variableScope);

return new ServiceTaskDelegate(processPluginApi, variablesFactory, target);
return new ServiceTaskDelegate(getProcessPluginApi(), variablesFactory, target);
}

@Override
Expand All @@ -406,7 +457,7 @@ public JavaDelegate getMessageEndEvent(String className, List<FieldDeclaration>
SendTaskValues sendTaskValues = getSendTaskValues(fieldDeclarations, variableScope)
.orElseThrow(noOrIncompleteFhirTaskFields("MessageEndEvent", className));

return new MessageEndEventDelegate(processPluginApi, variablesFactory, target, sendTaskValues);
return new MessageEndEventDelegate(getProcessPluginApi(), variablesFactory, target, sendTaskValues);
}

@Override
Expand All @@ -419,7 +470,8 @@ public JavaDelegate getMessageIntermediateThrowEvent(String className, List<Fiel
SendTaskValues sendTaskValues = getSendTaskValues(fieldDeclarations, variableScope)
.orElseThrow(noOrIncompleteFhirTaskFields("MessageIntermediateThrowEvent", className));

return new MessageIntermediateThrowEventDelegate(processPluginApi, variablesFactory, target, sendTaskValues);
return new MessageIntermediateThrowEventDelegate(getProcessPluginApi(), variablesFactory, target,
sendTaskValues);
}

@Override
Expand All @@ -429,7 +481,7 @@ public org.camunda.bpm.engine.delegate.ExecutionListener getExecutionListener(St
ExecutionListener target = get(ExecutionListener.class, className);
injectFields(target, fieldDeclarations, variableScope);

return new ExecutionListenerDelegate(processPluginApi, variablesFactory, target);
return new ExecutionListenerDelegate(getProcessPluginApi(), variablesFactory, target);
}

@Override
Expand All @@ -439,7 +491,7 @@ public TaskListener getTaskListener(String className, List<FieldDeclaration> fie
UserTaskListener target = get(UserTaskListener.class, className);
ClassDelegateUtil.applyFieldDeclaration(fieldDeclarations, target);

return new UserTaskListenerDelegate(processPluginApi, variablesFactory, target);
return new UserTaskListenerDelegate(getProcessPluginApi(), variablesFactory, target);
}

private List<FieldDeclaration> filterFhirTaskValues(List<FieldDeclaration> fieldDeclarations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import dev.dsf.bpe.api.service.BpeMailService;
import dev.dsf.bpe.api.service.BpeOidcClientProvider;
import dev.dsf.bpe.api.service.BuildInfoProvider;
import dev.dsf.bpe.v2.ProcessPluginApi;
import dev.dsf.bpe.v2.ProcessPluginApiImpl;
import dev.dsf.bpe.v2.client.dsf.ReferenceCleaner;
import dev.dsf.bpe.v2.client.dsf.ReferenceCleanerImpl;
import dev.dsf.bpe.v2.client.dsf.ReferenceExtractor;
Expand Down Expand Up @@ -99,16 +97,6 @@ public class ApiServiceConfig
@Autowired
private BpeOidcClientProvider bpeOidcClientProvider;

@Bean
public ProcessPluginApi processPluginApiV2()
{
return new ProcessPluginApiImpl(proxyConfigDelegate(), endpointProvider(), fhirContext(), dsfClientProvider(),
fhirClientProvider(), fhirClientConfigProvider(), oidcClientProvider(), mailService(),
mimeTypeService(), objectMapper(), organizationProvider(), processAuthorizationHelper(),
questionnaireResponseHelper(), readAccessHelper(), taskHelper(), cryptoService(), targetProvider(),
dataLogger());
}

@Bean
public ProxyConfig proxyConfigDelegate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
public interface ProcessPluginApi
{
ProcessPluginDefinition getProcessPluginDefinition();

ProxyConfig getProxyConfig();

EndpointProvider getEndpointProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* Helper class to register {@link Activity}s as prototype beans. Must be configured as a <code>static</code>
* {@link Bean} inside a {@link Configuration} class.
* {@link Bean} inside a {@link Configuration} class. Autowiring via constructor arguments is enabled.
* <p>
* Usage:
* <p>
Expand Down Expand Up @@ -73,6 +73,7 @@ private BeanDefinition createBeanDefinition(Class<? extends Activity> activity)
GenericBeanDefinition definition = new GenericBeanDefinition();
definition.setBeanClass(activity);
definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR);
return definition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ private AnnotationConfigApplicationContext createApplicationContext()
.concat(Stream.of(apiServicesSpringConfiguration), getDefinitionSpringConfigurations().stream())
.toArray(Class<?>[]::new));
context.setEnvironment(environment);

customizeApplicationContext(context, apiApplicationContext);

context.refresh();

return context;
Expand All @@ -576,6 +579,11 @@ private AnnotationConfigApplicationContext createApplicationContext()
}
}

protected void customizeApplicationContext(AnnotationConfigApplicationContext context,
ApplicationContext parentContext)
{
}

private Stream<BpmnFileAndModel> loadBpmnModels(String localOrganizationIdentifierValue)
{
return getDefinitionProcessModels().stream().map(loadBpmnModelOrNull(localOrganizationIdentifierValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,10 @@ public void startSensitiveDataLoggerTest() throws Exception
{
executePluginTest(createTestTask("DataLoggerTest"));
}

@Test
public void startAutowireTest() throws Exception
{
executePluginTest(createTestTask("AutowireTest"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

public class TestProcessPluginDefinition implements ProcessPluginDefinition
{
public static final String NAME = "dsf-process-test";
public static final String VERSION = "2.0.0.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2025, 3, 25);
public static final LocalDate RELEASE_DATE = LocalDate.of(2025, 9, 1);

@Override
public String getName()
{
return "dsf-process-test";
return NAME;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.dsf.bpe.test.autowire;

public class DemoService
{
// Intentionally empty
}
Loading