|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openmrs.util.OpenmrsUtil
public class OpenmrsUtil
Utility methods used in openmrs
Constructor Summary | |
---|---|
OpenmrsUtil()
|
Method Summary | ||
---|---|---|
static
|
addToListMap(java.util.Map<K,java.util.List<V>> map,
K key,
V obj)
|
|
static
|
addToSetMap(java.util.Map<K,java.util.Set<V>> map,
K key,
V obj)
Allows easy manipulation of a Map, Set> |
|
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
|
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
|
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
|
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
|
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
|
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
|
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 |
|
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 |
---|
public OpenmrsUtil()
Method Detail |
---|
@Deprecated public static int getCheckDigit(java.lang.String idWithoutCheckdigit) throws java.lang.Exception
PatientService.getIdentifierValidator(String)
idWithoutCheckdigit
-
java.lang.Exception
@Deprecated public static boolean isValidCheckDigit(java.lang.String id) throws java.lang.Exception
PatientService.getIdentifierValidator(String)
id
-
java.lang.Exception
- on invalid characters and invalid id formationpublic static <E> java.util.Collection<java.util.Collection<E>> compareLists(java.util.Collection<E> origList, java.util.Collection<E> newList)
origList
- newList
-
public static boolean isStringInArray(java.lang.String str, java.lang.String[] arr)
public static java.lang.Boolean isInNormalNumericRange(java.lang.Float value, ConceptNumeric concept)
public static java.lang.Boolean isInCriticalNumericRange(java.lang.Float value, ConceptNumeric concept)
public static java.lang.Boolean isInAbsoluteNumericRange(java.lang.Float value, ConceptNumeric concept)
public static java.lang.Boolean isValidNumericValue(java.lang.Float value, ConceptNumeric concept)
public static java.lang.String getFileAsString(java.io.File file) throws java.io.IOException
file
-
java.io.IOException
public static byte[] getFileAsBytes(java.io.File file) throws java.io.IOException
file
-
java.io.IOException
public static void copyFile(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws java.io.IOException
inputStream
- Stream to copy fromoutputStream
- Stream/location to copy to
java.io.IOException
- thrown if an error occurs during read/writepublic static boolean folderContains(java.io.File folder, java.lang.String filename)
filename
in folder
folder
- filename
-
public static void startup(java.util.Properties p)
p
- properties from runtime configurationpublic static void applyLogLevels()
public static void applyLogLevel(java.lang.String logClass, java.lang.String logLevel)
logClass
to logLevel
.
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_*public static java.util.Map<java.lang.String,java.lang.String> parseParameterList(java.lang.String paramList)
paramList
- String
with a list of parameters
public static <Arg1,Arg2 extends Arg1> boolean nullSafeEquals(Arg1 d1, Arg2 d2)
public static int compare(java.util.Date d1, java.util.Date d2)
public static int compareWithNullAsEarliest(java.util.Date d1, java.util.Date d2)
public static int compareWithNullAsLatest(java.util.Date d1, java.util.Date d2)
public static <E extends java.lang.Comparable<E>> int compareWithNullAsLowest(E c1, E c2)
public static <E extends java.lang.Comparable<E>> int compareWithNullAsGreatest(E c1, E c2)
@Deprecated public static java.lang.Integer ageFromBirthdate(java.util.Date birthdate)
Person.getAge(Date)
public static <E> java.lang.String join(java.util.Collection<E> c, java.lang.String separator)
c
- Collection to be joinedseparator
- string to put between all elements
public static java.util.Set<Concept> conceptSetHelper(java.lang.String descriptor)
public static java.util.List<Concept> delimitedStringToConceptList(java.lang.String delimitedString, java.lang.String delimiter, Context context)
public static java.util.Map<java.lang.String,Concept> delimitedStringToConceptMap(java.lang.String delimitedString, java.lang.String delimiter)
public static Concept getConceptByIdOrName(java.lang.String idOrName)
public static java.util.List<Concept> conceptListHelper(java.lang.String descriptor)
public static java.util.Date lastSecondOfDay(java.util.Date date)
date
- date to adjust
public static java.util.Date safeDate(java.util.Date d1)
public static boolean deleteDirectory(java.io.File dir) throws java.io.IOException
dir
folder
dir
- File directory to delete
java.io.IOException
- if dir
is not a directorypublic static java.io.File url2file(java.net.URL url)
url
- an URL
null
if URL is not localpublic static java.io.InputStream getResourceInputStream(java.net.URL url) throws java.io.IOException
url
- resource URL
java.io.IOException
- if any I/O error has occurredpublic static java.lang.String getApplicationDataDirectory()
public static java.io.File getDirectoryInApplicationDataDirectory(java.lang.String folderName) throws APIException
folderName
-
APIException
public static void saveDocument(org.w3c.dom.Document doc, java.io.File outFile)
doc
- Document to be savedoutFile
- file pointer to the location the xml file is to be saved topublic static java.util.List<java.lang.Integer> delimitedStringToIntegerList(java.lang.String delimitedString, java.lang.String delimiter)
public static boolean isConceptInList(Concept concept, java.util.List<Concept> list)
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)
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)
public static <T> boolean containsAny(java.util.Collection<T> collection, java.util.Collection<T> elements)
collection
- elements
-
public static <K,V> void addToSetMap(java.util.Map<K,java.util.Set<V>> map, K key, V obj)
public static <K,V> void addToListMap(java.util.Map<K,java.util.List<V>> map, K key, V obj)
@Deprecated public static java.text.SimpleDateFormat getDateFormat()
Context.getDateFormat()
or #getDateFormat(Context#getLocale())
instead
public static java.text.SimpleDateFormat getDateFormat(java.util.Locale locale)
@Deprecated public static PatientFilter toPatientFilter(PatientSearch search, CohortSearchHistory history)
public static java.lang.Object parse(java.lang.String string, java.lang.Class clazz)
string
- clazz
-
clazz
with the data from string
@Deprecated public static PatientFilter toPatientFilter(PatientSearch search, CohortSearchHistory history, EvaluationContext evalContext)
public static boolean collectionContains(java.util.Collection<?> objects, java.lang.Object obj)
obj
will return false
objects
- collection to loop overobj
- Object to look for in the objects
@Deprecated public static org.simpleframework.xml.Serializer getSerializer()
@Deprecated public static org.simpleframework.xml.Serializer getShortSerializer()
OpenmrsConstants.SHORT_SERIALIZATION
@Deprecated public static boolean isShortSerialization(java.util.Map<?,?> sessionMap)
Map
parameter.
sessionMap
- current serialization session
public static java.io.File getOutFile(java.io.File dir, java.util.Date date, User user)
dir
- directory to make the random filename indate
- optional Date object used for the nameuser
- optional User creating this file object
public static java.lang.String generateUid(java.lang.Integer size)
public static java.lang.String generateUid()
generateUid(Integer)
public static java.lang.String postToUrl(java.lang.String urlString, java.util.Map<java.lang.String,java.lang.String> dataToPost)
urlString
- valid http url to post data todataToPost
- Mappublic static void storeProperties(java.util.Properties properties, java.io.File file, java.lang.String comment)
properties
- file
- comment
- public static void storeProperties(java.util.Properties properties, java.io.OutputStream outStream, java.lang.String comment)
properties
- file
- comment
- (which appears in comments in properties file)public static void loadProperties(java.util.Properties props, java.io.InputStream input)
loadProperties(Properties, File)
props
- the properties object to write intoinput
- the input stream to read frompublic static void loadProperties(java.util.Properties props, java.io.File propertyFile)
props
- the properties object to be loaded intopropertyFile
- the properties file to readpublic static java.lang.String getMessage(java.lang.String code, java.lang.Object... args)
code
- the message key to lookupargs
- the replacement values for the translation string
public static void validatePassword(java.lang.String username, java.lang.String password, java.lang.String systemId) throws PasswordException
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 |
username
- user name of the user with password to validatedpassword
- string that will be validatedsystemId
- system id of the user with password to be validated
PasswordException
public static boolean containsUpperAndLowerCase(java.lang.String test)
test
- the string to test
public static boolean containsOnlyDigits(java.lang.String test)
test
- the string to test
public static boolean containsDigit(java.lang.String test)
test
- the string to test
public static void closeStream(java.io.Closeable closableStream)
closableStream
- an InputStream or OutputStream to closepublic static java.lang.String shortenedStackTrace(java.lang.String stackTrace)
stackTrace
- original stack trace from an error
|
OpenMRS-1.7.x | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |