org.openmrs.util
Class OpenmrsUtil

java.lang.Object
  extended by org.openmrs.util.OpenmrsUtil

public class OpenmrsUtil
extends java.lang.Object

Utility methods used in openmrs


Constructor Summary
OpenmrsUtil()
           
 
Method Summary
static
<K,V> void
addToListMap(java.util.Map<K,java.util.List<V>> map, K key, V obj)
           
static
<K,V> void
addToSetMap(java.util.Map<K,java.util.Set<V>> map, K key, V obj)
          Allows easy manipulation of a Map
static java.lang.Integer ageFromBirthdate(java.util.Date birthdate)
          Deprecated. this method is not currently used within OpenMRS and is a duplicate of Person.getAge(Date)
static void applyLogLevel(java.lang.String logClass, java.lang.String logLevel)
          Set the log4j log level for class logClass to logLevel.
static void applyLogLevels()
          Set the org.openmrs log4j logger's level if global property log.level.openmrs ( OpenmrsConstants.GLOBAL_PROPERTY_LOG_LEVEL ) exists.
static void closeStream(java.io.Closeable closableStream)
          A null-safe and exception safe way to close an inputstream or an outputstream
static boolean collectionContains(java.util.Collection<?> objects, java.lang.Object obj)
          Loops over the collection to check to see if the given object is in that collection.
static int compare(java.util.Date d1, java.util.Date d2)
          Compares two java.util.Date objects, but handles java.sql.Timestamp (which is not directly comparable to a date) by dropping its nanosecond value.
static
<E> java.util.Collection<java.util.Collection<E>>
compareLists(java.util.Collection<E> origList, java.util.Collection<E> newList)
          Compares origList to newList returning map of differences
static int compareWithNullAsEarliest(java.util.Date d1, java.util.Date d2)
          Compares two Date/Timestamp objects, treating null as the earliest possible date.
static
<E extends java.lang.Comparable<E>>
int
compareWithNullAsGreatest(E c1, E c2)
           
static int compareWithNullAsLatest(java.util.Date d1, java.util.Date d2)
          Compares two Date/Timestamp objects, treating null as the earliest possible date.
static
<E extends java.lang.Comparable<E>>
int
compareWithNullAsLowest(E c1, E c2)
           
static java.util.List<Concept> conceptListHelper(java.lang.String descriptor)
           
static java.util.Set<Concept> conceptSetHelper(java.lang.String descriptor)
           
static
<T> boolean
containsAny(java.util.Collection<T> collection, java.util.Collection<T> elements)
           
static boolean containsDigit(java.lang.String test)
           
static boolean containsOnlyDigits(java.lang.String test)
           
static boolean containsUpperAndLowerCase(java.lang.String test)
           
