Page 1 of 1

Rename file names to include categories

PostPosted:Mon Feb 25, 2019 2:46 pm
by skreisel
Hi there.

Wanted to check out if this is at all possible, before I start to learn Java... Am using the latest COMMUNITY version.

Use case is: rename a document to append the documents name with categories, including their parents, as in:

filename = "xyz.pdf"
categories = "a" "b/b1" "c/c1/c2"
result then is = "xyz [a b_b1 c_c1_c2].pdf"

There has been a bit on scripting and renaming on this forum previously viewtopic.php?t=21830.

Wondering because:
  • Be possible at all, because the categories and their parents may not be exposed?
  • Output not parsable via scripting, to e.g. get rid of backslashes to make names filesystem congruent?
BTW: I know that one can customize thesaurus(es). But is it possible to import categories and their structures via e.g. text files - or via database; manually adding categories and their structures may be somewhat tedious?

Cheers

Stefan

Re: Rename file names to include categories

PostPosted:Fri Mar 01, 2019 5:25 pm
by jllort
Should be added an automation event when you assign category to a node. I can give you the clues about how doing it in the source code.

Re: Rename file names to include categories

PostPosted:Sat Mar 02, 2019 3:43 pm
by skreisel
Sure - would be much appreciated; if you could give me a couple of bullet points, that might trigger enough to get me going...

Cheers

Re: Rename file names to include categories

PostPosted:Sun Mar 03, 2019 7:41 pm
by jllort
I think the easies is understanding one event and then follow same steps in the addCategory method.

Folder creation event analysis:
* In AutomationRule.java class you have the event definition https://github.com/openkm/document-mana ... nRule.java
* DbFolderModule are set the events what call automation ( 2 lines involved )
https://github.com/openkm/document-mana ... e.java#L97
https://github.com/openkm/document-mana ... .java#L106

You might understanding these lines:
Code: Select all
// AUTOMATION - PRE
Map<String, Object> env = new HashMap<String, Object>();
env.put(AutomationUtils.PARENT_UUID, parentUuid);
env.put(AutomationUtils.PARENT_PATH, parentPath);
env.put(AutomationUtils.PARENT_NODE, parentFolder);
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_FOLDER_CREATE, AutomationRule.AT_PRE, env);
parentFolder = (NodeFolder) env.get(AutomationUtils.PARENT_NODE);

// Create node
NodeFolder fldNode = BaseFolderModule.create(auth.getName(), parentFolder, name, fld.getCreated(), new HashSet<String>(),
		new HashSet<String>(), new HashSet<NodeProperty>(), new ArrayList<NodeNote>(), null);

// AUTOMATION - POST
env.put(AutomationUtils.FOLDER_NODE, fldNode);
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_FOLDER_CREATE, AutomationRule.AT_POST, env);
The key is that between this method and automation you are sharing variables into environment Map. This environment map will be used later for automation events ( actions and validations ). I suggest you undestanding these two clases
AddKeyword.java -> https://github.com/openkm/document-mana ... yword.java
PathContains.java -> https://github.com/openkm/document-mana ... tains.java
AutomationsUtils.java -> https://github.com/openkm/document-mana ... Utils.java

In your case you should add the event into the class DBpropertyModule in the line 82 https://github.com/openkm/document-mana ... e.java#L82

I suggest debug current implementation, for example ( folder and document creation ) and if you understand how the code works you can quickly extend the current code.