Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting Activiti to “Talk” to an External Database Koorosh Vakhshoori Software Architect/Senior developer at Synopsys Inc.

Similar presentations


Presentation on theme: "Getting Activiti to “Talk” to an External Database Koorosh Vakhshoori Software Architect/Senior developer at Synopsys Inc."— Presentation transcript:

1 Getting Activiti to “Talk” to an External Database Koorosh Vakhshoori Software Architect/Senior developer at Synopsys Inc.

2 Agenda Activiti in Alfresco ‘talking’ to a database Use cases How to Unit Testing

3 Use Cases: Activiti DataBase Sending to DB Reporting Logging Dashboard Retrieving from DB Populating some form field Signal for action or NO action

4 Use Cases: Activiti DataBase Sending to DB Reporting Logging Dashboard Retrieving from DB Populating some form field Signal for action or NO action

5 A Simple Activiti Workflow

6

7 Activiti Solution: Leveraging alfresco-global.properties Spring Dependency Injection Apache BasicDataSource Spring JdbcTemplate Activiti User Task Listener Service Task

8 Activiti Solution: Leveraging alfresco-global.properties Spring Dependency Injection Apache BasicDataSource Spring JdbcTemplate Activiti User Task Listener Service Task

9 Activiti Leveraging Alfresco configuration... ### database connection properties ### external_db.driver=org.gjt.mm.mysql.Driver external_db.username=activiti_app external_db.password=activiti_password external_db.name=ext_db external_db.url=jdbc:mysql://localhost:3306/ext_db?useUnicode=yes &characterEncoding=UTF-8 alfresco-global.properties activiti-context.xml LogActionListener.java

10 Activiti Leveraging Dependency Injection - extDataSource... <bean id=“extDataSource“ class="org.apache.commons.dbcp.BasicDataSource“ destroy-method="close"> <property name="driverClassName“ value="${external_db.driver}"/>... alfresco-global.properties activiti-context.xml LogActionListener.java

11 Activiti Leveraging Dependency Injection - LogActionListener... <bean id=“extDataSource“...... <bean id="LogActionClass" parent="AbstractUserTaskDelegate" class="com.example.activiti.workflow.LogActionListener"> alfresco-global.properties activiti-context.xml LogActionListener.java

12 Activiti Leveraging – Listener Code Spring JdbcTemplate - 1 package com.example.workflow.listener; … public class LogTaskActionListener extends BaseJavaDelegate implements TaskListener { public void notify(DelegateTask task) { … String query = "INSERT INTO article_actions (user, article_id, action) VALUES (?, ?, ?)"; jdbcTemplate.update(query, new Object[] { userName, articleId, action }); } public void setExtDBSource(DataSource extDBSource) { this.jdbcTemplate = new JdbcTemplate(extDBSource); } alfresco-global.properties activiti-context.xml LogActionListener.java

13 Activiti Leveraging – Listener Code Spring JdbcTemplate - 2 package com.example.workflow.listener; … public class LogTaskActionListener extends BaseJavaDelegate implements TaskListener { public void notify(DelegateTask task) { … String query = "INSERT INTO article_actions (user, article_id, action) VALUES (?, ?, ?)"; jdbcTemplate.update(query, new Object[] { userName, articleId, action }); } public void setExtDBSource(DataSource extDBSource) { this.jdbcTemplate = new JdbcTemplate(extDBSource); } alfresco-global.properties activiti-context.xml LogActionListener.java

14 Activiti Unit Testing Challenges Keep it concise Has to be fast Focus on target code Make it light weight Photo from Flickr by Guy Sie

15 Activiti Unit Testing Inspiration Keep it simple Has to be fast Focus on target code Make it light weight Check out Alfresco test class: AbstractActivitiComponentTest

16 Unit Testing Components Junit framework Mock framework (mockito) Spring framework SpringJUnit4ClassRunner JdbcTemplate H2 database engine

17 Unit Testing Components Junit framework Mocking framework (mockito) Spring framework SpringJUnit4ClassRunner JdbcTemplate H2 database engine

18 Unit Testing Components Junit framework Mock framework (mockito) Spring framework SpringJUnit4ClassRunner JdbcTemplate H2 database engine

19 Unit Testing Components Junit framework Mock framework (mockito) Spring framework SpringJUnit4ClassRunner JdbcTemplate H2 database engine

20 Test Execution Flow Initialize H2 schema Record behavior (mock) Run test scenario Validate database table Drop table and cleanup

21 Test Execution Flow Initialize H2 schema Record behavior (mock) Run test scenario Validate database table Drop table and cleanup

22 Resources Blog Post on How to Implement http://vakhshoori.blogspot.com/2014/08/alfresco-activiti-talking- to-external.html http://vakhshoori.blogspot.com/2014/08/alfresco-activiti-talking- to-external.html Blog Post on How to test http://vakhshoori.blogspot.com/2014/08/junit-testing-alfresco- activiti-talking.html http://vakhshoori.blogspot.com/2014/08/junit-testing-alfresco- activiti-talking.html


Download ppt "Getting Activiti to “Talk” to an External Database Koorosh Vakhshoori Software Architect/Senior developer at Synopsys Inc."

Similar presentations


Ads by Google