Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Advanced Wiki Search

Table of
Contents...
Hide

Project Zero Developer’s Guide?

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout?
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging?
Dependencies?
Packaging?
Application classpath
Logging and tracing
RESTful resources?
RESTful documentation?
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools?
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

Project Zero resource model overview

The Zero resource model (ZRM) extension is a layer of abstraction between the REST and persistence. ZRM reduces the amount of boilerplate code that is repetitive for certain types of situational applications and simplifies resource handler development to a simple "model" definition. The typical resource-handler features, such as handlers for CRUD, persistence, and content negotiation are provided. ZRM is not yet complete, but there is enough function to demonstrate ZRM to collect feedback.

Objectives

The objectives of ZRM are to provide:

  • A constrained set of APIs that encourage a RESTful application architecture
  • A data model that maps well to REST and feeds
    • Default top-down data mapping scheme and automatic table creation
  • First class support for accessing data in a RESTful fashion both programmatically and using HTTP
    • Resources defined in the data model can be accessed via HTTP with no manual coding
  • First class support for accessing data as feeds
  • Robust frameworks for persistence, validation, and serialization

ZRM implements a significantly constrained REST model to liberate developer attention from mundane persistence details to the application. ZRM is not an attempt to introduce a general purpose ORM. For example, its data model is geared toward REST rather than to an arbitrary POJO model by asserting fundamental persistence assumptions.

Elements of ZRM

The ZRM programming model consists of the following parts:
Configuring ZRM
Setting up and configuring resource models
Resource model declaration
Declaring the data shape of the resource model
Programmatic Model API
Interacting with resource models using the programmatic model API
HTTP REST API
Interacting with resource models using the HTTP REST API

Configuring the Project Zero resource model

Configuring ZRM consists of the database configuration, Resource model declaration, and the resource event handler configuration. You can find an example ZRM application in the employee.resource.demo package in the Project Zero samples.

Resource model declaration

The Resource model declaration is a collection of resource definitions. It contains the definitions for fields, constraints, and filtered collections among other optional configuration. The resource definitions are datastore independent and can be shared across applications. They can be created and manipulated either declaratively or programmatically or using HTTP.

// Resource Model declaration
// File: /app/models/employees.groovy
fields = [ 
	name: [type: 'CharField', max_length:50],
	birthdate: [type: 'DateField'],
	state: [type: 'USStateField'],
	phone: [type: 'USPhoneField'],
]

Programmatic model API

The Model API allows accessing resources programmatically using collection-like constructs. In addition to the basic CRUD programming model, ZRM introduces a list-function and therefore we call this LCRUD model. The list function allows for listing and filtering collection members using simple conditions (for example, published_between: ['01-01-2003'..'12-31-2007']). A filter can be applied to a collection to create a new collection that is a subset of the original. The filter conditions can be passed in dynamically, therefore eliminating the need for writing a different service for each subset of the data that the client might need.

import zero.resource.TypeCollection
...
def employees =  TypeCollection.retrieve('employees')
def allEmployees = employees.list()
def employee = employees.retrieve(1)
def someEmployees = employees.list(firstname__contains: 'e')

HTTP REST API

The HTTP REST API is symmetrical to the programmatic API. The default result rendering is for JSON but other formats can also be specified, such as Atom, Basic XML, HTML, and microformats.

http://localhost:8081/resources/employees
http://localhost:8081/resources/employees/1
http://localhost:8081/resources/employees?firstname_contains=e

The HTTP access is not enabled by default. It can be enabled by introducing a resource event handler that, in its simplest form, delegates the HTTP requests to a system-provided ZRM handler with only one line of application code.

r20 - 09 Feb 2008 - 17:56:23 - paynel
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site