Skip to content

User Information

Get User Information from SAP Cloud Platform Mobile Services

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
UserRoles roles = new UserRoles(ClientProvider.get(),
    CpmsParameters.getSettingsParameters());

// Must be invoked from UI thread
roles.load(
    new UserRoles.CallbackListener() {

        // Executes on UI thread
        @Override
        public void onSuccess(@NonNull UserInfo result) {
            if (result != null) {
                sLogger.debug("Current user id: {}", result.getId());
                sLogger.debug("User name: {}", result.getUserName());
                sLogger.debug("Roles: {} " + Arrays.toString(result.getRoles()));
            }
        }

        // Executes on UI thread
        @Override
        public void onError(@NonNull Throwable e) {
            // com.sap.cloud.mobile.foundation.networking.HttpException
            if (e instanceof HttpException) {
                sLogger.error("User roles request failed. Message: {}, http code: {}",
                    ((HttpException) e).message(), ((HttpException) e).code());
            } else {
                sLogger.error("Request failed: {}", e.getMessage());
            }
        }
});
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
val roles = UserRoles(ClientProvider.get(),
                CpmsParameters.getSettingsParameters())

// Must be invoked from UI thread
roles.load(
        object : UserRoles.CallbackListener {

        // Executes on UI thread
        override fun onSuccess(result: UserInfo) {
            if (result != null) {
                sLogger.debug("Current user id: {}", result.id)
                sLogger.debug("User name: {}", result.userName)
                sLogger.debug("Roles: {} " + Arrays.toString(result.roles))
            }
        }

        // Executes on UI thread
        override fun onError(e: Throwable) {
            // com.sap.cloud.mobile.foundation.networking.HttpException
            if (e is HttpException) {
                sLogger.error("User roles request failed. Message: {}, http code: {}",
                            e.message(), e.code())
            } else {
                sLogger.error("Request failed: {}", e.message)
            }
        }
})