You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Eugen Stan <eu...@netdava.com> on 2021/07/04 12:59:23 UTC

Clojure service engine proposal for inclusion

Hello,

I've implemented a clojure engine for OFBiz and I would like to 
contribute this to OFBiz repo.

It was simpler than I thought.

NOTE: Right now the code is bundled with the ofbiz-repl-plugin in 
https://github.com/netdava/ofbiz-clojure-repl .
Code is a draft and will be cleaned up for inclusion.

== Why?

* Allow OFBiz to use clojure libraries and ecosystem
* Allow Clojure developers to work with OFBiz in a friendlier way
* Does not increase OFBiz complexity
* Clojure is also dynamic like Groovy
* Enables powerful OFBiz administration and development via Clojure Repl 
(work in progress, I have working babshka scripts that I can use to 
manage OFBiz and call services remotely via REPL)

== The code

Code is based off of java engine:
https://github.com/netdava/ofbiz-clojure-repl/blob/main/src/main/java/com/netdava/ofbiz/clojure/ClojureEngine.java

Service it is defined the usual way: 
https://github.com/netdava/ofbiz-clojure-repl/blob/main/servicedef/services.xml 


A sample service looks like this 
https://github.com/netdava/ofbiz-clojure-repl/blob/main/src/main/resources/com/netdava/ofbiz/clojure/sample.clj

Copy pasting code snippets from above links:

   <service name="com.netdava.ofbiz.clojure.sample/clojure-test-service" 
engine="clojure"
            location="com.netdava.ofbiz.clojure.sample" 
invoke="clojure-test-service" export="true"
            max-retry="3" use-transaction="false">
     <description>
       Clojure repl service. Get service stats.
     </description>
     <attribute name="status" type="java.util.Map" mode="OUT"/>
   </service>


(ns com.netdava.ofbiz.clojure.sample
   (:gen-class)
   (:import org.apache.ofbiz.service.DispatchContext))

(defn clojure-test-service [^DispatchContext dctx ^java.util.Map ctx]
   (println "test " dctx " " ctx)
   {"status" {"msg" "Hello OFBiz from clojure"}})

The service prints contexts and returns a clojure map with "status" key 
and a map as a value (that implements java.util.Map).
	

To test out the code, clone ofbiz-clojure-repl into plugins/
and apply two changes: clojars maven repo and the service engine definition.

https://github.com/ieugen/ofbiz-framework/commit/d50254ed57358544c8765a2647ec4bbdd3baf6a5
https://github.com/ieugen/ofbiz-framework/commit/e58ad5ed9d102210a1f1363e8337cef486cf999e


Regards,
-- 
Eugen Stan
+40720 898 747 / netdava.com

Re: Clojure service engine proposal for inclusion

Posted by Eugen Stan <eu...@netdava.com>.
Hello Nicolas, Pierre,

Thanks for your feedback, I replied to the issue.

@Pierre: I would like to be able to use a "slim" OFBiz version but that 
is not easy to do at the moment.

I would like to announce my intention to work on this issue.

One way that would get us closer to a "Slim" (composable) OFBiz is to 
have concrete gradle projects for OFBiz components instead of 
dynamically created projects as we have now.

Once that is done, we could build and publish each component and 
assemble them in a different way than Apache OFBiz currently does.

I think this is doable and the project workflow will not change too much 
from how it is now.

Regards,

