Page 1 of 1

Get user name who uploaded the document (Scripting)

Posted: Thu Feb 23, 2017 2:22 am
by jimac
Good Day!

Can I know how to get the name of the user who uploaded the file?
What Im planning to do is, in automation, when the user uploaded the document, the name of the user will automatically be put in the property group example okp:okp:cdir.stno.

How to do that?

Thanks! :D

Re: Get user name who uploaded the document (Scripting)

Posted: Fri Feb 24, 2017 7:36 am
by jllort
I suggest Automation based in java classes rather scripting anyway can be done in both ways. From scripting you receive a variable named uuid what can be used directly in your script ( uuid is type of String ) and from Automation class you must do something like this ( take a look for example here https://sourceforge.net/p/openkm/code/H ... egory.java ):

Code: Select all

String uuid = AutomationUtils.getUuid(env);
When you have the uuid, simply must capture the data of the document:

Code: Select all

import com.openkm.api.*;
import com.openkm.bean.*;
import java.util.*;

// Get author
Document doc = OKMDocument.getInstance().getProperties(null, uuid);
String author = doc.getActualVersion().getAuthor();

// From here simply must be added the metadata group
OKMPropertyGroup.getInstance().addGroup(null, uuid, "okg:group_name");

// And set the properties
Map map = new HashMap<String,String>();
map.put("okp:group_name.field",author);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, uuid, "okg:group_name", map);
Hope it can give you some clue about how doing it

Re: Get user name who uploaded the document (Scripting)

Posted: Tue Feb 28, 2017 7:14 am
by jimac
jllort wrote:I suggest Automation based in java classes rather scripting anyway can be done in both ways. From scripting you receive a variable named uuid what can be used directly in your script ( uuid is type of String ) and from Automation class you must do something like this ( take a look for example here https://sourceforge.net/p/openkm/code/H ... egory.java ):

Code: Select all

String uuid = AutomationUtils.getUuid(env);
When you have the uuid, simply must capture the data of the document:

Code: Select all

import com.openkm.api.*;
import com.openkm.bean.*;
import java.util.*;

// Get author
Document doc = OKMDocument.getInstance().getProperties(null, uuid);
String author = doc.getActualVersion().getAuthor();
// From here simply must be added the metadata group
OKMPropertyGroup.getInstance().addGroup(null, uuid, "okg:group_name");
// And set the properties
Map map = new HashMap<String,String>();
map.put("okp:group_name.field",author);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, uuid, "okg:group_name", map);
Hope it can give you some clue about how doing it

This is the script:

Code: Select all

import com.openkm.api.*;
import com.openkm.bean.*;
import java.util.*;

String uuid = AutomationUtils.getUuid(env);

// Get author
Document doc = OKMDocument.getInstance().getProperties(null, uuid);
String author = doc.getActualVersion().getAuthor();

// From here simply must be added the metadata group
OKMPropertyGroup.getInstance().addGroup(null, uuid, "okg:group_name");

// And set the properties
Map map = new HashMap<String,String>();
map.put("okp.cdir.stno",author);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, uuid, "okg:cdiap", map);

// rename document
String newName = "Store Number."+author  + "." + FileUtils.getFileExtension(PathUtils.getName(path));
OKMDocument.getInstance().rename(null, path, newName);
(I used Document creation , post.)

When I tried uploading a document, it seems like it does not work..
How to fix?
Thanks :D

Re: Get user name who uploaded the document (Scripting)

Posted: Wed Mar 01, 2017 7:10 pm
by jllort
Did you tested before from scripting ? check from there, might be some error ?
Declare the variable uuid

Code: Select all

String uuid = "some document uuid";

Re: Get user name who uploaded the document (Scripting)

Posted: Thu Mar 02, 2017 1:12 am
by jimac
jllort wrote:Did you tested before from scripting ? check from there, might be some error ?
Declare the variable uuid

Code: Select all

String uuid = "some document uuid";
I tried to set the uuid ex. (8fca2db5-a55b-4dc2-8ffb-2d46c766e49e)\
but still it does not work.

I have a question..in the code
does this code gets the uuid of the document uploaded by the user?? what is env for?

Code: Select all

String uuid = AutomationUtils.getUuid(env);

I also tried this script but it does not work also , the file is just uploaded normally..
Please see the script. Tell me what is wrong with it. Thanks :D

Code: Select all

import com.openkm.api.*;
import com.openkm.bean.*;
import java.util.*;

String uuid = AutomationUtils.getUuid(env);

// Get author
Document doc = OKMDocument.getInstance().getProperties(null, uuid);
String author = doc.getActualVersion().getAuthor();

// From here simply must be added the metadata group
OKMPropertyGroup.getInstance().addGroup(null, uuid, "okg:cdiap");

// And set the properties
Map map = new HashMap<String,String>();
map.put("okp.cdir.stno",author);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, uuid, "okg:cdiap", map);

// rename document
String newName = "Store Number."+author + "." + FileUtils.getFileExtension(PathUtils.getName(uuid));
OKMDocument.getInstance().rename(null,uuid, newName);

Re: Get user name who uploaded the document (Scripting)

Posted: Fri Mar 03, 2017 7:29 pm
by jllort
From scripting you can not doing it ( can only be done if you create an Automation class ):

Code: Select all

String uuid = AutomationUtils.getUuid(env);
When you use scripting is automatically injected a variable named uuid, what you can use directly. What I said is you can simulate it from Administration / Scripting view setting

Code: Select all

String uuid = "some uuid";