• SOLVED Parse Workflow Form Element Values

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #42681  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!
Last edited by alexwgordon on Thu Dec 01, 2016 7:22 am, edited 1 time in total.
 #42683  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!

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.