Class GrouperServiceUtils
java.lang.Object
edu.internet2.middleware.grouper.ws.util.GrouperServiceUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic edu.internet2.middleware.grouper.GrouperSession
test session so we can run tests not in a containerstatic final String
url param for the classname of a bean -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addResponseHeaders
(WsResultMeta wsResultMeta, boolean isSoap) add response headers for a success and response code will retrieve the response object from threadlocalstatic void
addResponseHeaders
(javax.servlet.http.HttpServletResponse response, String success, String resultCode, String resultCode2) add response headers for a success and response codestatic int
arrayLengthAtLeastOne
(Object[] objects, String configNameOfMax, int defaultMax, String label) get array length, make sure at least 1static 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 Fstatic 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
fast class loaderstatic URL
computeUrl
(String resourceName, boolean canBeNull) compute a url of a resourcestatic Set<edu.internet2.middleware.grouper.privs.Privilege>
convertAccessPrivilegesToPrivileges
(Set<edu.internet2.middleware.grouper.privs.AccessPrivilege> accessPrivileges) convert a set of access privileges to privilegesstatic edu.internet2.middleware.grouper.attr.assign.AttributeAssignDelegatable
convertAttributeAssignDelegatable
(String attributeAssignDelegatable) convert the AttributeAssignDelegatable, default to nullstatic edu.internet2.middleware.grouper.attr.assign.AttributeAssignOperation
convertAttributeAssignOperation
(String attributeAssignOperation) convert the attributeAssignOperation, default to nullstatic edu.internet2.middleware.grouper.attr.assign.AttributeAssignType
convertAttributeAssignType
(String attributeAssignType) convert the attributeAssignType, default to nullstatic edu.internet2.middleware.grouper.attr.value.AttributeAssignValueOperation
convertAttributeAssignValueOperation
(String attributeAssignValueOperation) convert the attributeAssignValueOperation, default to nullstatic edu.internet2.middleware.grouper.attr.AttributeDefType
convertAttributeDefType
(String attributeDefTypeString) convert the attributeDefType, default to nullstatic edu.internet2.middleware.grouper.attr.AttributeDefValueType
convertAttributeDefValueType
(String attributeDefValueTypeString) convert the attributeDefValueType, default to nullstatic edu.internet2.middleware.grouper.misc.GrouperVersion
convertGrouperWsVersion
(String theVersion) convert the version safely with a descriptive message.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 allconvertParamsToMap
(WsParam[] params) if wrong size or a name is blank, then throw descriptive exception.static edu.internet2.middleware.grouper.permissions.PermissionAssignOperation
convertPermissionAssignOperation
(String permissionAssignOperation) convert the permissionAssignOperation, default to nullstatic edu.internet2.middleware.grouper.permissions.PermissionEntry.PermissionType
convertPermissionType
(String permissionType) convert the permissionType, default to nullconvertQueryStringToMap
(String queryString) convert a query string to a map (for testing purposes only, in a real system the HttpServletRequest would be used.static edu.internet2.middleware.grouper.misc.SaveMode
convertSaveMode
(String theSaveMode) convert the save mode safely with a descriptive messagestatic edu.internet2.middleware.grouper.Member
convertSubjectToMember
(edu.internet2.middleware.grouper.GrouperSession session, edu.internet2.middleware.subject.Subject subject) convert a subject to a member, throw an invalid query exception if there is a problem, with a descriptive causestatic edu.internet2.middleware.grouper.hibernate.GrouperTransactionType
convertTransactionType
(String txTypeString) convert the tx type safely with a descriptive messagestatic Class<?>
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-23static <E extends Enum<?>>
EenumValueOfIgnoreCase
(Class<E> theEnumClass, String string, boolean exceptionOnNull) do a case-insensitive matchingstatic String
extractSubjectInfoFromUrlStrings
(List<String> urlStrings, int startIndex, boolean sourceIdOrSubjectId, boolean removeSubjectUrlStrings) from url strings, get the subjectId e.g.static String
fieldName
(edu.internet2.middleware.grouper.Field field) get null safe field name from fieldstatic File
fileFromResourceName
(String resourceName) get a file name from a resource namestatic <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 nullstatic WsPermissionEnvVar[]
limitEnvVars
(String limitEnvVarName0, String limitEnvVarValue0, String limitEnvVarType0, String limitEnvVarName1, String limitEnvVarValue1, String limitEnvVarType1) organize limit env varsstatic String
mapToString
(Map<?, ?> map) convert a set to a string (comma separate)static Object
marshalHttpParamsToObject
(Map<String, String[]> paramMap, javax.servlet.http.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 itstatic <T> T[]
mergeArrays
(T[] toArray, T[] fromArray, String propertyNameForEquality, Class<T> theClass) merge one array into another array and return itstatic <T> boolean
nullArray
(T[] array) see if array is empty or size 0 or size 1 with null insidestatic WsParam[]
organize paramsstatic String
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 therestatic edu.internet2.middleware.grouperClient.collections.MultiKey
propertyNameValues
(Object object, String[] propertyNamesForEquality) static edu.internet2.middleware.grouper.Field
retrieveField
(String fieldName) convert a fieldName into a Fieldstatic edu.internet2.middleware.grouper.FieldType
retrieveFieldType
(String fieldTypeName) convert a fieldTypeName into a FieldTypestatic edu.internet2.middleware.grouper.GrouperSession
retrieveGrouperSession
(WsSubjectLookup actAsSubjectLookup) convert the actAsSubjectLookup (and the currently logged in user) to a grouper sessionstatic edu.internet2.middleware.grouper.GroupType
retrieveGroupType
(String groupTypeName) retrieve group type based on namestatic Date
stringToDate
(String dateString) convert a string to a date using the standard web service pattern Note that HH is 0-23static Timestamp
stringToTimestamp
(String timestampString) convert a string to a date using the standard web service pattern Note that HH is 0-23static String
toStringForLog
(Object object, int maxChars) print out various types of objectsstatic String
toStringForWsLog
(Object object)
-
Field Details
-
WS_LITE_OBJECT_TYPE
url param for the classname of a bean- See Also:
-
testSession
public static edu.internet2.middleware.grouper.GrouperSession testSessiontest session so we can run tests not in a container
-
-
Method Details
-
currentServiceClass
- Returns:
- the class
-
computeUrl
compute a url of a resource- Parameters:
resourceName
-canBeNull
- if cant be null, throw runtime- Returns:
- the URL
-
classLoader
fast class loader- Returns:
- the class loader
-
fileFromResourceName
get a file name from a resource name- Parameters:
resourceName
- is the classpath location- Returns:
- the file path on the system
-
retrieveGroupType
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 enumstring
-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
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 datasourceIdOrSubjectId
- 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, javax.servlet.http.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 itwarnings
- is the warnings, if null, just throw exception- Returns:
- the object or null if nothing in query params
-
convertQueryStringToMap
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 nullsincludeClassName
- true to include the classname in the params- Returns:
- the query string
-
formatHttp
take an http request and format it (assume xml or json)- Parameters:
http
-- Returns:
- format
-
fieldName
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 edu.internet2.middleware.grouper.Member convertSubjectToMember(edu.internet2.middleware.grouper.GrouperSession session, edu.internet2.middleware.subject.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 edu.internet2.middleware.grouper.attr.assign.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 edu.internet2.middleware.grouper.permissions.PermissionEntry.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 edu.internet2.middleware.grouper.attr.assign.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 edu.internet2.middleware.grouper.attr.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 edu.internet2.middleware.grouper.attr.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 edu.internet2.middleware.grouper.permissions.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 edu.internet2.middleware.grouper.attr.assign.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 edu.internet2.middleware.grouper.attr.value.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 edu.internet2.middleware.grouper.hibernate.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 edu.internet2.middleware.grouper.misc.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 edu.internet2.middleware.grouper.misc.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 edu.internet2.middleware.grouper.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 countconfigNameOfMax
- is the config name of grouper-ws.properties where the max number of subjects isdefaultMax
- is the default if not in the config filelabel
- 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
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
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
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
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
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
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
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
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: 50limitEnvVarValue0
- first limit env var valuelimitEnvVarType0
- first limit env var typelimitEnvVarName1
- second limit env var namelimitEnvVarValue1
- second limit env var valuelimitEnvVarType1
- second limit env var type- Returns:
- the array limit env vars
-
convertAccessPrivilegesToPrivileges
public static Set<edu.internet2.middleware.grouper.privs.Privilege> convertAccessPrivilegesToPrivileges(Set<edu.internet2.middleware.grouper.privs.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(javax.servlet.http.HttpServletResponse response, String success, String resultCode, String resultCode2) add response headers for a success and response code- Parameters:
response
-success
- T or FresultCode
-resultCode2
-
-
addResponseHeaders
add response headers for a success and response code will retrieve the response object from threadlocal- Parameters:
wsResultMeta
- result metadataisSoap
- 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 equalitytheClass
-- Returns:
- the new array
-
propertyNameValues
public static edu.internet2.middleware.grouperClient.collections.MultiKey propertyNameValues(Object object, String[] propertyNamesForEquality) - Parameters:
object
-propertyNamesForEquality
-- Returns:
- the multikey of property values
-
toStringForLog
print out various types of objects- Parameters:
object
-maxChars
- is the max chars that should be returned (abbreviate if longer), or -1 for any amount- Returns:
- the string value
-
mapToString
convert a set to a string (comma separate)- Parameters:
map
-- Returns:
- the String
-
toStringForWsLog
- Parameters:
object
-- Returns:
- the string value
-