static void copyFile(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Copy file from inputStream onto the outputStream inputStream is not closed in this method outputStream /is/ closed at completion of this method
static boolean deleteDirectory(java.io.File dir)
          Recursively deletes files in the given dir folder
static java.util.List<Concept> delimitedStringToConceptList(java.lang.String delimitedString, java.lang.String delimiter, Context context)
           
static java.util.Map<java.lang.String,Concept> delimitedStringToConceptMap(java.lang.String delimitedString, java.lang.String delimiter)
           
static java.util.List<java.lang.Integer> delimitedStringToIntegerList(java.lang.String delimitedString, java.lang.String delimiter)
           
static boolean folderContains(java.io.File folder, java.lang.String filename)
          Look for a file named filename in folder
static java.util.Date fromDateHelper(java.util.Date comparisonDate, java.lang.Integer withinLastDays, java.lang.Integer withinLastMonths, java.lang.Integer untilDaysAgo, java.lang.Integer untilMonthsAgo, java.util.Date sinceDate, java.util.Date untilDate)
           
static java.lang.String generateUid()
          Creates a uid of length 20
static java.lang.String generateUid(java.lang.Integer size)
          Creates a relatively acceptable unique string of the give size
static java.lang.String getApplicationDataDirectory()
           
static int getCheckDigit(java.lang.String idWithoutCheckdigit)
          Deprecated. Use PatientService.getIdentifierValidator(String)
static Concept getConceptByIdOrName(java.lang.String idOrName)
           
static java.text.SimpleDateFormat getDateFormat()
          Deprecated. use Context.getDateFormat() or #getDateFormat(Context#getLocale()) instead
static java.text.SimpleDateFormat getDateFormat(java.util.Locale locale)
          Get the current user's date format Will look similar to "mm-dd-yyyy".
static java.io.File getDirectoryInApplicationDataDirectory(java.lang.String folderName)
          Find the given folderName in the application data directory.
static byte[] getFileAsBytes(java.io.File file)
          Return a byte array representation of the given file
static java.lang.String getFileAsString(java.io.File file)
          Return a string representation of the given file
static java.lang.String getMessage(java.lang.String code, java.lang.Object... args)
          Utility method for getting the translation for the passed code
static java.io.File getOutFile(java.io.File dir, java.util.Date date, User user)
          Gets an out File object.
static java.io.InputStream getResourceInputStream(java.net.URL url)
          Opens input stream for given resource.
static org.simpleframework.xml.Serializer getSerializer()
          Deprecated. - Use OpenmrsSerializer from Context.getSerializationService.getDefaultSerializer() Note, this uses a different Serialization mechanism, so you may need to use this for conversion
static org.simpleframework.xml.Serializer getShortSerializer()
          Deprecated. - Use OpenmrsSerializer from Context.getSerializationService.getDefaultSerializer() Note, this uses a different Serialization mechanism, so you may need to use this for conversion
static boolean isConceptInList(Concept concept, java.util.List<Concept> list)
           
static java.lang.Boolean isInAbsoluteNumericRange(java.lang.Float value, ConceptNumeric concept)
           
static java.lang.Boolean isInCriticalNumericRange(java.lang.Float value, ConceptNumeric concept)
           
static java.lang.Boolean isInNormalNumericRange(java.lang.Float value, ConceptNumeric concept)
           
static boolean isShortSerialization(java.util.Map<?,?> sessionMap)
          Deprecated. - use SerializationService and OpenmrsSerializer implementation for Serialization
static boolean isStringInArray(java.lang.String str, java.lang.String[] arr)
           
static boolean isValidCheckDigit(java.lang.String id)
          Deprecated. Should be using PatientService.getIdentifierValidator(String)
static java.lang.Boolean isValidNumericValue(java.lang.Float value, ConceptNumeric concept)
           
static
<E> java.lang.String
join(java.util.Collection<E> c, java.lang.String separator)
          Converts a collection to a String with a specified separator between all elements
static java.util.Date lastSecondOfDay(java.util.Date date)
          Return a date that is the same day as the passed in date, but the hours and seconds are the latest possible for that day.
static void loadProperties(java.util.Properties props, java.io.File propertyFile)
          Convenience method used to load properties from the given file.
static void loadProperties(java.util.Properties props, java.io.InputStream input)
          Deprecated. use loadProperties(Properties, File)
static
<Arg1,Arg2 extends Arg1>
boolean
nullSafeEquals(Arg1 d1, Arg2 d2)
           
static java.lang.Object parse(java.lang.String string, java.lang.Class clazz)
          Takes a String (e.g.
static java.util.Map<java.lang.String,java.lang.String> parseParameterList(java.lang.String paramList)
          Takes a String like "size=compact|order=date" and returns a Map from the keys to the values.
static java.lang.String postToUrl(java.lang.String urlString, java.util.Map<java.lang.String,java.lang.String> dataToPost)
          Post the given map of variables to the given url string
static java.util.Date safeDate(java.util.Date d1)
           
static void saveDocument(org.w3c.dom.Document doc, java.io.File outFile)
          Save the given xml document to the given outfile
static java.lang.String shortenedStackTrace(java.lang.String stackTrace)
          Convert a stack trace into a shortened version for easier viewing and data storage, including only those lines we are most concerned with
static void startup(java.util.Properties p)
          Initialize global settings Find and load modules
static void storeProperties(java.util.Properties properties, java.io.File file, java.lang.String comment)
          Convenience method to replace Properties.store(), which isn't UTF-8 compliant
NOTE: In Java 6, you will be able to pass the load() and store() methods a UTF-8 Reader/Writer object as an argument, making this method unnecessary.
static void storeProperties(java.util.Properties properties, java.io.OutputStream outStream, java.lang.String comment)
          Convenience method to replace Properties.store(), which isn't UTF-8 compliant NOTE: In Java 6, you will be able to pass the load() and store() methods a UTF-8 Reader/Writer object as an argument.
static java.util.Date toDateHelper(java.util.Date comparisonDate, java.lang.Integer withinLastDays, java.lang.Integer withinLastMonths, java.lang.Integer untilDaysAgo, java.lang.Integer untilMonthsAgo, java.util.Date sinceDate, java.util.Date untilDate)
           
static PatientFilter toPatientFilter(PatientSearch search, CohortSearchHistory history)
          Deprecated. see reportingcompatibility module
static PatientFilter toPatientFilter(PatientSearch search, CohortSearchHistory history, EvaluationContext evalContext)
          Deprecated. see reportingcompatibility module
static java.io.File url2file(java.net.URL url)
          Utility method to convert local URL to a File object.
static void validatePassword(java.lang.String username, java.lang.String password, java.lang.String systemId)
          Utility to check the validity of a password for a certain User.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenmrsUtil

public OpenmrsUtil()
Method Detail

getCheckDigit

@Deprecated
public static int getCheckDigit(java.lang.String idWithoutCheckdigit)
                         throws java.lang.Exception
Deprecated. Use PatientService.getIdentifierValidator(String)

Parameters:
idWithoutCheckdigit -
Returns:
int - the calculated check digit for the given string
Throws:
java.lang.Exception
Expected behavior:
get valid check digits

isValidCheckDigit

@Deprecated
public static boolean isValidCheckDigit(java.lang.String id)
                                 throws java.lang.Exception
Deprecated. Should be using PatientService.getIdentifierValidator(String)

Parameters:
id -
Returns:
true/false whether id has a valid check digit
Throws:
java.lang.Exception - on invalid characters and invalid id formation
Expected behavior:
validate correct check digits, not validate invalid check digits, throw error if given an invalid character in id

compareLists

public static <E> java.util.Collection<java.util.Collection<E>> compareLists(java.util.Collection<E> origList,
                                                                             java.util.Collection<E> newList)
Compares origList to newList returning map of differences

Parameters:
origList -
newList -
Returns:
[List toAdd, List toDelete] with respect to origList

isStringInArray

public static boolean isStringInArray(java.lang.String str,
                                      java.lang.String[] arr)

isInNormalNumericRange

public static java.lang.Boolean isInNormalNumericRange(java.lang.Float value,
                                                       ConceptNumeric concept)

isInCriticalNumericRange

public static java.lang.Boolean isInCriticalNumericRange(java.lang.Float value,
                                                         ConceptNumeric concept)

isInAbsoluteNumericRange

public static java.lang.Boolean isInAbsoluteNumericRange(java.lang.Float value,
                                                         ConceptNumeric concept)

isValidNumericValue

public static java.lang.Boolean isValidNumericValue(java.lang.Float value,
                                                    ConceptNumeric concept)

getFileAsString

public static java.lang.String getFileAsString(java.io.File file)
                                        throws java.io.IOException
Return a string representation of the given file

Parameters:
file -
Returns:
String file contents
Throws:
java.io.IOException

getFileAsBytes

public static byte[] getFileAsBytes(java.io.File file)
                             throws java.io.IOException
Return a byte array representation of the given file

Parameters:
file -
Returns:
byte[] file contents
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.InputStream inputStream,
                            java.io.OutputStream outputStream)
                     throws java.io.IOException
Copy file from inputStream onto the outputStream inputStream is not closed in this method outputStream /is/ closed at completion of this method

Parameters:
inputStream - Stream to copy from
outputStream - Stream/location to copy to
Throws:
java.io.IOException - thrown if an error occurs during read/write

folderContains

public static boolean folderContains(java.io.File folder,
                                     java.lang.String filename)
Look for a file named filename in folder

Parameters:
folder -
filename -
Returns:
true/false whether filename exists in folder

startup

public static void startup(java.util.Properties p)
Initialize global settings Find and load modules

Parameters:
p - properties from runtime configuration

applyLogLevels

public static void applyLogLevels()
Set the org.openmrs log4j logger's level if global property log.level.openmrs ( OpenmrsConstants.GLOBAL_PROPERTY_LOG_LEVEL ) exists. Valid values for global property are trace, debug, info, warn, error or fatal.


applyLogLevel

public static void applyLogLevel(java.lang.String logClass,
                                 java.lang.String logLevel)
Set the log4j log level for class logClass to logLevel.

Parameters:
logClass - optional string giving the class level to change. Defaults to OpenmrsConstants.LOG_CLASS_DEFAULT . Should be something like org.openmrs.___
logLevel - one of OpenmrsConstants.LOG_LEVEL_*

parseParameterList

public static java.util.Map<java.lang.String,java.lang.String> parseParameterList(java.lang.String paramList)
Takes a String like "size=compact|order=date" and returns a Map from the keys to the values.

Parameters:
paramList - String with a list of parameters
Returns:
Map of the parameters passed

nullSafeEquals

public static <Arg1,Arg2 extends Arg1> boolean nullSafeEquals(Arg1 d1,
                                                              Arg2 d2)

compare

public static int compare(java.util.Date d1,
                          java.util.Date d2)
Compares two java.util.Date objects, but handles java.sql.Timestamp (which is not directly comparable to a date) by dropping its nanosecond value.


compareWithNullAsEarliest

public static int compareWithNullAsEarliest(java.util.Date d1,
                                            java.util.Date d2)
Compares two Date/Timestamp objects, treating null as the earliest possible date.


compareWithNullAsLatest

public static int compareWithNullAsLatest(java.util.Date d1,
                                          java.util.Date d2)
Compares two Date/Timestamp objects, treating null as the earliest possible date.


compareWithNullAsLowest

public static <E extends java.lang.Comparable<E>> int compareWithNullAsLowest(E c1,
                                                                              E c2)

compareWithNullAsGreatest

public static <E extends java.lang.Comparable<E>> int compareWithNullAsGreatest(E c1,
                                                                                E c2)

ageFromBirthdate

@Deprecated
public static java.lang.Integer ageFromBirthdate(java.util.Date birthdate)
Deprecated. this method is not currently used within OpenMRS and is a duplicate of Person.getAge(Date)


join

public static <E> java.lang.String join(java.util.Collection<E> c,
                                        java.lang.String separator)
Converts a collection to a String with a specified separator between all elements

Parameters:
c - Collection to be joined
separator - string to put between all elements
Returns:
a String representing the toString() of all elements in c, separated by separator

conceptSetHelper

public static java.util.Set<Concept> conceptSetHelper(java.lang.String descriptor)

delimitedStringToConceptList

public static java.util.List<Concept> delimitedStringToConceptList(java.lang.String delimitedString,
                                                                   java.lang.String delimiter,
                                                                   Context context)

delimitedStringToConceptMap

public static java.util.Map<java.lang.String,Concept> delimitedStringToConceptMap(java.lang.String delimitedString,
                                                                                  java.lang.String delimiter)

getConceptByIdOrName

public static Concept getConceptByIdOrName(java.lang.String idOrName)

conceptListHelper

public static java.util.List<Concept> conceptListHelper(java.lang.String descriptor)

lastSecondOfDay

public static java.util.Date lastSecondOfDay(java.util.Date date)
Return a date that is the same day as the passed in date, but the hours and seconds are the latest possible for that day.

Parameters:
date - date to adjust
Returns:
a date that is the last possible time in the day

safeDate

public static java.util.Date safeDate(java.util.Date d1)

deleteDirectory

public static boolean deleteDirectory(java.io.File dir)
                               throws java.io.IOException
Recursively deletes files in the given dir folder

Parameters:
dir - File directory to delete
Returns:
true/false whether the delete was completed successfully
Throws:
java.io.IOException - if dir is not a directory

url2file

public static java.io.File url2file(java.net.URL url)
Utility method to convert local URL to a File object.

Parameters:
url - an URL
Returns:
file object for given URL or null if URL is not local
Expected behavior:
return null given null parameter

getResourceInputStream

public static java.io.InputStream getResourceInputStream(java.net.URL url)
                                                  throws java.io.IOException
Opens input stream for given resource. This method behaves differently for different URL types: It is not recommended to use this method for big resources within JAR files.

Parameters:
url - resource URL
Returns:
input stream for given resource
Throws:
java.io.IOException - if any I/O error has occurred

getApplicationDataDirectory

public static java.lang.String getApplicationDataDirectory()
Returns:
The path to the directory on the file system that will hold miscellaneous data about the application (runtime properties, modules, etc)

getDirectoryInApplicationDataDirectory

public static java.io.File getDirectoryInApplicationDataDirectory(java.lang.String folderName)
                                                           throws APIException
Find the given folderName in the application data directory. Or, treat folderName like an absolute url to a directory

Parameters:
folderName -
Returns:
folder capable of storing information
Throws:
APIException

saveDocument

public static void saveDocument(org.w3c.dom.Document doc,
                                java.io.File outFile)
Save the given xml document to the given outfile

Parameters:
doc - Document to be saved
outFile - file pointer to the location the xml file is to be saved to

delimitedStringToIntegerList

public static java.util.List<java.lang.Integer> delimitedStringToIntegerList(java.lang.String delimitedString,
                                                                             java.lang.String delimiter)

isConceptInList

public static boolean isConceptInList(Concept concept,
                                      java.util.List<Concept> list)

fromDateHelper

public static java.util.Date fromDateHelper(java.util.Date comparisonDate,
                                            java.lang.Integer withinLastDays,
                                            java.lang.Integer withinLastMonths,
                                            java.lang.Integer untilDaysAgo,
                                            java.lang.Integer untilMonthsAgo,
                                            java.util.Date sinceDate,
                                            java.util.Date untilDate)

toDateHelper

public static java.util.Date toDateHelper(java.util.Date comparisonDate,
                                          java.lang.Integer withinLastDays,
                                          java.lang.Integer withinLastMonths,
                                          java.lang.Integer untilDaysAgo,
                                          java.lang.Integer untilMonthsAgo,
                                          java.util.Date sinceDate,
                                          java.util.Date untilDate)

containsAny

public static <T> boolean containsAny(java.util.Collection<T> collection,
                                      java.util.Collection<T> elements)
Parameters:
collection -
elements -
Returns:
Whether _collection_ contains any of _elements_

addToSetMap

public static <K,V> void addToSetMap(java.util.Map<K,java.util.Set<V>> map,
                                     K key,
                                     V obj)
Allows easy manipulation of a Map


addToListMap

public static <K,V> void addToListMap(java.util.Map<K,java.util.List<V>> map,
                                      K key,
                                      V obj)

getDateFormat

@Deprecated
public static java.text.SimpleDateFormat getDateFormat()
Deprecated. use Context.getDateFormat() or #getDateFormat(Context#getLocale()) instead

Get the current user's date format Will look similar to "mm-dd-yyyy". Depends on user's locale.

Returns:
a simple date format

getDateFormat

public static java.text.SimpleDateFormat getDateFormat(java.util.Locale locale)
Get the current user's date format Will look similar to "mm-dd-yyyy". Depends on user's locale.

Returns:
a simple date format
Since:
1.5
Expected behavior:
return a pattern with four y characters in it, not allow the returned SimpleDateFormat to be modified

toPatientFilter

@Deprecated
public static PatientFilter toPatientFilter(PatientSearch search,
                                                       CohortSearchHistory history)
Deprecated. see reportingcompatibility module


parse

public static java.lang.Object parse(java.lang.String string,
                                     java.lang.Class clazz)
Takes a String (e.g. a user-entered one) and parses it into an object of the specified class

Parameters:
string -
clazz -
Returns:
Object of type clazz with the data from string

toPatientFilter

@Deprecated
public static PatientFilter toPatientFilter(PatientSearch search,
                                                       CohortSearchHistory history,
                                                       EvaluationContext evalContext)
Deprecated. see reportingcompatibility module

Uses reflection to translate a PatientSearch into a PatientFilter


collectionContains

public static boolean collectionContains(java.util.Collection<?> objects,
                                         java.lang.Object obj)
Loops over the collection to check to see if the given object is in that collection. This method only uses the .equals() method for comparison. This should be used in the patient/person objects on their collections. Their collections are SortedSets which use the compareTo method for equality as well. The compareTo method is currently optimized for sorting, not for equality. A null obj will return false

Parameters:
objects - collection to loop over
obj - Object to look for in the objects
Returns:
true/false whether the given object is found
Expected behavior:
use equals method for comparison instead of compareTo given List collection, use equals method for comparison instead of compareTo given SortedSet collection

getSerializer

@Deprecated
public static org.simpleframework.xml.Serializer getSerializer()
Deprecated. - Use OpenmrsSerializer from Context.getSerializationService.getDefaultSerializer() Note, this uses a different Serialization mechanism, so you may need to use this for conversion

Get a serializer that will do the common type of serialization and deserialization. Cycles of objects are taken into account

Returns:
Serializer to do the (de)serialization

getShortSerializer

@Deprecated
public static org.simpleframework.xml.Serializer getShortSerializer()
Deprecated. - Use OpenmrsSerializer from Context.getSerializationService.getDefaultSerializer() Note, this uses a different Serialization mechanism, so you may need to use this for conversion

Get a short serializer that will only do the very basic serialization necessary. This is controlled by the objects that are being serialized via the @Replace methods

Returns:
Serializer to do the short (de)serialization
See Also:
OpenmrsConstants.SHORT_SERIALIZATION

isShortSerialization

@Deprecated
public static boolean isShortSerialization(java.util.Map<?,?> sessionMap)
Deprecated. - use SerializationService and OpenmrsSerializer implementation for Serialization

True/false whether the current serialization is supposed to be a short serialization. A shortened serialization This should be called from methods marked with the @Replace notation that take in a single Map parameter.

Parameters:
sessionMap - current serialization session
Returns:
true/false whether or not to do the shortened serialization

getOutFile

public static java.io.File getOutFile(java.io.File dir,
                                      java.util.Date date,
                                      User user)
Gets an out File object. If date is not provided, the current timestamp is used. If user is not provided, the user id is not put into the filename. Assumes dir is already created

Parameters:
dir - directory to make the random filename in
date - optional Date object used for the name
user - optional User creating this file object
Returns:
file new file that is able to be written to

generateUid

public static java.lang.String generateUid(java.lang.Integer size)
Creates a relatively acceptable unique string of the give size

Returns:
unique string

generateUid

public static java.lang.String generateUid()
Creates a uid of length 20

See Also:
generateUid(Integer)

postToUrl

public static java.lang.String postToUrl(java.lang.String urlString,
                                         java.util.Map<java.lang.String,java.lang.String> dataToPost)
Post the given map of variables to the given url string

Parameters:
urlString - valid http url to post data to
dataToPost - Map of key value pairs to post to urlString
Returns:
response from urlString after posting

storeProperties

public static void storeProperties(java.util.Properties properties,
                                   java.io.File file,
                                   java.lang.String comment)
Convenience method to replace Properties.store(), which isn't UTF-8 compliant
NOTE: In Java 6, you will be able to pass the load() and store() methods a UTF-8 Reader/Writer object as an argument, making this method unnecessary.

Parameters:
properties -
file -
comment -

storeProperties

public static void storeProperties(java.util.Properties properties,
                                   java.io.OutputStream outStream,
                                   java.lang.String comment)
Convenience method to replace Properties.store(), which isn't UTF-8 compliant NOTE: In Java 6, you will be able to pass the load() and store() methods a UTF-8 Reader/Writer object as an argument.

Parameters:
properties -
file -
comment - (which appears in comments in properties file)

loadProperties

public static void loadProperties(java.util.Properties props,
                                  java.io.InputStream input)
Deprecated. use loadProperties(Properties, File)

This method is a replacement for Properties.load(InputStream) so that we can load in utf-8 characters. Currently the load method expects the inputStream to point to a latin1 encoded file.
NOTE: In Java 6, you will be able to pass the load() and store() methods a UTF-8 Reader/Writer object as an argument, making this method unnecesary.

Parameters:
props - the properties object to write into
input - the input stream to read from

loadProperties

public static void loadProperties(java.util.Properties props,
                                  java.io.File propertyFile)
Convenience method used to load properties from the given file.

Parameters:
props - the properties object to be loaded into
propertyFile - the properties file to read

getMessage

public static java.lang.String getMessage(java.lang.String code,
                                          java.lang.Object... args)
Utility method for getting the translation for the passed code

Parameters:
code - the message key to lookup
args - the replacement values for the translation string
Returns:
the message, or if not found, the code

validatePassword

public static void validatePassword(java.lang.String username,
                                    java.lang.String password,
                                    java.lang.String systemId)
                             throws PasswordException
Utility to check the validity of a password for a certain User. Passwords must be non-null. Their required strength is configured via global properties:
Description Property Default Value
Require that it not match the User's username or system id OpenmrsConstants.GP_PASSWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID true
Require a minimum length OpenmrsConstants.GP_PASSWORD_MINIMUM_LENGTH 8
Require both an upper and lower case character OpenmrsConstants.GP_PASSWORD_REQUIRES_UPPER_AND_LOWER_CASE true
Require at least one numeric character OpenmrsConstants.GP_PASSWORD_REQUIRES_DIGIT true
Require at least one non-numeric character OpenmrsConstants.GP_PASSWORD_REQUIRES_NON_DIGIT true
Require a match on the specified regular expression OpenmrsConstants.GP_PASSWORD_CUSTOM_REGEX null

Parameters:
username - user name of the user with password to validated
password - string that will be validated
systemId - system id of the user with password to be validated
Throws:
PasswordException
Since:
1.5
Expected behavior:
fail with short password by default, fail with short password if not allowed, pass with short password if allowed, fail with digit only password by default, fail with digit only password if not allowed, pass with digit only password if allowed, fail with char only password by default, fail with char only password if not allowed, pass with char only password if allowed, fail without both upper and lower case password by default, fail without both upper and lower case password if not allowed, pass without both upper and lower case password if allowed, fail with password equals to user name by default, fail with password equals to user name if not allowed, pass with password equals to user name if allowed, fail with password equals to system id by default, fail with password equals to system id if not allowed, pass with password equals to system id if allowed, fail with password not matching configured regex, pass with password matching configured regex, allow password to contain non alphanumeric characters, allow password to contain white spaces, still work without an open session

containsUpperAndLowerCase

public static boolean containsUpperAndLowerCase(java.lang.String test)
Parameters:
test - the string to test
Returns:
true if the passed string contains both upper and lower case characters
Expected behavior:
return true if string contains upper and lower case, return false if string does not contain lower case characters, return false if string does not contain upper case characters

containsOnlyDigits

public static boolean containsOnlyDigits(java.lang.String test)
Parameters:
test - the string to test
Returns:
true if the passed string contains only numeric characters
Expected behavior:
return true if string contains only digits, return false if string contains any non-digits

containsDigit

public static boolean containsDigit(java.lang.String test)
Parameters:
test - the string to test
Returns:
true if the passed string contains any numeric characters
Expected behavior:
return true if string contains any digits, return false if string contains no digits

closeStream

public static void closeStream(java.io.Closeable closableStream)
A null-safe and exception safe way to close an inputstream or an outputstream

Parameters:
closableStream - an InputStream or OutputStream to close

shortenedStackTrace

public static java.lang.String shortenedStackTrace(java.lang.String stackTrace)
Convert a stack trace into a shortened version for easier viewing and data storage, including only those lines we are most concerned with

Parameters:
stackTrace - original stack trace from an error
Returns:
shortened stack trace
Expected behavior:
return null if stackTrace is null, remove springframework and reflection related lines

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change