package org.yeastrc.nrseq_fasta_importer.uploaded_file;

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.yeastrc.nrseq_fasta_importer.constants.ConfigSystemsKeysConstants;
import org.yeastrc.nrseq_fasta_importer.dao.ConfigSystemDAO;

/**
 * 
 *
 */
public class GetTempDirForFileUploads {
	
	
	private static final Logger log = Logger.getLogger(GetTempDirForFileUploads.class);

	//  private constructor
	private GetTempDirForFileUploads() { }
	
	/**
	 * @return newly created instance
	 */
	public static GetTempDirForFileUploads getInstance() { 
		return new GetTempDirForFileUploads(); 
	}

	/**
	 * @return true if valid, otherwise throws exception
	 * @throws Exception
	 */
	public boolean validateTempDirForFileUploads() throws Exception {
		
		File tempDir = getTempDirForFileUploads();
				
		return true;
	}
	
	/**
	 * @return File pointing to temp dir, otherwise throws Exception
	 * @throws Exception
	 */
	public File getTempDirForFileUploads() throws Exception {
		

		String tempDirString = null; 
				
		try {
			tempDirString = ConfigSystemDAO.getInstance().getConfigValueForConfigKey( ConfigSystemsKeysConstants.UPLOADED_FILES_TEMP_DIRECTORY_KEY );
			

		} catch (Exception e ) {

			String msg = "Exception getting file upload temp dir for validation";
			log.error( msg, e );
			
			throw e;
		}
		
		
		if ( StringUtils.isEmpty(tempDirString) ) {
			
			String msg = "Upload files temp Dir not found in configuration table. config_key: " 
					+ ConfigSystemsKeysConstants.UPLOADED_FILES_TEMP_DIRECTORY_KEY ;
			
			log.error( msg );
			throw new Exception(msg);
		}
		
		File tempDir = new File( tempDirString );
		
		if ( ! tempDir.exists() ) {

			String msg = "Upload files temp dir does not exist for 'config_key' in configuration table : '" 
					+ ConfigSystemsKeysConstants.UPLOADED_FILES_TEMP_DIRECTORY_KEY 
					+ "'.  Upload files temp dir: " + tempDir.getAbsolutePath();
			
			log.error( msg );
			throw new Exception(msg);
		}
		
		return tempDir;
		
	}
}

@@ -38,21 +38,31 @@
 ter.
-uploaded_file
+fasta_importer_work_dir
 ;%0A%0Ai
@@ -237,16 +237,101 @@
 stants;%0A
+import org.yeastrc.nrseq_fasta_importer.constants.FileNameAndDirectoryNameConstants;%0A
 import o
@@ -415,36 +415,57 @@
 lass Get
-TempDirForFileUpload
+_FASTA_Importer_Work_Directory_And_SubDir
 s %7B%0A%09%0A%09%0A
@@ -519,36 +519,57 @@
 gger(Get
-TempDirForFileUpload
+_FASTA_Importer_Work_Directory_And_SubDir
 s.class)
@@ -608,36 +608,57 @@
 vate Get
-TempDirForFileUpload
+_FASTA_Importer_Work_Directory_And_SubDir
 s() %7B %7D%0A
@@ -726,83 +726,125 @@
  Get
-TempDirForFileUploads getInstance() %7B %0A%09%09return new GetTempDirForFileUpload
+_FASTA_Importer_Work_Directory_And_SubDirs getInstance() %7B %0A%09%09return new Get_FASTA_Importer_Work_Directory_And_SubDir
 s();
@@ -959,37 +959,46 @@
 validate
-TempDirForFileUploads
+_FASTA_Importer_Work_Directory
 () throw
@@ -1034,37 +1034,46 @@
 ir = get
-TempDirForFileUploads
+_FASTA_Importer_Work_Directory
 ();%0A%09%09%09%09
@@ -1211,29 +1211,38 @@
  get
-TempDirForFileUploads
+_FASTA_Importer_Work_Directory
 () t
@@ -1412,35 +1412,35 @@
 nstants.
-UPLOADED_FILES_TEMP
+FASTA_IMPORTER_WORK
 _DIRECTO
@@ -1676,29 +1676,37 @@
  = %22
-Upload files temp Dir
+FASTA_Importer_Work_Directory
  not
@@ -1785,35 +1785,35 @@
 nstants.
-UPLOADED_FILES_TEMP
+FASTA_IMPORTER_WORK
 _DIRECTO
@@ -1977,37 +1977,45 @@
  msg = %22
-Upload files temp dir
+FASTA_Importer_Work_Directory
  does no
@@ -2106,27 +2106,27 @@
 nts.
-UPLOADED_FILES_TEMP
+FASTA_IMPORTER_WORK
 _DIR
@@ -2153,29 +2153,37 @@
 '.  
-Upload files temp dir
+FASTA_Importer_Work_Directory
 : %22 
@@ -2296,10 +2296,396 @@
 ;%0A%09%09%0A%09%7D%0A
+%09%0A%09%0A%09/**%0A%09 * @return%0A%09 */%0A%09public String getDirForUploadFileTempDir( ) %7B%0A%0A%09%09String dirName = FileNameAndDirectoryNameConstants.UPLOAD_FILE_TEMP_DIR;%0A%09%09%0A%09%09return dirName;%0A%09%7D%0A%09%0A%09%0A%09/**%0A%09 * @return%0A%09 */%0A%09public String getDirForImportTrackingId( int importTrackingId ) %7B%0A%0A%09%09String dirName = FileNameAndDirectoryNameConstants.IMPORT_DIR_FOR_ID + importTrackingId;%0A%09%09%0A%09%09return dirName;%0A%09%7D%0A%09%0A%09%0A
 %7D%0A

Change work files locations under main work directory. Change getNextQueued to lock the selected queued item and immediately update to 'started'