Skip to content

Commit

Permalink
Merge pull request #268 from netgrif/NAE-1567
Browse files Browse the repository at this point in the history
[NAE-1567] Global event system
  • Loading branch information
machacjozef authored Nov 12, 2024
2 parents 0d8a94f + 42c5757 commit 06210d3
Show file tree
Hide file tree
Showing 92 changed files with 3,870 additions and 2,076 deletions.
67 changes: 39 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -392,35 +392,46 @@
</dependency>

<!-- Drools -->
<!-- <dependency>-->
<!-- <groupId>org.kie</groupId>-->
<!-- <artifactId>kie-ci</artifactId>-->
<!-- <version>${drools-version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.drools</groupId>-->
<!-- <artifactId>drools-decisiontables</artifactId>-->
<!-- <version>${drools-version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.drools</groupId>-->
<!-- <artifactId>drools-mvel</artifactId>-->
<!-- <version>${drools-version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.drools</groupId>-->
<!-- <artifactId>drools-core</artifactId>-->
<!-- <version>${drools-version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.drools</groupId>-->
<!-- <artifactId>drools-compiler</artifactId>-->
<!-- <version>${drools-version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.kie</groupId>-->
<!-- <artifactId>kie-spring</artifactId>-->
<!-- <version>${kie-spring.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.netgrif</groupId>-->
<!-- <artifactId>netgrif-drools</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-mvel</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools-version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${kie-spring.version}</version>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.1.0</version>
</dependency>
<!-- QRGen -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.netgrif.application.engine.integration.plugins.services

import com.netgrif.application.engine.integration.plugins.config.PluginProperties
import com.netgrif.application.engine.integration.plugins.exceptions.IncompatibleClassLoaderException
import com.netgrif.application.engine.integration.plugins.exceptions.IncompatiblePluginException
import com.netgrif.application.engine.integration.plugins.exceptions.RestrictedPackageException
import com.netgrif.application.engine.petrinet.domain.dataset.logic.action.ActionDelegate
//import extensions.NaeExtensionPoint
//import groovy.util.logging.Slf4j
//import org.pf4j.ExtensionPoint
//import org.pf4j.PluginClassLoader
//import org.pf4j.PluginWrapper
//import org.springframework.beans.factory.annotation.Autowired
//import org.springframework.beans.factory.annotation.Value
//import org.springframework.stereotype.Component
//import wrapper.NaePlugin
//import wrapper.PluginExtensionHolder
//
//import java.util.stream.Collectors
//
//@Slf4j
//@Component
//class PluginInjector {
//
// @Autowired
// private PluginProperties pluginProperties
//
// @Value('${project.version}')
// private String projectVersion
//
// protected void injectExtension(PluginWrapper pluginWrapper) {
// pluginWrapper.getPluginManager().getExtensions(NaeExtensionPoint.class).each { extension ->
// checkCompatibility(extension)
// checkClassLoader(extension as NaeExtensionPoint)
// secureCheck(extension as NaeExtensionPoint)
// }
//
// PluginExtensionHolder extensionHolder = ((NaePlugin) pluginWrapper.getPlugin()).getExtensionHolder()
// MetaClass actionDelegateMc = ActionDelegate.getMetaClass()
// actionDelegateMc[pluginWrapper.pluginId] = extensionHolder
// }
//
// protected void secureCheck(NaeExtensionPoint extension) {
// checkPackages(extension.getClass())
// }
//
// private void checkPackages(Class<?> aClass) {
// List<Package> filteredRestrictedPackages = filterRestrictedPackages(aClass)
// if (!filteredRestrictedPackages.isEmpty()) {
// String message = "Plugin " + aClass.getName() + " contains restricted packages: " +
// filteredRestrictedPackages.toString()
// log.error(message)
// throw new RestrictedPackageException(message)
// }
// aClass.declaredFields.each { field ->
// checkPackages(field.class)
// }
// }
//
// private List<Package> filterRestrictedPackages(Class<?> aClass) {
// return aClass.classLoader.definedPackages.toList().stream().filter(p -> {
// pluginProperties.restrictedPackages.toList().stream().anyMatch(rp -> {
// return p.getName().startsWith(rp) || p.getName().contains(rp)
// })
// }).collect(Collectors.toList())
// }
//
// private void checkCompatibility(NaeExtensionPoint extension) {
// if (extension.getPluginVersion() != projectVersion)
// log.warn("Netgrif Application Engine end imported library versions are not the same. Some functions may work improperly.")
// }
//
// private void checkClassLoader(NaeExtensionPoint extensionPoint) {
// ClassLoader classLoader = extensionPoint.class.classLoader
// if (!classLoader instanceof PluginClassLoader) {
// String message = "Plugin class loader [" + classLoader.getClass().getName() + "] is not compatible with class loader for plugins."
// log.error(message)
// throw new IncompatibleClassLoaderException(message)
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.netgrif.application.engine.petrinet.domain.roles.ProcessRole
import com.netgrif.application.engine.petrinet.domain.version.Version
import com.netgrif.application.engine.petrinet.service.interfaces.IPetriNetService
import com.netgrif.application.engine.petrinet.service.interfaces.IUriService
import com.netgrif.application.engine.rules.domain.RuleRepository
//import com.netgrif.application.engine.rules.domain.RuleRepository
import com.netgrif.application.engine.startup.runner.DefaultFiltersRunner
import com.netgrif.application.engine.startup.runner.FilterRunner
import com.netgrif.application.engine.startup.ImportHelper
Expand Down Expand Up @@ -144,8 +144,8 @@ class ActionDelegate {
@Autowired
IInitValueExpressionEvaluator initValueExpressionEvaluator

@Autowired
RuleRepository ruleRepository
// @Autowired
// RuleRepository ruleRepository

@Autowired
Scheduler scheduler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
package com.netgrif.application.engine.configuration.drools;

import com.netgrif.application.engine.configuration.drools.interfaces.IKnowledgeBaseInitializer;
import com.netgrif.application.engine.configuration.drools.interfaces.IRefreshableKieBase;
import com.netgrif.application.engine.configuration.drools.interfaces.IRuleEngineGlobalsProvider;
import com.netgrif.application.engine.rules.domain.RuleRepository;
import org.drools.template.ObjectDataCompiler;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.KieModule;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
public class DroolsConfiguration {

@Autowired
private IKnowledgeBaseInitializer baseInitializer;

@Autowired
private IRuleEngineGlobalsProvider sessionInitializer;

@Autowired
private RuleRepository ruleRepository;

@Value("${drools.template.path:rules/templates/template.drl}")
private String templatePath;

@Bean(name = "kieRuntime")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public KieSession kieRuntime() {
IRefreshableKieBase baseWrapper = refreshableKieBase();
if (baseWrapper.shouldRefresh()) {
baseWrapper.refresh();
}

KieSession runtime = baseWrapper.kieBase().newKieSession();
sessionInitializer.setGlobals(runtime);
return runtime;
}

// @Bean
// public KieContainer kieContainer() {
// KieServices kieServices = KieServices.Factory.get();
//package com.netgrif.application.engine.configuration.drools;
//
//import com.netgrif.application.engine.configuration.drools.interfaces.IKnowledgeBaseInitializer;
//import com.netgrif.application.engine.configuration.drools.interfaces.IRefreshableKieBase;
//import com.netgrif.application.engine.configuration.drools.interfaces.IRuleEngineGlobalsProvider;
//import com.netgrif.application.engine.rules.domain.RuleRepository;
//import org.drools.template.ObjectDataCompiler;
//import org.kie.api.KieServices;
//import org.kie.api.builder.KieBuilder;
//import org.kie.api.builder.KieFileSystem;
//import org.kie.api.builder.KieModule;
//import org.kie.api.runtime.KieContainer;
//import org.kie.api.runtime.KieSession;
//import org.kie.internal.io.ResourceFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.beans.factory.config.ConfigurableBeanFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Scope;
//
//@Configuration
//public class DroolsConfiguration {
//
// @Autowired
// private IKnowledgeBaseInitializer baseInitializer;
//
// @Autowired
// private IRuleEngineGlobalsProvider sessionInitializer;
//
// @Autowired
// private RuleRepository ruleRepository;
//
// @Value("${drools.template.path:rules/templates/template.drl}")
// private String templatePath;
//
// KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
// kieFileSystem.write(ResourceFactory.newClassPathResource(templatePath));
// KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
// kieBuilder.buildAll();
// KieModule kieModule = kieBuilder.getKieModule();
// @Bean(name = "kieRuntime")
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
// public KieSession kieRuntime() {
// IRefreshableKieBase baseWrapper = refreshableKieBase();
// if (baseWrapper.shouldRefresh()) {
// baseWrapper.refresh();
// }
//
// return kieServices.newKieContainer(kieModule.getReleaseId());
// KieSession runtime = baseWrapper.kieBase().newKieSession();
// sessionInitializer.setGlobals(runtime);
// return runtime;
// }
//
//// @Bean
//// public KieContainer kieContainer() {
//// KieServices kieServices = KieServices.Factory.get();
////
//// KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
//// kieFileSystem.write(ResourceFactory.newClassPathResource(templatePath));
//// KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
//// kieBuilder.buildAll();
//// KieModule kieModule = kieBuilder.getKieModule();
////
//// return kieServices.newKieContainer(kieModule.getReleaseId());
//// }
//
// @Bean
// public IRefreshableKieBase refreshableKieBase() {
// return new RefreshableKieBase(ruleRepository, baseInitializer);
// }
//
// @Bean
// public ObjectDataCompiler objectDataCompiler() {
// return new ObjectDataCompiler();
// }

@Bean
public IRefreshableKieBase refreshableKieBase() {
return new RefreshableKieBase(ruleRepository, baseInitializer);
}

@Bean
public ObjectDataCompiler objectDataCompiler() {
return new ObjectDataCompiler();
}
}
//}
Loading

0 comments on commit 06210d3

Please sign in to comment.