edu.internet2.middleware.grouper.ws.util
Class GrouperServiceUtils

java.lang.Object
  extended by edu.internet2.middleware.grouper.ws.util.GrouperServiceUtils

public final class GrouperServiceUtils
extends Object

Author:
mchyzer

Field Summary
static GrouperSession testSession
          test session so we can run tests not in a container
static String WS_LITE_OBJECT_TYPE
          url param for the classname of a bean
 
Method Summary
static void addResponseHeaders(HttpServletResponse response, String success, String resultCode, String resultCode2)
          add response headers for a success and response code
static void addResponseHeaders(WsResultMeta wsResultMeta, boolean isSoap)
          add response headers for a success and response code will retrieve the response object from threadlocal
static int arrayLengthAtLeastOne(Object[] objects, String configNameOfMax, int defaultMax, String label)
          get array length, make sure at least 1
static Boolean booleanObjectValue(String input, String paramName)
          parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
static String booleanToStringOneChar(Boolean theBoolean)
          convert a boolean to a T or F
static boolean booleanValue(String input, boolean defaultValue, String paramName)
          parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
static boolean booleanValue(String input, String paramName)
          parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
static String[] calculateSubjectAttributes(String[] requestedAttributes, boolean includeSubjectDetailBoolean)
           
static ClassLoader classLoader()
          fast class loader
static URL computeUrl(String resourceName, boolean canBeNull)
          compute a url of a resource
static Set<Privilege> convertAccessPrivilegesToPrivileges(Set<AccessPrivilege> accessPrivileges)
          convert a set of access privileges to privileges
static AttributeAssignDelegatable convertAttributeAssignDelegatable(String attributeAssignDelegatable)
          convert the AttributeAssignDelegatable, default to null
static AttributeAssignOperation convertAttributeAssignOperation(String attributeAssignOperation)
          convert the attributeAssignOperation, default to null
static AttributeAssignType convertAttributeAssignType(String attributeAssignType)
          convert the attributeAssignType, default to null
static AttributeAssignValueOperation convertAttributeAssignValueOperation(String attributeAssignValueOperation)
          convert the attributeAssignValueOperation, default to null
static AttributeDefType convertAttributeDefType(String attributeDefTypeString)
          convert the attributeDefType, default to null
static AttributeDefValueType convertAttributeDefValueType(String attributeDefValueTypeString)
          convert the attributeDefValueType, default to null
static GrouperVersion convertGrouperWsVersion(String theVersion)
          convert the version safely with a descriptive message.
static Map<String,Object> convertLimitsToMap(WsPermissionEnvVar[] limitEnvParams)
          if wrong size or a name is blank, then throw descriptive exception.
static WsMemberFilter convertMemberFilter(String memberFilter)
          convert the member filter, default to all
static Map<String,String> convertParamsToMap(WsParam[] params)
          if wrong size or a name is blank, then throw descriptive exception.
static PermissionAssignOperation convertPermissionAssignOperation(String permissionAssignOperation)
          convert the permissionAssignOperation, default to null
static PermissionType convertPermissionType(String permissionType)
          convert the permissionType, default to null
static Map<String,String> convertQueryStringToMap(String queryString)
          convert a query string to a map (for testing purposes only, in a real system the HttpServletRequest would be used.
static SaveMode convertSaveMode(String theSaveMode)
          convert the save mode safely with a descriptive message
static Member convertSubjectToMember(GrouperSession session, Subject subject)
          convert a subject to a member, throw an invalid query exception if there is a problem, with a descriptive cause
static GrouperTransactionType convertTransactionType(String txTypeString)
          convert the tx type safely with a descriptive message
static Class<?> currentServiceClass()
           
static String dateToString(Date date)
          convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23
static
<E extends Enum<?>>
E
enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNull)
          do a case-insensitive matching
static String extractSubjectInfoFromUrlStrings(List<String> urlStrings, int startIndex, boolean sourceIdOrSubjectId, boolean removeSubjectUrlStrings)
           from url strings, get the subjectId e.g.
static String fieldName(Field field)
          get null safe field name from field
static File fileFromResourceName(String resourceName)
          get a file name from a resource name
static
<T> T
firstInArrayOfOne(T[] array)
          take an array.
static String formatHttp(String http)
          take an http request and format it (assume xml or json)
static Integer integerValue(String input, String paramName)
          parse an integer or null
