org.hackystat.sensorshell.usermap
Class UserMap

java.lang.Object
  extended by org.hackystat.sensorshell.usermap.UserMap

 class UserMap
extends java.lang.Object

Gets hackystat information for a specific tool by parsing a predefined xml file located in the user's .hackystat/usermap directory. The file should be named 'UserMaps.xml'. It is important to keep in mind that this code is working client-side, not on the Hackystat server.

Instantiation of UserMap will parse the assumed xml file and derive a mapping from specific tool accounts for users to their Hackystat information.

Developers should not have to directly use this class at all. They should only have to interface with the SensorShellMap class which manages an instance of this class.

If the UserMap.xml file does not exist, an empty UserMap is returned.

The "tool" string is always compared in a case-insensitive fashion. The User, ToolAccount, Password, and Sensorbase are case-sensitive.

Author:
Julie Ann Sakuda

Nested Class Summary
(package private) static class UserMap.UserMapKey
          Keys in the user map used to access information.
 
Constructor Summary
UserMap()
          Creates the user map and initializes the user mappings.
UserMap(java.io.File userMapFile)
          This constructor initializes the user mappings from a given file.
 
Method Summary
(package private)  java.lang.String get(java.lang.String tool, java.lang.String toolAccount, UserMap.UserMapKey key)
          Gets the value of the given UserMapKey associated with the given tool and toolAccount, or null if not found.
(package private)  java.util.Set<java.lang.String> getToolAccounts(java.lang.String tool)
          Returns the set of tool account names for the passed tool.
(package private)  java.lang.String getUserMapFile()
          Returns the usermap.xml file path, which may or may not exist.
(package private)  boolean hasUser(java.lang.String tool, java.lang.String toolAccount)
          Returns true if there is a defined userKey for the given Tool and ToolAccount.
 void validateHackystatUsers(java.lang.String tool)
          A method that will check all of the mappings associated with the given tool and throw an error if (a) any of the sensorbases could not be contacted, and/or (b) any of the users did not appear to be registered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserMap

UserMap()
  throws SensorShellMapException
Creates the user map and initializes the user mappings. Returns an empty UserMap if the UserMap.xml file cannot be found.

Throws:
SensorShellMapException - Thrown if the UserMap.xml cannot be parsed.

UserMap

UserMap(java.io.File userMapFile)
  throws SensorShellMapException
This constructor initializes the user mappings from a given file. This version of the constructor is mainly useful for junit test cases that want to verify the content of a dummy UserMap.xml file.

Parameters:
userMapFile - A UserMap.xml file.
Throws:
SensorShellMapException - Occurs if UserMap.xml is invalid.
Method Detail

validateHackystatUsers

public void validateHackystatUsers(java.lang.String tool)
                            throws SensorShellMapException
A method that will check all of the mappings associated with the given tool and throw an error if (a) any of the sensorbases could not be contacted, and/or (b) any of the users did not appear to be registered.

Parameters:
tool - The tool of interest.
Throws:
SensorShellMapException - The exception thrown if any errors are discovered.

get

java.lang.String get(java.lang.String tool,
                     java.lang.String toolAccount,
                     UserMap.UserMapKey key)
Gets the value of the given UserMapKey associated with the given tool and toolAccount, or null if not found.

Parameters:
tool - The tool name. This is case-insensitive.
toolAccount - The tool account name. This is case-insensitive.
key - The USER, PASSWORD, or SENSORBASE key representing the desired value.
Returns:
Returns the value matching the criteria given or null if none can be found.

hasUser

boolean hasUser(java.lang.String tool,
                java.lang.String toolAccount)
Returns true if there is a defined userKey for the given Tool and ToolAccount.

Parameters:
tool - A Tool, such as "Jira".
toolAccount - A Tool account, such as "johnson".
Returns:
True if the toolAccount is defined for the given tool in this userMap.

getUserMapFile

java.lang.String getUserMapFile()
Returns the usermap.xml file path, which may or may not exist.

Returns:
The usermap.xml file path.

getToolAccounts

java.util.Set<java.lang.String> getToolAccounts(java.lang.String tool)
Returns the set of tool account names for the passed tool.

Parameters:
tool - The tool of interest.
Returns:
The tool account names.