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

Parents
  • 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");
    
    }

Reply
  • 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");
    
    }

Children
No Data