forked from apache/incubator-kie-drools
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DROOLS-3367] Created DMNRuntimeFluent and related APIs (apache#2179)
* [DROOLS-3401] Moved Fluent API to kie-internal * [DROOLS-3367] Implemented DMNRuntimeFluent APIs * [DROOLS-3367] Implemented DMNRuntimeFluent APIs * [DROOLS-3367] Fixed bug * [DROOLS-3367] Added copyright * [DROOLS-3367] Use DMNRuntime.newContext() instead of DMNFactory.newContext()
- Loading branch information
1 parent
354e200
commit b668b12
Showing
22 changed files
with
913 additions
and
6 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
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
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
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
32 changes: 32 additions & 0 deletions
32
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/AbstractDMNResultCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import org.kie.dmn.api.core.DMNResult; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public abstract class AbstractDMNResultCommand { | |||
|
|||
protected DMNResult extractDMNResult(RegistryContext context) { | |||
RegistryContext registryContext = context; | |||
DMNResult dmnResult = registryContext.lookup(DMNResult.class); | |||
if (dmnResult == null) { | |||
throw new IllegalStateException("There is no DMNResult available"); | |||
} | |||
return dmnResult; | |||
} | |||
} |
81 changes: 81 additions & 0 deletions
81
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/DMNRuntimeFluentImpl.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,81 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import org.drools.core.fluent.impl.BaseBatchFluent; | |||
import org.kie.api.io.Resource; | |||
import org.kie.internal.builder.fluent.CommandBasedExecutable; | |||
import org.kie.internal.builder.fluent.DMNRuntimeFluent; | |||
import org.kie.internal.builder.fluent.ExecutableBuilder; | |||
|
|||
public class DMNRuntimeFluentImpl extends BaseBatchFluent<DMNRuntimeFluent, ExecutableBuilder> implements DMNRuntimeFluent { | |||
|
|||
private final CommandBasedExecutable ctx; | |||
|
|||
public DMNRuntimeFluentImpl(CommandBasedExecutable ctx) { | |||
super(ctx); | |||
this.ctx = ctx; | |||
newDMNRuntime(); | |||
} | |||
|
|||
protected DMNRuntimeFluent newDMNRuntime() { | |||
ctx.addCommand(new NewDMNRuntimeCommand()); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent setInput(String name, Object value) { | |||
ctx.addCommand(new SetDMNInputCommand(name, value)); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent setActiveModel(String namespace, String modelName) { | |||
ctx.addCommand(new SetDMNActiveModelCommand(namespace, modelName)); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent setActiveModel(Resource resource) { | |||
ctx.addCommand(new SetDMNActiveModelCommand(resource)); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent evaluateModel() { | |||
ctx.addCommand(new ExecuteDMNCommand()); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent getAllContext() { | |||
ctx.addCommand(new GetAllDMNContextCommand()); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent getDecisionResults() { | |||
ctx.addCommand(new GetDMNDecisionResultsCommand()); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public DMNRuntimeFluent getMessages() { | |||
ctx.addCommand(new GetDMNMessagesCommand()); | |||
return this; | |||
} | |||
} |
53 changes: 53 additions & 0 deletions
53
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/ExecuteDMNCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import org.kie.api.command.ExecutableCommand; | |||
import org.kie.api.runtime.Context; | |||
import org.kie.dmn.api.core.DMNContext; | |||
import org.kie.dmn.api.core.DMNModel; | |||
import org.kie.dmn.api.core.DMNResult; | |||
import org.kie.dmn.api.core.DMNRuntime; | |||
import org.kie.dmn.core.api.DMNFactory; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public class ExecuteDMNCommand implements ExecutableCommand<DMNResult> { | |||
|
|||
@Override | |||
public DMNResult execute(Context context) { | |||
RegistryContext registryContext = (RegistryContext) context; | |||
DMNModel activeModel = registryContext.lookup(DMNModel.class); | |||
DMNRuntime dmnRuntime = registryContext.lookup(DMNRuntime.class); | |||
DMNContext dmnContext = registryContext.lookup(DMNContext.class); | |||
if (activeModel == null) { | |||
throw new IllegalStateException("No DMN active model defined"); | |||
} | |||
if (dmnRuntime == null) { | |||
throw new IllegalStateException("No DMNRuntime available"); | |||
} | |||
if (dmnContext == null) { | |||
dmnContext = dmnRuntime.newContext(); | |||
} | |||
DMNResult dmnResult = dmnRuntime.evaluateAll(activeModel, dmnContext); | |||
registryContext.register(DMNResult.class, dmnResult); | |||
|
|||
// reset context | |||
registryContext.register(DMNContext.class, dmnRuntime.newContext()); | |||
|
|||
return dmnResult; | |||
} | |||
} |
38 changes: 38 additions & 0 deletions
38
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/GetAllDMNContextCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,38 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import java.util.Map; | |||
|
|||
import org.kie.api.command.ExecutableCommand; | |||
import org.kie.api.runtime.Context; | |||
import org.kie.dmn.api.core.DMNResult; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public class GetAllDMNContextCommand implements ExecutableCommand<Map<String, Object>> { | |||
|
|||
@Override | |||
public Map<String, Object> execute(Context context) { | |||
RegistryContext registryContext = (RegistryContext) context; | |||
DMNResult dmnResult = registryContext.lookup(DMNResult.class); | |||
if(dmnResult == null) { | |||
throw new IllegalStateException("There is not DMNResult available"); | |||
} | |||
|
|||
return dmnResult.getContext().getAll(); | |||
} | |||
} |
32 changes: 32 additions & 0 deletions
32
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/GetDMNDecisionResultsCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import java.util.List; | |||
|
|||
import org.kie.api.command.ExecutableCommand; | |||
import org.kie.api.runtime.Context; | |||
import org.kie.dmn.api.core.DMNDecisionResult; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public class GetDMNDecisionResultsCommand extends AbstractDMNResultCommand implements ExecutableCommand<List<DMNDecisionResult>> { | |||
|
|||
@Override | |||
public List<DMNDecisionResult> execute(Context context) { | |||
return extractDMNResult((RegistryContext) context).getDecisionResults(); | |||
} | |||
} |
32 changes: 32 additions & 0 deletions
32
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/GetDMNMessagesCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import java.util.List; | |||
|
|||
import org.kie.api.command.ExecutableCommand; | |||
import org.kie.api.runtime.Context; | |||
import org.kie.dmn.api.core.DMNMessage; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public class GetDMNMessagesCommand extends AbstractDMNResultCommand implements ExecutableCommand<List<DMNMessage>> { | |||
|
|||
@Override | |||
public List<DMNMessage> execute(Context context) { | |||
return extractDMNResult((RegistryContext) context).getMessages(); | |||
} | |||
} |
39 changes: 39 additions & 0 deletions
39
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/fluent/NewDMNRuntimeCommand.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
/* | |||
* Copyright 2018 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.kie.dmn.core.fluent; | |||
|
|||
import org.kie.api.command.ExecutableCommand; | |||
import org.kie.api.runtime.Context; | |||
import org.kie.api.runtime.KieContainer; | |||
import org.kie.dmn.api.core.DMNRuntime; | |||
import org.kie.internal.command.RegistryContext; | |||
|
|||
public class NewDMNRuntimeCommand implements ExecutableCommand<DMNRuntime> { | |||
|
|||
@Override | |||
public DMNRuntime execute(Context context) { | |||
RegistryContext registryContext = (RegistryContext) context; | |||
KieContainer kieContainer = registryContext.lookup(KieContainer.class); | |||
if (kieContainer == null) { | |||
throw new IllegalStateException("There is no existing KieContainer assigned to the Registry"); | |||
} | |||
DMNRuntime dmnRuntime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class); | |||
|
|||
registryContext.register(DMNRuntime.class, dmnRuntime); | |||
return dmnRuntime; | |||
} | |||
} |
Oops, something went wrong.