ERXStandardRestEntityDelegate Class Reference

Inherits er::rest::entityDelegates::ERXAbstractRestEntityDelegate.

Inherited by ERXUnsafeReadOnlyRestEntityDelegate, and ERXUnsafeRestEntityDelegate.

Collaboration diagram for ERXStandardRestEntityDelegate:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void addInsertPropertyName (String entityName, String insertPropertyName)
void addUpdatePropertyName (String entityName, String updatePropertyName)
void addViewPropertyName (String entityName, String visiblePropertyName)
boolean canInsertProperty (EOEntity entity, EOEnterpriseObject eo, String propertyName, ERXRestContext context)
boolean canUpdateProperty (EOEntity entity, EOEnterpriseObject eo, String propertyName, ERXRestContext context)
boolean canViewProperty (EOEntity entity, Object obj, String propertyName, ERXRestContext context)
String entityAliasForEntityNamed (String entityName)
 ERXStandardRestEntityDelegate (String entityName)
 ERXStandardRestEntityDelegate (String entityName, boolean detailsPropertiesAreViewProperties)
 ERXStandardRestEntityDelegate ()
void inserted (EOEntity entity, EOEnterpriseObject eo, ERXRestContext context) throws ERXRestException, ERXRestSecurityException
EOEntity nextEntity (EOEntity entity, String key)
String propertyAliasForPropertyNamed (EOEntity entity, String propertyName)
String propertyNameForPropertyAlias (EOEntity entity, String propertyAlias)
void setDefaultIDAttributeName (String defaultIDAttributeName)
void updated (EOEntity entity, EOEnterpriseObject eo, ERXRestContext context) throws ERXRestException, ERXRestSecurityException

Protected Member Functions

String defaultIDAttributeName ()
boolean hasViewProperties ()
String idAttributeName (EOEntity entity)
void loadDetailsPropertiesAsViewPropertiesForEntityNamed (String entityName)
void loadInsertPropertiesForEntityNamed (String entityName)
void loadUpdatePropertiesForEntityNamed (String entityName)
void loadViewPropertiesForEntityNamed (String entityName)
EOQualifier qualifierFromContext (ERXRestContext context)
NSArray< EOSortOrdering > sortOrderingsFromContext (ERXRestContext context)
void updatePropertyAliasForPropertyNamed (String entityName, String propertyName)

Private Attributes

String _defaultIDAttributeName
NSMutableSet< String_insertPropertyNames
NSMutableDictionary< String,
String
_propertyAliasForPropertyName
NSMutableDictionary< String,
String
_propertyNameForPropertyAlias
NSMutableSet< String_updatePropertyNames
NSMutableSet< String_viewPropertyNames


Detailed Description

ERXStandardRestEntityDelegate provides additional implementations of methods above and beyond ERXAbstractRestEntityDelegate.

In particular it adds support for loading certain common configuration out of your application Properties file, including:

Entity Aliases

Entity aliases allow you to remap the name of entity from its actual internal name to some other name that is shown to consumers of your service:

 ERXRest.[EntityName].alias=SomeOtherName
 

For example:

 ERXRest.Person.alias = Employee
 

In the above example, our entity is named Person, but we want users of our service to see it named "Employee."

Property Aliases

Just like entity aliases, it is often desirable to be able to rename properties of your entity for use externally. Property aliases provide a mechanism to do this, and ERXStandardRestEntityDelegate allows you to define these mappings in your Application properties file.

 ERXRest.[EntityName].[propertyName].alias=someOtherName
 

For example:

 ERXRest.Person.displayName.alias = name
 

In the above example, the we are saying that the "displayName" property of the "Person" entity should be called "name" to users of the service. The entity name in this property should be the actual entity name, not the entity alias if one exists.

View/Update/Insert Properties

There are three types of properties you can control: view, update, and insert. View properties are the set of properties (keys, attributes, relationships, etc) that a particular caller is allowed to view on an object. Insert properties are the properties that a caller is allowed to specify at creation time for a new object. Update properties are the properties that a caller is allowed to update during an update request. Insert and update properties are implicitly view properties, and update properties are implicitly insert properties.

Note that all properties that appear in a properties definition should be "actual" property names, not property aliases. Similarly, all entity names should be the actual entity names and not entity aliases.

If you have already ERXXmlRestResponseWriter (if not, you should), you know that it can define a set of properties that CAN be displayed to your users for any particular entity or keypath (the "detailsProperties"). The properties defined for the renderer only define what the user can possibly see -- it does not deal with security, which is the entity delegate's responsibility. So it is possible to declare that the renderer should show "firstName,lastName,email" for a Person in details, but your view properties may only allow you to see "firstName".

