introduction to a groovy based dsl for apache ofbiz...ofbiz committer since before the project...

34
Introduction to a Groovy based DSL for Apache OFBiz Jacopo Cappellato

Upload: others

Post on 19-Jul-2020

31 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Introduction to a Groovy based

DSL for Apache OFBiz™

Jacopo Cappellato

Page 2: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

“How to write better business logic code

with the new OFBiz DSL”

Presented by Jacopo Cappellato

OFBiz committer since before the project joined the ASF (2006) ASF member since 2007

OFBiz PMC Chair since 2010 VP Technology at HotWax Media www.hotwaxmedia.com

Email: [email protected] or [email protected]

Page 3: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Outline

11/17/2014 3

• Introduction to the business logic in OFBiz

– Business logic contexts

– Languages currently adopted

• Introduction to the OFBiz DSL

• Language comparison by examples

• Summary and references

Page 4: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Introduction to the business logic in OFBiz

Page 5: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Business logic contexts in OFBiz and

languages currently adopted

11/17/2014 5

Contexts

Services

Events

Data Preparation

Scriptlets

Page 6: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Business logic contexts in OFBiz and

languages currently adopted

11/17/2014 6

Contexts

Services

Events

Data Preparation

Scriptlets

Languages

Java

Groovy

Minilang

Page 7: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

From different languages for different

contexts…

11/17/2014 7

Minilang

• Services

• Events

Java

• Services

• Events

Groovy

• Data preparation

• Scriptlets

Page 8: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

… to one language for all the contexts.

11/17/2014 8

OFBiz DSL

• Services

• Events

• Data preparation

• Scriptlets

Page 9: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Introduction to the OFBiz DSL

Page 10: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Definitions

11/17/2014 10

• Domain Specific Language

– “A Domain Specific Language (DSL) is a

programming language designed specifically to

express solutions to problems in a specific

domain”

• OFBiz DSL

– A simple Groovy-based DSL for the

implementation of business logic in OFBiz

(events, services, data preparation scripts,

scriptlets)

Page 11: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

The OFBiz DSL as an evolution of the

existing languages used in OFBiz

OFBiz DSL

Minilang

Java

Groovy

11/17/2014 The OFBiz DSL brings together into one unified language all the

powerful features of Java, Groovy and Minilang 11

Page 12: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

How to use the OFBiz DSL

11/17/2014 12

• Full support available in the OFBiz trunk

• All Groovy code in OFBiz is already enabled to use the DSL

– Services • engine=“groovy”

– Events • type="groovy”

– Data preparation scripts • *.groovy

– Scriptlets • ${groovy:

Page 13: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

How to implement OFBiz DSL code

11/17/2014 13

• DSL methods currently available

– Service operations • runService

– Entity operations • findOne, findList, makeValue, select, from

– Results • success, failure, error

– Logging • logInfo, logWarning, logError

• In evolution

Page 14: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Language comparison by examples

Page 15: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service method definitions

11/17/2014 15

Page 16: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service method definitions

11/17/2014 16

Page 17: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service method definitions

11/17/2014 17

Page 18: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Logging

11/17/2014 18

Page 19: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Logging

11/17/2014 19

Page 20: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Logging

11/17/2014 20

Page 21: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Arithmetic operations

11/17/2014 21

Page 22: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Arithmetic operations

11/17/2014 22

Page 23: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service calls

11/17/2014 23

Page 24: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service calls

11/17/2014 24

Page 25: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service calls

11/17/2014 25

Page 26: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service calls

11/17/2014 26

Page 27: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Service calls

11/17/2014 27

Page 28: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Database operations

11/17/2014 28

Page 29: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Database operations

11/17/2014 29

Page 30: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Database operations

11/17/2014 30

Page 31: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Summary and references

Page 32: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Highlights of OFBiz DSL features

11/17/2014 32

• Available in all the contexts (events, services, data

preparation, scriptlets)

• Clean and simple API (in evolution)

• Powerful programming language (Groovy)

• Programming by exception pattern:

– “Unless specified differently, the framework will apply the default

rules”

• Automatic context detection

– return success()

• Automatic parameter detection (e.g. userLogin)

– runSync(‘createProduct’, [productId:’TEST-PRODUCT’])

• Transparent error and db transaction handling

Page 33: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

Next steps

11/17/2014 33

• Migrating Java/Minilang/Groovy code

• Testing and bug fixing

• Enhancing the OFBiz DSL

• IDE integration (Eclipse, IntelliJ available)

Page 34: Introduction to a Groovy based DSL for Apache OFBiz...OFBiz committer since before the project joined the ASF (2006) ASF member since 2007 OFBiz PMC Chair since 2010 VP Technology

References

11/17/2014 34

• Further information (and code samples):

– https://cwiki.apache.org/confluence/x/_M_oAQ

• Apache OFBiz website:

– http://ofbiz.apache.org

• Emails:

[email protected]

[email protected] • Trademarks

– Apache OFBiz, Apache are trademarks of The Apache Software Foundation

– Java is a registered trademark of Oracle and/or its affiliates

– Groovy is a registered trademark of The Codehaus