static WsPermissionEnvVar[] limitEnvVars(String limitEnvVarName0, String limitEnvVarValue0, String limitEnvVarType0, String limitEnvVarName1, String limitEnvVarValue1, String limitEnvVarType1)
          organize limit env vars
static Object marshalHttpParamsToObject(Map<String,String> paramMap, HttpServletRequest httpServletRequest, StringBuilder warnings)
          take http params and put into an object (type is specified in the http params object if there is an object specified)
static String marshalLiteBeanToQueryString(Object object, boolean convertNullToEmpty, boolean includeClassName)
          convert a bean to a query string (including bean type)
static
<T> T[]
mergeArrays(T[] toArray, T[] fromArray, String[] propertyNamesForEquality, Class<T> theClass)
          merge one array into another array and return it
static
<T> T[]
mergeArrays(T[] toArray, T[] fromArray, String propertyNameForEquality, Class<T> theClass)
          merge one array into another array and return it
static
<T> boolean
nullArray(T[] array)
          see if array is empty or size 0 or size 1 with null inside
static WsParam[] params(String paramName0, String paramValue0, String paramName1, String paramValue1)
          organize params
static String pickOne(String first, String second, boolean allowBlank, String reasonFieldName)
          pick one of the values which is not null or empty.
static String popUrlString(List<String> urlStrings)
          pop first url string, retrieve, and remove, or null if not there
static MultiKey propertyNameValues(Object object, String[] propertyNamesForEquality)
           
static Field retrieveField(String fieldName)
          convert a fieldName into a Field
static FieldType retrieveFieldType(String fieldTypeName)
          convert a fieldTypeName into a FieldType
static GrouperSession retrieveGrouperSession(WsSubjectLookup actAsSubjectLookup)
          convert the actAsSubjectLookup (and the currently logged in user) to a grouper session
static GroupType retrieveGroupType(String groupTypeName)
          retrieve group type based on name
static Date stringToDate(String dateString)
          convert a string to a date using the standard web service pattern Note that HH is 0-23
static Timestamp stringToTimestamp(String timestampString)
          convert a string to a date using the standard web service pattern Note that HH is 0-23
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WS_LITE_OBJECT_TYPE

public static final String WS_LITE_OBJECT_TYPE
url param for the classname of a bean

See Also:
Constant Field Values

testSession

public static GrouperSession testSession
test session so we can run tests not in a container

Method Detail

currentServiceClass

public static Class<?> currentServiceClass()
Returns:
the class

computeUrl

public static URL computeUrl(String resourceName,
                             boolean canBeNull)
compute a url of a resource

Parameters:
resourceName -
canBeNull - if cant be null, throw runtime
Returns:
the URL

classLoader

public static ClassLoader classLoader()
fast class loader

Returns:
the class loader

fileFromResourceName

public static File fileFromResourceName(String resourceName)
get a file name from a resource name

Parameters:
resourceName - is the classpath location
Returns:
the file path on the system

retrieveGroupType

public static GroupType retrieveGroupType(String groupTypeName)
retrieve group type based on name

Parameters:
groupTypeName -
Returns:
group type

enumValueOfIgnoreCase

public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass,
                                                          String string,
                                                          boolean exceptionOnNull)
                                               throws GrouperRestInvalidRequest
do a case-insensitive matching

Type Parameters:
E - generic type
Parameters:
theEnumClass - class of the enum
string -
exceptionOnNull - true if exception should be thrown on null or blank
Returns:
the enum or null or exception if not found
Throws:
GrouperRestInvalidRequest - if there is a problem

popUrlString

public static String popUrlString(List<String> urlStrings)
pop first url string, retrieve, and remove, or null if not there

Parameters:
urlStrings -
Returns:
the string or null if not there

extractSubjectInfoFromUrlStrings

public static String extractSubjectInfoFromUrlStrings(List<String> urlStrings,
                                                      int startIndex,
                                                      boolean sourceIdOrSubjectId,
                                                      boolean removeSubjectUrlStrings)
 from url strings, get the subjectId
 e.g. if the url is: /groups/aStem:aGroup/members/123412345
 then the index should be 3 (0 for group, 1 for group name, etc) 
 
 if url is: /groups/aStem:aGroup/members/sourceId/someSource/subjectId/123412345
 then index is still 3
 

Parameters:
urlStrings -
startIndex -
removeSubjectUrlStrings - true to remove these url strings after getting data
sourceIdOrSubjectId - true to get sourceId, false to get subjectId
Returns:
the subjectId if it is found, null if not

