Seaside: A Glance at MetaData and REST

Damien Cassou, St├ęphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

Magritte: Taking Advantages of MetaData

Address

Address Description

Describe

Address >> descriptionStreet
   ^ MAStringDescription new
        autoAccessor: #street;
        label: 'Street';
        priority: 100

Address >> descriptionPlz
   ^ MANumberDescription new
        autoAccessor: #plz;
        priority: 200; label: 'PLZ';
        beRequired;
        min: 1000; 
        max: 9999

Interpret

anAddress description do: [ :description |
   Transcript
       show: description label; show: ':'; tab;
       show: (description toString: (anAddress readUsing: description));
       cr ]
Street:	Schutzenmattstrasse
PLZ:	3012
Place:	Bern
Canton:	Bern

Generate Forms

self call: (anAddress asComponent addValidatedForm; yourself)

Generate Automatic Reports

Seaside-REST

Filter Definition

WARestfulFilter subclass: #TBRestfulFilter
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'TinyBlog-REST'
TBApplicationRootComponent class >> initialize
	   "self initialize"
	   | app |
	   app := WAAdmin register: self asApplicationAt: 'TinyBlog'.
	   app
	      addLibrary: JQDeploymentLibrary;
	      addLibrary: JQUiDeploymentLibrary;
	      addLibrary: TBSDeploymentLibrary.
	   app addFilter: TBRestfulFilter new.

Getting All Blogs

Getting All blogs

TBRestfulFilter >> listAll
  <get>
  <produces: 'text/json'>

  ^ String streamContents: [ :astream | 
  		TBBlog current allBlogPosts
			do: [ :each | each javascriptOn: stream ]
			separatedBy: [ stream << ',' ] ] 

Finding a Blog

Finding a Blog

TBRestfulFilter >> post: title
  <get>
  <path: 'post/{title}'>
  <produces: 'text/json'>
  | post |
  post := TBBlog current postWithTitle: title.
  post ifNil: [ ^ self notFound ]. 
  ^ String streamContents: [ :astream | 
         post javascriptOn: astream ]

With Search

TBRestfulFilter >> search: title
   <get>
   <path: 'search?title={title}'>
   <produces: 'text/json'>
   | post |
   post := TBBlog current postWithTitle: title.
   post ifNil: [ ^ self notFound ]. 
   ^ String streamContents: [ :astream | 
		post javascriptOn: astream attributes: #(title category date text) ]
http://localhost:8080/TinyBlog/search?title=Welcome%20in%20TinyBlog

Conclusion

/