org.hackystat.sensorbase.resource.projects
Class ProjectManager

java.lang.Object
  extended by org.hackystat.sensorbase.resource.projects.ProjectManager

public class ProjectManager
extends java.lang.Object

Provides a manager for the Project resource.

Author:
Philip Johnson

Field Summary
(package private)  DbManager dbManager
          The DbManager associated with this server.
static java.lang.String DEFAULT_PROJECT_NAME
          The String naming the Default project.
static java.lang.String projectIndexCloseTag
          The ProjectIndex close tag.
static java.lang.String projectIndexOpenTag
          The ProjectIndex open tag.
(package private)  Server server
          The Server associated with this SdtManager.
(package private)  UserManager userManager
          The UserManager.
 
Constructor Summary
ProjectManager(Server server)
          The constructor for ProjectManagers.
 
Method Summary
 void addDefaultProject(User owner)
          Creates and stores the "Default" project for the specified user.
 java.lang.String convertOwnerToEmail(java.lang.String owner)
          Converts an "Owner" string to an email address.
 java.lang.String convertOwnerToUri(java.lang.String owner)
          Returns the owner string as a URI.
 void deleteProject(User owner, java.lang.String projectName)
          Ensures that the passed Project is no longer present in this Manager.
 void deleteProjects(User owner)
          Deletes all projects including the default project owned by this user.
 java.lang.String getMultiDayProjectSummaryString(Project project, javax.xml.datatype.XMLGregorianCalendar startTime, java.lang.Integer numDays)
          Returns a MultiDayProjectSummary instance for the given project, startTime, and number of days.
 Project getProject(User owner, java.lang.String projectName)
          Returns the Project associated with user and projectName, or null if not found.
 java.lang.String getProjectIndex()
          Returns the XML string containing the ProjectIndex with all defined Projects.
 java.lang.String getProjectIndex(User user)
          Returns the XML string containing the ProjectIndex with all Projects associated with this user.
 java.util.Set<Project> getProjects()
          Returns a set containing the current Project instances.
 java.util.Set<Project> getProjects(User user)
          Returns all of the projects owned by this user.
 java.lang.String getProjectSensorDataIndex(User owner, Project project)
          Returns an XML SensorDataIndex String for all data associated with the Project owned by this user.
 java.lang.String getProjectSensorDataIndex(User owner, Project project, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, int startIndex, int maxInstances)
          Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times and startIndex and maxInstances.
 java.lang.String getProjectSensorDataIndex(User owner, Project project, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt)
          Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times.
 java.lang.String getProjectSensorDataIndex(User owner, Project project, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt, java.lang.String tool)
          Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times.
 java.lang.String getProjectSensorDataSnapshot(Project project, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt, java.lang.String tool)
          Returns a string containing a SensorDataIndex representing the "snapshot" of the sensor data for the given project in the given interval for the given sdt.
 java.lang.String getProjectString(User owner, java.lang.String projectName)
          Returns the Project Xml String associated with this User and project name.
 java.lang.String getProjectSummaryString(Project project, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime)
          Returns the XML ProjectSummary string for the data associated with this Project within the specified start and end times.
 boolean hasProject(User owner, java.lang.String projectName)
          Returns true if the passed Project name is defined for this User (who must be the owner).
 boolean hasProjects(User owner)
          Returns true if the passed user has any defined Projects.
 boolean inProject(java.lang.String userEmail1, java.lang.String userEmail2, java.lang.String tstampString)
          Returns true if user1 and user2 are members of the same Project and that project encompasses the given day.
 boolean isInvited(User owner, java.lang.String projectName, java.lang.String invitee)
          Returns true if member is invited to be a member of the project owned by owner.
 boolean isMember(User owner, java.lang.String projectName, java.lang.String member)
          Returns true if member is a member of the project owned by owner.
 boolean isSpectator(User owner, java.lang.String projectName, java.lang.String spectator)
          Returns true if member is a spectator of the project owned by owner.
 java.lang.String makeMultiDayProjectSummaryString(MultiDayProjectSummary summary)
          Returns the passed MultiDayProjectSummary as a String encoding of its XML representation.
 java.lang.String makeProject(Project project)
          Returns the passed Project instance as a String encoding of its XML representation.
 Project makeProject(java.lang.String xmlString)
          Takes a String encoding of a Project in XML format and converts it to an instance.
 ProjectIndex makeProjectIndex(java.lang.String xmlString)
          Takes a String encoding of a ProjectIndex in XML format and converts it to an instance.
 ProjectRef makeProjectRef(Project project)
          Returns a ProjectRef instance constructed from a Project instance.
 java.lang.String makeProjectRefString(Project project)
          Returns the passed Project instance as a String encoding of its XML representation as a ProjectRef object.
 java.lang.String makeProjectSummaryString(ProjectSummary summary)
          Returns the passed ProjectSummary instance as a String encoding of its XML representation.
 void putProject(Project project)
          Updates the Manager with this Project.
 void renameProject(User owner, java.lang.String projectName, java.lang.String newProjectName)
          Renames the project.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROJECT_NAME

