Skip to main content
January 27, 2021
Question

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

  • January 27, 2021
  • 3 replies
  • 0 views

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 

3 replies

February 3, 2021

Like in the next reply 

February 3, 2021

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");

}

February 3, 2021

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