public final class GrouperServiceUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static GrouperSession |
testSession
test session so we can run tests not in a container
|
static java.lang.String |
WS_LITE_OBJECT_TYPE
url param for the classname of a bean
|
Modifier and Type | Method and Description |
---|---|
static void |
addResponseHeaders(javax.servlet.http.HttpServletResponse response,
java.lang.String success,
java.lang.String resultCode,
java.lang.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(java.lang.Object[] objects,
java.lang.String configNameOfMax,
int defaultMax,
java.lang.String label)
get array length, make sure at least 1
|
static java.lang.Boolean |
booleanObjectValue(java.lang.String input,
java.lang.String paramName)
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
|
static java.lang.String |
booleanToStringOneChar(java.lang.Boolean theBoolean)
convert a boolean to a T or F
|
static boolean |
booleanValue(java.lang.String input,
boolean defaultValue,
java.lang.String paramName)
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
|
static boolean |
booleanValue(java.lang.String input,
java.lang.String paramName)
parse a boolean as "T" or "F" or "TRUE" or "FALSE" case insensitive.
|
static java.lang.String[] |
calculateSubjectAttributes(java.lang.String[] requestedAttributes,
boolean includeSubjectDetailBoolean) |
static java.lang.ClassLoader |
classLoader()
fast class loader
|
static java.net.URL |
computeUrl(java.lang.String resourceName,
boolean canBeNull)
compute a url of a resource
|
static java.util.Set<Privilege> |
convertAccessPrivilegesToPrivileges(java.util.Set<AccessPrivilege> accessPrivileges)
convert a set of access privileges to privileges
|
static AttributeAssignDelegatable |
convertAttributeAssignDelegatable(java.lang.String attributeAssignDelegatable)
convert the AttributeAssignDelegatable, default to null
|
static AttributeAssignOperation |
convertAttributeAssignOperation(java.lang.String attributeAssignOperation)
convert the attributeAssignOperation, default to null
|
static AttributeAssignType |
convertAttributeAssignType(java.lang.String attributeAssignType)
convert the attributeAssignType, default to null
|
static AttributeAssignValueOperation |
convertAttributeAssignValueOperation(java.lang.String attributeAssignValueOperation)
convert the attributeAssignValueOperation, default to null
|
static AttributeDefType |
convertAttributeDefType(java.lang.String attributeDefTypeString)
convert the attributeDefType, default to null
|
static AttributeDefValueType |
convertAttributeDefValueType(java.lang.String attributeDefValueTypeString)
convert the attributeDefValueType, default to null
|
static GrouperVersion |
convertGrouperWsVersion(java.lang.String theVersion)
convert the version safely with a descriptive message.
|
static java.util.Map<java.lang.String,java.lang.Object> |
convertLimitsToMap(WsPermissionEnvVar[] limitEnvParams)
if wrong size or a name is blank, then throw descriptive exception.
|
static WsMemberFilter |
convertMemberFilter(java.lang.String memberFilter)
convert the member filter, default to all
|
static java.util.Map<java.lang.String,java.lang.String> |
convertParamsToMap(WsParam[] params)
if wrong size or a name is blank, then throw descriptive exception.
|
static PermissionAssignOperation |
convertPermissionAssignOperation(java.lang.String permissionAssignOperation)
convert the permissionAssignOperation, default to null
|
static PermissionType |
convertPermissionType(java.lang.String permissionType)
convert the permissionType, default to null
|
static java.util.Map<java.lang.String,java.lang.String[]> |
convertQueryStringToMap(java.lang.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(java.lang.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(java.lang.String txTypeString)
convert the tx type safely with a descriptive message
|
static java.lang.Class<?> |
currentServiceClass() |
static java.lang.String |
dateToString(java.util.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 java.lang.Enum<?>> |
enumValueOfIgnoreCase(java.lang.Class<E> theEnumClass,
java.lang.String string,
boolean exceptionOnNull)
do a case-insensitive matching
|
static java.lang.String |
extractSubjectInfoFromUrlStrings(java.util.List<java.lang.String> urlStrings,
int startIndex,
boolean sourceIdOrSubjectId,
boolean removeSubjectUrlStrings)
from url strings, get the subjectId
e.g.
|
static java.lang.String |
fieldName(Field field)
get null safe field name from field
|
static java.io.File |
fileFromResourceName(java.lang.String resourceName)
get a file name from a resource name
|
static <T> T |
firstInArrayOfOne(T[] array)
take an array.
|
static java.lang.String |
formatHttp(java.lang.String http)
take an http request and format it (assume xml or json)
|
static java.lang.Integer |
integerValue(java.lang.String input,
java.lang.String paramName)
parse an integer or null
|
static WsPermissionEnvVar[] |
limitEnvVars(java.lang.String limitEnvVarName0,
java.lang.String limitEnvVarValue0,
java.lang.String limitEnvVarType0,
java.lang.String limitEnvVarName1,
java.lang.String limitEnvVarValue1,
java.lang.String limitEnvVarType1)
organize limit env vars
|
static java.lang.String |
mapToString(java.util.Map<?,?> map)
convert a set to a string (comma separate)
|
static java.lang.Object |
marshalHttpParamsToObject(java.util.Map<java.lang.String,java.lang.String[]> paramMap,
javax.servlet.http.HttpServletRequest httpServletRequest,
java.lang.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 java.lang.String |
marshalLiteBeanToQueryString(java.lang.Object object,
boolean convertNullToEmpty,
boolean includeClassName)
convert a bean to a query string (including bean type)
|
static <T> T[] |
mergeArrays(T[] toArray,
T[] fromArray,
java.lang.String[] propertyNamesForEquality,
java.lang.Class<T> theClass)
merge one array into another array and return it
|
static <T> T[] |
mergeArrays(T[] toArray,
T[] fromArray,
java.lang.String propertyNameForEquality,
java.lang.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(java.lang.String paramName0,
java.lang.String paramValue0,
java.lang.String paramName1,
java.lang.String paramValue1)
organize params
|
static java.lang.String |
pickOne(java.lang.String first,
java.lang.String second,
boolean allowBlank,
java.lang.String reasonFieldName)
pick one of the values which is not null or empty.
|
static java.lang.String |
popUrlString(java.util.List<java.lang.String> urlStrings)
pop first url string, retrieve, and remove, or null if not there
|
static MultiKey |
propertyNameValues(java.lang.Object object,
java.lang.String[] propertyNamesForEquality) |
static Field |
retrieveField(java.lang.String fieldName)
convert a fieldName into a Field
|
static FieldType |
retrieveFieldType(java.lang.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(java.lang.String groupTypeName)
retrieve group type based on name
|
static java.util.Date |
stringToDate(java.lang.String dateString)
convert a string to a date using the standard web service pattern Note
that HH is 0-23
|
static java.sql.Timestamp |
stringToTimestamp(java.lang.String timestampString)
convert a string to a date using the standard web service pattern Note
that HH is 0-23
|
static java.lang.String |
toStringForLog(java.lang.Object object,
int maxChars)
print out various types of objects
|
static java.lang.String |
toStringForWsLog(java.lang.Object object) |
public static final java.lang.String WS_LITE_OBJECT_TYPE
public static GrouperSession testSession
public static java.lang.Class<?> currentServiceClass()
public static java.net.URL computeUrl(java.lang.String resourceName, boolean canBeNull)
resourceName
- canBeNull
- if cant be null, throw runtimepublic static java.lang.ClassLoader classLoader()
public static java.io.File fileFromResourceName(java.lang.String resourceName)
resourceName
- is the classpath locationpublic static GroupType retrieveGroupType(java.lang.String groupTypeName)
groupTypeName
- public static <E extends java.lang.Enum<?>> E enumValueOfIgnoreCase(java.lang.Class<E> theEnumClass, java.lang.String string, boolean exceptionOnNull) throws GrouperRestInvalidRequest
E
- generic typetheEnumClass
- class of the enumstring
- exceptionOnNull
- true if exception should be thrown on null or blankGrouperRestInvalidRequest
- if there is a problempublic static java.lang.String popUrlString(java.util.List<java.lang.String> urlStrings)
urlStrings
- public static java.lang.String extractSubjectInfoFromUrlStrings(java.util.List<java.lang.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
urlStrings
- startIndex
- removeSubjectUrlStrings
- true to remove these url strings after getting datasourceIdOrSubjectId
- true to get sourceId, false to get subjectIdpublic static java.lang.String pickOne(java.lang.String first, java.lang.String second, boolean allowBlank, java.lang.String reasonFieldName)
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 errorWsInvalidQueryException
- if there is a problem with the reason text in therepublic static java.lang.Object marshalHttpParamsToObject(java.util.Map<java.lang.String,java.lang.String[]> paramMap, javax.servlet.http.HttpServletRequest httpServletRequest, java.lang.StringBuilder warnings)
paramMap
- httpServletRequest
- if not null, make sure no dupes. if null, forget itwarnings
- is the warnings, if null, just throw exceptionpublic static java.util.Map<java.lang.String,java.lang.String[]> convertQueryStringToMap(java.lang.String queryString)
queryString
- public static java.lang.String marshalLiteBeanToQueryString(java.lang.Object object, boolean convertNullToEmpty, boolean includeClassName)
object
- convertNullToEmpty
- is true to convert null to empty, false to exclude nullsincludeClassName
- true to include the classname in the paramspublic static java.lang.String formatHttp(java.lang.String http)
http
- public static java.lang.String fieldName(Field field)
field
- public static <T> T firstInArrayOfOne(T[] array)
T
- array
- is the array to interrogatepublic static Member convertSubjectToMember(GrouperSession session, Subject subject)
session
- subject
- public static WsMemberFilter convertMemberFilter(java.lang.String memberFilter) throws WsInvalidQueryException
memberFilter
- WsInvalidQueryException
- if there is a problempublic static AttributeAssignType convertAttributeAssignType(java.lang.String attributeAssignType) throws WsInvalidQueryException
attributeAssignType
- WsInvalidQueryException
- if there is a problempublic static PermissionType convertPermissionType(java.lang.String permissionType) throws WsInvalidQueryException
permissionType
- WsInvalidQueryException
- if there is a problempublic static AttributeAssignOperation convertAttributeAssignOperation(java.lang.String attributeAssignOperation) throws WsInvalidQueryException
attributeAssignOperation
- WsInvalidQueryException
- if there is a problempublic static AttributeDefValueType convertAttributeDefValueType(java.lang.String attributeDefValueTypeString) throws WsInvalidQueryException
attributeDefValueTypeString
- WsInvalidQueryException
- if there is a problempublic static AttributeDefType convertAttributeDefType(java.lang.String attributeDefTypeString) throws WsInvalidQueryException
attributeDefTypeString
- WsInvalidQueryException
- if there is a problempublic static PermissionAssignOperation convertPermissionAssignOperation(java.lang.String permissionAssignOperation) throws WsInvalidQueryException
permissionAssignOperation
- WsInvalidQueryException
- if there is a problempublic static AttributeAssignDelegatable convertAttributeAssignDelegatable(java.lang.String attributeAssignDelegatable) throws WsInvalidQueryException
attributeAssignDelegatable
- WsInvalidQueryException
- if there is a problempublic static AttributeAssignValueOperation convertAttributeAssignValueOperation(java.lang.String attributeAssignValueOperation) throws WsInvalidQueryException
attributeAssignValueOperation
- WsInvalidQueryException
- if there is a problempublic static GrouperTransactionType convertTransactionType(java.lang.String txTypeString) throws WsInvalidQueryException
txTypeString
- WsInvalidQueryException
public static SaveMode convertSaveMode(java.lang.String theSaveMode) throws WsInvalidQueryException
theSaveMode
- WsInvalidQueryException
public static GrouperVersion convertGrouperWsVersion(java.lang.String theVersion) throws WsInvalidQueryException
theVersion
- WsInvalidQueryException
public static GrouperSession retrieveGrouperSession(WsSubjectLookup actAsSubjectLookup)
actAsSubjectLookup
- public static int arrayLengthAtLeastOne(java.lang.Object[] objects, java.lang.String configNameOfMax, int defaultMax, java.lang.String label) throws WsInvalidQueryException
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 errorWsInvalidQueryException
- if array is null or size 0 or more than maxpublic static java.util.Map<java.lang.String,java.lang.String> convertParamsToMap(WsParam[] params) throws WsInvalidQueryException
params
- WsInvalidQueryException
- if problem with inputspublic static java.util.Map<java.lang.String,java.lang.Object> convertLimitsToMap(WsPermissionEnvVar[] limitEnvParams) throws WsInvalidQueryException
limitEnvParams
- WsInvalidQueryException
- if problem with inputspublic static java.lang.String[] calculateSubjectAttributes(java.lang.String[] requestedAttributes, boolean includeSubjectDetailBoolean)
requestedAttributes
- requestedAttributesLength
- includeSubjectDetailBoolean
- public static java.lang.String booleanToStringOneChar(java.lang.Boolean theBoolean)
theBoolean
- public static boolean booleanValue(java.lang.String input, boolean defaultValue, java.lang.String paramName) throws WsInvalidQueryException
input
- defaultValue
- paramName
- to put in the invalid query exceptionWsInvalidQueryException
- if there is a problempublic static boolean booleanValue(java.lang.String input, java.lang.String paramName) throws WsInvalidQueryException
input
- paramName
- to put in the invalid query exceptionWsInvalidQueryException
- if there is a problempublic static java.lang.Boolean booleanObjectValue(java.lang.String input, java.lang.String paramName) throws WsInvalidQueryException
input
- paramName
- to put in the invalid query exceptionWsInvalidQueryException
- if there is a problempublic static java.lang.Integer integerValue(java.lang.String input, java.lang.String paramName) throws WsInvalidQueryException
input
- paramName
- to put in the invalid query exceptionWsInvalidQueryException
- if there is a problempublic static Field retrieveField(java.lang.String fieldName)
fieldName
- name of fieldpublic static FieldType retrieveFieldType(java.lang.String fieldTypeName)
fieldTypeName
- name of fieldType e.g. list (default, memberships),
access (privs on groups), attribute_def (privs on attribute definitions), naming (privs on folders)public static java.lang.String dateToString(java.util.Date date)
date
- public static java.util.Date stringToDate(java.lang.String dateString)
dateString
- public static java.sql.Timestamp stringToTimestamp(java.lang.String timestampString)
timestampString
- public static WsParam[] params(java.lang.String paramName0, java.lang.String paramValue0, java.lang.String paramName1, java.lang.String paramValue1)
paramName0
- paramValue0
- paramName1
- paramValue1
- public static WsPermissionEnvVar[] limitEnvVars(java.lang.String limitEnvVarName0, java.lang.String limitEnvVarValue0, java.lang.String limitEnvVarType0, java.lang.String limitEnvVarName1, java.lang.String limitEnvVarValue1, java.lang.String limitEnvVarType1)
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 typepublic static java.util.Set<Privilege> convertAccessPrivilegesToPrivileges(java.util.Set<AccessPrivilege> accessPrivileges)
accessPrivileges
- public static void addResponseHeaders(javax.servlet.http.HttpServletResponse response, java.lang.String success, java.lang.String resultCode, java.lang.String resultCode2)
response
- success
- T or FresultCode
- resultCode2
- public static void addResponseHeaders(WsResultMeta wsResultMeta, boolean isSoap)
wsResultMeta
- result metadataisSoap
- if soappublic static <T> boolean nullArray(T[] array)
T
- array
- public static <T> T[] mergeArrays(T[] toArray, T[] fromArray, java.lang.String propertyNameForEquality, java.lang.Class<T> theClass)
T
- is the type that is being handledtoArray
- fromArray
- propertyNameForEquality
- theClass
- public static <T> T[] mergeArrays(T[] toArray, T[] fromArray, java.lang.String[] propertyNamesForEquality, java.lang.Class<T> theClass)
T
- is the type that is being handledtoArray
- fromArray
- propertyNamesForEquality
- list of property names which are used for equalitytheClass
- public static MultiKey propertyNameValues(java.lang.Object object, java.lang.String[] propertyNamesForEquality)
object
- propertyNamesForEquality
- public static java.lang.String toStringForLog(java.lang.Object object, int maxChars)
object
- maxChars
- is the max chars that should be returned (abbreviate if longer), or -1 for any amountpublic static java.lang.String mapToString(java.util.Map<?,?> map)
map
- public static java.lang.String toStringForWsLog(java.lang.Object object)
object
-