This implementation provides a simple way to define view, insert, and update properties for an entity. These definitions, by default, are fixed for any use of the entity by any user. If you want to dynamically adjust what keypaths users can view, insert, and update based on some more complicated permissions structure, then you can either override the corresponding methods, or extend ERXAbstractRestEntityDelegate instead of this implementation.

Because the view properties are not dynamic by default, it is a common desire to use the detailsProperties declaration from ERXXmlRestResponseWriter as the view properties also. To do this, you can use the the ERXStandardRestEntityDelegate(String entityName) variant of the constructor, or you can use the ERXStandardRestEntityDelegate() constructor and manually call loadDetailsPropertiesAsViewPropertiesForEntityNamed(String entityName) and it will automatically make all details properties view properties.

To define view, insert, and update properties in your Application's Properties file, you can declare:

 ERXRest.[EntityName].viewProperties=property1,property2,property3,...
 ERXRest.[EntityName].insertProperties=property1,property2,property3,...
 ERXRest.[EntityName].updateProperties=property1,property2,property3,...
 

For example:

 ERXRest.BlogPost.viewProperties=author,title,submissionDate,contents
 ERXRest.BlogPost.insertProperties=author,title,contents
 ERXRest.BlogPost.updateProperties=title,contents
 

In the above example, we allow users to see the author, title, submissionDate and contents properties of a BlogPost. However, when they insert, we want to automatically set "submissionDate", so we do not allow that property. Additionally we don't want to allow users to change the original author of a post (note this example is a bit contrived), so we don't include "author" key in the updateProperties.

Author:
mschrag

Constructor & Destructor Documentation

Constructs an ERXStandardRestEntityDelegate without an explicit entity reference. loadDetailsPropertiesAsViewPropertiesForEntityNamed, loadViewPropertiesForEntityNamed, loadUpdatePropertiesForEntityNamed, and loadInsertPropertiesForEntityNamed will NOT be called.

ERXStandardRestEntityDelegate ( String  entityName,
boolean  detailsPropertiesAreViewProperties 
)

Constructs an ERXStandardRestEntityDelegate with an explicit entity name, optionally loading details properties as view properties. Additionally, loadViewPropertiesForEntityNamed, loadUpdatePropertiesForEntityNamed, and loadInsertPropertiesForEntityNamed WILL be called.

Parameters:
entityName the name of the entity that this delegate represents
detailsPropertiesAreViewProperties if true, .detailsProperties will be loaded as .viewProperties

ERXStandardRestEntityDelegate ( String  entityName  ) 

Constructs an ERXStandardRestEntityDelegate with an explicit entity name, and WILL load details properties as view properties. Additionally, loadViewPropertiesForEntityNamed, loadUpdatePropertiesForEntityNamed, and loadInsertPropertiesForEntityNamed WILL be called.

Parameters:
entityName the name of the entity that this delegate represents


Member Function Documentation

void addInsertPropertyName ( String  entityName,
String  insertPropertyName 
)

Adds an insert property for the specified entity.

Parameters:
entityName the name of the entity
insertPropertyName the name of the insert property

void addUpdatePropertyName ( String  entityName,
String  updatePropertyName 
)

Adds an update property for the specified entity.

Parameters:
entityName the name of the entity
updatePropertyName the name of the update property

void addViewPropertyName ( String  entityName,
String  visiblePropertyName 
)

Adds a view property for the specified entity.

Parameters:
entityName the name of the entity
visiblePropertyName the name of the view property

boolean canInsertProperty ( EOEntity  entity,
EOEnterpriseObject  eo,
String  propertyName,
ERXRestContext  context 
) [virtual]

Returns true if propertyName is declared as an insert property.

Parameters:
entity the entity
eo the object to check
propertyName the property name to check
context the rest context
Returns:
true if propertyName is declared as an insert property

Implements IERXRestSecurityDelegate.

Reimplemented in ERXUnsafeReadOnlyRestEntityDelegate, and ERXUnsafeRestEntityDelegate.

boolean canUpdateProperty ( EOEntity  entity,
EOEnterpriseObject  eo,
String  propertyName,
ERXRestContext  context 
) [virtual]

Returns true if propertyName is declared as an update property.

Parameters:
entity the entity
eo the object to check
propertyName the property name to check
context the rest context
Returns:
true if propertyName is declared as an update property

Implements IERXRestSecurityDelegate.

Reimplemented in ERXUnsafeReadOnlyRestEntityDelegate, and ERXUnsafeRestEntityDelegate.

boolean canViewProperty ( EOEntity  entity,
Object  obj,
String  propertyName,
ERXRestContext  context 
) [virtual]

Returns true if propertyName is declared as a view property.

Parameters:
entity the entity
obj the object to check
propertyName the property name to check
context the rest context
Returns:
true if propertyName is declared as a view property

Implements IERXRestSecurityDelegate.

Reimplemented in ERXUnsafeReadOnlyRestEntityDelegate, and ERXUnsafeRestEntityDelegate.

