Skip to content

Commit

Permalink
introduce new public API for prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Jan 4, 2024
1 parent 6279ef5 commit 0579039
Show file tree
Hide file tree
Showing 37 changed files with 619 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
*/
package org.drools.base.facttemplates;

import java.util.concurrent.TimeUnit;
import org.kie.api.prototype.PrototypeEventInstance;

public interface Event extends Fact {

long getTimestamp();

long getExpiration();

Event withExpiration( long value, TimeUnit unit );
public interface Event extends Fact, PrototypeEventInstance {

default boolean isEvent() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
*/
package org.drools.base.facttemplates;

import java.util.Map;
import org.kie.api.prototype.PrototypeFactInstance;

public interface Fact {

Object get(String name);

void set(String name, Object value);

Map<String, Object> asMap();
public interface Fact extends PrototypeFactInstance {

FactTemplate getFactTemplate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.util.Map;
import java.util.Objects;

//import woolfel.engine.rule.Rule;

public class FactImpl implements Fact, Externalizable {

private FactTemplate factTemplate = null;
Expand Down Expand Up @@ -58,6 +56,11 @@ public void set(final String name, final Object value) {
this.values.put( name, value );
}

@Override
public boolean has(String name) {
return values.containsKey(name);
}

/**
* Return the deftemplate for the fact
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.type.Type;
import org.drools.model.prototype.PrototypeFact;
import org.kie.api.prototype.PrototypeFactInstance;

import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.toClassOrInterfaceType;

Expand Down Expand Up @@ -70,7 +70,7 @@ public NodeList<Parameter> getParametersForPrototype(Collection<String> declarat
DeclarationSpec declaration = context.getDeclarationByIdWithException(parameterName);
Parameter boxedParameter = declaration instanceof TypedDeclarationSpec tSpec ?
getTypedParameter(methodBody, parameterName, tSpec) :
new Parameter(toClassOrInterfaceType(PrototypeFact.class), parameterName);
new Parameter(toClassOrInterfaceType(PrototypeFactInstance.class), parameterName);
parameters.add(boxedParameter);
}
return parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private DslMethodNames() { }
public static final NameExpr PROTO_DSL_NAMESPACE = new NameExpr(PrototypeDSL.class.getCanonicalName());
public static final String PROTO_PATTERN_CALL = "protoPattern";
public static final String PROTO_EXPR_CALL = "expr";
public static final String PROTOTYPE_CALL = "prototype";
public static final String PROTOTYPE_FACT_CALL = "prototypeFact";
public static final String PROTOTYPE_VARIABLE_CALL = "variable";

// expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.drools.model.prototype.PrototypeVariable;

import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.toClassOrInterfaceType;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.PROTOTYPE_CALL;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.PROTOTYPE_FACT_CALL;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.PROTOTYPE_VARIABLE_CALL;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.createProtoDslTopLevelMethod;

Expand Down Expand Up @@ -71,7 +71,7 @@ public void registerOnPackage(PackageModel packageModel, RuleContext context, Bl
ClassOrInterfaceType varType = toClassOrInterfaceType(PrototypeVariable.class);
VariableDeclarationExpr varExpr = new VariableDeclarationExpr(varType, context.getVar(getBindingId()), Modifier.finalModifier());

MethodCallExpr prototypeCall = createProtoDslTopLevelMethod(PROTOTYPE_CALL);
MethodCallExpr prototypeCall = createProtoDslTopLevelMethod(PROTOTYPE_FACT_CALL);
prototypeCall.addArgument(new StringLiteralExpr(prototypeType));
MethodCallExpr variableCall = createProtoDslTopLevelMethod(PROTOTYPE_VARIABLE_CALL);
variableCall.addArgument(prototypeCall);
Expand Down
Loading

0 comments on commit 0579039

Please sign in to comment.