Buenos días, tengo un script que lo que hace es crear una carpeta si no existe y importar los ficheros del servidor al OpenKM.
Bien, si la carpeta existe la importación funciona correctamente, si la carpeta no existe me encuentro con lo siguiente:
1. Si ejecuto la tarea del crontab desde el OpenKM manualmente todo funciona correctamente, crea la carpeta y realiza la importación.
2. si la tarea se ejecuta automaticamente desde el crontab y la carpeta no existe no la crea y no realiza la importación.
Alguien sabe a que puede ser debido que no cree la carpeta si la tarea es ejecutada automaticament y si si es ejecutada manualmente? es la misma tarea!
Gracias.
Bien, si la carpeta existe la importación funciona correctamente, si la carpeta no existe me encuentro con lo siguiente:
1. Si ejecuto la tarea del crontab desde el OpenKM manualmente todo funciona correctamente, crea la carpeta y realiza la importación.
2. si la tarea se ejecuta automaticamente desde el crontab y la carpeta no existe no la crea y no realiza la importación.
Alguien sabe a que puede ser debido que no cree la carpeta si la tarea es ejecutada automaticament y si si es ejecutada manualmente? es la misma tarea!
Gracias.
Code: Select all
import com.openkm.core.*;
import com.openkm.api.*;
import java.io.*;
import com.openkm.module.db.stuff.DbSessionManager;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
String token = DbSessionManager.getInstance().getSystemToken();
OKMDocument document = OKMDocument.getInstance();
OKMFolder folder = OKMFolder.getInstance();
String mes = "";
String ano = "";
public void autoImport(String okmPath, File fldpath){
try {
print("Scanning " + fldpath.getName() + "<br>");
Date now = new Date();
String dateString = now.toString();
System.out.println(" 1. " + dateString);
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
System.out.println(" 2. " + format.format(now));
SimpleDateFormat format = new SimpleDateFormat("MM");
System.out.println(" MES. " + format.format(now));
mes = format.format(now);
SimpleDateFormat format = new SimpleDateFormat("yyyy");
System.out.println(" ANY. " + format.format(now));
ano = format.format(now);
for (File file : fldpath.listFiles()) {
print("Importing " + file.getName() + "<br>");
try {
if (file.isDirectory()) {
try {
folder.createSimple(token, okmPath + file.getName());
} catch (ItemExistsException ie) {
print("folder already exists<br>");
// Folder already exists - just ignore exception
}
autoImport( okmPath + file.getName() + "/", file);
} else {
// Check if file is still being written to
long length = file.length();
Thread.sleep(1000);
if (file.length() > length) continue; // Skip file this time
document.createSimple(token, okmPath + file.getName(), new FileInputStream(file));
//iniciem Workflow accepthours
List formElements = new ArrayList();
String UUID = document.getProperties(token, okmPath + file.getName()).getUuid(); //agafem uuid del document a iniciar Workflow
System.out.println("UUID: " + UUID);
int idWorflow = 19; //id del workflow que volem arrancar
OKMWorkflow.getInstance().runProcessDefinition(token, new Double(idWorflow).longValue(), UUID, formElements); //iniciem Workflow
}
print("Created " + okmPath + file.getName() + "<br>");
} catch (Exception e) {
print ("Exception:" + e + "<br>");
// Something bad happened to prevent import. Skip to next file.
continue;
}
file.delete();
}
} catch (Exception e) {
print("Exception: " + e + "<br>");
}
}
public void month_folder(String path) {
try {
Date now = new Date();
String dateString = now.toString();
System.out.println(" 1. " + dateString);
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
System.out.println(" 2. " + format.format(now));
SimpleDateFormat format = new SimpleDateFormat("MM");
System.out.println(" MES. " + format.format(now));
mes = format.format(now);
SimpleDateFormat format = new SimpleDateFormat("yyyy");
System.out.println(" ANY. " + format.format(now));
ano = format.format(now);
//creem carpeta mes
String pathc = path + ano + "/" + mes;
OKMFolder.getInstance().createSimple(null, pathc);
//OKMPropertyGroup.getInstance().addGroup(null, path, "okg:ROLE_USER");
//okmPath = path + "/" + ano + "/" + mes + "/";
} catch (Exception e) {
print("Exception: " + e + "<br>");
}
}
month_folder("/okm:root/carpeta/carpeta/carpeta/");
autoImport("/okm:root/carpeta/carpeta/carpeta/" + ano + "/" + mes + "/", new File("/var/carpeta/carpeta"));