String defaultIDAttributeName (  )  [protected]

Returns the default "id" attribute name for all entities.

Returns:
the default "id" attribute name for all entities

String entityAliasForEntityNamed ( String  entityName  ) 

Returns the entity alias for the given entity name. This looks in the ERXRest.[EntityName].alias property. If not found, entityName is returned.

Parameters:
entityName the name of the entity
Returns:
the entity alias

Reimplemented from ERXAbstractRestEntityDelegate.

boolean hasViewProperties (  )  [protected]

Returns whether or not there are any view properties.

Returns:
whether or not there are any view properties

String idAttributeName ( EOEntity  entity  )  [protected]

Reimplemented from ERXAbstractRestEntityDelegate.

void inserted ( EOEntity  entity,
EOEnterpriseObject  eo,
ERXRestContext  context 
) throws ERXRestException, ERXRestSecurityException [virtual]

Default empty implementation. Extend to do custom insertion processing for the object.

Parameters:
entity the entity of the object
eo the inserted object
context the rest context
Exceptions:
ERXRestException if a general error occurs
ERXRestSecurityException if a security exception occurs

Implements ERXAbstractRestEntityDelegate.

Reimplemented in ERXUnsafeReadOnlyRestEntityDelegate.

void loadDetailsPropertiesAsViewPropertiesForEntityNamed ( String  entityName  )  [protected]

Loads the details properties for the specified entity from the configuration for ERXXmlRestResponseWriter and calls addViewPropertyName for each.

Parameters:
entityName the name of the entity to load properties for

void loadInsertPropertiesForEntityNamed ( String  entityName  )  [protected]

Loads the insert properties for the specified entity from the property ERXRest.[EntityName].insertProperties and calls addInsertPropertyName for each.

Parameters:
entityName the name of the entity to load properties for

void loadUpdatePropertiesForEntityNamed ( String  entityName  )  [protected]

Loads the update properties for the specified entity from the property ERXRest.[EntityName].updateProperties and calls addUpdatePropertyName for each.

Parameters:
entityName the name of the entity to load properties for

void loadViewPropertiesForEntityNamed ( String  entityName  )  [protected]

Loads the view properties for the specified entity from the property ERXRest.[EntityName].viewProperties and calls addViewPropertyName for each.

Parameters:
entityName the name of the entity to load properties for

EOEntity nextEntity ( EOEntity  entity,
String  key 
)

Looks up the key from the property ERXRest.[EntityName].[key].nextEntity . Extend to provide support for custom non-model properties.

Parameters:
entity the entity of the object
key the key of the entity to return an entity definition for

Implements IERXRestEntityDelegate.

String propertyAliasForPropertyNamed ( EOEntity  entity,
String  propertyName 
)

Returns the property alias for the given property name for the specified entity. This looks in the ERXRest.[EntityName].[propertyName].alias property. If not found, entityName is returned.

Parameters:
entity the entity
propertyName the name of the property
Returns:
the property alias

Reimplemented from ERXAbstractRestEntityDelegate.

String propertyNameForPropertyAlias ( EOEntity  entity,
String  propertyAlias 
)

Returns the property name for the given property alias for the specified entity. This looks in the ERXRest.[EntityName].[propertyName].alias property. If not found, entityName is returned.

Parameters:
entity the entity
propertyAlias the name of the property alias
Returns:
the property name

Reimplemented from ERXAbstractRestEntityDelegate.

EOQualifier qualifierFromContext ( ERXRestContext  context  )  [protected]

A shortcut for pulling a qualifier from the "qualifier" form value.

Parameters:
context the rest context
Returns:
the requested qualifir

void setDefaultIDAttributeName ( String  defaultIDAttributeName  ) 

Sets the default "id" attribute name for all entities.

Parameters:
defaultIDAttributeName the default "id" attribute name for all entities

NSArray<EOSortOrdering> sortOrderingsFromContext ( ERXRestContext  context  )  [protected]

A shortcut for pulling the sort ordering from the "order" and "direction" form values.

Parameters:
context the rest context
Returns:
an array of sort orderings

void updated ( EOEntity  entity,
EOEnterpriseObject  eo,
ERXRestContext  context 
) throws ERXRestException, ERXRestSecurityException [virtual]

Default empty implementation. Extend to do custom update processing for the object.

Parameters:
entity the entity of the object
eo the updated object
context the rest context
Exceptions:
ERXRestException if a general error occurs
ERXRestSecurityException if a security exception occurs

Implements ERXAbstractRestEntityDelegate.

Reimplemented in ERXUnsafeReadOnlyRestEntityDelegate.

void updatePropertyAliasForPropertyNamed ( String  entityName,
String  propertyName 
) [protected]


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:28 2012 for Project Wonder by  doxygen 1.5.8