SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION SAILPOINT.ES_V2_GET_IBM_I_USER_INFO ( 
	NAME_OR_ID VARCHAR(60) DEFAULT  NULL  ) 
	RETURNS CLOB(2147483647)   
	LANGUAGE SQL 
	SPECIFIC SAILPOINT.V2_ESRTVIUSRI 
	NOT DETERMINISTIC 
	MODIFIES SQL DATA 
	CALLED ON NULL INPUT 
	NOT FENCED 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DBGVIEW = *SOURCE , 
	DECRESULT = (31, 31, 00) , 
	DLYPRP = *NO , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *OWNER , 
	SRTSEQ = *HEX   
	BEGIN 
RETURN 
( 
SELECT JSON_OBJECT ( 
'data' : 
JSON_ARRAYAGG ( 
JSON_OBJECT ( 
'userId' VALUE AUTHORIZATION_NAME , 
'textDescription' VALUE TEXT_DESCRIPTION , 
'status' VALUE STATUS , 
'previousSignOn' VALUE PREVIOUS_SIGNON , 
'signonInvalidAttempts' VALUE 
SIGN_ON_ATTEMPTS_NOT_VALID , 
'userClass' VALUE USER_CLASS_NAME , 
'specialAuths' VALUE JSON_ARRAY ( SELECT TRIM ( FRAGMENT ) 
FROM TABLE ( 
CISTOOLS . SPLIT_STRING ( 
SPECIAL_AUTHORITIES , ' ' ) 
) 
WHERE TRIM ( FRAGMENT ) IS NOT NULL 
AND TRIM ( FRAGMENT ) <> '' ) , 
'groupProfile' VALUE GROUP_PROFILE_NAME , 
'supplementalGroups' VALUE SUPPLEMENTAL_GROUP_LIST , 
'passwordChanged' VALUE PASSWORD_CHANGE_DATE , 
'pwExpires' VALUE DATE_PASSWORD_EXPIRES , 
'daysUntilPwExpires' VALUE DAYS_UNTIL_PASSWORD_EXPIRES , 
'pwExpireFlag' VALUE SET_PASSWORD_TO_EXPIRE , 
'userEmpNo' VALUE JSON_QUERY ( SAILPOINT . 
ES_V2_GET_EMPLOYEE_NUMBER ( AUTHORIZATION_NAME ) , '$.data' ) FORMAT 
JSON , 'jobDesc' VALUE JOB_DESCRIPTION_NAME , 
'msgQueue' VALUE MESSAGE_QUEUE_NAME , 
'outQueue' VALUE OUTPUT_QUEUE_NAME , 
'homeDir' VALUE HOME_DIRECTORY , 
'locale' VALUE LOCALE_PATH_NAME , 
'uid' VALUE USER_ID_NUMBER , 
'gid' VALUE GROUP_ID_NUMBER , 
'digitalCert' VALUE DIGITAL_CERTIFICATE_INDICATOR , 
'pwLevel01' VALUE PASSWORD_LEVEL_0_1 , 
'pwLevel23' VALUE PASSWORD_LEVEL_2_3 , 
'localPwMgmt' VALUE LOCAL_PASSWORD_MANAGEMENT 
) FORMAT JSON 
) , 
'errors' : JSON_ARRAY ( ) 
) 
FROM QSYS2 . USER_INFO_BASIC 
WHERE ( LOCATE ( 
UPPER ( TRIM ( IFNULL ( NAME_OR_ID , AUTHORIZATION_NAME ) ) ) , 
UPPER ( AUTHORIZATION_NAME ) ) > 0 
OR LOCATE ( 
UPPER ( TRIM ( IFNULL ( NAME_OR_ID , AUTHORIZATION_NAME ) ) ) , 
UPPER ( TEXT_DESCRIPTION ) ) > 0 ) ) ; 
END  ; 

GRANT ALTER , EXECUTE   
ON SPECIFIC FUNCTION SAILPOINT.V2_ESRTVIUSRI 
TO AMAPICS WITH GRANT OPTION ; 

GRANT EXECUTE   
ON SPECIFIC FUNCTION SAILPOINT.V2_ESRTVIUSRI 
TO PUBLIC ; 

