org.hackystat.sensorbase.resource.sensorbase
Class SensorBaseResource

java.lang.Object
  extended by org.restlet.Handler
      extended by org.restlet.resource.Resource
          extended by org.hackystat.sensorbase.resource.sensorbase.SensorBaseResource
Direct Known Subclasses:
CompressResource, HomePageResource, IndexResource, PingResource, ProjectsResource, RegistrationResource, RowCountResource, SensorDataResource, SensorDataTypeResource, SensorDataTypesResource, UserProjectInvitationResource, UserProjectRenameResource, UserProjectResource, UserProjectSensorDataResource, UserProjectSnapshotResource, UserProjectsResource, UserProjectSummaryResource, UserResource, UserSensorDataResource, UsersResource

public abstract class SensorBaseResource
extends org.restlet.resource.Resource

An abstract superclass for all SensorBase resources that supplies common initialization and validation processing.

Initialization processing includes:

Validation processing involves a set of "validated" methods. These check the values of various parameters in the request, potentially initializing instance variables as a result. If the validation process fails, these methods set the Restlet Status value appropriately and return false.

Author:
Philip Johnson

Field Summary
protected  java.lang.String authUser
          The authenticated user, retrieved from the ChallengeResponse, or null.
protected  Project project
          The project corresponding to the projectName, or null.
protected  ProjectManager projectManager
          The ProjectManager.
protected  java.lang.String projectName
          The projectName found within the URL string, or null.
protected  java.lang.String responseMsg
          Everyone generally wants to create one of these, so declare it here.
protected  SdtManager sdtManager
          The SdtManager.
protected  SensorDataManager sensorDataManager
          The SensorDataManager.
protected  Server server
          The server.
protected  java.lang.String uriUser
          To be retrieved from the URL as the 'user' template parameter, or null.
protected  User user
          The user instance corresponding to the user indicated in the URI string, or null.
protected  UserManager userManager
          The UserManager.
 
Constructor Summary
SensorBaseResource(org.restlet.Context context, org.restlet.data.Request request, org.restlet.data.Response response)
          Provides the following representational variants: TEXT_XML.
 
Method Summary
static org.restlet.resource.StringRepresentation getStringRepresentation(java.lang.String xmlData)
          Creates and returns a new Restlet StringRepresentation built from xmlData.
abstract  org.restlet.resource.Representation represent(org.restlet.resource.Variant variant)
          The Restlet getRepresentation method which must be overridden by all concrete Resources.
protected  void setStatusBadTimestamp(java.lang.String timestamp)
          Called when an exception is caught while processing a request.
protected  void setStatusInternalError(java.lang.Exception e)
          Called when an exception is caught while processing a request.
protected  void setStatusMiscError(java.lang.String msg)
          Called when a miscellaneous "one off" error is caught during processing.
protected  boolean validateAuthUserIsAdmin()
          Returns true if the authorized user is the administrator.
protected  boolean validateAuthUserIsAdminOrUriUser()
          Returns true if the authorized user is either the admin or user in the URI string.
protected  boolean validateProjectOwner()
          Returns true if the authorized user is the owner of the project in the URL string.
protected  boolean validateProjectViewer()
          Returns true if the authorized user can view the project definition.
protected  boolean validateUriProjectName()
          Returns true if the project name in the URI string is defined in the ProjectManager.
protected  boolean validateUriUserIsUser()
          Returns true if the user in the URI string is defined in the UserManager.
 
Methods inherited from class org.restlet.resource.Resource
acceptRepresentation, allowDelete, allowGet, allowPost, allowPut, delete, getPreferredRepresentation, getPreferredVariant, getRepresentation, getVariants, handleDelete, handleGet, handlePost, handlePut, init, isAvailable, isModifiable, isNegotiateContent, isReadable, post, put, removeRepresentations, represent, setAvailable, setModifiable, setNegotiateContent, setReadable, setVariants, storeRepresentation
 
