EGL Development User Group

  • 1.  DojoUploader - Background

    Posted Fri October 23, 2020 04:22 PM
    Edited by Osvaldo Jose de Oliveira Menezes Wed January 06, 2021 06:33 AM


    Hello Guys

    I am working with DojoUploader on an RUI.
    I need to work with this plugin, in the background .. that is, the idea is to pass the uploadUrl, and automatically it uploads the files from this folder and I capture it in FileInfo.
    Has anyone done this? to run DojoUploader in the background?

    myFileInfo FileInfo [] = []; uploader1 DojoUploader { showInput = Dojolib.INPUT_NONE , layoutData = new GridLayoutData {row = 2, column = 1, horizontalSpan = 1} , text = "Upload Multiple Files" , uploadOnSelect = true //, multiple = true //, uploadUrl = "/ updserver / spldesd1 / trash / XML3 /" , onComplete :: = uploader1Complete , onError :: = upError , onBegin :: = uploader1Begin , onProgress :: = uploader1Progress };​

    ------------------------------
    Osvaldo Jose de Oliveira Menezes
    Analista
    RellegusTI
    Orlândia
    +55 11 96565-6368
    ------------------------------


    ____________________________________________________________________________________________________________________________________________

    Hello colleagues, experts !!! ..

    Based on the tip from our colleague Nick, I solved the challenge as follows:
    1) I created a class in native java (see code1)
    a) This code only searches the file-system for a list of files and puts it in memory, returning the method signature;

    2) I have a dedicated service (see code2), which communicates with my RUI web app
    a) I used the external type to access the native java.
    b) I trigger the native java method to fetch the list of files
    c)  Process this list of files as needed

    3) WEB App - RUI
    a) I stopped using DojoUploader
    b) I used the JOB Scheduler to trigger the dedicated service from time to time
    c) Returning from the service I update my DataGrid.

    Thank you very much Nick

    code1
    package br.com.morlan.rui.common.db.external;
    
    import java.io.File;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    
    public class geraListaArquivos {
    
    	private static final String MY_CLASS_CONST = "geraListaArquivos_v01.00";
    
    	static int LogLevel = 0;
    	static int LogWrite = 0;  //1 - alterado em 06/09/2019
    	static String codRetorno = "0";
    	static String myMensagem = ""; 
    
    	public static ArrayList<String> visualizaListaArquivos(final String aDiretorio,
    			 int aLogLevel
    			) {
    
    		LogLevel = aLogLevel; 
    		
    		final String MY_METODO = ".visualizaListaArquivos";
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " BEGIN  ");
    
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " ARGs "
    				+  " aFileArg=" +  aDiretorio
    				+  " aLogLevel=" +  aLogLevel
    				);
    		
    		ArrayList<String> retornoFuncao = new ArrayList<String>(); 
    		
    		try {
    			
    			File file = new File(aDiretorio);
    			File afile[] = file.listFiles();
    			int i = 0;
    
    			DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " qtde arquivos "
    					+  afile.length 
    					); 
    			
    			for (int j = afile.length; i < j; i++) {
    				File arquivos = afile[i];
    				retornoFuncao.add(arquivos.getName());
    //				DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " files "
    //						+  arquivos.getName() + "\n"  );
    			}
    			
    //			DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " DESCARREGANDO A retornoFuncao ");
    //			for (int i = 0; i < retornoFuncao.size(); i++) {
    //				DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " retornoFuncao(i) =" + i + " = " + retornoFuncao.get(i) );
    //			}
    
    		} catch (Exception e) {
    			myMensagem = (" 1036 - visualizaListaArquivos  exception " + e.toString());
    			DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 2, myMensagem);
    			return montaRetorno("1036",((MY_CLASS_CONST + MY_METODO + myMensagem)),"" ); 
    		}
    
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " END ");
    		return retornoFuncao; // montaRetorno("0","",""); 
    	} 
    	
    	private static String getCurrentTimeStamp() {
    		final String MY_METODO = ".getCurrentTimeStamp ";
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " BEGIN ");
    		/*
    		 * Returns a string with the current date and time yyyy-MM-dd_HH-mm-ss
    		 * suitable to compose a fileid
    		 */
    		SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    		Date now = new Date();
    		String strDate = sdfDate.format(now);
    
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " END ");
    		return strDate;
    	}
    
    	//@BEGIN montaRetorno 
    	static private ArrayList<String> montaRetorno(String aCodigoError, String aMensagem, String aResult)  {
    		final String MY_METODO = ".montaRetorno ";
    		DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " BEGIN ");
    
    		ArrayList<String> result = new ArrayList<String>();
    
        	result.add("#01CodigoError:"+aCodigoError);
        	result.add("#02Mensagem:"+aMensagem);
        	result.add("#03Resultado:"+aResult);
    
    //    	DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 9, " aCodigoError" + aCodigoError
    //    			+ " aMensagem=" + aMensagem
    //    			+ " aResult=" + aResult
    //    			);
    
        	DisplayLog(MY_CLASS_CONST, MY_METODO, LogLevel, 1, " END ");
        	return result;
        }
    	//@END montaRetorno 
    
    
    	/*
    	 * -- @DisplayLog - exibir erro de log nos metodos
    	 * -- Niveis de Log: 0-sem log / 1-apenas log da classe-app / 2-apenas log error fatal -abend / 9-todas mensagens
    	 * --
    	 * -- aLogLevel = Nivel de log recebido pelo usuario, o qual deseja ver
    	 * -- aLogLevelMsg = Nivel de log classificado pela mensagem
    	 */
    	    static private void DisplayLog(String aClasse, String aMetodo, Integer aLogLevel, Integer aLogLevelMsg, String aMsg) { 
    	    	String aMsgError = "";
    
    	    	if (aLogLevelMsg == 2) // error fatal
    	        {
    	    		aMsgError = (aClasse + aMetodo + ".##FATAL_ERROR " + aMsg);
    	    	}
    
    	    	if (aLogLevel > 0) {
    	        	if (aLogLevelMsg <= aLogLevel) {
    	        		aMsgError = (aClasse + aMetodo + aMsg);
    	        	}
    	        }
    
    	    	if (LogWrite > 0) { 
    		    	try {
    					WriteFileLog(aMsgError);
    				} catch (IOException e) {
    		       		System.out.printf(e.toString());
    		       		e.printStackTrace(); 
    				} 
    		    	}
    		    else {
    		    	if (aMsgError != "") {
    		    		System.out.printf(aMsgError );
    		    	}
    	       	}
    	    }
    	    static private void WriteFileLog(String aMsg) throws IOException {
    //		    logFS.write(aMsg.getBytes()); 
           		System.out.printf(aMsg);
    	    }	
    }​




    code2
    service ConverterXmlNfeToEgl 
        const SERVICE_CONST string = "ConverterXmlNfeToEgl";
        const VERSAO string = ".v05.37";
        myLogLevel int =0;
    /*
    **
    **
    **
    **
    **
    /*
    	 
        function LerCms(aFileNameArg string[] in, aPathFiles string in, aWI_DEBUG_LEVEL int? in) returns(NfeToEglRec[])
            const aFunction string = ".LerCms";
    
    /*
    **
    **
    **
    **
    */
    
    	  	mygeraListaArquivosExt geraListaArquivosExt = new geraListaArquivosExt{};   
    		myFiles = mygeraListaArquivosExt.visualizaListaArquivos(aPathFiles, aWI_DEBUG_LEVEL);
            LogMensagem(aFunction, ".DADOS JAVANATIVO - QTDE ARQUIVOS " :: myFiles.getsize() :: " - ":: currenttimestamp());
            for (wi int from 1 to myFiles.getsize() by 1)
            	LogMensagem(aFunction, ".DADOS JAVANATIVO - ARQUIVOS =[" :: wi :: "] " :: myFiles[wi] );
    		end
            LogMensagem(aFunction, ".END JAVANATIVO - busca lista de arquivos " :: currenttimestamp());
    
    
    /*
    **
    **
    **
    **
    */
    
    end
    
    
    externalType geraListaArquivosExt type JavaObject{JavaName = "geraListaArquivos", PackageName = "br.com.morlan.rui.common.db.external"} 
    	function visualizaListaArquivos(aDiretorio String in, aLogLevel int in  ) returns (string[]);
    end
    ​


    ------------------------------
    Osvaldo Jose de Oliveira Menezes
    Analista
    RellegusTI
    Orlândia
    +55 11 96565-6368
    ------------------------------


  • 2.  RE: DojoUploader - Background
    Best Answer

    Posted Mon October 26, 2020 08:12 AM
    Hello,

    I am currently using the uploader. Basically, i use a java servlet to handle the file upload functions for example.
    uploader DojoUploader{ text = "Attach File(s)", multiple = true, showInput=DojoLib.INPUT_NONE, uploadUrl = "UploadHandler", THIS IS HANDLER NAME onBegin ::= uploader2begin, onabort ::= uploader2abort, onchange ::= uploader2change, onProgress ::= uploader2Progress, onError ::= uploader2error, onComplete ::= uploadercomplete, showLabel = true, onChange ::= uploader2_onchange​


    The source for the handler goes under service project/javasource.

    package uploadHandler; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import java.util.Iterator; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; @WebServlet("" + "") @MultipartConfig(location = "c:\\files\\temp", fileSizeThreshold = 1048576, maxFileSize = 52428800, maxRequestSize = 52428800) public class UploadHandler extends HttpServlet { private static final long serialVersionUID = 1L; private static final String uploadPath = "/files"; public UploadHandler() { super(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String claimin = null, userin = null, fromin = null, plctypin = null, descin = null, invin = null, credappin = null; String savedfile = null, timestmp = null, fileName = null, ofileName = null; response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); fromin = request.getParameter("from"); userin = request.getParameter("user"); plctypin = request.getParameter("plctyp"); descin = request.getParameter("desc"); invin = request.getParameter("inv"); credappin = request.getParameter("credapp"); claimin = request.getParameter("claim"); // Create path components to save the file Collection<Part> files = request.getParts(); Iterator<Part> iter = files.iterator(); OutputStream out = null; InputStream filecontent = null; final PrintWriter writer = response.getWriter(); while (iter.hasNext()) { Part part = iter.next(); String fieldName = null; fileName = null; String partHeader = part.getHeader("content-disposition"); // TODO add encoding conversion here if necessary for (String content : partHeader.split(";")) { if (content.trim().startsWith("filename")) { fileName = content.substring(content.indexOf('=') + 1) .trim().replace("\"", ""); int lastIndex = Math.max(fileName.lastIndexOf('\\'), fileName.lastIndexOf('/')); if (lastIndex >= 0) { fileName = fileName.substring(lastIndex + 1); } } else if (content.trim().startsWith("name")) { fieldName = content.substring(content.indexOf('=') + 1) .trim().replace("\"", ""); } } if (fileName != null) { try { ofileName = fileName; fileName = fileName.replaceAll(" ", "_"); fileName = fileName.replaceAll("[^a-zA-Z0-9_.]+", ""); timestmp = new SimpleDateFormat("yyyMMdd_hhmmss") .format(new Date()); savedfile = uploadPath + File.separator + timestmp + "_" + fromin + "_" + fileName; File newFile = new File(savedfile); boolean bool = false; bool = newFile.getParentFile().mkdirs(); out = new FileOutputStream(newFile); filecontent = part.getInputStream(); int read = 0, size = 0; final byte[] bytes = new byte[2048]; // was 1024 while ((read = filecontent.read(bytes)) != -1) { out.write(bytes, 0, read); size += read; } writeResponse(writer, fieldName, fileName, size, fromin, plctypin, descin, invin, credappin, claimin, timestmp, userin, ofileName); } catch (FileNotFoundException fne) { writer.println("You either did not specify a file to upload or are " + "trying to upload a file to a protected or nonexistent " + "location."); writer.println("<br/> ERROR: " + fne.getMessage()); System.out.println("Problems during file upload. Error: " + fne.getMessage()); fne.printStackTrace(); } finally { if (out != null) { out.close(); } if (filecontent != null) { filecontent.close(); } if (writer != null) { writer.close(); } } } } } private void writeResponse(final PrintWriter writer, String fieldName, String fileName, int size, String fromin, String plctypin, String descin, String invin, String credappin, String claimin, String timestmp, String userin, String ofilename) { final String type = fileName.substring(fileName.indexOf('.') + 1) .trim(); int width, height; BufferedImage bimg; try { bimg = ImageIO.read(new File(fileName)); width = bimg.getWidth(); height = bimg.getHeight(); } catch (IOException e) { width = 0; height = 0; } if (fieldName.equals("uploadedfileFlash")) { writer.print("file=" + downloadPath + '/' + fileName + ",name=" + fileName + ",width=" + width + ",height=" + height + ",type=" + type + ",size=" + size); } else { writer.print("{\"file\":\"" + fileName + "\",\"name\":\"" + fileName + "\",\"width\":" + width + ",\"height\":" + height + ",\"type\":\"" + type + "\",\"size\":" + size + "}"); } } }


    Hope this helps.



    ------------------------------
    nick jones
    ams
    englewood cliffs NJ
    ------------------------------



  • 3.  RE: DojoUploader - Background

    Posted Mon October 26, 2020 10:35 AM

    Hi, Nick,

    I will better explain my need.

    I need when entering a RUI Handler, that the JOB resource, be started and executed every xx in xx minutes (so far so good), start the uploader (in hidden / backgroud mode - here's the difficulty) to get the list files in a given folder. With this list of files (FileInfo), I will work with each name obtained.

    With your tip in native java can I do this?

    I thank you for your collaboration.
    Thank you

    ------------------------------
    Osvaldo Jose de Oliveira Menezes
    Analista
    RellegusTI
    Orlândia
    +55 16 3818-0203
    ------------------------------



  • 4.  RE: DojoUploader - Background

    Posted Mon October 26, 2020 10:56 AM
    Hello Osvaldo.

    I'm not quite sure i get what you are trying to do. When a web user wants to upload something to us, they click the upload button and off it goes.

    Are you saying your web user will select files, then a background job would process them?

    ------------------------------
    nick jones
    ams
    englewood cliffs NJ
    ------------------------------



  • 5.  RE: DojoUploader - Background

    Posted Mon October 26, 2020 11:05 AM

    Come on!

    in fact I already know the folder that I have to search for the files, so (the idea is), the user will not inform anything .. that is, when he enters the application, the job starts the process of scanning the folder and searching for the names of the files it contains. I thought of the Uploader, but if you have another way to do that, no problem ..
    So, in summary, what I need is to get the names of the files contained in a folder, in a hidden way, because the user doesn't even need to know what is there. folder..

    Is it clearer?

    TKS

    ------------------------------
    Osvaldo Jose de Oliveira Menezes
    Analista
    RellegusTI
    Orlândia
    +55 16 3818-0203
    ------------------------------



  • 6.  RE: DojoUploader - Background