• Get user name who uploaded the document (Scripting)

  • Nous essayons de faire OpenKM aussi intuitif que possible, mais tout avis est bienvenu.
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).
 #43277  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
 #43285  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
 #43309  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
 #43321  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);
 #43331  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";

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.