KEMBAR78
Alfresco Mvc - a seamless integration with Spring Mvc | PPTX
Alfresco Mvc
a seamless integration
with Spring Mvc
Daniel Gradečak
Learn. Connect. Collaborate.
Who am I
• Daniel Gradečak
• Analyst Developer
• Alfresco experience 12y+
• And I am not a webscript fan 
Learn. Connect. Collaborate.
Why I do not like webscripts?
• A user needs to be able to
– Get a person
– Save a person
– ...
• For each feature
– desc.xml
– ftl
– java/javascript controller
– xml config
Learn. Connect. Collaborate.
Why I do not like webscripts?
• There is quite a lot of configurations
• Difficult to change / maintain
• Difficult to unit test
Learn. Connect. Collaborate.
What if we could code like this ...
@Controller
@RequestMapping("/person")
public class PersonController {
@RequestMapping(value = "{id}", method = { RequestMethod.GET })
public ResponseEntity<?> get(@PathVariable Long id) {
return new ResponseEntity<>(..., HttpStatus.OK);
}
@RequestMapping(value = "{id}", method = { RequestMethod.POST })
public ResponseEntity<?> save(@RequestBody final Map<String, String> body) {
return new ResponseEntity<>(..., HttpStatus.OK);
}
}
And the response would be json:
HTTP Status 200 – {username:test, groups:[]}
... instead of Webscripts.
1
Learn. Connect. Collaborate.
What if we could code like this ...
@Controller
@RequestMapping("/person")
public class PersonController {
@RequestMapping(value = "{id}", method = { RequestMethod.GET })
public ResponseEntity<?> get(@PathVariable Long id) {
return new ResponseEntity<>(..., HttpStatus.OK);
}
@RequestMapping(value = "{id}", method = { RequestMethod.POST })
public ResponseEntity<?> save(@RequestBody final Map<String, String> body) {
return new ResponseEntity<>(..., HttpStatus.OK);
}
}
And the response would be json:
HTTP Status 200 – {username:test, groups:[]}
... instead of Webscripts.
Learn. Connect. Collaborate.
What is Alfresco MVC?
• A set of 3 independent libraries
– REST => Spring MVC
– AOP => Simple and easy Spring AOP for Alfresco
– QueryTemplate => Helper inspired by Spring’s JdbcTemplate
Learn. Connect. Collaborate.
Alfresco MVC REST is ... a webscript
• The missing glue between Alfresco and Spring MVC
• DispatcherWebscript is the entry point
– forwards requests to spring’s DispatcherServlet (servlet-context)
• Default configuration provided (alfresco/service/mvc)
Learn. Connect. Collaborate.
Alfresco MVC REST is ... a webscript
• The missing glue between Alfresco and Spring MVC
• DispatcherWebscript is the entry point
– forwards requests to spring’s DispatcherServlet (servlet-context)
• Default configuration provided (alfresco/service/mvc)
2
Learn. Connect. Collaborate.
Alfresco MVC REST - howto
• Configure once
– xml
– java config
• Write Spring controllers
– json responses
– spring interceptors
– spring exception handlers
Learn. Connect. Collaborate.
Alfresco MVC REST - howto
• Configure once
– xml
– java config
• Write Spring controllers
– json responses
– spring interceptors
– spring exception handlers
Learn. Connect. Collaborate.
Alfresco MVC REST – testing APIs
• MvcMock
• Spring rest docs
• MockWebscriptBuilder
Learn. Connect. Collaborate.
Alfresco MVC AOP is ...
• Simple Spring AOP for Alfresco
– @AlfrescoTransaction
– @AlfrescoAuthentication
– @AlfrescoRunAs
3
Learn. Connect. Collaborate.
Alfresco MVC AOP
• Very often we write such code
• It could be a simple annotation
Learn. Connect. Collaborate.
Alfresco MVC – with AOP
• Enhances
– Controllers
– Services
• Simple transaction handling
• Easy RunAs
• on Controllers or Services
Learn. Connect. Collaborate.
Alfresco MVC QueryTemplate is ...
• Type safe queries
• ORM for Alfresco nodes
– QueryBuilder / QueryTemplate
• The mapper could be used with „Canned Queries”
Learn. Connect. Collaborate.
Do people use it?
• companies and organizations
– small and large
• Freelancers
• The library is in production for more than 7 years
4
Learn. Connect. Collaborate.
Should you use it? (of course you should)
• When
– You need custom APIs
– You want to be more productive
– You write custom webscripts
• Why
– Faster development
– Java developers know how to use Spring MVC
– Reuses a widely accepted „REST framework”
=> Works on Community and on Enterprise
Learn. Connect. Collaborate.
Should you use it? (of course you should)
• When
– You need custom APIs
– You want to be more productive
– You write custom webscripts
• Why
– Faster development
– Java developers know how to use Spring MVC
– Reuses a widely accepted „REST framework”
=> Works on Community and on Enterprise
Learn. Connect. Collaborate.
How to use it?
• Distributed as jars / not amp
• Include the jar(s) from maven central
• Check out the samples at
– github.com/dgradecak/alfresco-mvc-sample
Learn. Connect. Collaborate.
Find out more …
• On github
– github.com/dgradecak/alfresco-mvc
• Or ping me at
– daniel@pleosoft.com
– Twitter @gradecak
– irc: dgradecak
Alfresco Mvc
a seamless integration
with Spring Mvc
Thank you!

