sakesh_snippet

import java.io.*;
import ariba.util.scheduler.ScheduledTask;
import ariba.util.scheduler.ScheduledTaskException;
import ariba.base.core.Base;
import ariba.base.core.BaseId;
import ariba.base.core.aql.*;
import ariba.base.core.Partition;
import ariba.base.fields.ValueSource;
import ariba.collaborate.util.CollaborateUtil;
import ariba.collaborate.util.Log;
import java.sql.*;
import ariba.util.core.IOUtil;
import java.io.IOException;
import ariba.util.core.SystemUtil;
import java.util.Map;
import ariba.base.core.Partition;
import java.util.Iterator;
 
// queryString  - Will be the above query
// exportFile – Will be the location of file
 
 public void extractDoc(String queryString,String exportFile) throws Exception 
 
{
 
        try
 {
           // Creating database connection 
 
 	String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);
            Connection conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();
 
            // Executing the query
 
ResultSet results = stmt.executeQuery(queryString);
           debug(" results size :"+results.getFetchSize());
 
 
// result set contains details of all the documents linked to a 
particular project            
while(results.next())
            {
 
           // project internal id  
           String wsInternalId = results.getString(6);
 
          // Status of document		
            String Status = results.getString(7);
 
// If we are extracting the documents for multiple projects we need to create          separate folders in the file system for each project.
 
String FolderName = results.getString(6); // we are giving InternalId of project as folder name
 
	// Getting blob object.
             Blob blob = results.getBlob(2);
 
           // Title of the document, title also contains the extension of the file.
              So we  don’t need to worry about the extension of the file.
 
            String documentTitle = (String)results.getString(3);
 
            String folderName = exportFile+"/"+FolderName; 
 
// so if exportFile value is like config/../data/Extract_Document then
folder structure could be like thisconfig/../data/ExtractDocument/InternalID(value)
 
 
           // getting binary stream from blob object
            InputStream blobStream = blob.getBinaryStream();
 
            File file = new File(folderName);
            file.mkdirs();
 
            String fileName = folderName +"/" + documentTitle;
          // fileName would be like 
             config/../data/ExtractDocument/InternalId(value)/XXX.FileExtension
 
            File fileOut = new File(fileName);
 
           debug("Calling writeToFile function to write the csv in Document");
           writeToFile(blobStream, fileOut);
}
 
 
private void writeToFile (InputStream in, File outputFile) throws Exception 
{
        FileOutputStream out = new FileOutputStream(outputFile);
 
        // We are using ariba IOUtil instead of java functionality 
        boolean written = IOUtil.inputStreamToOutputStream(in, out);
 
 if(written) 
       	{
            	debug("Done !!!");
        	}
 else
       	{
            	debug("Error while writing file...");
            	throw new Exception("Error in writing output file");
        	}
 }
 

Download this snippet

Twitter Twitter

2 Comments to “ sakesh_snippet”

  1. Anonymous  on May 08, 2010

    dDjSH7 <a href="http://efzzxacozbmw.com/">efzzxacozbmw</a>, [url=http://bhosaewyrtiw.com/]bhosaewyrtiw[/url], [link=http://vjmsluckysyc.com/]vjmsluckysyc[/link], http://liccekfbjopj.com/

  2. Anonymous  on Jun 11, 2010

    WQVWzh <a href="http://nhaswlpdaayw.com/">nhaswlpdaayw</a>, [url=http://pdsngtrofngj.com/]pdsngtrofngj[/url], [link=http://genmbmudfpwp.com/]genmbmudfpwp[/link], http://gooadjdtkfmn.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>