Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch
Browse files Browse the repository at this point in the history
'origin/issues/261_Mechanism_to_Communicate_Process_Deployment_State'
into develop
  • Loading branch information
hhund committed Dec 21, 2021
2 parents 1a83d7e + 7305916 commit 68ba4e5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.camunda.bpm.engine.impl.variable.serializer.TypedValueSerializer;
import org.highmed.dsf.fhir.resources.ResourceProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.PropertyResolver;
Expand Down Expand Up @@ -83,4 +84,17 @@ default List<String> getDependencyNamesAndVersions()
{
return Collections.emptyList();
}

/**
* Override this method to implement custom logic after a process has been deployed and is active, e.g. test the
* connection to an external server needed by a process.
*
* @param pluginApplicationContext
* the process plugin spring application context, never <code>null</code>
* @param activeProcesses
* active processes from this plugin by process key
*/
default void onProcessesDeployed(ApplicationContext pluginApplicationContext, List<String> activeProcesses)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ClassLoader getClassLoader()
return classLoader;
}

public ApplicationContext createPluginApplicationContext(ApplicationContext mainContext)
public ApplicationContext getPluginApplicationContext(ApplicationContext mainContext)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;

import org.highmed.dsf.bpe.process.ProcessKeyAndVersion;
import org.highmed.dsf.bpe.process.ProcessStateChangeOutcome;
import org.highmed.dsf.fhir.resources.ResourceProvider;
import org.springframework.context.ApplicationContext;

Expand Down Expand Up @@ -53,4 +54,6 @@ public interface ProcessPluginProvider
List<ProcessKeyAndVersion> getProcessKeyAndVersions();

List<ProcessKeyAndVersion> getDraftProcessKeyAndVersions();

void onProcessesDeployed(List<ProcessStateChangeOutcome> changes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;
import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -23,6 +26,8 @@

import org.highmed.dsf.bpe.ProcessPluginDefinition;
import org.highmed.dsf.bpe.process.ProcessKeyAndVersion;
import org.highmed.dsf.bpe.process.ProcessState;
import org.highmed.dsf.bpe.process.ProcessStateChangeOutcome;
import org.highmed.dsf.fhir.resources.ResourceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -333,7 +338,7 @@ private <T> BinaryOperator<T> dupplicatedProcessKeyVersion()
public Map<ProcessKeyAndVersion, ApplicationContext> getApplicationContextsByProcessDefinitionKeyAndVersion()
{
return getDefinitions().stream().flatMap(def -> def.getProcessKeysAndVersions().stream().map(
keyAndVersion -> new Pair<>(keyAndVersion, def.createPluginApplicationContext(mainApplicationContext))))
keyAndVersion -> new Pair<>(keyAndVersion, def.getPluginApplicationContext(mainApplicationContext))))
.collect(Collectors.toMap(p -> p.k, p -> p.v, dupplicatedProcessKeyVersion()));
}

Expand Down Expand Up @@ -365,4 +370,32 @@ public List<ProcessKeyAndVersion> getDraftProcessKeyAndVersions()
return getDefinitions().stream().filter(ProcessPluginDefinitionAndClassLoader::isDraft)
.flatMap(def -> def.getProcessKeysAndVersions().stream()).collect(Collectors.toList());
}

@Override
public void onProcessesDeployed(List<ProcessStateChangeOutcome> changes)
{
Set<ProcessKeyAndVersion> activeProcesses = changes.stream()
.filter(c -> EnumSet.of(ProcessState.ACTIVE, ProcessState.DRAFT).contains(c.getNewProcessState()))
.map(ProcessStateChangeOutcome::getProcessKeyAndVersion).collect(Collectors.toCollection(HashSet::new));

for (ProcessPluginDefinitionAndClassLoader definition : getDefinitions())
{
List<String> pluginActiveProcesses = definition.getProcessKeysAndVersions().stream()
.filter(activeProcesses::contains).map(ProcessKeyAndVersion::getKey).sorted()
.collect(Collectors.toList());

ApplicationContext pluginApplicationContext = definition
.getPluginApplicationContext(mainApplicationContext);

try
{
definition.getDefinition().onProcessesDeployed(pluginApplicationContext, pluginActiveProcesses);
}
catch (Exception e)
{
logger.warn("Error while executing onProcessesDeployed for plugin "
+ definition.getDefinition().getNameAndVersion(), e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void onContextRefreshedEvent(ContextRefreshedEvent event)

fhirResourceHandler().applyStateChangesAndStoreNewResourcesInDb(
processPluginProvider.getDefinitionByProcessKeyAndVersion(), changes);

processPluginProvider.onProcessesDeployed(changes);
}

@Bean
Expand Down

0 comments on commit 68ba4e5

Please sign in to comment.