Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KOGITO-590: Rules should "see" process variables #269

Merged
merged 9 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -30,6 +30,8 @@ static RuleUnitComponentFactory get() {

RuleUnitDescription createRuleUnitDescription( KiePackage pkg, Class<?> ruleUnitClass );

RuleUnitDescription createRuleUnitDescription( KiePackage pkg, String ruleUnitSimpleName );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should backport this, although it will be a no-op

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


ApplyPmmlModelCommandExecutor newApplyPmmlModelCommandExecutor();

boolean isRuleUnitClass( Class<?> ruleUnitClass );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@
public interface RuleUnitDescription {

/**
* @deprecated this is only used by PMML
* @deprecated this is only used by PMML / it should not be used for other purposes
*
*/
@Deprecated
Class<?> getRuleUnitClass();

default String getRuleUnitName() {
return getRuleUnitClass().getName();
}
String getRuleUnitName();

default String getCanonicalName() {
return getRuleUnitClass().getCanonicalName();
}
String getCanonicalName();

String getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ private RuleUnitDescription findDescription(final String ruleUnit) {
if (nonExistingUnits.contains(ruleUnit)) {
return null;
}
RuleUnitComponentFactory ruleUnitComponentFactory = RuleUnitComponentFactory.get();
// short-circuit if there is no support for units
if (ruleUnitComponentFactory == null) {
return null;
}
try {
return RuleUnitComponentFactory.get().createRuleUnitDescription( pkg, pkg.getTypeResolver().resolveType(ruleUnit) );
return ruleUnitComponentFactory.createRuleUnitDescription(pkg, pkg.getTypeResolver().resolveType(ruleUnit) );
} catch (final ClassNotFoundException e) {
nonExistingUnits.add(ruleUnit);
return null;
RuleUnitDescription ruleUnitDescription = ruleUnitComponentFactory.createRuleUnitDescription(pkg, ruleUnit);
if (ruleUnitDescription == null) {
nonExistingUnits.add(ruleUnit);
return null;
} else {
return ruleUnitDescription;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this change should be backported, There is no way createRuleUnitDescription(pkg, String) != null in the 7 series

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public abstract class AbstractRuleUnitDescription implements RuleUnitDescription

private final Map<String, RuleUnitVariable> varDeclarations = new HashMap<>();

// @Override
// public Optional<EntryPointId> getEntryPointId(String name) {
// return Optional.ofNullable(varDeclarations.get(name))
// .filter(RuleUnitVariable::isDataSource)
// .map(ds -> new EntryPointId(name));
// }

@Override
public Optional<Class<?>> getDatasourceType(String name) {
return Optional.ofNullable(varDeclarations.get(name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.drools.core.ruleunit;
package org.kie.kogito.rules.units;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -59,6 +59,11 @@ public Class<?> getRuleUnitClass() {
return null;
}

@Override
public String getCanonicalName() {
return getPackageName() + '.' + getSimpleName();
}

@Override
public String getSimpleName() {
return simpleName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public Class<?> getRuleUnitClass() {
return ruleUnitClass;
}

@Override
public String getCanonicalName() {
return getRuleUnitClass().getCanonicalName();
}

@Override
public String getSimpleName() {
return ruleUnitClass.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kie.kogito.rules.units;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,37 @@

package org.kie.kogito.rules.units.impl;

import java.util.HashMap;
import java.util.Map;

import org.drools.core.definitions.InternalKnowledgePackage;
import org.kie.api.definition.KiePackage;
import org.kie.internal.ruleunit.ApplyPmmlModelCommandExecutor;
import org.kie.internal.ruleunit.RuleUnitComponentFactory;
import org.kie.internal.ruleunit.RuleUnitDescription;
import org.kie.kogito.rules.DataSource;
import org.kie.kogito.rules.RuleUnitData;
import org.kie.kogito.rules.units.GeneratedRuleUnitDescription;
import org.kie.kogito.rules.units.ReflectiveRuleUnitDescription;

public class RuleUnitComponentFactoryImpl implements RuleUnitComponentFactory {

private final Map<String, GeneratedRuleUnitDescription> generatedRuleUnitDescriptions = new HashMap<>();

public void registerRuleUnitDescription(GeneratedRuleUnitDescription ruleUnitDescription) {
generatedRuleUnitDescriptions.put(ruleUnitDescription.getCanonicalName(), ruleUnitDescription);
}

@Override
public RuleUnitDescription createRuleUnitDescription(KiePackage pkg, Class<?> ruleUnitClass ) {
return new ReflectiveRuleUnitDescription((InternalKnowledgePackage) pkg, (Class<? extends RuleUnitData>) ruleUnitClass );
}

@Override
public RuleUnitDescription createRuleUnitDescription(KiePackage pkg, String ruleUnitSimpleName ) {
return generatedRuleUnitDescriptions.get(pkg.getName() + '.' + ruleUnitSimpleName);
}

@Override
public ApplyPmmlModelCommandExecutor newApplyPmmlModelCommandExecutor() {
throw new UnsupportedOperationException();
Expand Down
4 changes: 4 additions & 0 deletions jbpm/jbpm-flow-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>org.kie.kogito</groupId>
<artifactId>drools-core</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-ruleunits</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-api</artifactId>
Expand Down
Loading