Skip to content
New issue

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

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

Already on GitHub? # to your account

Adding easy-rules-jexl to support Java Expression Language (JEXL) #271

Closed
wants to merge 1 commit into from

Conversation

laurikimmel
Copy link

Adding a module to support JEXL.

@fmbenhassine
Copy link
Member

This is awesome, thank you! I will take a look in details and get back to you asap.


// then
assertThat(adultRule.getName()).isEqualTo("adult rule");
assertThat(adultRule.getDescription()).isEqualTo("when age is greater then 18, then mark as adult");
Copy link
Member

Choose a reason for hiding this comment

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

There is a typo here: then should be than. It was fixed in 94d29cc. Please fix it here as well. (there are a couple of other occurrences in this PR).

Comment on lines +181 to +182
facts.put("System", System.class);
facts.put("UUID", UUID.class);
Copy link
Member

Choose a reason for hiding this comment

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

Facts are designed to store business data. I'm not a fan of putting technical classes as facts like in here. MVEL and SpEL provide a ParserContext API that allows to register/import packages and functions (See example here). Is there something similar in JEXL?

My big concern here is that those tests serve as documentation as well, and in my experience, people will copy/paste and misuse facts to store any kind of non business facts.

Copy link
Member

@fmbenhassine fmbenhassine Jun 1, 2020

Choose a reason for hiding this comment

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

Is there something similar in JEXL?

It looks like Jexl namespaces are the closest concept to ParserContext in Mvel/SpEL. Here is a quick example:

	@Test
	public void testJexlNamespaces() {
		Map<String, Object> namspaces = new HashMap<>();
		namspaces.put("greeter", new Greeter());
		JexlEngine jexlEngine = new JexlBuilder()
				.namespaces(namspaces)
				.create();
		MapContext mapContext = new MapContext();
		mapContext.set("name", "foo");
		JexlScript jexlScript = jexlEngine.createScript("greeter:sayHello(name)");
		jexlScript.execute(mapContext);// prints "hello foo"
	}

	public static class Greeter {
		public void sayHello(String name) {
			System.out.println("hello " + name);
		}
	}

.create();

Facts facts = new Facts();
facts.put("result", null);
Copy link
Member

Choose a reason for hiding this comment

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

This is not type safe. Even though it is possible, I would not use it in real case scenario. While defining a method in an EL expression and call it later on is ok, assigning a variable inside the expression and get the result outside is not a good practice IMO. This comment is about the practice itself rather than the code (again, as mentioned in my other comment in this PR, my concern is that people will just do the same). Each time I write something like this, there is a little voice in my head reminding me that the end goal is not to put code in Strings 😄

@fmbenhassine
Copy link
Member

Hi @laurikimmel ,

Thank you for your PR! I really like this new module, but we need some updates before merging it (I can take care of some of those if needed).

I added a couple of minor inline comments. There are also some changes that were introduced since you opened the PR, so I pushed a few commits here: https://github.com/j-easy/easy-rules/commits/pull/271 to explain them (see the messages of the last 3 commits).

Please take a look and let me know about your thoughts. Do not hesitate to add javadocs to public APIs and add your name in the @author tag as well as in the readme file (the credit goes to you!).

Thank you upfront!

@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();

@SuppressWarnings("deprecation")
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding @SuppressWarnings, I would update the code to not use the deprecated API (See example in 90ecf58).

@fmbenhassine
Copy link
Member

Hi @laurikimmel ,

I just noticed that JEXL has not been released since 14 April 2017 and seems to be dead.. Depending on a dead project is unfortunately a big concern for me and I'm not ready to maintain this new JEXL module in the long term.

I suggest that you create a repo that you own/maintain with the JEXL module in this PR and I will add a reference to it in the readme. wdyt?

@laurikimmel
Copy link
Author

Hi @benas!

My apologies for not answering sooner. I have been busy with other tasks lately. I hope to have some time to deal with the concerns you raised.

I agree, latest version of JEXL is quite old. At the same time, development is still ongoing and judging by the issue list they are getting close to releasing new version.

@fmbenhassine
Copy link
Member

If JEXL is still maintained then it's ok for me to merge this module once v3.2 is released. In the meantime, please update the PR and let me know if you need help.

I still want to have your opinion on you owning this module and me adding a reference to it in the readme.

@fmbenhassine
Copy link
Member

Rebased and merged as eab2e3b. Revised in 1a06601 to address the comments above (see commit message for more details).

I believe this module is consistent with other EL modules now. This is a great addition, thank you very much @laurikimmel for your contribution! This will be part of the upcoming v4.1.

As a side note, since JEXL 3.2 is not released yet, I will release ER 4.1 based on JEXL 3.1 (as in this PR) and update JEXL to 3.2 in ER 4.2.

@fmbenhassine fmbenhassine added this to the 4.1.0 milestone Dec 6, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants