Commit 85a81b90 authored by spawar's avatar spawar

Added by Manish for DDUK WMS merge.


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@99247 ce508802-f39f-4f6c-b175-0d175dae99d5
parent f4eca954
package ibase.webitm.utility.wms;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.utility.GenericUtility;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.vfs2.FileSystemOptions;
import org.w3c.dom.Document;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
public class DDUpdStockSchedule implements Schedule
{
private String hostName = "";
private String username = "";
private String password = "";
private String remoteFilePath = "uat/Stock.csv";
private String csvFileNameUpd = "";
private FileSystemOptions opts = null;
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule(HashMap map)throws Exception
{
return "";
}
public String schedule(String scheduleParamXML)throws Exception
{
System.out.println("calling schedule DDUpdStockSchedule..................");
Connection conn = null;
ConnDriver connDriver = null;
String tranDate="",fileName = "Stock.csv";
try
{
setDDSalesConfig();
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
GenericUtility genericUtility = GenericUtility.getInstance();
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
tranDate = simpleDateFormat.format(currentDate.getTime());
System.out.println("csvFileNameUpd12---->>["+csvFileNameUpd+"]");
File file = new File(csvFileNameUpd);
System.out.println("file.separatorChar---->>["+file.separatorChar+"]");
file.mkdirs();
char ch = csvFileNameUpd.charAt(csvFileNameUpd.length() -1 );
System.out.println("Ch @@@@---->>["+ch+"]");
if(ch != file.separatorChar)
{
fileName = file.separator+fileName;
}
generateCsvFile (csvFileNameUpd +fileName,conn);
System.out.println("CSV file successfully created....... ");
final String vtest = csvFileNameUpd+fileName;
//putFile(username, hostName, password, remoteFilePath, csvFileNameUpd+fileName);
Thread t = new Thread()
{
public void run()
{
System.out.println("Thread started........");
putFile(username, hostName, password, remoteFilePath,vtest);
System.out.println("Thread commited........");
}
};
t.start();
System.out.println("End of program........");
System.out.println("The file is uploaded successfully.......");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(conn != null)
{
conn.close();
conn = null;
}
}
return "";
}
private void generateCsvFile(String sFileName,Connection conn) throws IOException,Exception
{
System.out.println("calling generateCsvFile..................");
ResultSet rs = null;
PreparedStatement pstmt = null;
String sql="";
File newFile = new File(sFileName);
if(newFile.exists())
newFile.createNewFile();
BufferedWriter writer = new BufferedWriter(new FileWriter(sFileName));
//FileWriter writer = new FileWriter(sFileName);
writer.append("sku");
writer.append(',');
writer.append("qty");
writer.append('\n');
sql="SELECT S.ITEM_CODE,SUM(S.QUANTITY) - (CASE WHEN SUM(S.ALLOC_QTY) IS NULL THEN 0 ELSE SUM(S.ALLOC_QTY) END + CASE WHEN SUM(S.HOLD_QTY) IS NULL THEN 0 ELSE SUM(S.HOLD_QTY) END) AS QUANTITY "
+ "FROM STOCK S,ITEM I WHERE INV_STAT NOT IN (?,?,?) AND S.ITEM_CODE = I.ITEM_CODE "
+ "AND I.ACTIVE = 'Y' GROUP BY I.ACTIVE, S.ITEM_CODE";
pstmt =conn.prepareStatement(sql);
pstmt.setString(1, "SALE");
pstmt.setString(2, "GRL");
pstmt.setString(3, "PGRL");
rs = pstmt.executeQuery();
while(rs.next())
{
//Changed by Samadhan D14HKAT002 on 10/06/2015 from upload file on katdev.com. start
/*
writer.append(rs.getString(1)));
writer.append(',');
writer.append(rs.getString(2)));
writer.append('\n');
*/
writer.append("\""+checkNullAndTrim(rs.getString(1))+"\"");
writer.append(',');
writer.append("\""+checkNullAndTrim(rs.getString(2))+"\"");
writer.append('\n');
//Changed by Samadhan D14HKAT002 on 10/06/2015 from upload file on katdev.com. end
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt !=null)
{
pstmt.close();
pstmt = null;
}
writer.flush();
writer.close();
}
//Changed by Samadhan D14HKAT002 on 10/06/2015 from upload file on katdev.com. start
/*
private void putFile(String username, String host, String password, String remotefile, String localfile)
{
JSch jsch = new JSch();
Session session = null;
try {
System.out.println("inside put file");
System.out.println("user name: ["+username+"]password["+password+"]host["+host+"]");
System.out.println("putFile success...........");
session = jsch.getSession(username, host, 21);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
System.out.println("channel success...........");
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.put(localfile, remotefile);
System.out.println("The first file is uploaded successfully.");
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
*/
private void putFile(String username, String host, String password, String remotefile, String localfile)
{
FTPClient ftpClient = new FTPClient();
try
{
System.out.println("Remote File: "+remotefile);
System.out.println("Local File: "+localfile);
ftpClient.connect(host, 21);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
{
System.out.println("Operation failed. Server reply code: " + replyCode);
return;
}
boolean success = ftpClient.login(username, password);
showServerReply(ftpClient);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
if (!success)
{
System.out.println("Could not login to the server");
return;
}
else
{
System.out.println("LOGGED IN SERVER");
File firstLocalFile = new File(localfile);
InputStream inputStream = new FileInputStream(firstLocalFile);
ftpClient.storeFile(remotefile, inputStream);
inputStream.close();
if (ftpClient.isConnected())
{
ftpClient.logout();
ftpClient.disconnect();
}
System.out.println("File Uploaded successfully");
}
}
catch (IOException ex)
{
System.out.println("Oops! Something wrong happened");
ex.printStackTrace();
}
}
private static void showServerReply(FTPClient ftpClient)
{
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0)
{
for (String aReply : replies)
{
System.out.println("SERVER: " + aReply);
}
}
}
public String checkNullAndTrim(String input)
{
if (input == null || "null".equalsIgnoreCase(input))
{
input= "";
}
return input.trim();
}
// Changed by Samadhan D14HKAT002 on 10/06/2015 from upload file on katdev.com. end
private void setDDSalesConfig()
{
CommonConstants objCommon =new CommonConstants();
GenericUtility genericUtility=GenericUtility.getInstance();
String fileName = null,xmlString = "";
Document dom=null;
String sCurrentLine = "";
String xmlFile="DDSalesConfig";
System.out.println(" in setDDSalesConfig -------------------------");
String xmlFileName = CommonConstants.APPLICATION_CONTEXT + "setting" + File.separator + "DDSalesConfig.xml";
//fileName = ".." + File.separator + "setting" + File.separator + xmlFile + ".xml";
StringBuilder sb = new StringBuilder();
System.out.println("xmlFileName-->>["+xmlFileName+"]");
try
{
BufferedReader br = new BufferedReader(new FileReader(xmlFileName));
while (( sCurrentLine = br.readLine()) != null)
{
sb.append(sCurrentLine);
}
xmlString =sb.toString();
System.out.println("DDSalesConfig xmlString---->>["+xmlString+"]");
dom = genericUtility.parseString(xmlString);
if(dom != null)
{
this.csvFileNameUpd = genericUtility.getColumnValue("STOCK_TEMP_UPD_PATH",dom);
this.hostName = genericUtility.getColumnValue("SFTP_HOST",dom);
this.username = genericUtility.getColumnValue("SFTP_USER",dom);
this.password = genericUtility.getColumnValue("SFTP_PWD",dom);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
package ibase.webitm.utility.wms;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.bean.wms.Product;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.wms.CommonWmsUtil;
import ibase.webitm.ejb.ValidatorEJB;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import org.w3c.dom.Document;
public class MagentoProductSchedule implements Schedule
{
private String apiSimpleUrl = "",apiConfigUrl = "",loginSite = "";
CommonWmsUtil commonutility = new CommonWmsUtil();
boolean isError = false;
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule(HashMap map)throws Exception
{
return "";//
}
public String schedule(String scheduleParamXML)throws Exception
{
isError = false;
System.out.println("calling schedule MagentoProductSchedule@..................");
Connection conn = null;
ConnDriver connDriver = null;
String tranDate="",fileName = "Stock.csv";
Document dom = null;
try
{
CommonConstants.setIBASEHOME();
setDDSalesConfig();
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
GenericUtility genericUtility = GenericUtility.getInstance();
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
tranDate = simpleDateFormat.format(currentDate.getTime());
dom = new ValidatorEJB().parseString(scheduleParamXML);
if(dom != null)
{
loginSite = checkNull(genericUtility.getColumnValue("siteCode", dom));
}
updateMagentoProducts(this.apiSimpleUrl,this.apiConfigUrl,conn);
//createParent(conn);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("in Finally isError---->>"+isError);
if(isError)
{
conn.rollback();
}
else
{
conn.commit();
}
if(conn != null)
{
conn.close();
conn = null;
}
}
return "";
}
private void updateMagentoProducts(String apiSimpleURL,String apiConfigURL,Connection conn)
{
System.out.println("--------updateMagentoProducts12------------------");
String sSQL = "";
ResultSet rsParent = null;
ResultSet rsSku = null;
PreparedStatement pstmtParent = null;
PreparedStatement pstmtSku = null;
String simpleSku = "Product0001";
int udfNumParent = 0;
String configSku = "Product0002";
//Product objProducts = null;
try
{
/*sSQL = "SELECT ITEM_CODE,UDF_NUM FROM ITEM WHERE ITEM_PARNT IS NULL AND "
+ "(UDF_NUM IS NULL OR UDF_NUM = 0) ";*/
sSQL = "SELECT * FROM ITEM A WHERE ITEM_PARNT IS NULL "
+" AND (SELECT COUNT(*) FROM ITEM WHERE ITEM.ITEM_PARNT = A.ITEM_CODE AND UDF_NUM IS NULL) > 0 ";
pstmtSku = conn.prepareStatement(sSQL);
rsParent = pstmtSku.executeQuery();
//for parent iteration
while(rsParent.next())
{
simpleSku = checkNull((String)rsParent.getString("ITEM_CODE"));
udfNumParent = rsParent.getInt("UDF_NUM");
getProductList(simpleSku, udfNumParent, conn);
}
}
catch(Exception e)
{
isError =true;
e.printStackTrace();
}
}
private void getProductList(String itemCodec,int udfNum, Connection conn) throws Exception
{
List<Integer> simpleProductIdCollection = new ArrayList<Integer>();
ArrayList<Double> parentMaxPrice = new ArrayList<Double>();
Product objProductsParent = new Product();
Product objProductsChild = null;
ResultSet rs = null,rs1= null;
PreparedStatement pstmt = null, pstmt1 = null;
double rate = 0,grossWeight = 0;
String sql = "",sql1="",phyAttribute2 = "",udfCategory = "",categoryId = "",colorId = "",manufacturerId = "",
suppCode="",itemCodeParent = "",itemCodeDescrP = "",itemCodeSDescrP = "",itemCodeChild = "",
itemCodeDescrC = "",itemCodeSDescrC = "",phyAttrib17="",phyAttrib18 ="",countCodeMfg = "",sizeStrGen = "",
phyAttrib19 ="",phyAttrib20 ="",phyAttrib21 ="",categoty = "",dimensionStr = "",sizeStr = "";
int simpleProductId = 0,dimension = 0;
try
{
sql = "SELECT ITEM_CODE,DESCR,SH_DESCR,PHY_ATTRIB_17,COUNT_CODE__MFG,PHY_ATTRIB_18,"
+ "PHY_ATTRIB_19,PHY_ATTRIB_20,PHY_ATTRIB_21,GROSS_WEIGHT,DIMENSION "
+ " FROM ITEM WHERE ITEM_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCodec);
rs = pstmt.executeQuery();
if (rs.next())
{
itemCodeParent = checkNull(rs.getString("ITEM_CODE"));
itemCodeDescrP = checkNull(rs.getString("DESCR"));
itemCodeSDescrP = checkNull(rs.getString("SH_DESCR"));
countCodeMfg = checkNull(rs.getString("COUNT_CODE__MFG"));
phyAttrib17 = checkNull(rs.getString("PHY_ATTRIB_17"));
phyAttrib18 = checkNull(rs.getString("PHY_ATTRIB_18"));
phyAttrib19 = checkNull(rs.getString("PHY_ATTRIB_19"));
phyAttrib20 = checkNull(rs.getString("PHY_ATTRIB_20"));
phyAttrib21 = checkNull(rs.getString("PHY_ATTRIB_21"));
grossWeight = rs.getDouble("GROSS_WEIGHT");
dimension = rs.getInt("DIMENSION");
//child start
/*sql = "SELECT I.ITEM_CODE,P.RATE,I.PHY_ATTRIB_2,I.UDF__STR2,S.SUPP_CODE,I.DESCR,I.SH_DESCR,"
+ "I.PHY_ATTRIB_17,I.COUNT_CODE__MFG,I.PHY_ATTRIB_18,I.PHY_ATTRIB_19,I.PHY_ATTRIB_20,I.PHY_ATTRIB_21,"
+ "I.GROSS_WEIGHT,I.DIMENSION "
+ " FROM ITEM I,SUPPLIERITEM S,PRICELIST P WHERE I.ITEM_PARNT = ? "
+ "AND I.ITEM_CODE = S.ITEM_CODE AND I.ITEM_CODE = P.ITEM_CODE "
+ " AND (I.UDF_NUM IS NULL OR I.UDF_NUM = 0)";*/
sql = "SELECT I.ITEM_CODE,P.RATE,I.PHY_ATTRIB_2,I.PHY_ATTRIB_23,S.SUPP_CODE,I.DESCR,I.SH_DESCR,I.PHY_ATTRIB_17,"
+"SP.COUNT_CODE,I.PHY_ATTRIB_18,I.PHY_ATTRIB_19,I.PHY_ATTRIB_20,I.PHY_ATTRIB_21,"
+ "I.GROSS_WEIGHT,I.PHY_ATTRIB_3,I.PHY_ATTRIB_1 "
+"FROM ITEM I,SUPPLIERITEM S,PRICELIST P ,SUPPLIER SP "
+"WHERE I.ITEM_PARNT = ? "
+"AND I.ITEM_CODE = S.ITEM_CODE "
+"AND I.ITEM_CODE = P.ITEM_CODE "
+"AND P.PRICE_LIST = SP.PRICE_LIST "
+"AND SP.SUPP_CODE = S.SUPP_CODE "
+"AND (I.UDF_NUM IS NULL OR I.UDF_NUM = 0)";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, itemCodeParent);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
itemCodeChild = checkNull(rs1.getString("ITEM_CODE"));
rate = rs1.getDouble("RATE");
phyAttribute2 = checkNull(rs1.getString("PHY_ATTRIB_2"));
colorId = checkNull(getGencodesValue("UDF_STR1",phyAttribute2, "COLOR_CODE", conn));
System.out.println("colorId------>>["+colorId+"]");
colorId = colorId.length() == 0 ? "0" : colorId;
udfCategory = checkNull(rs1.getString("PHY_ATTRIB_23"));
System.out.println("udfCategory---->>"+udfCategory);
String [] id = udfCategory.split(",");
categoty ="";
for(String str : id)
{
categoryId = checkNull(getGencodesValue("FLD_VALUE",checkNull(str), "CATEGORY", conn));
categoty = categoty + categoryId+",";
//categoty = categoty + str;
}
categoty = categoty.substring(0 ,categoty.length() -1);
//categoryId = checkNull(getGencodesValue(udfCategory, "CATEGORY", conn));
System.out.println("categoty------>>["+categoty+"]");
suppCode = checkNull(rs1.getString("SUPP_CODE"));
itemCodeDescrC = checkNull(rs1.getString("DESCR"));
itemCodeSDescrC = checkNull(rs1.getString("SH_DESCR"));
countCodeMfg = checkNull(rs1.getString("COUNT_CODE"));
phyAttrib17 = checkNull(rs1.getString("PHY_ATTRIB_17"));
//phyAttrib18 = checkNull(rs1.getString("PHY_ATTRIB_18"));
//phyAttrib19 = checkNull(rs1.getString("PHY_ATTRIB_19"));
//phyAttrib20 = checkNull(rs1.getString("PHY_ATTRIB_20"));
//phyAttrib21 = checkNull(rs1.getString("PHY_ATTRIB_21"));
grossWeight = rs1.getDouble("GROSS_WEIGHT");
dimensionStr = rs1.getString("PHY_ATTRIB_3");
sizeStr = rs1.getString("PHY_ATTRIB_1");
System.out.println("phyAttrib17@---->>["+phyAttrib17+"]");
System.out.println("phyAttrib18---->>["+phyAttrib18+"]");
System.out.println("phyAttrib19---->>["+phyAttrib19+"]");
System.out.println("phyAttrib20---->>["+phyAttrib20+"]");
System.out.println("phyAttrib21---->>["+phyAttrib21+"]");
System.out.println("sizeStr@@@@---->>["+sizeStr+"]");
objProductsChild = new Product();
double price = getPriceListRate(suppCode, itemCodeChild, conn);
parentMaxPrice.add(price);
objProductsChild.setCost(price);//-------------------------
objProductsChild.setStoreId(0);
objProductsChild.setColorId(Integer.parseInt(colorId));
objProductsChild.setTaxClass(2);
sizeStrGen = checkNull(getGencodesValue("UDF_STR1",sizeStr,"", conn));
sizeStrGen = sizeStrGen.length() == 0 ? "0" : sizeStrGen;
System.out.println("sizeStrGen@@------------>>["+sizeStrGen+"]");
objProductsChild.setProductSizeId(Integer.parseInt(sizeStrGen)); //4.5
String dimension1 = checkNull(getGencodesValue("UDF_STR1",dimensionStr, "DIMENSION", conn));
dimension1 = dimension1.length() == 0 ? "0" : dimension1;
dimension = Integer.parseInt(dimension1);
System.out.println("dimension@@------------>>["+dimension+"]");
objProductsChild.setProductDimensionId(dimension); //MEDIUM
objProductsChild.setImagePath("");//phy_attrib_17
objProductsChild.setLongDescription(phyAttrib18);//.phy_attrib_18
objProductsChild.setCategories(categoty);
manufacturerId = getColumnDescr(conn,"udf_1","supplier","supp_code",suppCode);
manufacturerId = manufacturerId.length() == 0 ? "0" :manufacturerId;
objProductsChild.setManufacturerId(Integer.parseInt(manufacturerId));//supplier code
System.out.println("countCodeMfg------->>["+countCodeMfg+"]");
objProductsChild.setManufacturerCountryCode(countCodeMfg); //count_code__mfg
objProductsChild.setMetaDescription(phyAttrib19); //.phy_attrib_19
objProductsChild.setMetaKeywords(phyAttrib20);//phy_attrib_20
objProductsChild.setMetaTitle(phyAttrib21);//phy_attrib_21
objProductsChild.setPrice(price);
System.out.println("Price------------>>["+price+"]");
objProductsChild.setProductName(itemCodeDescrC);
objProductsChild.setProductStatus(1);
objProductsChild.setProductWeight(grossWeight);
objProductsChild.setQty(5);
objProductsChild.setShortDescription(itemCodeSDescrP);
objProductsChild.setSku(itemCodeChild);
/*objProductsChild.setStoreId(1);
objProductsChild.setTaxClass(2);*/
int simpleId = commonutility.Call(objProductsChild,this.apiSimpleUrl, null);
System.out.println("simpleId child---->>["+simpleId+"]");
if(simpleId != 0)
{
simpleProductIdCollection.add(simpleId);
updateItemUdfNum(itemCodeChild,simpleId,conn);
}
} //end child while
System.out.println("simpleProductId Parent@------>>["+simpleProductId+"]");
System.out.println("simpleProductIdCollection Parent------>>["+simpleProductIdCollection+"]");
if(simpleProductIdCollection !=null && ! simpleProductIdCollection.isEmpty())
{
System.out.println("itemCodec Parent@------>>["+itemCodec+"] itemCodeDescrP--->>"+itemCodeDescrP);
System.out.println("parentMaxPrice parentMaxPrice@------>>["+parentMaxPrice+"]");
objProductsChild.setProductName(itemCodeDescrP);
objProductsChild.setSku(itemCodec);
double objMaxPrice = Collections.max(parentMaxPrice);
objProductsChild.setPrice(objMaxPrice);
simpleProductId = commonutility.Call(objProductsChild,this.apiConfigUrl, simpleProductIdCollection);
//simpleProductIdCollection.add(simpleProductId);
updateItemUdfNum(itemCodeParent,simpleProductId,conn);
}
if(rs1!=null)
{
rs1.close();
rs1 = null;
}
if(pstmt1!=null)
{
pstmt1.close();
pstmt1 = null;
}
//Child End
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
isError = true;
e.printStackTrace();
throw new Exception(e);
}
//return objProducts ;
}
private void updateItemUdfNum(String itemCode,int simpleProductId,Connection conn) throws Exception
{
String sql = "";
int count = 0;
PreparedStatement pstmt = null;
try
{
sql = "update item set udf_num = ? where item_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, simpleProductId);
pstmt.setString(2, itemCode);
count = pstmt.executeUpdate();
}
catch(Exception e)
{
isError = true;
throw new Exception(e);
}
}
private double getPriceListRate(String suppCode,String itemCode,Connection conn) throws Exception
{
ResultSet rs = null;
PreparedStatement pstmt = null;
String sql = "",supplierPriceList = "",pricelist = "";
double rate = 0;
loginSite = loginSite == null ? "" : loginSite.trim();
suppCode = suppCode == null ? "" : suppCode.trim();
System.out.println("getPriceListRate loginSite------>["+loginSite+"]");
try
{
supplierPriceList=checkNull(getColumnDescr(conn, "price_list", "supplier", "supp_code", suppCode));
System.out.println("getPriceListRate supplierPriceList------>["+supplierPriceList+"]");
sql ="SELECT DESCR FROM GENCODES WHERE MOD_NAME = ? AND FLD_NAME = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "W_DD_PRODUCTWIZ");
pstmt.setString(2, "SITE_PRICE");
//pstmt.setString(3, loginSite);
rs = pstmt.executeQuery();
while(rs.next())
{
pricelist = checkNull(rs.getString(1));
System.out.println("pricelist while------>>["+pricelist+"]");
if(!(supplierPriceList.equalsIgnoreCase(pricelist)) )
{
break;
}
}
rs.close();
rs= null;
pstmt.close();
pstmt = null;
System.out.println("getPriceListRate pricelist------>["+pricelist+"]");
sql = "SELECT RATE FROM PRICELIST WHERE PRICE_LIST = ? AND ITEM_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pricelist);
pstmt.setString(2, itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
rate = rs.getDouble(1);
}
rs.close();
rs= null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
isError = true;
throw new Exception(e);
}
System.out.println("getPriceListRate rate------>["+rate+"]");
return rate;
}
private String getGencodesValue(String selectColumn,String descr,String fldName,Connection conn) throws Exception
{
//("UDF_STR1",sizeStr,"", conn));
ResultSet rs = null;
PreparedStatement pstmt =null;
String sql = "",udfStr1 = "";
try
{
fldName = fldName == null ? "" :fldName.trim();
if(fldName.length() > 0)
{
sql ="select "+selectColumn+" from gencodes where mod_name = ? and fld_name = ? and descr = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "W_DD_PRODUCTWIZ");
pstmt.setString(2, fldName);
pstmt.setString(3, descr);
}
else
{
sql ="select "+selectColumn+" from gencodes where mod_name = ? and descr = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "W_DD_PRODUCTWIZ");
pstmt.setString(2, descr);
}
rs = pstmt.executeQuery();
if(rs.next())
{
udfStr1 = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
isError = true;
throw new Exception(e);
}
return udfStr1;
}
public String getColumnDescr(Connection conn, String columnName ,String tableName, String columnName2, String value)throws Exception
{
PreparedStatement pstmt = null ;
ResultSet rs = null ;
String sql = "";
String findValue = "";
sql = "SELECT " + columnName + " from " + tableName + " where " + columnName2 +"= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,value);
rs = pstmt.executeQuery();
if(rs.next())
{
findValue = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("returning String from getColumnDescr " + findValue);
return checkNull(findValue);
}
private void setDDSalesConfig()
{
CommonConstants objCommon =new CommonConstants();
GenericUtility genericUtility=GenericUtility.getInstance();
String fileName = null,xmlString = "",xmlFileName = "";
Document dom=null;
String sCurrentLine = "";
String xmlFile="DDSalesConfig";
System.out.println(" in setDDSalesConfig -------------------------");
System.out.println("CommonConstants.APPLICATION_CONTEXT-->>["+CommonConstants.APPLICATION_CONTEXT+"]");
System.out.println("CommonConstants.JBOSSHOME-->>["+CommonConstants.JBOSSHOME+"]");
if(CommonConstants.APPLICATION_CONTEXT != null)
{
xmlFileName = CommonConstants.APPLICATION_CONTEXT + "setting" + File.separator + "DDSalesConfig.xml";
}
else
{
xmlFileName = CommonConstants.JBOSSHOME + File.separator + "server" + File.separator + "default" + File.separator + "deploy" + File.separator + "ibase.ear" + File.separator + "ibase.war" + File.separator +"setting" + File.separator +"DDSalesConfig.xml";
}
//fileName = ".." + File.separator + "setting" + File.separator + xmlFile + ".xml";
StringBuilder sb = new StringBuilder();
System.out.println("xmlFileName-->>["+xmlFileName+"]");
try
{
BufferedReader br = new BufferedReader(new FileReader(xmlFileName));
while (( sCurrentLine = br.readLine()) != null)
{
sb.append(sCurrentLine);
}
xmlString =sb.toString();
System.out.println("DDSalesConfig xmlString---->>["+xmlString+"]");
dom = genericUtility.parseString(xmlString);
if(dom != null)
{
this.apiSimpleUrl = genericUtility.getColumnValue("PROD_SIMPLE_API_URL",dom);
this.apiConfigUrl = genericUtility.getColumnValue("PROD_CONFIG_API_URL",dom);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
private String checkNull(String input)
{
if(input == null)
{
input = "";
}
return input.trim();
}
}
package ibase.webitm.utility.wms;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import org.w3c.dom.Document;
import ibase.planner.utility.ITMException;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.wms.WaveGenerationPrc;
import ibase.webitm.utility.GenericUtility;
public class WaveGenSchedule implements Schedule
{
public String schedule(HashMap map)throws Exception
{
return "";
}
@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
public String schedule(String scheduleParamXML)throws ITMException, Exception
{
System.out.println("scheduleParamXML Thoug I am testing diffrently@@----->>["+scheduleParamXML+"]");
String siteCode="",tranDate="",currDate = "",loginSiteCode="",loginCode="",remoteHost="",sql = "",
applDateFormat = "";
GenericUtility genericUtility=GenericUtility.getInstance();
Document dom = genericUtility.parseString(scheduleParamXML);
ResultSet rs=null;
PreparedStatement pstmt=null,pstmt1=null;
Connection conn = null;
ConnDriver connDriver = null;
ibase.utility.UserInfoBean userInfo = null;
ArrayList<String> sorderList = new ArrayList<String>();
String errorString = "";
//GenericUtility genericUtility = GenericUtility.getInstance();
if(dom != null)
{
loginSiteCode = genericUtility.getColumnValue("siteCode",dom);
loginCode = genericUtility.getColumnValue("loginCode",dom);
remoteHost = genericUtility.getColumnValue("remoteHost",dom);
}
try
{
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
applDateFormat = genericUtility.getApplDateFormat();
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(applDateFormat);
tranDate = simpleDateFormat.format(currentDate.getTime());
userInfo = new ibase.utility.UserInfoBean(scheduleParamXML);
String xtraParams= getXtraParams( userInfo );
errorString = waveGeneration(xtraParams,applDateFormat,loginSiteCode,conn);
System.out.println("errorStringAfter waveGeneration@@.......................["+errorString+"]");
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(pstmt !=null)
{
pstmt.close();
pstmt = null;
}
}
return errorString;
}
public String waveGeneration(String xtraParams,String applDateFormat,String loginSiteCode, Connection conn) throws ITMException,Exception
{
ResultSet rs = null;
PreparedStatement pstmt = null;
String dueDateStr = "";
StringBuffer xmlString = null;
try
{
GenericUtility genericUtility = GenericUtility.getInstance();
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
dueDateStr = sdf.format(currentDate.getTime());
System.out.println("datestring@@--------->> : "+dueDateStr + " loginSiteCode--->>["+loginSiteCode+"]");
xmlString = new StringBuffer();
xmlString.append( "<DocumentRoot>" );
xmlString.append( "<description>").append("Datawindow Root").append( "</description>\r\n" );
xmlString.append( "<group0>\r\n" );
xmlString.append( "<description>").append("Group0 description").append( "</description>\r\n" );
xmlString.append( "<Header0>\r\n" );
xmlString.append( "<description>\r\n" ).append("Header0 members").append( "</description>\r\n" );
xmlString.append( "<Detail1 dbID=\"\" domID=\"1\" objContext=\"1\" objName=\"wavegen\">\r\n" );
xmlString.append( "<attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\"/>\r\n" );
xmlString.append( "<site_code><![CDATA[" ).append(loginSiteCode).append( "]]></site_code>\r\n" );
xmlString.append( "<default_qty_flag><![CDATA[" ).append( "Y" ).append( "]]></default_qty_flag>\r\n" );
xmlString.append( "<item_ser__from><![CDATA[" ).append( "00" ).append( "]]></item_ser__from>\r\n" );
xmlString.append("<item_ser__to><![CDATA[").append("ZZ").append("]]></item_ser__to>\r\n");
xmlString.append("<item_code__from><![CDATA[").append("00").append("]]></item_code__from>\r\n");
xmlString.append( "<item_code__to ><![CDATA[" ).append( "ZZ" ).append( "]]></item_code__to>\r\n" );
xmlString.append( "<cust_code__dlv__from ><![CDATA[" ).append( "00").append( "]]></cust_code__dlv__from>\r\n" );
xmlString.append( "<cust_code__dlv__to><![CDATA[" ).append("ZZ").append( "]]></cust_code__dlv__to>\r\n" );
xmlString.append( "<cust_code__from ><![CDATA[" ).append("00").append( "]]></cust_code__from>\r\n" );
xmlString.append("<cust_code__to ><![CDATA[").append("ZZ").append("]]></cust_code__to>\r\n");
xmlString.append("<sale_order__from><![CDATA[").append("00").append("]]></sale_order__from>\r\n");
xmlString.append("<sale_order__to><![CDATA[").append("ZZ").append("]]></sale_order__to>\r\n");
xmlString.append("<due_date__from><![CDATA[").append(dueDateStr).append("]]></due_date__from>\r\n");
xmlString.append("<due_date__to><![CDATA[").append(dueDateStr).append("]]></due_date__to>\r\n");
xmlString.append("<wave_mode><![CDATA[").append("P").append("]]></wave_mode>\r\n");
xmlString.append("<single_lot><![CDATA[").append("N").append("]]></single_lot>\r\n");
xmlString.append("<master_pack_allow><![CDATA[").append("N").append("]]></master_pack_allow>\r\n");
xmlString.append("<active_pick_allow><![CDATA[").append("Y").append("]]></active_pick_allow>\r\n");
xmlString.append("<stock_to_dock_allow><![CDATA[").append("N").append("]]></stock_to_dock_allow>\r\n");
xmlString.append("<printer_name><![CDATA[").append("N").append("]]></printer_name>\r\n");
xmlString.append("<print_label><![CDATA[").append("N").append("]]></print_label>\r\n");
xmlString.append("<parcelpack_allow><![CDATA[").append("Y").append("]]></parcelpack_allow>\r\n");
xmlString.append("<ship_type><![CDATA[").append("A").append("]]></ship_type>\r\n");
xmlString.append("<direct_pick_loc><![CDATA[").append("").append("]]></direct_pick_loc>\r\n");
xmlString.append("<pallet_no><![CDATA[").append("").append("]]></pallet_no>\r\n");
xmlString.append("<order_type><![CDATA[").append("").append("]]></order_type>\r\n");
xmlString.append("<remarks><![CDATA[").append("").append("]]></remarks>\r\n");
xmlString.append("<tran_code><![CDATA[").append("").append("]]></tran_code>\r\n");
xmlString.append("<tran_name><![CDATA[").append("").append("]]></tran_name>\r\n");
xmlString.append("<loc_type_parent><![CDATA[").append("").append("]]></loc_type_parent>\r\n");
xmlString.append("<trans_mode><![CDATA[").append("").append("]]></trans_mode>\r\n");
xmlString.append( "</Detail1>\r\n" );
xmlString.append( "</Header0>\r\n" );
xmlString.append( "</group0>\r\n" );
xmlString.append( "</DocumentRoot>\r\n" );
System.out.println("Before waveGeneration xmlString------>>["+xmlString.toString()+"]");
WaveGenerationPrc prcNew = new WaveGenerationPrc();
String getData = prcNew.getData(xmlString.toString(), xmlString.toString(), "W_WAVEGEN", xtraParams);
System.out.println("Return String from WaveGenerationPrc getData---->>["+getData+"]");
String processData = prcNew.process(xmlString.toString(), getData, "w_wavegen", xtraParams);
System.out.println("Return String from WaveGenerationPrc process------["+processData+"]");
//} //end for loop of sorderList
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(pstmt !=null)
{
pstmt.close();
pstmt = null;
}
}
return "";
}
public String getXtraParams( UserInfoBean userInfoBean )throws Exception
{
String XTRA_PARAMS_SEPARATOR = "~~";
StringBuffer xtraParamsBuff = new StringBuffer();
xtraParamsBuff.append("loginCode=" + userInfoBean.getLoginCode());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginEmpCode=" + userInfoBean.getEmpCode());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("loginSiteCode=" + userInfoBean.getSiteCode());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("entityCode=" + userInfoBean.getEntityCode());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("profileId=" + userInfoBean.getProfileId());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("userType=" + userInfoBean.getUserType());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("runMode=I");
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_lang=" + userInfoBean.getUserLanguage());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("user_country=" + userInfoBean.getUserCountry());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("charEnc=" + userInfoBean.getCharEnc());
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("termId="+userInfoBean.getRemoteHost());
String chgTerm = userInfoBean.getRemoteHostName();
if( chgTerm != null && chgTerm.length() > 15 )
{
chgTerm = chgTerm.substring(0, 15);
}
else if( chgTerm == null || chgTerm.length() == 0 )
{
chgTerm = userInfoBean.getRemoteHost();
}
xtraParamsBuff.append(XTRA_PARAMS_SEPARATOR).append("chgTerm=" + chgTerm );
System.out.println("xtraParamsBuff ["+xtraParamsBuff+"]");
return xtraParamsBuff.toString();
}
private String checkNull(String input)
{
if(input == null)
{
return "";
}
else
{
return input.trim();
}
}
}
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