Upload New File

parent 26ac6bd6
/* */ package com.communication.engn.servlets;
/* */
/* */ import com.cm.dao.UploadDocumentDAO;
/* */ import com.connect.CommonFunction;
/* */ import com.connect.ConnectionDAO;
/* */ import com.connect.DaoImplInstanceFactory;
/* */ import com.connect.PrepStmtObject;
/* */ import com.login.roleManager.UserObject;
/* */ import java.io.File;
/* */ import java.util.ArrayList;
/* */ import java.util.List;
/* */ import java.util.ResourceBundle;
/* */ import javax.servlet.http.HttpServletRequest;
/* */ import javax.servlet.http.HttpServletResponse;
/* */ import javax.servlet.http.HttpSession;
/* */ import org.apache.commons.io.FileUtils;
/* */ import org.apache.log4j.Logger;
/* */ import org.apache.struts.action.ActionForm;
/* */ import org.apache.struts.action.ActionForward;
/* */ import org.apache.struts.action.ActionMapping;
/* */ import org.apache.struts.actions.DispatchAction;
/* */
/* */
/* */ public class DocumentUploadBulkProcessAction
/* */ extends DispatchAction
/* */ {
/* 45 */ private static final Logger logger = Logger.getLogger(DocumentUploadBulkProcessAction.class.getName());
/* 46 */ static ResourceBundle resource = ResourceBundle.getBundle("com.yourcompany.struts.utill");
/* 47 */ List<String> fileList = new ArrayList<>();
/* 48 */ List<String> filesListInDir = null;
/* 49 */ String dateFormat = resource.getString("lbl.dateInDao");
/* 50 */ String dateFormatWithTime = resource.getString("lbl.dateWithTimeInDaoYear");
/* */
/* */
/* */ public ActionForward callDocUploadInBulk(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
/* 54 */ logger.info("the method is in callDocUploadInBulk");
/* 55 */ HttpSession session = request.getSession();
/* 56 */ boolean flag = false;
/* 57 */ UserObject userobj = (UserObject)session.getAttribute("userobject");
/* */
/* 59 */ String bDate = "";
/* 60 */ if (userobj != null) {
/* 61 */ String str = userobj.getUserId();
/* 62 */ bDate = userobj.getBusinessdate();
/* */ }
/* 64 */ UploadDocumentDAO dao = (UploadDocumentDAO)DaoImplInstanceFactory.getDaoImplInstance("UPLOADDOCD");
/* 65 */ logger.info("Implementation class: " + dao.getClass());
/* 66 */ StringBuilder query = new StringBuilder();
/* 67 */ ArrayList loanDetailList = new ArrayList();
/* 68 */ StringBuilder pathquery = new StringBuilder();
/* 69 */ StringBuilder pathquery1 = new StringBuilder();
/* 70 */ String makerId = "ADMIN";
/* 71 */ String UPLOAD_PATCH = "";
/* 72 */ String UPLOAD_PROCESS_PATH = "";
/* 73 */ String status = null;
/* 74 */ boolean HStatus = false;
/* 75 */ String txntype = "LGL";
/* 76 */ double loan_id = Math.random();
/* 77 */ String loanId = Double.toString(loan_id);
/* 78 */ String DocDesc = "Document Upload By Legal";
/* 79 */ String pdateFormat = "%Y-%m-%d";
/* */
/* */
/* */
/* */ try {
/* 84 */ pathquery.append(" select PARAMETER_VALUE from parameter_mst where PARAMETER_KEY = 'BULK_DOC_UPLOAD' ");
/* 85 */ UPLOAD_PATCH = ConnectionDAO.singleReturn(pathquery.toString());
/* 86 */ pathquery1.append(" select PARAMETER_VALUE from parameter_mst where PARAMETER_KEY = 'BULK_DOC_UPLOAD_PROCESS' ");
/* 87 */ UPLOAD_PROCESS_PATH = ConnectionDAO.singleReturn(pathquery1.toString());
/* 88 */ String businessDate = " SELECT PARAMETER_VALUE FROM PARAMETER_MST WHERE PARAMETER_KEY = 'BUSINESS_DATE' ";
/* 89 */ businessDate = ConnectionDAO.singleReturn(businessDate);
/* 90 */ String path = UPLOAD_PATCH + "/";
/* 91 */ logger.info("final path=" + path);
/* 92 */ File directory = new File(path + "/");
/* 93 */ boolean isDirectory = directory.isDirectory();
/* 94 */ if (isDirectory) {
/* */
/* */
/* */ try {
/* 98 */ File listfiles = new File(path);
/* */
/* 118 */ File[] files = listfiles.listFiles();
/* 119 */ if (files.length > 0) {
/* 120 */ ArrayList<PrepStmtObject> qryList = new ArrayList();
/* 121 */ for (int i = 0; i < files.length; i++) {
/* 122 */ String filename = files[i].getName();
/* 123 */ String filewithpath1 = files[i].getCanonicalPath();
/* 124 */ File outputfile = new File(filewithpath1);
/* 125 */ File destDir1 = new File(UPLOAD_PROCESS_PATH);
/* */
/* */
/* */ try {
/* 129 */ if (outputfile.exists()) {
/* 130 */ FileUtils.copyFileToDirectory(outputfile, destDir1, true);
/* */ }
/* 132 */ } catch (Exception e) {
/* 133 */ e.printStackTrace();
/* */ }
// create a method isFileNamedvalid(filename) --return type is boolean
boolean isValid = isFileNamedvalid(filename);
logger.info("isValid value :: " + isValid);
if (isValid) {
logger.info(" inside the if block.... " );
/* 135 */ String loan_no = filename.substring(0, 20);
/* 136 */ String getloanId = " SELECT loan_id FROM cr_loan_dtl WHERE loan_no ='" + loan_no + "' ";
/* 137 */ String LOANID = ConnectionDAO.singleReturn(getloanId);
/* 138 */ String filewithpath = files[i].getCanonicalPath();
/* */
/* 140 */ String fcount = "select count(*) from CR_UPLOADED_DOCUMENTS where FILE_NAME='" + filename + "' and txn_type='LGL' ";
/* 141 */ String filecount = ConnectionDAO.singleReturn(fcount);
/* 142 */ if (filecount.equalsIgnoreCase("0")) {
/* 143 */ PrepStmtObject insertPrepStmtObject = new PrepStmtObject();
/* 144 */ StringBuffer bufInsSql = new StringBuffer();
/* 145 */ bufInsSql.append("insert into CR_UPLOADED_DOCUMENTS(TXN_TYPE,TXN_ID,DOCUMENT_DESC,FILE_NAME,DOCUMENT_PATH,DOCUMENT_TYPE,DOCUMENT_STATUS,UPLOADED_DATE,REC_STATUS,UPLOADED_BY)");
/* 146 */ bufInsSql.append(" values ( ");
/* 147 */ bufInsSql.append(" ?,");
/* 148 */ bufInsSql.append(" ?,");
/* 149 */ bufInsSql.append(" ?,");
/* 150 */ bufInsSql.append(" ?,");
/* 151 */ bufInsSql.append(" ?,");
/* 152 */ bufInsSql.append(" ?,");
/* 153 */ bufInsSql.append(" ?,");
/* 154 */ bufInsSql.append(" now(), ");
/* 155 */ bufInsSql.append(" ?, ");
/* 156 */ bufInsSql.append(" ? ");
/* 157 */ bufInsSql.append(" )");
/* */
/* 159 */ if (CommonFunction.checkNull(txntype).trim().equalsIgnoreCase("")) {
/* 160 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 162 */ insertPrepStmtObject.addString(txntype);
/* */ }
/* 164 */ if (CommonFunction.checkNull(LOANID).trim().equalsIgnoreCase("")) {
/* 165 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 167 */ insertPrepStmtObject.addString(LOANID);
/* */ }
/* 169 */ if (CommonFunction.checkNull(DocDesc).trim().equalsIgnoreCase("")) {
/* 170 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 172 */ insertPrepStmtObject.addString(DocDesc);
/* */ }
/* 174 */ if (CommonFunction.checkNull(filename).trim().equalsIgnoreCase("")) {
/* 175 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 177 */ insertPrepStmtObject.addString(filename);
/* */ }
/* 179 */ if (CommonFunction.checkNull(UPLOAD_PROCESS_PATH).trim().equalsIgnoreCase("")) {
/* 180 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 182 */ insertPrepStmtObject.addString(UPLOAD_PROCESS_PATH);
/* */ }
/* 184 */ insertPrepStmtObject.addString("LEGAL");
/* */
/* 186 */ insertPrepStmtObject.addString("A");
/* */
/* 188 */ insertPrepStmtObject.addString("A");
/* */
/* 190 */ if (CommonFunction.checkNull(makerId).trim().equalsIgnoreCase("")) {
/* 191 */ insertPrepStmtObject.addNull();
/* */ } else {
/* 193 */ insertPrepStmtObject.addString(makerId);
/* */ }
/* */
/* 196 */ insertPrepStmtObject.setSql(bufInsSql.toString());
/* 197 */ logger.info("IN saveNewInstallPlan() insert query1 ### " + insertPrepStmtObject.printQuery());
/* 198 */ qryList.add(insertPrepStmtObject);
/* 199 */ bufInsSql = null;
/* 200 */ insertPrepStmtObject = null;
/* */ } else {
/* 202 */ logger.info("This file " + filename + " is already uploaded.");
/* */ }
/* */ }
/* */ }
/* 206 */ HStatus = ConnectionDAO.sqlInsUpdDeletePrepStmt(qryList);
/* 207 */ logger.info("insert status: " + HStatus);
/* */ } else {
/* 209 */ logger.info("This file not found on location.");
/* */
/* */ }
/* */
/* */ }
/* 214 */ catch (Exception e) {
/* 215 */ e.printStackTrace();
/* */ }
/* */ finally {
/* */
/* 219 */ logger.info("Clear block: " + path);
/* */ }
/* */ } else {
/* 222 */ logger.info("Directory does not exiss: " + path);
/* */ }
/* */
/* 231 */ DeleteFiles(path);
/* 232 */ pathquery = null;
/* 233 */ pathquery1 = null;
/* */ }
/* 235 */ catch (Exception e) {
/* 236 */ e.printStackTrace();
/* */ }
/* 238 */ return null;
/* */ }
//Method Added by Amol S on 12-Nov to check the , valid file -strt
public boolean isFileNamedvalid(String filename)
{
logger.info(" Method called... " );
logger.info(" filename :--> " + filename);
if (filename.contains("'") || filename.length() < 20) {
return false;
}
return true;
}
//Method Added by Amol S on 12-Nov to check the , valid file -end
/* */
/* */
/* */ public static void DeleteFileFolder(String path) {
/* 243 */ File file = new File(path);
/* 244 */ if (file.exists()) {
/* */
/* */ do {
/* 247 */ delete(file);
/* 248 */ } while (file.exists());
/* */
/* */
/* 251 */ try { File[] listFiles = file.listFiles();
/* 252 */ logger.info("listFiles" + listFiles);
/* 253 */ for (File file1 : listFiles) {
/* 254 */ System.out.println("Deleting " + file1.getName());
/* 255 */ file1.delete();
/* */ } }
/* 257 */ catch (Exception ex) { ex.printStackTrace(); }
/* */
/* */ } else {
/* */
/* 261 */ System.out.println("File or Folder not found : " + path);
/* */ }
/* */ }
/* */
/* */
/* */ private static void delete(File file) {
/* 267 */ if (file.isDirectory()) {
/* */
/* 269 */ String[] fileList = file.list();
/* 270 */ if (fileList.length == 0) {
/* */
/* 272 */ System.out.println("Deleting Directory : " + file.getPath());
/* 273 */ file.delete();
/* */ } else {
/* */
/* 276 */ int size = fileList.length;
/* 277 */ for (int i = 0; i < size; i++)
/* */ {
/* 279 */ String fileName = fileList[i];
/* 280 */ System.out.println("File path : " + file.getPath() + " and name :" + fileName);
/* 281 */ String fullPath = file.getPath() + "/" + fileName;
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */ else {
/* */
/* 289 */ System.out.println("Deleting file : " + file.getPath());
/* 290 */ file.delete();
/* */ }
/* */ }
/* */
/* */
/* */ public static void DeleteFiles(String path) {
/* 337 */ File file = new File(path);
/* 338 */ if (file.exists()) {
/* */
/* */ try {
/* 341 */ if (file.exists()) {
/* 342 */ File[] files = file.listFiles();
/* 343 */ if (files != null)
/* 344 */ for (File f : files) {
/* 345 */ if (f.isFile() && f.exists())
/* 346 */ { f.delete();
/* 347 */ logger.info("successfully deleted"); }
/* */ else
/* 349 */ { logger.info("cant delete a file due to open or error"); }
/* */ }
/* */ }
/* 352 */ } catch (Exception ex) {
/* */
/* 354 */ ex.printStackTrace();
/* */ }
/* */ } else {
/* */
/* 358 */ System.out.println("File or Folder not found : " + path);
/* */ }
/* */ }
/* */ }
/* Location: C:\Users\amols\Documents\OmniFinServer.jar\com (1).zip!\com\communication\engn\servlets\DocumentUploadBulkProcessAction.class
* Java compiler version: 7 (51.0)
* JD-Core Version: 1.1.3
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment