plat-10 actions & behaviors

27
Actions and Behaviors Roy Wetherall – Founding Engineer - @rwetherall

Upload: alfresco-software

Post on 19-Jul-2015

1.150 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: PLAT-10 Actions & Behaviors

Actions and Behaviors!

Roy Wetherall – Founding Engineer - @rwetherall!

Page 2: PLAT-10 Actions & Behaviors

Agenda!

1.  Breaking it Down!2.  Behaviours!3.  Actions!4.  Demo!5.  Questions!

Page 3: PLAT-10 Actions & Behaviors

Breaking It Down!

Page 4: PLAT-10 Actions & Behaviors

Why Actions and Behaviours?!

Extend beyond content models.

Make extensions smarter. Encapsulate features.

React to changes.

Page 5: PLAT-10 Actions & Behaviors

Sum of the Parts ...!

Content Model +

Behaviours +

Actions =

Smart Repository Extension

Page 6: PLAT-10 Actions & Behaviors

Breaking it down ...!

Content Model – data structure and constraints

Behaviours – interactions, consequences and restrictions

Actions – execution

Page 7: PLAT-10 Actions & Behaviors

Behaviours!

Page 8: PLAT-10 Actions & Behaviors

Architecture!

Page 9: PLAT-10 Actions & Behaviors

Binding Behaviours!

Page 10: PLAT-10 Actions & Behaviors

Different Types Of Bindings!

Service – called every time Class – most common, bound to type or

aspect Association – bound to association, useful

for adding smarts to custom hierarchies

Properties – bound to property, too granular

Page 11: PLAT-10 Actions & Behaviors

Code Example – Java Behaviour!

Bind class behaviour. Java implementation.

Execute behaviour when aspect is added.

e.g. Initialise property with calculated value.

@see IdentifiableAspectPartOne.java

Page 12: PLAT-10 Actions & Behaviors

Notification Frequencies!

Every Time

First Event Transaction Commit

Page 13: PLAT-10 Actions & Behaviors

JavaScript Behaviours!

More accessible for developers.

Greater flexibility. Common Script API.

Spring configurable. No Java code!

Page 14: PLAT-10 Actions & Behaviors

Code Example – JavaScript !

Add identifiable aspect to content. JavaScript implementation.

Special ‘behaviour’ object available. Spring configured.

@see onCreateChildAssociation_cmContent_cmContains.js

Page 15: PLAT-10 Actions & Behaviors

Common uses for behaviours ... !!

Built in “rules”. Service call-back extension points.

Calculated properties. Complex constraints.

Auto-casting.

A model with behaviour is a “Smart Model”.

Page 16: PLAT-10 Actions & Behaviors

Code Example – Copy Service Callback!

Define custom behaviour copy. Ensures id is not duplicated.

New id defined on copy. Technique can be used to prevent aspects

being copied all.

See @IdentifiableAspectPartTwo.java

Page 17: PLAT-10 Actions & Behaviors

Code Example – Model Restrictions !

Behaviours can throw exceptions. Runtime exceptions rollback transactions. Can be used to enforce model constraints

(e.g. read only properties).

See @IdentifiableAspectPartThree.java

Page 18: PLAT-10 Actions & Behaviors

Behaviour Filter Bean!

Enable and disable behaviours from other services.

By type and/or node. Per transaction.

Enable/disable all.

See @BehaviourFilter.java

Page 19: PLAT-10 Actions & Behaviors

Actions!

Page 20: PLAT-10 Actions & Behaviors

What is an Action?!

Unit of work. Executed in the repository.

Passed parameters, return value. Sync or async execution.

Puts the ‘do’ in API. Reusable.

Alfresco implementation of the GoF “Command” pattern

Page 21: PLAT-10 Actions & Behaviors

Architecture!

Page 22: PLAT-10 Actions & Behaviors

Anatomy of an Action!

Page 23: PLAT-10 Actions & Behaviors

Code Example - Executing An Action!

Notify author when Identifiable node is deleted.

Execute custom action from behaviour. Use action service.

@see IdentifiableAspect.java

Page 24: PLAT-10 Actions & Behaviors

Custom Actions!

Extend built-in actions. Implemented in Java or JavaScript.

Available in Share UI. Executable as rules.

Custom conditions implemented in the same way.

Convenient way to execute asynchronous work.

Page 25: PLAT-10 Actions & Behaviors

Code Example – Custom Action !

Custom Java action. Notifies author via email. Configured using Spring.

Private action, does not appear in UI.

See @DeleteNotificationActionExecuter.java

Page 26: PLAT-10 Actions & Behaviors

Putting It All Together(or a quick demo in Share 4.0)!

Page 27: PLAT-10 Actions & Behaviors

Questions?!