Alfresco Mvc - a seamless integration with Spring Mvc

  • 1.
    Alfresco Mvc a seamlessintegration with Spring Mvc Daniel Gradečak
  • 2.
    Learn. Connect. Collaborate. Whoam I • Daniel Gradečak • Analyst Developer • Alfresco experience 12y+ • And I am not a webscript fan 
  • 3.
    Learn. Connect. Collaborate. WhyI do not like webscripts? • A user needs to be able to – Get a person – Save a person – ... • For each feature – desc.xml – ftl – java/javascript controller – xml config
  • 4.
    Learn. Connect. Collaborate. WhyI do not like webscripts? • There is quite a lot of configurations • Difficult to change / maintain • Difficult to unit test
  • 5.
    Learn. Connect. Collaborate. Whatif we could code like this ... @Controller @RequestMapping("/person") public class PersonController { @RequestMapping(value = "{id}", method = { RequestMethod.GET }) public ResponseEntity<?> get(@PathVariable Long id) { return new ResponseEntity<>(..., HttpStatus.OK); } @RequestMapping(value = "{id}", method = { RequestMethod.POST }) public ResponseEntity<?> save(@RequestBody final Map<String, String> body) { return new ResponseEntity<>(..., HttpStatus.OK); } } And the response would be json: HTTP Status 200 – {username:test, groups:[]} ... instead of Webscripts. 1
  • 6.
    Learn. Connect. Collaborate. Whatif we could code like this ... @Controller @RequestMapping("/person") public class PersonController { @RequestMapping(value = "{id}", method = { RequestMethod.GET }) public ResponseEntity<?> get(@PathVariable Long id) { return new ResponseEntity<>(..., HttpStatus.OK); } @RequestMapping(value = "{id}", method = { RequestMethod.POST }) public ResponseEntity<?> save(@RequestBody final Map<String, String> body) { return new ResponseEntity<>(..., HttpStatus.OK); } } And the response would be json: HTTP Status 200 – {username:test, groups:[]} ... instead of Webscripts.
  • 7.
    Learn. Connect. Collaborate. Whatis Alfresco MVC? • A set of 3 independent libraries – REST => Spring MVC – AOP => Simple and easy Spring AOP for Alfresco – QueryTemplate => Helper inspired by Spring’s JdbcTemplate
  • 8.
    Learn. Connect. Collaborate. AlfrescoMVC REST is ... a webscript • The missing glue between Alfresco and Spring MVC • DispatcherWebscript is the entry point – forwards requests to spring’s DispatcherServlet (servlet-context) • Default configuration provided (alfresco/service/mvc)
  • 9.
    Learn. Connect. Collaborate. AlfrescoMVC REST is ... a webscript • The missing glue between Alfresco and Spring MVC • DispatcherWebscript is the entry point – forwards requests to spring’s DispatcherServlet (servlet-context) • Default configuration provided (alfresco/service/mvc) 2
  • 10.
    Learn. Connect. Collaborate. AlfrescoMVC REST - howto • Configure once – xml – java config • Write Spring controllers – json responses – spring interceptors – spring exception handlers
  • 11.
    Learn. Connect. Collaborate. AlfrescoMVC REST - howto • Configure once – xml – java config • Write Spring controllers – json responses – spring interceptors – spring exception handlers
  • 12.
    Learn. Connect. Collaborate. AlfrescoMVC REST – testing APIs • MvcMock • Spring rest docs • MockWebscriptBuilder
  • 13.
    Learn. Connect. Collaborate. AlfrescoMVC AOP is ... • Simple Spring AOP for Alfresco – @AlfrescoTransaction – @AlfrescoAuthentication – @AlfrescoRunAs 3
  • 14.
    Learn. Connect. Collaborate. AlfrescoMVC AOP • Very often we write such code • It could be a simple annotation
  • 15.
    Learn. Connect. Collaborate. AlfrescoMVC – with AOP • Enhances – Controllers – Services • Simple transaction handling • Easy RunAs • on Controllers or Services
  • 16.
    Learn. Connect. Collaborate. AlfrescoMVC QueryTemplate is ... • Type safe queries • ORM for Alfresco nodes – QueryBuilder / QueryTemplate • The mapper could be used with „Canned Queries”
  • 17.
    Learn. Connect. Collaborate. Dopeople use it? • companies and organizations – small and large • Freelancers • The library is in production for more than 7 years 4
  • 18.
    Learn. Connect. Collaborate. Shouldyou use it? (of course you should) • When – You need custom APIs – You want to be more productive – You write custom webscripts • Why – Faster development – Java developers know how to use Spring MVC – Reuses a widely accepted „REST framework” => Works on Community and on Enterprise
  • 19.
    Learn. Connect. Collaborate. Shouldyou use it? (of course you should) • When – You need custom APIs – You want to be more productive – You write custom webscripts • Why – Faster development – Java developers know how to use Spring MVC – Reuses a widely accepted „REST framework” => Works on Community and on Enterprise
  • 20.
    Learn. Connect. Collaborate. Howto use it? • Distributed as jars / not amp • Include the jar(s) from maven central • Check out the samples at – github.com/dgradecak/alfresco-mvc-sample
  • 21.
    Learn. Connect. Collaborate. Findout more … • On github – github.com/dgradecak/alfresco-mvc • Or ping me at – daniel@pleosoft.com – Twitter @gradecak – irc: dgradecak
  • 22.
    Alfresco Mvc a seamlessintegration with Spring Mvc Thank you!

