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

Reply via email to