Skip to content

Commit

Permalink
[BKNDLSS-28440]:ISE if get userRole for undefined user (#518)
Browse files Browse the repository at this point in the history
* [BKNDLSS-28440]:ISE if get userRole for undefined user

* [BKNDLSS-28440]:Make change more compact

Co-authored-by: yurii.zaripa <[email protected]>
  • Loading branch information
YuriiZaripa and yurii.zaripa authored Jul 8, 2022
1 parent c65fb06 commit 95e4956
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/com/backendless/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.backendless.utils.ResponderHelper;
import weborb.types.Types;

import java.util.Collections;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -686,7 +687,9 @@ public List<String> getUserRoles( String userId )
if( userId == null || userId.isEmpty() )
throw new IllegalArgumentException( ExceptionMessage.NULL_IDENTITY );

return Arrays.asList( (String[]) Invoker.invokeSync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { userId } ) );
Object[] objects = Invoker.invokeSync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { userId } );

return objects.length == 0 ? Collections.<String>emptyList() : Arrays.asList( (String[]) objects );
}

public void getUserRoles( final AsyncCallback<List<String>> responder )
Expand All @@ -709,7 +712,7 @@ public void handleFault( BackendlessFault fault )
responder.handleFault( fault );
}
};
Invoker.invokeAsync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { }, callback );
Invoker.invokeAsync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] {}, callback );
}
catch( Throwable e )
{
Expand All @@ -725,13 +728,13 @@ public void getUserRoles( String userId, final AsyncCallback<List<String>> respo
if( userId == null || userId.isEmpty() )
throw new IllegalArgumentException( ExceptionMessage.NULL_IDENTITY );

AsyncCallback<String[]> callback = new AsyncCallback<String[]>()
AsyncCallback<Object[]> callback = new AsyncCallback<Object[]>()
{
@Override
public void handleResponse( String[] response )
public void handleResponse( Object[] response )
{
if( responder != null )
responder.handleResponse( Arrays.asList( response ) );
responder.handleResponse( response.length == 0 ? Collections.<String>emptyList() : Arrays.asList( (String[]) response ) );
}

@Override
Expand Down

0 comments on commit 95e4956

Please sign in to comment.