Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROOLS-3355: Improve Assembler/Weaver API (#1393)
* assemblers * move jbpm to assemblers * moved to assembler * wip * wip * revert * fix style issues * whitespace * moved assemblers, weavers to jbm-flow * use create API to create package in weaver * do not parse resource twice * minimal change: report dialect-related errors * style issues
- Loading branch information
1 parent
2909e8d
commit 1cc1cbd
Showing
12 changed files
with
336 additions
and
57 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...m-case-mgmt-cmmn/src/main/java/org/jbpm/casemgmt/cmmn/assembler/CMMNAssemblerService.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.jbpm.casemgmt.cmmn.assembler; | ||
|
||
import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; | ||
import org.drools.compiler.compiler.CMMNCaseFactory; | ||
import org.jbpm.assembler.AbstractProcessAssembler; | ||
import org.kie.api.io.ResourceType; | ||
|
||
public class CMMNAssemblerService extends AbstractProcessAssembler { | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.CMMN; | ||
} | ||
|
||
@Override | ||
protected void configurePackageBuilder(KnowledgeBuilderImpl kb) { | ||
CMMNCaseFactory.configurePackageBuilder(kb); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
jbpm-case-mgmt/jbpm-case-mgmt-cmmn/src/main/resources/META-INF/kie.conf
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,2 +1,2 @@ | ||
org.drools.compiler.compiler.CMMNCaseProvider=org.jbpm.casemgmt.cmmn.CMMNCaseProviderImpl | ||
|
||
org.kie.api.internal.assembler.KieAssemblers = +org.jbpm.casemgmt.cmmn.assembler.CMMNAssemblerService |
77 changes: 77 additions & 0 deletions
77
jbpm-flow-builder/src/main/java/org/jbpm/assembler/AbstractProcessAssembler.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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.jbpm.assembler; | ||
|
||
import java.util.List; | ||
|
||
import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; | ||
import org.drools.compiler.compiler.BaseKnowledgeBuilderResultImpl; | ||
import org.drools.compiler.compiler.PackageRegistry; | ||
import org.drools.compiler.compiler.ProcessLoadError; | ||
import org.drools.core.impl.InternalKnowledgeBase; | ||
import org.jbpm.compiler.ProcessBuilderImpl; | ||
import org.kie.api.definition.process.Process; | ||
import org.kie.api.internal.assembler.KieAssemblerService; | ||
import org.kie.api.io.Resource; | ||
import org.kie.api.io.ResourceConfiguration; | ||
import org.kie.api.io.ResourceType; | ||
import org.kie.internal.builder.KnowledgeBuilderResult; | ||
|
||
public abstract class AbstractProcessAssembler implements KieAssemblerService { | ||
|
||
public void addResource( | ||
Object kbuilder, | ||
Resource resource, | ||
ResourceType type, | ||
ResourceConfiguration configuration) { | ||
|
||
KnowledgeBuilderImpl kb = (KnowledgeBuilderImpl) kbuilder; | ||
ProcessBuilderImpl processBuilder = (ProcessBuilderImpl) kb.getProcessBuilder(); | ||
configurePackageBuilder(kb); | ||
|
||
try { | ||
List<Process> processes = processBuilder.addProcessFromXml(resource); | ||
List<BaseKnowledgeBuilderResultImpl> errors = processBuilder.getErrors(); | ||
if (errors.isEmpty()) { | ||
InternalKnowledgeBase kBase = kb.getKnowledgeBase(); | ||
if (kBase != null && processes != null) { | ||
for (Process process : processes) { | ||
kBase.addProcess(process); | ||
} | ||
} | ||
} else { | ||
errors.forEach(kb::addBuilderResult); | ||
errors.clear(); | ||
} | ||
} catch (Exception e) { | ||
if (e instanceof RuntimeException) { | ||
throw (RuntimeException) e; | ||
} | ||
kb.addBuilderResult(new ProcessLoadError(resource, "Unable to load process.", e)); | ||
} | ||
|
||
// propagate dialect errors to process building errors | ||
for (PackageRegistry pkg : kb.getPackageRegistry().values()) { | ||
// addResults() method, contrary to what could be expectations, | ||
// *adds* the result to the *given* list | ||
List<KnowledgeBuilderResult> es = pkg.getDialectCompiletimeRegistry().addResults(null); | ||
es.forEach(kb::addBuilderResult); | ||
} | ||
} | ||
|
||
protected abstract void configurePackageBuilder(KnowledgeBuilderImpl kb); | ||
} |
34 changes: 34 additions & 0 deletions
34
jbpm-flow-builder/src/main/java/org/jbpm/assembler/BPMN2AssemblerService.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.jbpm.assembler; | ||
|
||
import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; | ||
import org.drools.compiler.compiler.BPMN2ProcessFactory; | ||
import org.kie.api.io.ResourceType; | ||
|
||
public class BPMN2AssemblerService extends AbstractProcessAssembler { | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.BPMN2; | ||
} | ||
|
||
@Override | ||
protected void configurePackageBuilder(KnowledgeBuilderImpl kb) { | ||
BPMN2ProcessFactory.configurePackageBuilder(kb); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
jbpm-flow-builder/src/main/java/org/jbpm/assembler/DRFAssemblerService.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 |
---|---|---|
@@ -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.jbpm.assembler; | ||
|
||
import org.drools.compiler.builder.impl.KnowledgeBuilderImpl; | ||
import org.kie.api.io.ResourceType; | ||
|
||
public class DRFAssemblerService extends AbstractProcessAssembler { | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.DRF; | ||
} | ||
|
||
@Override | ||
protected void configurePackageBuilder(KnowledgeBuilderImpl kb) { | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
jbpm-flow-builder/src/main/java/org/jbpm/weaver/AbstractWeaverService.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 |
---|---|---|
@@ -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.jbpm.weaver; | ||
|
||
import org.drools.core.definitions.InternalKnowledgePackage; | ||
import org.drools.core.definitions.ProcessPackage; | ||
import org.kie.api.KieBase; | ||
import org.kie.api.definition.KiePackage; | ||
import org.kie.api.internal.weaver.KieWeaverService; | ||
|
||
public abstract class AbstractWeaverService implements KieWeaverService<ProcessPackage> { | ||
|
||
@Override | ||
public void merge(KieBase kieBase, KiePackage kiePkg, ProcessPackage processPkg) { | ||
ProcessPackage existing = | ||
ProcessPackage.getOrCreate(((InternalKnowledgePackage) kiePkg).getResourceTypePackages()); | ||
existing.getRuleFlows().putAll(processPkg.getRuleFlows()); | ||
} | ||
|
||
@Override | ||
public void weave(KieBase kieBase, KiePackage kiePackage, ProcessPackage processPackage) { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.