Methods inherited from class org.restlet.Handler
allowHead, allowOptions, generateRef, getAllowedMethods, getApplication, getContext, getLogger, getMatrix, getQuery, getRequest, getResponse, handleHead, handleOptions, setContext, setRequest, setResponse, updateAllowedMethods
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

authUser

protected java.lang.String authUser
The authenticated user, retrieved from the ChallengeResponse, or null.


uriUser

protected java.lang.String uriUser
To be retrieved from the URL as the 'user' template parameter, or null.


user

protected User user
The user instance corresponding to the user indicated in the URI string, or null.


projectName

protected java.lang.String projectName
The projectName found within the URL string, or null.


project

protected Project project
The project corresponding to the projectName, or null.


projectManager

protected ProjectManager projectManager
The ProjectManager.


userManager

protected UserManager userManager
The UserManager.


sdtManager

protected SdtManager sdtManager
The SdtManager.


sensorDataManager

protected SensorDataManager sensorDataManager
The SensorDataManager.


server

protected Server server
The server.


responseMsg

protected java.lang.String responseMsg
Everyone generally wants to create one of these, so declare it here.

Constructor Detail

SensorBaseResource

public SensorBaseResource(org.restlet.Context context,
                          org.restlet.data.Request request,
                          org.restlet.data.Response response)
Provides the following representational variants: TEXT_XML.

Parameters:
context - The context.
request - The request object.
response - The response object.
Method Detail

represent

public abstract org.restlet.resource.Representation represent(org.restlet.resource.Variant variant)
The Restlet getRepresentation method which must be overridden by all concrete Resources.

Overrides:
represent in class org.restlet.resource.Resource
Parameters:
variant - The variant requested.
Returns:
The Representation.

getStringRepresentation

public static org.restlet.resource.StringRepresentation getStringRepresentation(java.lang.String xmlData)
Creates and returns a new Restlet StringRepresentation built from xmlData. The xmlData will be prefixed with a processing instruction indicating UTF-8 and version 1.0.

Parameters:
xmlData - The xml data as a string.
Returns:
A StringRepresentation of that xmldata.

validateAuthUserIsAdmin

protected boolean validateAuthUserIsAdmin()
Returns true if the authorized user is the administrator. Otherwise sets the Response status and returns false.

Returns:
True if the authorized user is the admin.

validateUriUserIsUser

protected boolean validateUriUserIsUser()
Returns true if the user in the URI string is defined in the UserManager. Otherwise sets the Response status and returns false. If it returns true, then this.user has the corresponding User instance.

Returns:
True if the URI user is a real user.

validateUriProjectName

protected boolean validateUriProjectName()
Returns true if the project name in the URI string is defined in the ProjectManager. Otherwise sets the Response status and returns false. If it returns true, then this.project has the corresponding Project instance.

Returns:
True if the URI project name is a real project.

validateProjectOwner

protected boolean validateProjectOwner()
Returns true if the authorized user is the owner of the project in the URL string. Otherwise sets the Response status and returns false.

Returns:
True if the authorized user is the owner of the Project.

validateAuthUserIsAdminOrUriUser

protected boolean validateAuthUserIsAdminOrUriUser()
Returns true if the authorized user is either the admin or user in the URI string. Otherwise sets the Response status and returns false.

Returns:
True if the authorized user is the admin or the URI user.

validateProjectViewer

protected boolean validateProjectViewer()
Returns true if the authorized user can view the project definition. This is true if the authorized user is the admin, the project owner, or member, spectator, or invitee. Otherwise sets the Response status and returns false.

Returns:
True if the authorized user is a project participant.

setStatusBadTimestamp

protected void setStatusBadTimestamp(java.lang.String timestamp)
Called when an exception is caught while processing a request. Just sets the response code.

Parameters:
timestamp - The timestamp that could not be parsed.

setStatusInternalError

protected void setStatusInternalError(java.lang.Exception e)
Called when an exception is caught while processing a request. Just sets the response code.

Parameters:
e - The exception that was caught.

setStatusMiscError

protected void setStatusMiscError(java.lang.String msg)
Called when a miscellaneous "one off" error is caught during processing.

Parameters:
msg - A description of the error.