On 29.07.2021 20:13, Pierre Smits wrote:
> Hi Nicolas,
> 
> I wasn't aware of that constraint. Thanks for the insight.
> 
> 
> Pierre
> 
> Op do 29 jul. 2021 17:40 schreef Nicolas Malin <ni...@nereide.fr>:
> 
>> Hello,
>>
>> @Eugeu
>>
>> Yeah nice, I added some suggest to the PR, and create the linked jira
>> issue and we can push it on trunk
>>
>> @Pierre
>>
>> The service engine don't support an extension by plugins, you can't load
>> a new engine without change the framework.
>>
>> In this case I prefer to load the minimal quantity of code to
>> demonstrate an engine on the OFBiz framework instead of
>>
>> separate it in plugin and load it by apply a path or manually change the
>> configuration.
>>
>> Nicolas
>>
>> On 29/07/2021 10:58, Pierre Smits wrote:
>>> Hi Ioan,
>>>
>>> Would it not be better for the community to be able to implement this set
>>> of functionalities by means of a downloadable plugin?
>>>
>>> It seems to me that - in a way - this levels up to plugins like the
>>> indexing (lucene) or the REST plugins. Not every adopters would be keen
>> to
>>> have this by default OOTB.
>>>
>>> Best regards,
>>> Pierre Smits
>>>
>>> On Wed, Jul 28, 2021 at 10:23 PM Eugen Stan <eu...@netdava.com>
>> wrote:
>>>
>>>> Hello Nicolas,
>>>>
>>>> Thanks for the suggestions.
>>>> I've made a PR for this:
>>>> https://github.com/apache/ofbiz-framework/pull/317
>>>>
>>>> * has a service test
>>>> * has a service example
>>>>
>>>>
>>>> (defn echo-service
>>>>     "Echo back all the parameters"
>>>>     [dctx ctx]
>>>>     (doto (new java.util.LinkedHashMap)
>>>>       (.putAll ctx)
>>>>       (.put ModelService/RESPONSE_MESSAGE ModelService/RESPOND_SUCCESS)))
>>>>
>>>>
>>>> On 07.07.2021 09:58, Nicolas Malin wrote:
>>>>> Hello,
>>>>>
>>>>> Thanks for this detail email and your works.
>>>>>
>>>>> I'm not opposed to load closure in OFBiz code base for same reason that
>>>>> you exposed.
>>>>>
>>>>> For success the inclusion, I suggest to rename the namespace to
>>>>> org.apache.ofbiz, add test one framework/service/testdef and an example
>>>>> "hello world" service.
>>>>>
>>>>> Thanks Eugen !
>>>>>
>>>>> Nicolas
>>>> --
>>>> Eugen Stan
>>>> +40720 898 747 / netdava.com
>>>>
>>
> 


-- 
Eugen Stan
+40720 898 747 / netdava.com

Re: Clojure service engine proposal for inclusion

Posted by Pierre Smits <pi...@gmail.com>.
Hi Nicolas,

I wasn't aware of that constraint. Thanks for the insight.


Pierre

Op do 29 jul. 2021 17:40 schreef Nicolas Malin <ni...@nereide.fr>:

> Hello,
>
> @Eugeu
>
> Yeah nice, I added some suggest to the PR, and create the linked jira
> issue and we can push it on trunk
>
> @Pierre
>
> The service engine don't support an extension by plugins, you can't load
> a new engine without change the framework.
>
> In this case I prefer to load the minimal quantity of code to
> demonstrate an engine on the OFBiz framework instead of
>
> separate it in plugin and load it by apply a path or manually change the
> configuration.
>
> Nicolas
>
> On 29/07/2021 10:58, Pierre Smits wrote:
> > Hi Ioan,
> >
> > Would it not be better for the community to be able to implement this set
> > of functionalities by means of a downloadable plugin?
> >
> > It seems to me that - in a way - this levels up to plugins like the
> > indexing (lucene) or the REST plugins. Not every adopters would be keen
> to
> > have this by default OOTB.
> >
> > Best regards,
> > Pierre Smits
> >
> > On Wed, Jul 28, 2021 at 10:23 PM Eugen Stan <eu...@netdava.com>
> wrote:
> >
> >> Hello Nicolas,
> >>
> >> Thanks for the suggestions.
> >> I've made a PR for this:
> >> https://github.com/apache/ofbiz-framework/pull/317
> >>
> >> * has a service test
> >> * has a service example
> >>
> >>
> >> (defn echo-service
> >>    "Echo back all the parameters"
> >>    [dctx ctx]
> >>    (doto (new java.util.LinkedHashMap)
> >>      (.putAll ctx)
> >>      (.put ModelService/RESPONSE_MESSAGE ModelService/RESPOND_SUCCESS)))
> >>
> >>
> >> On 07.07.2021 09:58, Nicolas Malin wrote:
> >>> Hello,
> >>>
> >>> Thanks for this detail email and your works.
> >>>
> >>> I'm not opposed to load closure in OFBiz code base for same reason that
> >>> you exposed.
> >>>
> >>> For success the inclusion, I suggest to rename the namespace to
> >>> org.apache.ofbiz, add test one framework/service/testdef and an example
> >>> "hello world" service.
> >>>
> >>> Thanks Eugen !
> >>>
> >>> Nicolas
> >> --
> >> Eugen Stan
> >> +40720 898 747 / netdava.com
> >>
>

