-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from netgrif/NAE-1567
[NAE-1567] Global event system
- Loading branch information
Showing
92 changed files
with
3,870 additions
and
2,076 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
.../groovy/com/netgrif/application/engine/integration/plugins/services/PluginInjector.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 69 additions & 69 deletions
138
src/main/java/com/netgrif/application/engine/configuration/drools/DroolsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
//} |
Oops, something went wrong.