public static final java.lang.String DEFAULT_PROJECT_NAME
The String naming the Default project.

See Also:
Constant Field Values

server

Server server
The Server associated with this SdtManager.


dbManager

DbManager dbManager
The DbManager associated with this server.


userManager

UserManager userManager
The UserManager.


projectIndexOpenTag

public static final java.lang.String projectIndexOpenTag
The ProjectIndex open tag.

See Also:
Constant Field Values

projectIndexCloseTag

public static final java.lang.String projectIndexCloseTag
The ProjectIndex close tag.

See Also:
Constant Field Values
Constructor Detail

ProjectManager

public ProjectManager(Server server)
The constructor for ProjectManagers. There is one ProjectManager per Server.

Parameters:
server - The Server instance associated with this ProjectManager.
Method Detail

convertOwnerToEmail

public java.lang.String convertOwnerToEmail(java.lang.String owner)
Converts an "Owner" string to an email address. The owner string might be a URI (starting with http) or an email address.

Parameters:
owner - The owner string.
Returns:
The email address corresponding to the owner string.

convertOwnerToUri

public java.lang.String convertOwnerToUri(java.lang.String owner)
Returns the owner string as a URI. The owner string could either be an email address or the URI.

Parameters:
owner - The owner string.
Returns:
The URI corresponding to the owner string.

getProjectIndex

public java.lang.String getProjectIndex()
Returns the XML string containing the ProjectIndex with all defined Projects. Uses the in-memory cache of ProjectRef strings.

Returns:
The XML string providing an index to all current Projects.

getProjectIndex

public java.lang.String getProjectIndex(User user)
Returns the XML string containing the ProjectIndex with all Projects associated with this user. Uses the in-memory cache of ProjectRef strings.

Parameters:
user - The user whose associated Projects are to be retrieved. All projects for which this user is an owner, member, spectator, or invitee are returned.
Returns:
The XML string providing an index to all Projects associated with this user.

putProject

public void putProject(Project project)
Updates the Manager with this Project. Any old definition is overwritten. Provide default values for UriPatterns, Properties, Members, and Invitations if not provided.

Parameters:
project - The Project.

renameProject

public void renameProject(User owner,
                          java.lang.String projectName,
                          java.lang.String newProjectName)
                   throws java.lang.Exception
Renames the project.

Parameters:
owner - The owner of the project to be renamed.
projectName - The project to be renamed.
newProjectName - The new project name.
Throws:
java.lang.Exception - If projectName could not be found, or if newProjectName names an existing project.

hasProject

public boolean hasProject(User owner,
                          java.lang.String projectName)
Returns true if the passed Project name is defined for this User (who must be the owner).

Parameters:
owner - The project owner (can be null).
projectName - A project name (can be null).
Returns:
True if a Project with that name is owned by that User. False if the User or Project is not defined.

isMember

public boolean isMember(User owner,
                        java.lang.String projectName,
                        java.lang.String member)
Returns true if member is a member of the project owned by owner.

Parameters:
owner - The owner of projectName.
projectName - The name of the project owned by owner.
member - The user whose membership is being checked.
Returns:
True if member is a member of project, false otherwise.

isInvited

public boolean isInvited(User owner,
                         java.lang.String projectName,
                         java.lang.String invitee)
Returns true if member is invited to be a member of the project owned by owner.

Parameters:
owner - The owner of projectName.
projectName - The name of the project owned by owner.
invitee - The user whose invitation status is being checked.
Returns:
True if member is invited to be a member of project, false otherwise.

isSpectator

public boolean isSpectator(User owner,
                           java.lang.String projectName,
                           java.lang.String spectator)
Returns true if member is a spectator of the project owned by owner.

Parameters:
owner - The owner of projectName.
projectName - The name of the project owned by owner.
spectator - The user whose spectator status is being checked.
Returns:
True if spectator is a spectator.

inProject

public boolean inProject(java.lang.String userEmail1,
                         java.lang.String userEmail2,
                         java.lang.String tstampString)
Returns true if user1 and user2 are members of the same Project and that project encompasses the given day.

Parameters:
userEmail1 - The first user.
userEmail2 - The second user.
tstampString - The date in question, which could be null.
Returns:
True if the two users are in the same project that encompasses the given day.