Editor's Notes

  • #3 Hi and thank you for being here guys I am Daniel Gradečak "do not try to pronounce it” And my usual day to day job is developing business applications I usually like thinking that development should be fun
  • #4 Not sure about you but for me using webscripts is no fun anymore, actually it has never been People often ask me "why don't you like them?„ The main reason is the boilerplate configuration
  • #5 Quickly, it becomes difficult to maintain a project. And since I am developing many custom applications based on custom UI I need a simple way of creating REST services on top of Alfresco
  • #6  Many times the existing APIs are simply not enough or not good enough for what is needed to get the job done. So now, imagine that we could code like this on the repository side
  • #7 Using spring controllers and the full MVC stack with json responses for instance Where we use the benefit of webscripts but without coding them That is why I developed Alfresco MVC
  • #8 So, Alfresco MVC is a set of 3 small libraries - REST - AOP Query Template Each of them solves a different problem As there is not much time I will try to give a quick overview of each.
  • #9  So Alfresco MVC rest could be defined as the missing glue between Alfresco and Spring MVC However, before continuing, I have to appologize As The main entry is a webscript
  • #10  and acts as a proxy to spring's DispatcherServlet Since it is a webscript there is no need to configure anything in web.xml in order to enable Spring’s servlet By default we provide a default mapping that points to /mvc
  • #11 With this approach we can simply configure one webscript in xml or in java config and during the development time, we do not need to comeback to any new webscript configuration
  • #12 But we could simply concentrate on our application's buisness logic and just write new controller methods With usual spring features like interceptors, exception handlers that make our code better and cleaner.
  • #13 Those controllers could be tested as we would test a normal spring MVC application And if we want we could write spring rest docs or swagger documentation We also provide a nice mock builder for testing pure webscripts
  • #14 We now move to the AOP part. In short it is a set of annotations that make a developer's life easier We know that Alfresco uses a lot of AOP within XML and that is quite difficult to configure
  • #15 With this library we could easily enable the most frequently needed behaviors I am talking about those features Transactions Runas Where we have to write quite a lot of code that is not really readable
  • #16 So with simple annotations we could Enhance our classes with spring AOP and make our code cleaner and especially less boilerplate as on the previous slide Of course it could be enabled via XML or with java annotations
  • #17 A quick word about the QueryTemplate helper It helps in writting type safe queries and acts as an object relationship mapper for alfresco nodes This library has a similar behavior to Spring's JDBCTemplate
  • #18 Now if you wonder if anyone uses this I can tell you yes Large and small companies use it as well as freelancers It is being used in production for 7 years now
  • #19 The next question would be „should I use it”? Well, one of the biggest issue I have is when a new Java developer needs to start developing in Alfresco There is a long learning curve of the "webscript technology" and people tend to resist to it
  • #20 For most of Java developers webscripts are quite painfull oposed to Spring MVC So yes, I think that you should use this approach whenever you need to write any custom REST service Or simply if you want to be more productive in development Remember that it works on both Enterprise and Community
  • #21 All this is distrubuted as jar files and is accessible on maven central There are samples on github that could help you start with Alfresco MVC
  • #22 if you want to find out more check out our git repository Or simply ping me ...