Re: Clojure service engine proposal for inclusion

Posted by Nicolas Malin <ni...@nereide.fr>.
Hello,

@Eugeu

Yeah nice, I added some suggest to the PR, and create the linked jira
issue and we can push it on trunk

@Pierre

The service engine don't support an extension by plugins, you can't load
a new engine without change the framework.

In this case I prefer to load the minimal quantity of code to
demonstrate an engine on the OFBiz framework instead of

separate it in plugin and load it by apply a path or manually change the
configuration.

Nicolas

On 29/07/2021 10:58, Pierre Smits wrote:
> Hi Ioan,
>
> Would it not be better for the community to be able to implement this set
> of functionalities by means of a downloadable plugin?
>
> It seems to me that - in a way - this levels up to plugins like the
> indexing (lucene) or the REST plugins. Not every adopters would be keen to
> have this by default OOTB.
>
> Best regards,
> Pierre Smits
>
> On Wed, Jul 28, 2021 at 10:23 PM Eugen Stan <eu...@netdava.com> wrote:
>
>> Hello Nicolas,
>>
>> Thanks for the suggestions.
>> I've made a PR for this:
>> https://github.com/apache/ofbiz-framework/pull/317
>>
>> * has a service test
>> * has a service example
>>
>>
>> (defn echo-service
>>    "Echo back all the parameters"
>>    [dctx ctx]
>>    (doto (new java.util.LinkedHashMap)
>>      (.putAll ctx)
>>      (.put ModelService/RESPONSE_MESSAGE ModelService/RESPOND_SUCCESS)))
>>
>>
>> On 07.07.2021 09:58, Nicolas Malin wrote:
>>> Hello,
>>>
>>> Thanks for this detail email and your works.
>>>
>>> I'm not opposed to load closure in OFBiz code base for same reason that
>>> you exposed.
>>>
>>> For success the inclusion, I suggest to rename the namespace to
>>> org.apache.ofbiz, add test one framework/service/testdef and an example
>>> "hello world" service.
>>>
>>> Thanks Eugen !
>>>
>>> Nicolas
>> --
>> Eugen Stan
>> +40720 898 747 / netdava.com
>>

Re: Clojure service engine proposal for inclusion

Posted by Pierre Smits <pi...@gmail.com>.
Hi Ioan,

Would it not be better for the community to be able to implement this set
of functionalities by means of a downloadable plugin?

It seems to me that - in a way - this levels up to plugins like the
indexing (lucene) or the REST plugins. Not every adopters would be keen to
have this by default OOTB.

Best regards,
Pierre Smits

On Wed, Jul 28, 2021 at 10:23 PM Eugen Stan <eu...@netdava.com> wrote:

> Hello Nicolas,
>
> Thanks for the suggestions.
> I've made a PR for this:
> https://github.com/apache/ofbiz-framework/pull/317
>
> * has a service test
> * has a service example
>
>
> (defn echo-service
>    "Echo back all the parameters"
>    [dctx ctx]
>    (doto (new java.util.LinkedHashMap)
>      (.putAll ctx)
>      (.put ModelService/RESPONSE_MESSAGE ModelService/RESPOND_SUCCESS)))
>
>
> On 07.07.2021 09:58, Nicolas Malin wrote:
> > Hello,
> >
> > Thanks for this detail email and your works.
> >
> > I'm not opposed to load closure in OFBiz code base for same reason that
> > you exposed.
> >
> > For success the inclusion, I suggest to rename the namespace to
> > org.apache.ofbiz, add test one framework/service/testdef and an example
> > "hello world" service.
> >
> > Thanks Eugen !
> >
> > Nicolas
> --
> Eugen Stan
> +40720 898 747 / netdava.com
>

Re: Clojure service engine proposal for inclusion

