Idea: simple data dsl for process graph creation.
nrfm opened this issue · comments
Great work!
Idea, to make the creation of the graph less verbose, a little "data dsl" would work great.
Given:
(def case-model-dsl
'[
;; roles
applicant is-a role
system is-a role
officer is-a role
;; actions
create-case is-a action
enter-loan-details is-a action
produce-credit-application-document is-a action
sign-credit-application-document is-a action
payout-loan is-a action
;; data
case-id is-a data
customer-id is-a data
loan-details is-a data
credit-application-document is-a data
applicant-signature is-a data
officer-signature is-a data
loan-number is-a data
;; actions relationships
create-case produces customer-id
create-case produces case-id
enter-loan-details produces loan-details
enter-loan-details requires case-id
produce-credit-application-document produces credit-application-document
produce-credit-application-document requires loan-details
produce-credit-application-document requires customer-id
sign-credit-application-document produces applicant-signature
sign-credit-application-document produces officer-signature
sign-credit-application-document requires credit-application-document
payout-loan produces loan-number
payout-loan requires applicant-signature
payout-loan requires officer-signature
;; role-action edges
applicant performs create-case
applicant performs enter-loan-details
applicant performs sign-credit-application-document
officer performs sign-credit-application-document
system performs payout-loan
system performs produce-credit-application-document])
we can transform it into code easily. Here is an example using core.match,
but maybe a little parser based on spec could be a better option ( will play with that when i have time ).
disclaimer: first time using core.match ;)
(defn from-dsl
[model dsl]
(reduce
(fn [acc [from _ to :as i]]
(m/match i
[_ :is-a :action] (dativity.define/add-entity-to-model acc (dativity.define/action from))
[_ :is-a :data] (dativity.define/add-entity-to-model acc (dativity.define/data from))
[_ :is-a :role] (dativity.define/add-entity-to-model acc (dativity.define/role from))
[_ :requires _] (dativity.define/add-relationship-to-model acc (dativity.define/action-requires from to))
[_ :produces _] (dativity.define/add-relationship-to-model acc (dativity.define/action-produces from to))
[_ :performs _] (dativity.define/add-relationship-to-model acc (dativity.define/role-performs from to))
:else "todo/look into errors"
))
model (map vec (partition 3 (map keyword dsl)))))
and used
(from-dsl (dativity.define/empty-case-model) case-model-dsl)
Here is a pic of this approach working in my live editor and visualising it using cytoscape so you can interactively create the graphs.
I will play also with adding visualization of process progress and adding a UI on top to perform actions etc...
Good idea, and nice code. I haven't used core.match either.
I agree that it is a little wordy right now. I can certainly add this feature.
One question though: what is the reason that you use a vector of symbols instead of, say, keywords?
I generally think dsl's can be a bit confusing and flakey. I'd rather be as close to the host language as possible when possible, and clojure makes this really easy.
There is now support for a less verbose way of creating the process model in a way similar to your proposal, thanks for the input! Check out the tests for examples.
Closing this issue.