Page 1 of 1

workflow with folder

PostPosted:Mon Jan 31, 2011 2:52 am
by gaga
On http://www.openkm.com/Features.html is:
"Automatically trigger workflows for specific folders or document type"
How can I use workflow with folder ?

Re: workflow with folder

PostPosted:Mon Jan 31, 2011 5:42 pm
by jllort
The most simply way for doing it is using scripting. http://wiki.openkm.com/index.php/Scripting
Other possibility is on profiles to some users. http://wiki.openkm.com/index.php/Profiles
Another is using crontab ... scheduled task. http://wiki.openkm.com/index.php/Crontab

Re: workflow with folder

PostPosted:Thu Feb 10, 2011 12:58 pm
by liampadre
escogiendo la manera supuestamente mas simple de hacerlo, que es por scripting, veo que en la wiki de scripting mencionan como variables usadas solo 4:
* java.lang.String eventType - says the event that has fired the script. See below for event types.
* javax.jcr.Session session - users session that executes the script.
* javax.jcr.Node eventNode - node that causes the event.
* javax.jcr.Node scriptNode - node where is stored the script.
pero si kiero vincular un documento a un workflow y arrancar ese workflow... ke clases deberia usar, el javadoc de las clases que puedo usar en el entorno scripting no lo veo...

alguien puede darme una pista sobre esto...

Re: workflow with folder

PostPosted:Tue Feb 15, 2011 7:55 pm
by pavila
Esta característica de asociar un workflow a una carpeta en lugar de a un documento estaba planeada para la versión de desarrollo. Veré en qué estado está pq pensaba que ya estaba implementado.

Re: workflow with folder

PostPosted:Fri Feb 18, 2011 2:05 pm
by liampadre
Hola, he seguido investigando el tema de workflows y he logrado varias cosas, pero ahora estoy intentando con el usuario okmAdmin que cuando finaliza un workflow el fichero se cree (o se copie) en una carpeta X (en caso no exista) o hacerle un checkout y checkin en caso si exista en dicha carpeta X, pero al ejecutar el workflow por 1era vez ejecuta el codigo de crear el documento y al parecer no me lo hace porque no lo veo y tampoco me devuelve una excepcion, pero cuando lo ejecuto por 2da vez ejecuta el codigo de actualizar (e.d. checkout y checkin) y me devuelve una excepcion que es esta:
Code: Select all
2011-02-18 14:30:00,418 ERROR [org.apache.jackrabbit.core.XASessionImpl] Resource already associated with a transaction.
2011-02-18 14:30:00,418 ERROR [STDERR] javax.transaction.xa.XAException
al parecer porque si lo encuentra, porque si lo creo pero no lo veo, no se si se deba al tema del usuario, dado que al devolver las sesion actual solo me devuelve la del usuario "system" y con la sesion de este usuario se ejecuta el codigo, pero no se como obtener la sesion de otro usuario desde el objeto JcrSessionManager, les adjunto mi codigo haber si me pueden ayudar...
Code: Select all
imports...

public class VersionActionHandler implements ActionHandler{
	
	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(VersionActionHandler.class);
    
	public void execute(ExecutionContext context) throws Exception {
		String sTarea = context.getTask().getName();
		
		String actorId = context.getTaskInstance().getActorId();
		System.out.println("MAFE TASKINSTANCE actorId: " + actorId);

		JcrSessionManager sessionManager = JcrSessionManager.getInstance();
		DirectDocumentModule docModule = DirectDocumentModule.class.newInstance();
		DirectPropertyGroupModule pgModule = DirectPropertyGroupModule.class.newInstance();
		
		String uuid = (String)context.getContextInstance().getVariable("uuid");
		
		Map sessions = sessionManager.getSessions(); //AQUI DEVUELVO TODAS LAS SESIONES DISPONIBLES
		JcrSessionInfo info = null;
		Session session = null;
		String token = "";
		
		Iterator it = sessions.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry e = (Map.Entry)it.next();
			info = (JcrSessionInfo)e.getValue();
			token = String.valueOf(e.getKey());
			session = info.getSession(); //SOLO ME DEVUELVE LA SESION RELACIONADA AL USUARIO "system"
		}
		
		String path = docModule.getPath(token, uuid);
		Document doc = docModule.getProperties(session, path);
		InputStream is = docModule.getContent(token, path, false);
		
		String sComment = "Versionado por " + actorId + " en la tarea " + sTarea;
		String destino = "/okm:root/SISTEMAS/SAP/";
		String sfile = FileUtils.getName(doc.getPath());
		
		Document dfinal = null;
		try {
			dfinal = docModule.getProperties(session, destino + sfile);
		}catch(PathNotFoundException pnfe){}
		
		try {
			if (dfinal != null) {
				destino += sfile;
				docModule.checkout(token, destino);
				docModule.setContent(token, destino, is);
				docModule.checkin(token, destino, sComment);
			}else{
				dfinal = new Document();
				destino += sfile;
				dfinal.setPath(destino);
				dfinal.setMimeType(doc.getMimeType());
				dfinal.setAuthor(doc.getAuthor());
				dfinal.setCategories(doc.getCategories());
				dfinal.setKeywords(doc.getKeywords());
				dfinal.setNotes(doc.getNotes());
				dfinal.setSubscriptors(doc.getSubscriptors());
				dfinal.setPermissions(doc.getPermissions());
				docModule.create(token, dfinal, is);
			}
			context.getContextInstance().setVariable("okpub", "1");
			
		}catch(RepositoryException re){
			context.getContextInstance().setVariable("okpub", "0");
			re.printStackTrace();
		}catch(LockException le) {
			context.getContextInstance().setVariable("okpub", "0");
			le.printStackTrace();
		}catch(Exception e) {
			context.getContextInstance().setVariable("okpub", "0");
			throw e;
		}
	}
}


Re: workflow with folder

PostPosted:Thu Feb 24, 2011 11:21 am
by pavila
Las clases del tipo DirectPropertyGroupModule no están pensadas para ser usadas directamente. En mejor acceder a las respectivas del API, que en este caso sería la clase OKMPropertyGroup. Por otra parte, el primer parámetro de estos métodos es un token de autentificación. Dicho token se puede puede obtener mediante el método OKMAuth.login(String, String) y recuerda hace luego un OKMAuth.logout(String) al terminar. De esta forma puedes ejecutar métodos del API de OpenKM con cualquier usuario.