how to retrieve the right object (user or group) with a param UserOrGroupDataType inside a plugin (function) ?

Certified Associate Developer

Hello, 

I'm trying to implement functions to check the permissions of a group or a user (first param) on a specific folder or document   (second param) but i'm stuck with  the UserOrGroupDataType coming as a string.

How could i make the distinction  between the two kinds of objects inside the java code of the plugin ?

Regards 

David 

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    private EntityIdentity retrieveIdentityType(TypedValue userorGroup, UserService us, GroupService gs)
    throws InvalidLocalObjectTypeException {
    Object obj = userorGroup.getValue();
    if (AppianType.GROUP == userorGroup.getInstanceType().intValue()) {
    Long groupId = (Long) obj;
    if (gs.doesGroupExist(groupId))
    return new GroupIdentity((Long) obj);
    else
    throw new InvalidLocalObjectTypeException(
    "The grop with the following groupId doesn't exist:" + groupId);
    // Long groupId=(Long) obj;
    }
    
    if (AppianType.USERNAME == userorGroup.getInstanceType().intValue()) {
    String username = (String) obj;
    if (us.doesUserExist(username))
    return new UserIdentity(username);
    else
    throw new InvalidLocalObjectTypeException(
    "The user with the following username doesn't exist:" + username);
    }
    throw new InvalidLocalObjectTypeException(
    "the userorGroup param is invalid : it should be either a user or a group");
    
    }

  • 0
    Certified Associate Developer

    Where TypedValue userorGroup is an incoming parameter for the custom function 

    @Function
    public Boolean hasAdminRightOnDocument(ContentService _cs, UserService us, GroupService gs,
    @Parameter(required = true) @DocumentDataType @Name("document_to_check") Long documentId,
    @Parameter(required = false) @UserOrGroupDataType @Name("user_or_group") TypedValue userorGroup