Get user name who uploaded the document (Scripting)

Nous essayons de faire OpenKM aussi intuitif que possible, mais tout avis est bienvenu.

Moderator: dedisoft

Forum rules
Avant de poser une question, merci de regarder la documentation du wiki ou d'utiliser la fonction recherche du forum. Et rappelez vous que nous n'avons ni boule de cristal ni possibilité de lire dans les pensées, aussi pensez à spécifier quelle version d'OpenKM vous utilisez ainsi que la version du navigateur web et du système d'exploitation. Pour de plus amples informations lisez Comment reporter un bug efficacement (anglais).
Post Reply
jimac
Expert Boarder
Expert Boarder
Posts: 83
Joined: Thu Dec 01, 2016 4:01 am

Get user name who uploaded the document (Scripting)

Post by jimac » Thu Feb 23, 2017 2:22 am

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

jllort
Moderator
Moderator
Posts: 9124
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

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

Post by jllort » Fri Feb 24, 2017 7:36 am

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

jimac
Expert Boarder
Expert Boarder
Posts: 83
Joined: Thu Dec 01, 2016 4:01 am

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

Post by jimac » Tue Feb 28, 2017 7:14 am

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

jllort
Moderator
Moderator
Posts: 9124
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

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

Post by jllort » Wed Mar 01, 2017 7:10 pm

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

jimac
Expert Boarder
Expert Boarder
Posts: 83
Joined: Thu Dec 01, 2016 4:01 am

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

Post by jimac » Thu Mar 02, 2017 1:12 am

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

jllort
Moderator
Moderator
Posts: 9124
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

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

Post by jllort » Fri Mar 03, 2017 7:29 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest