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

[incubator-kie-issues#1478] Register DRG callbacks to assigned models from DMNCompilerImpl #6105

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

samuel-beniamin
Copy link
Contributor

@gitgabrio
Copy link
Contributor

👀

@yesamer yesamer added the DMN label Oct 14, 2024
@gitgabrio
Copy link
Contributor

Hi @samuel-beniamin thanks for the PR.
I tried to understand better the overall context, and I'm sharing my thoughts: please correct me if/where I'm wrong: I may misread something.

  1. by itself, I think the fix could be right
  2. but those AfterProcessDrgElements / addCallback / addCallbackForModel are used/needed only by the signavio module
  3. but being defined/ implemented in the "core" DMNCompilerImpl, those somehow "pollute" it with something that, IMO, has no reason to be there

So, I was thinking to

  1. change DMNCompilerImpl.processDrgElements from private to protected, to be overridable
  2. get rid of all signavio-specific stuff from it (double check also the tests)
  3. create a signavio-specific subclass of DMNCompilerImpl that add the behavior required by signavio
  4. put your modifications in that subclass

The idea would be to have DMNCompilerImpl dealing only with "core" responsibilities, and move implementation-specific ones (e.g. signavio) to dedicated subclasses

Wdyt ? Does this make sense ? Do you think you could do that ?

@baldimir @yesamer

@samuel-beniamin
Copy link
Contributor Author

Hi @samuel-beniamin thanks for the PR. I tried to understand better the overall context, and I'm sharing my thoughts: please correct me if/where I'm wrong: I may misread something.

  1. by itself, I think the fix could be right
  2. but those AfterProcessDrgElements / addCallback / addCallbackForModel are used/needed only by the signavio module
  3. but being defined/ implemented in the "core" DMNCompilerImpl, those somehow "pollute" it with something that, IMO, has no reason to be there

So, I was thinking to

  1. change DMNCompilerImpl.processDrgElements from private to protected, to be overridable
  2. get rid of all signavio-specific stuff from it (double check also the tests)
  3. create a signavio-specific subclass of DMNCompilerImpl that add the behavior required by signavio
  4. put your modifications in that subclass

The idea would be to have DMNCompilerImpl dealing only with "core" responsibilities, and move implementation-specific ones (e.g. signavio) to dedicated subclasses

Wdyt ? Does this make sense ? Do you think you could do that ?

@baldimir @yesamer

Hello @gitgabrio,

Thank you for taking the time to review the code and for your suggestions.

I think your suggestions make sense, I believe I understood what need to be done, and I will be happy to make these changes in this PR as well, if that is okay.

@@ -491,9 +493,30 @@ private void processDrgElements(DMNCompilerContext ctx, DMNModelImpl model, Defi
public interface AfterProcessDrgElements {
void callback(DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model);
}


/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!

private DMNCompilerConfiguration dmnCompilerConfig;
private Deque<DRGElementCompiler> drgCompilers = new LinkedList<>();
private final DMNCompilerConfiguration dmnCompilerConfig;
private final Deque<DRGElementCompiler> drgCompilers = new LinkedList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!

@@ -123,6 +121,7 @@ public class DMNCompilerImpl implements DMNCompiler {
drgCompilers.add( new KnowledgeSourceCompiler() ); // keep last as it's a void compiler
}
private final List<AfterProcessDrgElements> afterDRGcallbacks = new ArrayList<>();
private final Map<DMNModel, List<AfterProcessDrgElements>> afterDRGcallbacksForModel = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!

/**
* Adds a callback that will be invoked after the DRG elements have been processed, for a given model.
*/
public void addCallbackForModel(AfterProcessDrgElements callback, DMNModel model) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!


@BeforeAll
static void setup() {
String modelName = "LocalHrefs";
parent = new TDefinitions();
parent.setName(modelName);
parent.setNamespace(nameSpace);

DMNCompilerConfiguration config = DMNFactory.newCompilerConfiguration();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!

@@ -76,4 +98,27 @@ void getRootElement() {
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @samuel-beniamin
IINW this is signavio-only behaviour that get to the core code: if so, could you please remove and move to signavio module ? Thanks!

@samuel-beniamin
Copy link
Contributor Author

Hello @gitgabrio

Well, I tried the approach of the a separate subclass for Signavio specific things, I have some observation and a conclusion:

  1. I ended up not able to inject that Signavio specific compiler easily into the code.
  2. DMNCompilerConfiguration is not Signavio specific, this is related to the core compiler for extensions in general.
  3. drgCompilers are not Signavio specific, they are also used by other extensions, (e.g. trisotech is also using that).
    • This makes me think that AfterProcessDrgElements follows the same reasoning, is not Signavio specific (since drgCompilers are not), AfterProcessDrgElements is indeed used only now by Signavio, but that doesn't limit the need to Signavio only.

I have a question, do you know a way with which I can integrate the new compiler into the code by any means, I had the impression that the compiler is not intended to be changed but extended through the DMNCompilerConfiguration only, am I correct?

If I am correct on the previous point, I would actually close this ticket after rethinking this part and also close the ticket, since this is the way the compiler was meant to be extended actually.

@gitgabrio
Copy link
Contributor

First of all, many thanks @samuel-beniamin for all that.
I'll need a bit of time to double check, but it is very possible that you are right.
I've answered immediately to first of all thanks you again, I'll let you know ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DMNCompilerImpl calls DRG (Decision requirements graph) callbacks on all loaded models
3 participants