deleteProject

public void deleteProject(User owner,
                          java.lang.String projectName)
Ensures that the passed Project is no longer present in this Manager.

Parameters:
owner - The user who owns this Project.
projectName - The name of the project.

deleteProjects

public void deleteProjects(User owner)
Deletes all projects including the default project owned by this user. Note that this method should only be called immediately before deleting the user, since the system will be left in an inconsistent state if the Default project is deleted but the user is still around. (Here's a place where we really should be using a transaction.)

Parameters:
owner - The user of interest.

getProjectString

public java.lang.String getProjectString(User owner,
                                         java.lang.String projectName)
Returns the Project Xml String associated with this User and project name.

Parameters:
owner - The user that owns this project.
projectName - The name of the project.
Returns:
The Project XML string, or null if not found.

getProjects

public java.util.Set<Project> getProjects()
Returns a set containing the current Project instances. For thread safety, a fresh Set of Projects is built each time this is called.

Returns:
A Set containing the current Projects.

getProjects

public java.util.Set<Project> getProjects(User user)
Returns all of the projects owned by this user.

Parameters:
user - The user whose projects are to be returned.
Returns:
A set of the Projects owned by this user.

getProjectSensorDataIndex

public java.lang.String getProjectSensorDataIndex(User owner,
                                                  Project project)
                                           throws java.lang.Exception
Returns an XML SensorDataIndex String for all data associated with the Project owned by this user. Assumes that the owner and projectName define an existing Project.

Parameters:
owner - The User that owns this Project.
project - the Project instance.
Returns:
The XML SensorDataIndex string providing an index to all data for this project.
Throws:
java.lang.Exception - If things go wrong.

getProjectSensorDataIndex

public java.lang.String getProjectSensorDataIndex(User owner,
                                                  Project project,
                                                  javax.xml.datatype.XMLGregorianCalendar startTime,
                                                  javax.xml.datatype.XMLGregorianCalendar endTime,
                                                  java.lang.String sdt)
                                           throws java.lang.Exception
Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times. Assumes that owner, project, startTime, and endTime are non-null, and that startTime and endTime are within the Project start and end time interval.

Parameters:
owner - The User who owns this Project.
project - the Project.
startTime - The startTime.
endTime - The endTime.
sdt - The SensorDataType of interest, or null if all sensordatatypes are to be retrieved.
Returns:
The XML String providing a SensorDataIndex to the sensor data in this project starting at startTime and ending at endTime.
Throws:
java.lang.Exception - if problems occur.

getProjectSensorDataIndex

public java.lang.String getProjectSensorDataIndex(User owner,
                                                  Project project,
                                                  javax.xml.datatype.XMLGregorianCalendar startTime,
                                                  javax.xml.datatype.XMLGregorianCalendar endTime,
                                                  java.lang.String sdt,
                                                  java.lang.String tool)
                                           throws java.lang.Exception
Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times. Assumes that owner, project, startTime, and endTime are non-null, and that startTime and endTime are within the Project start and end time interval.

Parameters:
owner - The User who owns this Project.
project - the Project.
startTime - The startTime.
endTime - The endTime.
sdt - The SensorDataType of interest, or null if all sensordatatypes are to be retrieved.
tool - The tool of interest.
Returns:
The XML String providing a SensorDataIndex to the sensor data in this project starting at startTime and ending at endTime.
Throws:
java.lang.Exception - if problems occur.

getProjectSensorDataIndex

public java.lang.String getProjectSensorDataIndex(User owner,
                                                  Project project,
                                                  javax.xml.datatype.XMLGregorianCalendar startTime,
                                                  javax.xml.datatype.XMLGregorianCalendar endTime,
                                                  int startIndex,
                                                  int maxInstances)
                                           throws java.lang.Exception
Returns the XML SensorDataIndex string for the data associated with this Project within the specified start and end times and startIndex and maxInstances. Assumes that owner, project, startTime, and endTime are non-null, and that startTime and endTime are within the Project start and end time interval, and that startIndex and maxInstances are non-negative.

Parameters:
owner - The User who owns this Project.
project - the Project.
startTime - The startTime.
endTime - The endTime.
startIndex - The starting index within the timestamp-ordered list of all sensor data instances associated with this project at the time of this call.
maxInstances - The maximum number of instances to return in the index.
Returns:
The XML String providing a SensorDataIndex to the sensor data in this project starting at startTime and ending at endTime with the specified startIndex and maxInstances.
Throws:
java.lang.Exception - if problems occur.

getProjectSensorDataSnapshot

public java.lang.String getProjectSensorDataSnapshot(Project project,
                                                     javax.xml.datatype.XMLGregorianCalendar startTime,
                                                     javax.xml.datatype.XMLGregorianCalendar endTime,
                                                     java.lang.String sdt,
                                                     java.lang.String tool)
                                              throws java.lang.Exception
Returns a string containing a SensorDataIndex representing the "snapshot" of the sensor data for the given project in the given interval for the given sdt. Tool is optional and can be null.

Parameters:
project - The project.
startTime - The start time.
endTime - The end time.
sdt - The sensor data type of interest.
tool - The tool of interest, or null if any tool is acceptable.
Returns:
The SensorDataIndex containing the snapshot of sensor data.
Throws:
java.lang.Exception - If problems occur.

getProjectSummaryString

public java.lang.String getProjectSummaryString(Project project,
                                                javax.xml.datatype.XMLGregorianCalendar startTime,
                                                javax.xml.datatype.XMLGregorianCalendar endTime)
                                         throws java.lang.Exception
Returns the XML ProjectSummary string for the data associated with this Project within the specified start and end times. Note that the Project start and end times may further constrain the returned set of data. This method chooses the greater of startString and the Project startTime, and the lesser of endString and the Project endTime. Assumes that User and Project are valid.

Parameters:
project - the Project.
startTime - The startTimeXml.
endTime - The endTime.
Returns:
The XML String providing a ProjectSummary of this project starting at startTime and ending at endTime.
Throws:
java.lang.Exception - if startString or endString are not XMLGregorianCalendars.

getMultiDayProjectSummaryString

public java.lang.String getMultiDayProjectSummaryString(Project project,
                                                        javax.xml.datatype.XMLGregorianCalendar startTime,
                                                        java.lang.Integer numDays)
                                                 throws java.lang.Exception
Returns a MultiDayProjectSummary instance for the given project, startTime, and number of days.

Parameters:
project - The Project.
startTime - The startTime.
numDays - The number of days.
Returns:
The MultiDayProjectSummary instance for the given set of days.
Throws:
java.lang.Exception - If problems occur.

addDefaultProject

public final void addDefaultProject(User owner)
Creates and stores the "Default" project for the specified user.

Parameters:
owner - The user who will own this Project.

hasProjects

public boolean hasProjects(User owner)
Returns true if the passed user has any defined Projects.

Parameters:
owner - The user who is the owner of the Projects.
Returns:
True if that User is defined and has at least one Project.

getProject

public Project getProject(User owner,
                          java.lang.String projectName)
Returns the Project associated with user and projectName, or null if not found.

Parameters:
owner - The user.
projectName - A project name
Returns:
The project, or null if not found.

makeProject

public final Project makeProject(java.lang.String xmlString)
                          throws java.lang.Exception
Takes a String encoding of a Project in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a Project
Returns:
The corresponding Project instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeProjectIndex

public final ProjectIndex makeProjectIndex(java.lang.String xmlString)
                                    throws java.lang.Exception
Takes a String encoding of a ProjectIndex in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a ProjectIndex.
Returns:
The corresponding ProjectIndex instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeProject

public final java.lang.String makeProject(Project project)
                                   throws java.lang.Exception
Returns the passed Project instance as a String encoding of its XML representation. Final because it's called in constructor.

Parameters:
project - The Project instance.
Returns:
The XML String representation.
Throws:
java.lang.Exception - If problems occur during translation.

makeProjectRefString

public final java.lang.String makeProjectRefString(Project project)
                                            throws java.lang.Exception
Returns the passed Project instance as a String encoding of its XML representation as a ProjectRef object. Final because it's called in constructor.

Parameters:
project - The Project instance.
Returns:
The XML String representation of it as a ProjectRef
Throws:
java.lang.Exception - If problems occur during translation.

makeProjectSummaryString

public final java.lang.String makeProjectSummaryString(ProjectSummary summary)
                                                throws java.lang.Exception
Returns the passed ProjectSummary instance as a String encoding of its XML representation.

Parameters:
summary - The ProjectSummary instance.
Returns:
The XML String representation of it.
Throws:
java.lang.Exception - If problems occur during translation.

makeMultiDayProjectSummaryString

public final java.lang.String makeMultiDayProjectSummaryString(MultiDayProjectSummary summary)
                                                        throws java.lang.Exception
Returns the passed MultiDayProjectSummary as a String encoding of its XML representation.

Parameters:
summary - The MultiDayProjectSummary instance.
Returns:
The XML String representation of it.
Throws:
java.lang.Exception - If problems occur during translation.

makeProjectRef

public ProjectRef makeProjectRef(Project project)
Returns a ProjectRef instance constructed from a Project instance.

Parameters:
project - The Project instance.
Returns:
A ProjectRef instance.