Posted by Eugen Stan <eu...@netdava.com>.
Hello Nicolas,

Thanks for the suggestions.
I've made a PR for this: https://github.com/apache/ofbiz-framework/pull/317

* has a service test
* has a service example


(defn echo-service
   "Echo back all the parameters"
   [dctx ctx]
   (doto (new java.util.LinkedHashMap)
     (.putAll ctx)
     (.put ModelService/RESPONSE_MESSAGE ModelService/RESPOND_SUCCESS)))


On 07.07.2021 09:58, Nicolas Malin wrote:
> Hello,
> 
> Thanks for this detail email and your works.
> 
> I'm not opposed to load closure in OFBiz code base for same reason that
> you exposed.
> 
> For success the inclusion, I suggest to rename the namespace to
> org.apache.ofbiz, add test one framework/service/testdef and an example
> "hello world" service.
> 
> Thanks Eugen !
> 
> Nicolas
-- 
Eugen Stan
+40720 898 747 / netdava.com

Re: Clojure service engine proposal for inclusion

Posted by Nicolas Malin <ni...@nereide.fr>.
Hello,

Thanks for this detail email and your works.

I'm not opposed to load closure in OFBiz code base for same reason that
you exposed.

For success the inclusion, I suggest to rename the namespace to
org.apache.ofbiz, add test one framework/service/testdef and an example
"hello world" service.

Thanks Eugen !

Nicolas

On 04/07/2021 14:59, Eugen Stan wrote:
> Hello,
>
> I've implemented a clojure engine for OFBiz and I would like to
> contribute this to OFBiz repo.
>
> It was simpler than I thought.
>
> NOTE: Right now the code is bundled with the ofbiz-repl-plugin in
> https://github.com/netdava/ofbiz-clojure-repl .
> Code is a draft and will be cleaned up for inclusion.
>
> == Why?
>
> * Allow OFBiz to use clojure libraries and ecosystem
> * Allow Clojure developers to work with OFBiz in a friendlier way
> * Does not increase OFBiz complexity
> * Clojure is also dynamic like Groovy
> * Enables powerful OFBiz administration and development via Clojure
> Repl (work in progress, I have working babshka scripts that I can use
> to manage OFBiz and call services remotely via REPL)
>
> == The code
>
> Code is based off of java engine:
> https://github.com/netdava/ofbiz-clojure-repl/blob/main/src/main/java/com/netdava/ofbiz/clojure/ClojureEngine.java
>
>
> Service it is defined the usual way:
> https://github.com/netdava/ofbiz-clojure-repl/blob/main/servicedef/services.xml
>
>
> A sample service looks like this
> https://github.com/netdava/ofbiz-clojure-repl/blob/main/src/main/resources/com/netdava/ofbiz/clojure/sample.clj
>
> Copy pasting code snippets from above links:
>
>   <service
> name="com.netdava.ofbiz.clojure.sample/clojure-test-service"
> engine="clojure"
>            location="com.netdava.ofbiz.clojure.sample"
> invoke="clojure-test-service" export="true"
>            max-retry="3" use-transaction="false">
>     <description>
>       Clojure repl service. Get service stats.
>     </description>
>     <attribute name="status" type="java.util.Map" mode="OUT"/>
>   </service>
>
>
> (ns com.netdava.ofbiz.clojure.sample
>   (:gen-class)
>   (:import org.apache.ofbiz.service.DispatchContext))
>
> (defn clojure-test-service [^DispatchContext dctx ^java.util.Map ctx]
>   (println "test " dctx " " ctx)
>   {"status" {"msg" "Hello OFBiz from clojure"}})
>
> The service prints contexts and returns a clojure map with "status"
> key and a map as a value (that implements java.util.Map).
>     
>
> To test out the code, clone ofbiz-clojure-repl into plugins/
> and apply two changes: clojars maven repo and the service engine
> definition.
>
> https://github.com/ieugen/ofbiz-framework/commit/d50254ed57358544c8765a2647ec4bbdd3baf6a5
>
> https://github.com/ieugen/ofbiz-framework/commit/e58ad5ed9d102210a1f1363e8337cef486cf999e
>
>
>
> Regards,