Pre_Bulkload workflow Steps

=================================================== 

[1] Step = Check for Processing_Zips.txt, which is written while this workflow processed zip (finds, extracts & copies zips [Step 5]).

String toPath = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\FILEWATCHER\\Processing_Zips.txt";
//String toPath = "D:\\SHAREFILE_SYNC\\FILEWATCHER\\Processing_Zips.txt";

java.io.File fileExists = new java.io.File(toPath);

if (fileExists.exists() ) {
	System.out.printf ("\nFILE EXISTS [Fnd_Proc_Txt] ("+toPath+")");
	result="Fnd_Proc_Txt";
}
else {
	System.out.printf("\nFILE DOES NOT EXIST [No_Proc_Txt] ("+toPath+")");
	result="No_Proc_Txt";
}

=================================================== 

[2] Step = Timer. 10 minute timer, which waits 10 minutes before it goes back & checks Step 1 again (Checks for Processing_Zips.txt)

=================================================== 

[3] Step = Task checks for number of Zips in the 2 sharefile dump folders (BULKLOAD & DOCS). If both folders have 0 zips, it routes back to Step [1] & searches for Processing_Zips.txt, which means there are zips being processed & Bulk loaded.

String zipBulkLoc = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\GT_GTAUX\\BULKLOAD\\";
String zipDocsLoc = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\GT_GTAUX\\DOCS\\";

zipBulkCntr = 0;
zipDocsCntr = 0;

java.io.File[] zipBulkFiles = new java.io.File(zipBulkLoc).listFiles();
for(java.io.File zipBulkfile: zipBulkFiles){
	if(zipBulkfile.getName().endsWith(".zip")) { zipBulkCntr++; }
}

System.out.printf ("\nzipBulkCntr Counter: "+zipBulkCntr);

java.io.File[] zipDocsFiles = new java.io.File(zipDocsLoc).listFiles();
for(java.io.File zipDocsfile: zipDocsFiles){
	if(zipDocsfile.getName().endsWith(".zip")) { zipDocsCntr++; }
}

System.out.printf ("\nzipDocsCntr Counter: "+zipDocsCntr);

int zipCntr = zipDocsCntr + zipBulkCntr;

System.out.printf ("\nTotal Zips Counter (zipCntr): "+zipCntr);

if (zipCntr == 0 ) { result = "No_Zip_Files"; }
else { result = "Found_Zip_Files"; }

System.out.printf ("\nzipCntr: "+zipCntr+" - result: "+result);

=================================================== 

[4] Step = Task to create/copy Processing_Zips.txt, to halt any further zips being processed &/or Bulk loaded.

String fromPath = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\FILEWATCHER\\files\\Processing_Zips.txt";
java.io.File fromFile = new java.io.File(fromPath);

String toPath = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\FILEWATCHER\\Processing_Zips.txt";
java.io.File toFile = new java.io.File(toPath);

java.io.FileInputStream fis  = new java.io.FileInputStream(fromFile);
java.io.FileOutputStream fosx = new java.io.FileOutputStream(toFile);
try {
	byte[] buf = new byte[2048];
	int i = 0;
	while ((i = fis.read(buf)) != -1) { fosx.write(buf, 0, i); }
}
catch (Exception e) {  }
finally {
	if (fis != null) fis.close();
	if (fosx != null) fosx.close();
}

System.out.printf ("\nProcessing_Zips.txt has been created: "+toPath);

=================================================== 

[5] Step = Zips in BULKLOAD & DOCS Folders were processed (found, extracted & copied).

if (zipBulkCntr > 0 ) {
	String zipBulkLoc = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\GT_GTAUX\\BULKLOAD\\";
	ext.utils.PreBulkload_Unzip_05.findZips(zipBulkLoc);
	System.out.printf ("\nBULKLOAD Folder Zips have been Processed, for Folder (zipBulkLoc): "+zipBulkLoc);
}
else {
	if (zipBulkCntr > 0 ) {
		String zipDocsLoc = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\GT_GTAUX\\DOCS\\";
		ext.utils.PreBulkload_Unzip_05.findZips(zipDocsLoc);
		System.out.printf ("\nDOCS Folder Zips have been Processed, for Folder (zipDocsLoc): "+zipDocsLoc);
	}
}

=================================================== 

[6] Step = Delete_Dummy workflow Sync. It will later be replaced with DxN Multi Doc Loader workflow.

// delete dummy file

System.out.println("Deleting D:/ADMIN/LJETT/Bulkload/SHAREFILE_SYNC_Test/FILEWATCHER/Doc_Waiting2.txt");

ext.utils.DeleteFile_05.deleteFile("D:/ADMIN/LJETT/Bulkload/SHAREFILE_SYNC_Test/FILEWATCHER/Doc_Waiting2.txt");

String errStg = "Fake Exception String";

// create ERROR_ALERT.txt file to test file checking on return of Sync

String toPath = "D:\\SHAREFILE_SYNC\\FILEWATCHER\\ERROR_ALERT.txt";

java.io.PrintStream expfl = null;
expfl = new java.io.PrintStream(new java.io.FileOutputStream(toPath));
String txtToWrite = "Error because of Exception: "+errStg;

expfl.println(txtToWrite);

expfl.flush();
expfl.close();

=================================================== 

[7] Step = Check for ERROR_ALERT.txt that would have been created by DxN Multi Doc Loading Workflow. 
Found_ALERT Routes to Email Notification task [8] Step, if it found the file. 
No_ALERT Routes to [9] Step [Delete Processing_Zips.txt], if it doesnt find the error alert file.

//String toPath = "D:\\SHAREFILE_SYNC\\FILEWATCHER\\ERROR_ALERT.txt";
String toPath = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\FILEWATCHER\\ERROR_ALERT.txt";

java.io.File alertToFile = new java.io.File(toPath);

if (alertToFile.exists()) {
	System.out.printf("\nFILE EXISTS [Found_ALERT] ("+toPath+")");
	result="Found_ALERT";
}
else {
	System.out.printf("\nFILE DOES NOT EXIST [No_ALERT] ("+toPath+")");
	result="No_ALERT";
}


=================================================== 

[8] Step = Email Notification that ERROR_ALERT.txt file was found in [7] Step [Found_ALERT].

Emailed jett & ramy, with message: "Multi BulkLoad Error"

=================================================== 

[9] Step = Delete Processing_Zips.txt file, because a Multi Bulkload workflow Sync has returned & [7] 
Step found not ERROR_ALERT.txt file [No_ALERT].

String toPath = "D:\\ADMIN\\LJETT\\Bulkload\\SHAREFILE_SYNC_Test\\FILEWATCHER\\Processing_Zips.txt";
java.io.File ProcFile = new java.io.File(toPath);

if (ProcFile.exists()) {
	ProcFile.delete();
}

=================================================== 
