Page 1 of 1

SOLVED Parse Workflow Form Element Values

PostPosted:Thu Dec 01, 2016 12:35 am
by alexwgordon
Hi all,

I'm working on a workflow and this may be trivial, but I'm confused on how to parse two of these types of information.

1. I retrieve the security of a file by performing
Code: Select all
String mySecurityUsers = OKMAuth.getInstance().getGrantedUsers(systemToken, thisPath).toString();
However, when I get this information it comes out looking like this
Code: Select all
{okmAdmin=15, user1=3}
My question is: is there an easier way to pull out each username and security rights other than parsing the string using a .split() method? I'm currently doing
Code: Select all
List<String> items = Arrays.asList(mySecurityUsers.split("(=)|(\\{)|(,\\s)|(\\})"));
for (int i = 1 ; i < items.size() ; i += 2){
       	System.out.println(items.get(i) + " gets security " + items.get(i+1));
}
2. If I'm retrieving information from a folder input in a workflow form element, what is the best way to retrieve the actual path from that form element. I'm currently doing this with my form
Code: Select all
<input name="folderName" label="Folder" type="folder">
	<validator type="req" />
</input>
and then doing this with my workflow
Code: Select all
Object folderVar = executionContext.getContextInstance().getVariable("folderName");
however, there's no good way to get the path that I can see other than doing a .split method as well. I'm sure there must be a more elegant solution for both of these!

Any help and advice would be greatly appreciated!

Re: Parse Workflow Form Element Values

PostPosted:Thu Dec 01, 2016 7:21 am
by alexwgordon
Alright, this one is resolved! It was in fact much simpler than using some .split method. Here's my solutions for each:

1.
Code: Select all
String nodePath = (String) context.getContextInstance().getVariable("uuid");
// Get role/user security for current file so they can all be revoked
Map <String, Integer> maprFile = OKMAuth.getInstance().getGrantedRoles(systemToken, nodePath);
// Get keys for both
Set<String> keysrFile = maprFile.keySet();
// Revoke privileges for each current user except Admin
for (String role : keysrFile) {
	if (!role.contains("ROLE_ADMIN")) {
		OKMAuth.getInstance().revokeRole(systemToken, nodePath, role, ( Permission.ALL_GRANTS ), false);
	}
}
2.
Code: Select all
Input folderVar = (Input) executionContext.getContextInstance().getVariable("folderName");
String destination = folderVar.getValue();
They were both much more elegant and pretty simple solutions. Hope this will help someone as new to Java as me!

Re: SOLVED Parse Workflow Form Element Values

PostPosted:Thu Dec 01, 2016 8:33 am
by jllort
If you take a look at java doc you will see the object what returns each method, you should always use it.
https://docs.openkm.com/apidoc/com/okm/ ... MAuth.html

Here you have all api docs based on OpenKM version
https://docs.openkm.com/apidoc/