Page 1 of 1

Crear informe con campo nota

PostPosted:Wed Jun 15, 2022 5:37 pm
by albertogomez38
Estoy intentando crear un informe partiendo de este codigo...
Code: Select all
import java.util.*;
import com.openkm.api.*;
import com.openkm.bean.*;
import com.openkm.util.*;

int MAX_DEPTH = Integer.MAX_VALUE;
List al = new ArrayList();

void nodeTask(String path, int depth) throws Exception {
    for (Document doc : OKMDocument.getInstance().getChildren(null, path)) {
        Map mapDoc = new HashMap();
        mapDoc.put("name", PathUtils.getName(doc.getPath()));
        mapDoc.put("version",doc.getActualVersion().getName());
        mapDoc.put("checksum", doc.getActualVersion().getChecksum());
        mapDoc.put("path",doc.getPath().replace("/okm:root",""));
        mapDoc.put("nota",doc.getNotes());
        al.add(mapDoc);
    }

    for (Folder fld : OKMFolder.getInstance().getChildren(null, path)) {
        if (depth < MAX_DEPTH) {
            nodeTask(fld.getPath(), depth + 1);
        }
    }
}
nodeTask("/okm:root/c1", 0);
return al;

Cuando lo ejecuto tengo esta salida...


Code: Select all

[{path=/c1/f1.txt, name=f1.txt, checksum=3e7705498e8be60520841409ebc69bc1, version=1.0, nota=[{date=Wed Jun 15 18:46:26 CEST 2022, author=okmAdmin, text=111, path=c075bb24-6d03-4b4a-960c-d3dc67328c7e}, {date=Wed Jun 15 18:46:29 CEST 2022, author=okmAdmin, text=2222, path=c0bb2b5d-44e0-4c0e-ac93-888e38ecd036}]}]

El metodo getNotes() me devuelve todos los elementos de la lista, pero yo solo necesito el valor de la ultima nota, en el ejemplo 2222.

¿Es posible restringir los campos que devuelve getNotes()? para descartar los que no necesito...

Gracias

Re: Crear informe con campo nota

PostPosted:Fri Jun 17, 2022 4:38 am
by jllort
El método te devolverá toda la información de las notas.,algunos valores te seran de utilidad y otros no. Lo que tienes que hacer es iterar por todas la lista de las notas y quedarte únicamente por la parte que te interesa. Es decir iterando para cada Note quedarte con el text -> getText() ( aquí tienes los métodos de este bean https://docs.openkm.com/apidoc/com/okm/ ... /Note.html )

Re: Crear informe con campo nota

PostPosted:Sun Jun 19, 2022 10:24 am
by albertogomez38
Está....

Gracias por la ayuda.

Lo adjunto por si ayuda a alguien...
Code: Select all

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

int MAX_DEPTH = Integer.MAX_VALUE;
List al = new ArrayList();
List recorrenota = new ArrayList();
String ultimanota;

void nodeTask(String path, int depth) throws Exception {
    for (Document doc : OKMDocument.getInstance().getChildren(null, path)) {
        Map mapDoc = new HashMap();
        mapDoc.put("name", PathUtils.getName(doc.getPath()));
        mapDoc.put("version",doc.getActualVersion().getName());
        mapDoc.put("checksum", doc.getActualVersion().getChecksum());
        mapDoc.put("path",doc.getPath().replace("/okm:root",""));
        ultimanota="";
        recorrenota=doc.getNotes();
        for (int i=0; i < recorrenota.size(); i++){
            ultimanota=recorrenota.get(i).getText();
//            print(ultimanota);
        }
        mapDoc.put("nota",ultimanota);
        al.add(mapDoc);
    }
   
    for (Folder fld : OKMFolder.getInstance().getChildren(null, path)) {
        if (depth < MAX_DEPTH) {
            nodeTask(fld.getPath(), depth + 1);
        }
        
    }  
}


nodeTask("/okm:root", 0);
return al;