pickOne

public static String pickOne(String first,
                             String second,
                             boolean allowBlank,
                             String reasonFieldName)
pick one of the values which is not null or empty. if both sent in, make sure they are equal. if neither, then see if ok. return null if none sent in (blank)

Parameters:
first -
second -
allowBlank - if ok if blank (return null)
reasonFieldName - if not ok to be blank and both blank, then put this in error. or if both set to different things, then put this in error
Returns:
one or the other or null or exception
Throws:
WsInvalidQueryException - if there is a problem with the reason text in there

marshalHttpParamsToObject

public static Object marshalHttpParamsToObject(Map<String,String> paramMap,
                                               HttpServletRequest httpServletRequest,
                                               StringBuilder warnings)
take http params and put into an object (type is specified in the http params object if there is an object specified)

Parameters:
paramMap -
httpServletRequest - if not null, make sure no dupes. if null, forget it
warnings - is the warnings, if null, just throw exception
Returns:
the object or null if nothing in query params

convertQueryStringToMap

public static Map<String,String> convertQueryStringToMap(String queryString)
convert a query string to a map (for testing purposes only, in a real system the HttpServletRequest would be used. no dupes allowed

Parameters:
queryString -
Returns:
the map (null if no query string)

marshalLiteBeanToQueryString

public static String marshalLiteBeanToQueryString(Object object,
                                                  boolean convertNullToEmpty,
                                                  boolean includeClassName)
convert a bean to a query string (including bean type)

Parameters:
object -
convertNullToEmpty - is true to convert null to empty, false to exclude nulls
includeClassName - true to include the classname in the params
Returns:
the query string

formatHttp

public static String formatHttp(String http)
take an http request and format it (assume xml or json)

Parameters:
http -
Returns:
format

fieldName

public static String fieldName(Field field)
get null safe field name from field

Parameters:
field -
Returns:
field name

firstInArrayOfOne

public static <T> T firstInArrayOfOne(T[] array)
take an array. if array size is null or empty, then return null. if array size if more than one, then error return first

Type Parameters:
T -
Parameters:
array - is the array to interrogate
Returns:
the first or null

convertSubjectToMember

public static Member convertSubjectToMember(GrouperSession session,
                                            Subject subject)
convert a subject to a member, throw an invalid query exception if there is a problem, with a descriptive cause

Parameters:
session -
subject -
Returns:
the member

convertMemberFilter

public static WsMemberFilter convertMemberFilter(String memberFilter)
                                          throws WsInvalidQueryException
convert the member filter, default to all

Parameters:
memberFilter -
Returns:
the member filter
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeAssignType

public static AttributeAssignType convertAttributeAssignType(String attributeAssignType)
                                                      throws WsInvalidQueryException
convert the attributeAssignType, default to null

Parameters:
attributeAssignType -
Returns:
the attributeAssignType
Throws:
WsInvalidQueryException - if there is a problem

convertPermissionType

public static PermissionType convertPermissionType(String permissionType)
                                            throws WsInvalidQueryException
convert the permissionType, default to null

Parameters:
permissionType -
Returns:
the permissionType
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeAssignOperation

public static AttributeAssignOperation convertAttributeAssignOperation(String attributeAssignOperation)
                                                                throws WsInvalidQueryException
convert the attributeAssignOperation, default to null

Parameters:
attributeAssignOperation -
Returns:
the attributeAssignOperation
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeDefValueType

public static AttributeDefValueType convertAttributeDefValueType(String attributeDefValueTypeString)
                                                          throws WsInvalidQueryException
convert the attributeDefValueType, default to null

Parameters:
attributeDefValueTypeString -
Returns:
the attributeDefValueType
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeDefType

public static AttributeDefType convertAttributeDefType(String attributeDefTypeString)
                                                throws WsInvalidQueryException
convert the attributeDefType, default to null

Parameters:
attributeDefTypeString -
Returns:
the attributeDefType
Throws:
WsInvalidQueryException - if there is a problem

convertPermissionAssignOperation

public static PermissionAssignOperation convertPermissionAssignOperation(String permissionAssignOperation)
                                                                  throws WsInvalidQueryException
convert the permissionAssignOperation, default to null

Parameters:
permissionAssignOperation -
Returns:
the permissionAssignOperation
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeAssignDelegatable

public static AttributeAssignDelegatable convertAttributeAssignDelegatable(String attributeAssignDelegatable)
                                                                    throws WsInvalidQueryException
convert the AttributeAssignDelegatable, default to null

Parameters:
attributeAssignDelegatable -
Returns:
the AttributeAssignDelegatable
Throws:
WsInvalidQueryException - if there is a problem

convertAttributeAssignValueOperation

public static AttributeAssignValueOperation convertAttributeAssignValueOperation(String attributeAssignValueOperation)
                                                                          throws WsInvalidQueryException
convert the attributeAssignValueOperation, default to null

Parameters:
attributeAssignValueOperation -
Returns:
the attributeAssignValueOperation
Throws:
WsInvalidQueryException - if there is a problem

convertTransactionType

public static GrouperTransactionType convertTransactionType(String txTypeString)
                                                     throws WsInvalidQueryException
convert the tx type safely with a descriptive message

Parameters:
txTypeString -
Returns:
the tx type
Throws:
WsInvalidQueryException

convertSaveMode

public static SaveMode convertSaveMode(String theSaveMode)
                                throws WsInvalidQueryException
convert the save mode safely with a descriptive message

Parameters:
theSaveMode -
Returns:
the save mode
Throws:
WsInvalidQueryException

convertGrouperWsVersion

public static GrouperVersion convertGrouperWsVersion(String theVersion)
                                              throws WsInvalidQueryException
convert the version safely with a descriptive message. there is no default version

Parameters:
theVersion -
Returns:
the version
Throws:
WsInvalidQueryException

retrieveGrouperSession

public static GrouperSession retrieveGrouperSession(WsSubjectLookup actAsSubjectLookup)
convert the actAsSubjectLookup (and the currently logged in user) to a grouper session

Parameters:
actAsSubjectLookup -
Returns:
the session

arrayLengthAtLeastOne

public static int arrayLengthAtLeastOne(Object[] objects,
                                        String configNameOfMax,
                                        int defaultMax,
                                        String label)
                                 throws WsInvalidQueryException
get array length, make sure at least 1

Parameters:
objects - to count
configNameOfMax - is the config name of grouper-ws.properties where the max number of subjects is
defaultMax - is the default if not in the config file
label - for error
Returns:
the length
Throws:
WsInvalidQueryException - if array is null or size 0 or more than max

convertParamsToMap

public static Map<String,String> convertParamsToMap(WsParam[] params)
                                             throws WsInvalidQueryException
if wrong size or a name is blank, then throw descriptive exception. Assumes all params can be put into a map, only one name can be sent per request, no blank names.

Parameters:
params -
Returns:
the map of names to values, will not return null
Throws:
WsInvalidQueryException - if problem with inputs

convertLimitsToMap

public static Map<String,Object> convertLimitsToMap(WsPermissionEnvVar[] limitEnvParams)
                                             throws WsInvalidQueryException
if wrong size or a name is blank, then throw descriptive exception. Assumes all params can be put into a map, only one name can be sent per request, no blank names.

Parameters:
limitEnvParams -
Returns:
the map of names to values, will not return null
Throws:
WsInvalidQueryException - if problem with inputs

calculateSubjectAttributes

public static String[] calculateSubjectAttributes(String[] requestedAttributes,
                                                  boolean includeSubjectDetailBoolean)
Parameters:
requestedAttributes -
requestedAttributesLength -
includeSubjectDetailBoolean -
Returns:
the attributes calculated

booleanToStringOneChar

public static String booleanToStringOneChar(Boolean theBoolean)
convert a boolean to a T or F

Parameters:
theBoolean -
Returns:
T or F

booleanValue

public static boolean booleanValue(String input,
                                   boolean defaultValue,
                                   String paramName)
                            throws WsInvalidQueryException
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive. If not specified, then use default. If malformed, then exception

Parameters:
input -
defaultValue -
paramName - to put in the invalid query exception
Returns:
the boolean
Throws:
WsInvalidQueryException - if there is a problem

booleanValue

public static boolean booleanValue(String input,
                                   String paramName)
                            throws WsInvalidQueryException
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive. If not specified, then exception. If malformed, then exception

Parameters:
input -
paramName - to put in the invalid query exception
Returns:
the boolean
Throws:
WsInvalidQueryException - if there is a problem

booleanObjectValue

public static Boolean booleanObjectValue(String input,
                                         String paramName)
                                  throws WsInvalidQueryException
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive. If not specified, then use default. If malformed, then exception

Parameters:
input -
paramName - to put in the invalid query exception
Returns:
the Boolean
Throws:
WsInvalidQueryException - if there is a problem

integerValue

public static Integer integerValue(String input,
                                   String paramName)
                            throws WsInvalidQueryException
parse an integer or null

Parameters:
input -
paramName - to put in the invalid query exception
Returns:
the Integer
Throws:
WsInvalidQueryException - if there is a problem

retrieveField

public static Field retrieveField(String fieldName)
convert a fieldName into a Field

Parameters:
fieldName - name of field
Returns:
the field, or throw invalid query exception, or null if not there

retrieveFieldType

public static FieldType retrieveFieldType(String fieldTypeName)
convert a fieldTypeName into a FieldType

Parameters:
fieldTypeName - name of fieldType e.g. list (default, memberships), access (privs on groups), attribute_def (privs on attribute definitions), naming (privs on folders)
Returns:
the fieldType, or throw invalid query exception, or null if not there

dateToString

public static String dateToString(Date date)
convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23

Parameters:
date -
Returns:
the string, or null if the date is null

stringToDate

public static Date stringToDate(String dateString)
convert a string to a date using the standard web service pattern Note that HH is 0-23

Parameters:
dateString -
Returns:
the string, or null if the date was null

stringToTimestamp

public static Timestamp stringToTimestamp(String timestampString)
convert a string to a date using the standard web service pattern Note that HH is 0-23

Parameters:
timestampString -
Returns:
the string, or null if the date was null

params

public static WsParam[] params(String paramName0,
                               String paramValue0,
                               String paramName1,
                               String paramValue1)
organize params

Parameters:
paramName0 -
paramValue0 -
paramName1 -
paramValue1 -
Returns:
the array param names

limitEnvVars

public static WsPermissionEnvVar[] limitEnvVars(String limitEnvVarName0,
                                                String limitEnvVarValue0,
                                                String limitEnvVarType0,
                                                String limitEnvVarName1,
                                                String limitEnvVarValue1,
                                                String limitEnvVarType1)
organize limit env vars

Parameters:
limitEnvVarName0 - limitEnvVars if processing limits, pass in a set of limits. The name is the name of the variable, and the value is the value. Note, you can typecast the values by putting a valid type in parens in front of the param name. e.g. name: (int)amount, value: 50
limitEnvVarValue0 - first limit env var value
limitEnvVarType0 - first limit env var type
limitEnvVarName1 - second limit env var name
limitEnvVarValue1 - second limit env var value
limitEnvVarType1 - second limit env var type
Returns:
the array limit env vars

convertAccessPrivilegesToPrivileges

public static Set<Privilege> convertAccessPrivilegesToPrivileges(Set<AccessPrivilege> accessPrivileges)
convert a set of access privileges to privileges

Parameters:
accessPrivileges -
Returns:
the set of privileges, will never return null

addResponseHeaders

public static void addResponseHeaders(HttpServletResponse response,
                                      String success,
                                      String resultCode,
                                      String resultCode2)
add response headers for a success and response code

Parameters:
response -
success - T or F
resultCode -
resultCode2 -

addResponseHeaders

public static void addResponseHeaders(WsResultMeta wsResultMeta,
                                      boolean isSoap)
add response headers for a success and response code will retrieve the response object from threadlocal

Parameters:
wsResultMeta - result metadata
isSoap - if soap

nullArray

public static <T> boolean nullArray(T[] array)
see if array is empty or size 0 or size 1 with null inside

Type Parameters:
T -
Parameters:
array -
Returns:
true if empty false if not

mergeArrays

public static <T> T[] mergeArrays(T[] toArray,
                                  T[] fromArray,
                                  String propertyNameForEquality,
                                  Class<T> theClass)
merge one array into another array and return it

Type Parameters:
T - is the type that is being handled
Parameters:
toArray -
fromArray -
propertyNameForEquality -
theClass -
Returns:
the new array

mergeArrays

public static <T> T[] mergeArrays(T[] toArray,
                                  T[] fromArray,
                                  String[] propertyNamesForEquality,
                                  Class<T> theClass)
merge one array into another array and return it

Type Parameters:
T - is the type that is being handled
Parameters:
toArray -
fromArray -
propertyNamesForEquality - list of property names which are used for equality
theClass -
Returns:
the new array

propertyNameValues

public static MultiKey propertyNameValues(Object object,
                                          String[] propertyNamesForEquality)
Parameters:
object -
propertyNamesForEquality -
Returns:
the multikey of property values