* refactoring and clean up of 2pack
This commit is contained in:
parent
f4ceaac018
commit
716165ba91
|
@ -9,5 +9,6 @@
|
||||||
<classpathentry kind="src" path="/looks"/>
|
<classpathentry kind="src" path="/looks"/>
|
||||||
<classpathentry kind="lib" path="/interfaces/Interfaces.jar" sourcepath="/interfaces/src"/>
|
<classpathentry kind="lib" path="/interfaces/Interfaces.jar" sourcepath="/interfaces/src"/>
|
||||||
<classpathentry kind="lib" path="/tools/lib/commons-net-1.4.0.jar"/>
|
<classpathentry kind="lib" path="/tools/lib/commons-net-1.4.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/tools/lib/ant.jar"/>
|
||||||
<classpathentry kind="output" path="build"/>
|
<classpathentry kind="output" path="build"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,121 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
||||||
* See the GNU General Public License for more details. *
|
|
||||||
* You should have received a copy of the GNU General Public License along *
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
|
|
||||||
* _____________________________________________
|
|
||||||
*****************************************************************************/
|
|
||||||
package org.compiere.PackOut;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.zip.*;
|
|
||||||
import java.util.*;
|
|
||||||
import org.apache.tools.ant.Project;
|
|
||||||
import org.apache.tools.ant.Target;
|
|
||||||
import org.apache.tools.ant.taskdefs.Zip;
|
|
||||||
import org.apache.tools.ant.taskdefs.GZip;
|
|
||||||
import org.apache.tools.ant.taskdefs.Tar;
|
|
||||||
import org.apache.tools.ant.taskdefs.Expand;
|
|
||||||
/**
|
|
||||||
* Compress package
|
|
||||||
*
|
|
||||||
* @author Rob Klein
|
|
||||||
* @version $Id: ImportFAJournal2.java,v 1.0 $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CreateZipFile {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zip the srcFolder into the destFileZipFile. All the folder subtree of the src folder is added to the destZipFile
|
|
||||||
* archive.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param srcFolder File, the path of the srcFolder
|
|
||||||
* @param destZipFile File, the path of the destination zipFile. This file will be created or erased.
|
|
||||||
*/
|
|
||||||
static public void zipFolder(File srcFolder, File destZipFile, String includesdir)
|
|
||||||
{
|
|
||||||
Zip zipper = new Zip();
|
|
||||||
zipper.setDestFile(destZipFile);
|
|
||||||
zipper.setBasedir(srcFolder);
|
|
||||||
zipper.setIncludes(includesdir);
|
|
||||||
zipper.setUpdate(true);
|
|
||||||
zipper.setCompress(true);
|
|
||||||
zipper.setCaseSensitive(false);
|
|
||||||
zipper.setFilesonly(false);
|
|
||||||
zipper.setTaskName("zip");
|
|
||||||
zipper.setTaskType("zip");
|
|
||||||
zipper.setProject(new Project());
|
|
||||||
zipper.setOwningTarget(new Target());
|
|
||||||
zipper.execute();
|
|
||||||
System.out.println(destZipFile);
|
|
||||||
}
|
|
||||||
static public void tarFolder(File srcFolder, File destTarFile, String includesdir)
|
|
||||||
{
|
|
||||||
Tar tarer = new Tar();
|
|
||||||
tarer.setDestFile(destTarFile);
|
|
||||||
tarer.setBasedir(srcFolder);
|
|
||||||
tarer.setIncludes(includesdir);
|
|
||||||
tarer.setCaseSensitive(false);
|
|
||||||
tarer.setTaskName("tar");
|
|
||||||
tarer.setTaskType("tar");
|
|
||||||
tarer.setProject(new Project());
|
|
||||||
tarer.setOwningTarget(new Target());
|
|
||||||
tarer.execute();
|
|
||||||
}
|
|
||||||
static public void gzipFile(File srcFile, File destFile)
|
|
||||||
{
|
|
||||||
GZip GZiper = new GZip();
|
|
||||||
GZiper.setDestfile(destFile);
|
|
||||||
GZiper.setSrc(srcFile);
|
|
||||||
GZiper.setTaskName("gzip");
|
|
||||||
GZiper.setTaskType("gzip");
|
|
||||||
GZiper.setProject(new Project());
|
|
||||||
GZiper.setOwningTarget(new Target());
|
|
||||||
GZiper.execute();
|
|
||||||
}
|
|
||||||
static public void unpackFile(File zipFilepath, File destinationDir)
|
|
||||||
{
|
|
||||||
Expand Unzipper = new Expand();
|
|
||||||
Unzipper.setDest(destinationDir);
|
|
||||||
Unzipper.setSrc(zipFilepath);
|
|
||||||
Unzipper.setTaskType ("unzip");
|
|
||||||
Unzipper.setTaskName ("unzip");
|
|
||||||
Unzipper.setProject(new Project());
|
|
||||||
Unzipper.setOwningTarget(new Target());
|
|
||||||
Unzipper.execute();
|
|
||||||
}
|
|
||||||
static public String getParentDir(File zipFilepath)
|
|
||||||
{
|
|
||||||
String ParentDir=null;
|
|
||||||
try {
|
|
||||||
ZipFile zipFile = new ZipFile(zipFilepath);
|
|
||||||
Enumeration entries = zipFile.entries();
|
|
||||||
ZipEntry entry = (ZipEntry)entries.nextElement();
|
|
||||||
File tempfile = new File(entry.getName());
|
|
||||||
while (tempfile.getParent()!=null)
|
|
||||||
tempfile = tempfile.getParentFile();
|
|
||||||
return tempfile.getName();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.err.println("Unhandled exception:");
|
|
||||||
ioe.printStackTrace();
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}// CreateZipFile
|
|
||||||
|
|
||||||
|
|
|
@ -1,118 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
||||||
* See the GNU General Public License for more details. *
|
|
||||||
* You should have received a copy of the GNU General Public License along *
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
|
||||||
*
|
|
||||||
* Copyright (C) 2004 Marco LOMBARDO. lombardo@mayking.com
|
|
||||||
* Contributor(s): __________________________________________
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Generic PO.
|
|
||||||
// Used to insert/update data from a adempieredata.xml file.
|
|
||||||
|
|
||||||
package org.compiere.PackOut;
|
|
||||||
|
|
||||||
// import for GenericPO
|
|
||||||
import java.util.*;
|
|
||||||
import java.sql.*;
|
|
||||||
import java.math.*;
|
|
||||||
import org.compiere.util.*;
|
|
||||||
import org.compiere.model.*;
|
|
||||||
|
|
||||||
public class IntGenericPO extends PO {
|
|
||||||
|
|
||||||
//private Logger log = Logger.getCLogger(getClass());
|
|
||||||
|
|
||||||
/** Standard Constructor */
|
|
||||||
public IntGenericPO (Properties ctx, int ID)
|
|
||||||
{
|
|
||||||
super (ctx, ID,null,null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Load Constructor */
|
|
||||||
public IntGenericPO (Properties ctx, ResultSet rs)
|
|
||||||
{
|
|
||||||
super (ctx, 0, null, rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntGenericPO (Properties ctx, int ID, String trxName)
|
|
||||||
{
|
|
||||||
super (ctx, ID, trxName, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntGenericPO (Properties ctx, ResultSet rs, String trxName)
|
|
||||||
{
|
|
||||||
super (ctx, 0, trxName, rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int Table_ID = 0;
|
|
||||||
|
|
||||||
/** Load Meta Data */
|
|
||||||
protected POInfo initPO (Properties ctx)
|
|
||||||
{
|
|
||||||
Table_ID = Integer.valueOf(ctx.getProperty("adempieredataTable_ID")).intValue();
|
|
||||||
//log.info("Table_ID: "+Table_ID);
|
|
||||||
POInfo poi = POInfo.getPOInfo (ctx, Table_ID);
|
|
||||||
return poi;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuffer sb = new StringBuffer ("GenericPO[Table=").append(""+Table_ID+",ID=").append(get_ID()).append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int AD_ORGTRX_ID_AD_Reference_ID=130;
|
|
||||||
|
|
||||||
/** Set Trx Organization.
|
|
||||||
Performing or initiating organization */
|
|
||||||
public void setAD_OrgTrx_ID (int AD_OrgTrx_ID)
|
|
||||||
{
|
|
||||||
if (AD_OrgTrx_ID == 0) set_Value ("AD_OrgTrx_ID", null);
|
|
||||||
else
|
|
||||||
set_Value ("AD_OrgTrx_ID", new Integer(AD_OrgTrx_ID));
|
|
||||||
}
|
|
||||||
/** Get Trx Organization.
|
|
||||||
Performing or initiating organization */
|
|
||||||
public int getAD_OrgTrx_ID()
|
|
||||||
{
|
|
||||||
Integer ii = (Integer)get_Value("AD_OrgTrx_ID");
|
|
||||||
if (ii == null) return 0;
|
|
||||||
return ii.intValue();
|
|
||||||
}
|
|
||||||
// setValue
|
|
||||||
public void setValue(String columnName, Object value) {
|
|
||||||
set_Value(columnName, value);
|
|
||||||
}
|
|
||||||
// setValueNoCheck
|
|
||||||
public void setValueNoCheck(String columnName, Object value) {
|
|
||||||
set_ValueNoCheck(columnName, value);
|
|
||||||
}
|
|
||||||
// setValue
|
|
||||||
public void setValue(int index, Object value) {
|
|
||||||
set_Value(index, value);
|
|
||||||
}
|
|
||||||
public void copyRS(PO From, PO To) {
|
|
||||||
copyValues(From, To);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int get_AccessLevel() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // GenericPO
|
|
||||||
|
|
|
@ -1,156 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
||||||
* See the GNU General Public License for more details. *
|
|
||||||
* You should have received a copy of the GNU General Public License along *
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 Robert KLEIN. robeklein@hotmail.com
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
package org.compiere.PackOut;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
import javax.xml.parsers.SAXParser;
|
|
||||||
import org.compiere.process.ProcessInfoParameter;
|
|
||||||
import org.compiere.process.SvrProcess;
|
|
||||||
import org.compiere.util.CLogger;
|
|
||||||
import org.compiere.model.*;
|
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
|
||||||
import org.compiere.util.Ini;
|
|
||||||
import org.compiere.util.Util;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IntPackIn Tool.
|
|
||||||
* @author: Robert KLEIN. robeklein@hotmail.com
|
|
||||||
*/
|
|
||||||
public class IntPackIn extends SvrProcess
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Logger */
|
|
||||||
private CLogger log = CLogger.getCLogger("PackIn");
|
|
||||||
public static String m_UpdateMode = "false";
|
|
||||||
public static String m_Database = "Oracle";
|
|
||||||
public static String m_Package_Dir = null;
|
|
||||||
public int p_IntPackIn_ID = 0;
|
|
||||||
|
|
||||||
protected void prepare()
|
|
||||||
{
|
|
||||||
p_IntPackIn_ID = getRecord_ID();
|
|
||||||
ProcessInfoParameter[] para = getParameter();
|
|
||||||
for (int i = 0; i < para.length; i++)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
} // prepare
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses PackInHandler to update AD.
|
|
||||||
* @param fileName xml file to read
|
|
||||||
* @return status message
|
|
||||||
*/
|
|
||||||
public String importXML (String fileName, Properties ctx, String trxName) {
|
|
||||||
log.info("importXML:" + fileName);
|
|
||||||
File in = new File (fileName);
|
|
||||||
if (!in.exists()) {
|
|
||||||
String msg = "File does not exist: " + fileName;
|
|
||||||
log.info("importXML:" + msg);
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
log.info("starting");
|
|
||||||
System.setProperty("javax.xml.parsers.SAXParserFactory",
|
|
||||||
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
|
||||||
IntPackInHandler handler = new IntPackInHandler();
|
|
||||||
handler.set_TrxName(trxName);
|
|
||||||
handler.setCtx(ctx);
|
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
|
||||||
SAXParser parser = factory.newSAXParser();
|
|
||||||
String msg = "Start Parser";
|
|
||||||
log.info (msg);
|
|
||||||
parser.parse(in, handler);
|
|
||||||
msg = "End Parser";
|
|
||||||
log.info (msg);
|
|
||||||
return "OK.";
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.log(Level.SEVERE,"importXML:", e);
|
|
||||||
return e.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doit
|
|
||||||
* @return ""
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected String doIt()
|
|
||||||
{
|
|
||||||
|
|
||||||
X_AD_Package_Imp_Proc IntPackIn = new X_AD_Package_Imp_Proc(
|
|
||||||
getCtx(),p_IntPackIn_ID, null);
|
|
||||||
|
|
||||||
// Create Target directory if required
|
|
||||||
String fileSeparator=null;
|
|
||||||
File tempfile = new File("");
|
|
||||||
fileSeparator = tempfile.separator;
|
|
||||||
File targetDir = new
|
|
||||||
File(IntPackIn.getAD_Package_Dir()+fileSeparator+"packages");
|
|
||||||
|
|
||||||
if (!targetDir.exists()){
|
|
||||||
boolean success = (new File(IntPackIn.getAD_Package_Dir()+fileSeparator+"packages")).mkdirs();
|
|
||||||
if (!success) {
|
|
||||||
log.info("Target directory creation failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Unzip package
|
|
||||||
File zipFilepath = new File(IntPackIn.getAD_Package_Source());
|
|
||||||
log.info("zipFilepath->"+zipFilepath);
|
|
||||||
String PackageName = CreateZipFile.getParentDir(zipFilepath);
|
|
||||||
CreateZipFile.unpackFile(zipFilepath,targetDir);
|
|
||||||
|
|
||||||
|
|
||||||
String dict_file = IntPackIn.getAD_Package_Dir()+fileSeparator+"packages"+fileSeparator+PackageName+fileSeparator+"dict"+fileSeparator+"PackOut.xml";
|
|
||||||
log.info("dict file->"+dict_file);
|
|
||||||
IntPackIn impXML = new IntPackIn();
|
|
||||||
|
|
||||||
if(IntPackIn.isAD_Override_Dict()== true)
|
|
||||||
impXML.m_UpdateMode = "true";
|
|
||||||
else
|
|
||||||
impXML.m_UpdateMode = "false";
|
|
||||||
|
|
||||||
impXML.m_Package_Dir=IntPackIn.getAD_Package_Dir()+fileSeparator+"packages"+fileSeparator+PackageName+fileSeparator;
|
|
||||||
if (DB.isOracle())
|
|
||||||
impXML.m_Database = "Oracle";
|
|
||||||
else if (DB.isPostgreSQL())
|
|
||||||
impXML.m_Database = "PostgreSQL";
|
|
||||||
|
|
||||||
//call XML Handler
|
|
||||||
impXML.importXML(dict_file, getCtx(), get_TrxName());
|
|
||||||
|
|
||||||
//Generate Model Classes
|
|
||||||
// globalqss - don't call Generate Model must be done manual
|
|
||||||
// String args[] = {IntPackIn.getAD_Package_Dir()+"/dbPort/src/org/compiere/model/", "org.compiere.model","'U'"};
|
|
||||||
// org.compiere.util.GenerateModel.main(args) ;
|
|
||||||
|
|
||||||
return "Finish Process";
|
|
||||||
} // doIt
|
|
||||||
|
|
||||||
} // IntPackIn
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,464 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
||||||
* See the GNU General Public License for more details. *
|
|
||||||
* You should have received a copy of the GNU General Public License along *
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
|
||||||
* For the text or an alternative of this public license, you may reach us *
|
|
||||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
|
||||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
|
|
||||||
* Contributor(s): Carlos Ruiz - globalqss
|
|
||||||
*****************************************************************************/
|
|
||||||
package org.compiere.PackOut;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
import org.compiere.model.*;
|
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
|
||||||
import org.compiere.process.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse Package Install.
|
|
||||||
*
|
|
||||||
* @author Robert Klein
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PackRoll extends SvrProcess
|
|
||||||
{
|
|
||||||
/** Package from Record */
|
|
||||||
private int m_AD_Package_Imp_ID = 0;
|
|
||||||
private String m_Processing = null;
|
|
||||||
StringBuffer sql = null;
|
|
||||||
StringBuffer sqlB = null;
|
|
||||||
String columnIDName=null;
|
|
||||||
StringBuffer sqlC = null;
|
|
||||||
StringBuffer sqlD = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepare - e.g., get Parameters.
|
|
||||||
*/
|
|
||||||
protected void prepare()
|
|
||||||
{
|
|
||||||
ProcessInfoParameter[] para = getParameter();
|
|
||||||
for (int i = 0; i < para.length; i++)
|
|
||||||
{
|
|
||||||
String name = para[i].getParameterName();
|
|
||||||
if (para[i].getParameter() == null)
|
|
||||||
;
|
|
||||||
else if (name.equals("Processing"))
|
|
||||||
m_Processing = (String)para[i].getParameter();
|
|
||||||
else
|
|
||||||
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
|
|
||||||
}
|
|
||||||
m_AD_Package_Imp_ID = getRecord_ID();
|
|
||||||
} // prepare
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform process.
|
|
||||||
* @return Message (translated text)
|
|
||||||
* @throws Exception if not successful
|
|
||||||
*/
|
|
||||||
protected String doIt() throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
sqlB = new StringBuffer ("UPDATE AD_Package_Imp "
|
|
||||||
+ "SET PK_Status = 'Uninstalling' "
|
|
||||||
+ "WHERE AD_Package_Imp_ID = " + m_AD_Package_Imp_ID);
|
|
||||||
int no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
|
||||||
|
|
||||||
log.info("Starting Package Reversal");
|
|
||||||
//select all records that are new or have been updated by package install
|
|
||||||
sql = new StringBuffer ("SELECT * "
|
|
||||||
+ "FROM AD_Package_Imp_Detail "
|
|
||||||
+ "WHERE AD_Package_Imp_ID=" + m_AD_Package_Imp_ID
|
|
||||||
+ " ORDER BY AD_Package_Imp_Detail_ID DESC");
|
|
||||||
log.info(sql.toString());
|
|
||||||
int x = 0;
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql.toString (), null);
|
|
||||||
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (rs.getString("Type").compareTo("file") == 0){
|
|
||||||
|
|
||||||
sqlB = new StringBuffer ("SELECT * "
|
|
||||||
+ "FROM AD_Package_Imp_Backup "
|
|
||||||
+ "WHERE AD_Package_Imp_Detail_ID=" + rs.getInt("AD_Package_Imp_Detail_ID")
|
|
||||||
+ " AND AD_Package_Imp_ID=" + rs.getInt("AD_Package_Imp_ID")
|
|
||||||
);
|
|
||||||
PreparedStatement pstmt2 = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt2 = DB.prepareStatement (sqlB.toString (), get_TrxName());
|
|
||||||
|
|
||||||
ResultSet rs2 = pstmt2.executeQuery ();
|
|
||||||
|
|
||||||
while (rs2.next())
|
|
||||||
{
|
|
||||||
if (rs2.getString("AD_Package_Imp_Bck_Dir") != null && rs2.getString("AD_Package_Imp_Org_Dir") != null ){
|
|
||||||
copyFile (rs2.getString("AD_Package_Imp_Bck_Dir"),rs2.getString("AD_Package_Imp_Org_Dir"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update uninstall field for column
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Backup"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Backup_ID = "+ rs2.getInt("AD_Package_Imp_Backup_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
|
|
||||||
// Update uninstall field for record
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Detail"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Detail_ID = "+ rs.getInt("AD_Package_Imp_Detail_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
rs2.close ();
|
|
||||||
pstmt2.close ();
|
|
||||||
pstmt2 = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "doIt", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt2 != null)
|
|
||||||
pstmt2.close ();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{}
|
|
||||||
pstmt2 = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
String tableName = rs.getString("TableName");
|
|
||||||
|
|
||||||
|
|
||||||
int recordID = rs.getInt("AD_Original_ID");
|
|
||||||
|
|
||||||
//determine if record is an update to the original
|
|
||||||
//if record is an update then update record with backup settings
|
|
||||||
//else inactivate record
|
|
||||||
if (rs.getString("ACTION").compareTo("Update")== 0){
|
|
||||||
//select all backed up columns for the record
|
|
||||||
sqlB = new StringBuffer ("SELECT * "
|
|
||||||
+ "FROM AD_Package_Imp_Backup "
|
|
||||||
+ "WHERE AD_Package_Imp_Detail_ID=" + rs.getInt("AD_Package_Imp_Detail_ID")
|
|
||||||
+ " AND AD_Package_Imp_ID=" + rs.getInt("AD_Package_Imp_ID")
|
|
||||||
);
|
|
||||||
PreparedStatement pstmt2 = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt2 = DB.prepareStatement (sqlB.toString (), get_TrxName());
|
|
||||||
|
|
||||||
ResultSet rs2 = pstmt2.executeQuery ();
|
|
||||||
|
|
||||||
while (rs2.next())
|
|
||||||
{
|
|
||||||
|
|
||||||
sql = new StringBuffer ("SELECT IsKey FROM AD_Column WHERE AD_Column_ID = ?");
|
|
||||||
String IsKey = DB.getSQLValueString(get_TrxName(),sql.toString(),rs2.getInt("AD_Column_ID"));
|
|
||||||
|
|
||||||
//Get Table value
|
|
||||||
sql = new StringBuffer ("SELECT TableName FROM AD_Table WHERE AD_Table_ID = ?");
|
|
||||||
tableName = DB.getSQLValueString(get_TrxName(),sql.toString(),rs2.getInt("AD_Table_ID"));
|
|
||||||
|
|
||||||
//Get Column Name
|
|
||||||
sql = new StringBuffer ("SELECT ColumnName FROM AD_Column WHERE AD_Column_ID = ?");
|
|
||||||
String columnName = DB.getSQLValueString(get_TrxName(),sql.toString(),rs2.getInt("AD_Column_ID"));
|
|
||||||
//log.info(columnName);
|
|
||||||
|
|
||||||
//Update columns for record
|
|
||||||
//TODO make process more efficient!
|
|
||||||
if ( IsKey.equals("Y")||columnName.startsWith("Created"))
|
|
||||||
; // ignore is a Key Column or if it references a Created(By) Column
|
|
||||||
//Update "Updated" field with current date
|
|
||||||
else if ( columnName.equals("Updated")){
|
|
||||||
//Format Date
|
|
||||||
//TODO Correct to include proper time of update
|
|
||||||
Date today = new Date();
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
|
|
||||||
String colDate = formatter.format(today);
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = '"
|
|
||||||
+ colDate
|
|
||||||
+ "' WHERE " + columnIDName+" = "+ recordID);
|
|
||||||
|
|
||||||
no = DB.executeUpdate(sqlC.toString(), null);
|
|
||||||
//Update uninstall field
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Backup"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Backup_ID = "+ rs2.getInt("AD_Package_Imp_Backup_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
}
|
|
||||||
// Update "UpdatedBy" field with current user
|
|
||||||
else if ( columnName.equals("UpdatedBy")){
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = '"
|
|
||||||
+ Env.getAD_User_ID(Env.getCtx())
|
|
||||||
+ "' WHERE " + columnIDName+" = "+ recordID);
|
|
||||||
no = DB.executeUpdate(sqlC.toString(), null);
|
|
||||||
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Backup"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Backup_ID = "+ rs2.getInt("AD_Package_Imp_Backup_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
}
|
|
||||||
// Update all other fields with backup information
|
|
||||||
else{
|
|
||||||
|
|
||||||
int v_AD_Reference_ID = rs2.getInt("AD_Reference_ID");
|
|
||||||
// Adjust for Column reference table
|
|
||||||
if (tableName.equals("AD_Ref_Table")){
|
|
||||||
columnIDName = "AD_Reference_ID";
|
|
||||||
}
|
|
||||||
else if (tableName.equals("AD_TreeNodeMM")){
|
|
||||||
columnIDName = "Node_ID";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
columnIDName = tableName+"_ID";
|
|
||||||
}
|
|
||||||
//Update columns that are Strings adjusting for single quotes
|
|
||||||
if (v_AD_Reference_ID == 10 || v_AD_Reference_ID == 14 || v_AD_Reference_ID == 34 || v_AD_Reference_ID == 17
|
|
||||||
// Carlos Ruiz globalqss, special treatment for EntityType
|
|
||||||
// it's a Table reference but must be treated as String
|
|
||||||
|| (v_AD_Reference_ID == 18 && columnName.equalsIgnoreCase("EntityType")))
|
|
||||||
if (rs2.getObject("ColValue").toString().equals("null")){
|
|
||||||
;//Ignore null values
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = "
|
|
||||||
+ "'" + rs2.getObject("ColValue").toString().replaceAll("'","''") + "'"
|
|
||||||
+ " WHERE " + columnIDName+" = "+ recordID);}
|
|
||||||
//Update true/false columns
|
|
||||||
else if (v_AD_Reference_ID == 20|| v_AD_Reference_ID == 28){
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = "
|
|
||||||
+ (rs2.getObject("ColValue").toString().equals("true") ? "'Y'" : "'N'")
|
|
||||||
+ " WHERE " + columnIDName+" = "+ recordID);}
|
|
||||||
//Update columns that are Strings adjusting for single quotes
|
|
||||||
else if ( v_AD_Reference_ID == 13|| v_AD_Reference_ID == 18|| v_AD_Reference_ID == 19|| v_AD_Reference_ID == 21|| v_AD_Reference_ID == 25|| v_AD_Reference_ID == 27|| v_AD_Reference_ID == 30|| v_AD_Reference_ID == 31|| v_AD_Reference_ID == 35)
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = "
|
|
||||||
+ rs2.getObject("ColValue").toString().replaceAll("'","''")
|
|
||||||
+ " WHERE " + columnIDName+" = "+ recordID);
|
|
||||||
//Update columns that are numbers
|
|
||||||
else if ( v_AD_Reference_ID == 11|| v_AD_Reference_ID == 12|| v_AD_Reference_ID == 22|| v_AD_Reference_ID == 29)
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET " + columnName + " = "
|
|
||||||
+ rs2.getObject("ColValue").toString().replaceAll("'","''")
|
|
||||||
+ " WHERE " + columnIDName+" = "+ recordID);
|
|
||||||
//Update columns that are dates
|
|
||||||
else if (v_AD_Reference_ID == 15|| v_AD_Reference_ID == 16)
|
|
||||||
//TODO Develop portable code to update date columns
|
|
||||||
;// ignore
|
|
||||||
else // 23-Binary, 24-Radio, 26-RowID, 32-Image not supported
|
|
||||||
;// ignore
|
|
||||||
//execute update
|
|
||||||
no = DB.executeUpdate(sqlC.toString(), null);
|
|
||||||
|
|
||||||
//Update uninstall field for column
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Backup"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Backup_ID = "+ rs2.getInt("AD_Package_Imp_Backup_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
|
|
||||||
|
|
||||||
// Update uninstall field for record
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Detail"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Detail_ID = "+ rs.getInt("AD_Package_Imp_Detail_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rs2.close ();
|
|
||||||
pstmt2.close ();
|
|
||||||
pstmt2 = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "doIt", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt2 != null)
|
|
||||||
pstmt2.close ();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{}
|
|
||||||
pstmt2 = null;
|
|
||||||
}
|
|
||||||
} // ********* Update Loop
|
|
||||||
//Inactivate new records
|
|
||||||
else if (rs.getString("ACTION").compareTo("New")==0){
|
|
||||||
if (tableName.equals("AD_Ref_Table"))
|
|
||||||
columnIDName = "AD_Reference_ID";
|
|
||||||
else if (tableName.equals("AD_TreeNodeMM"))
|
|
||||||
columnIDName = "Node_ID";
|
|
||||||
else
|
|
||||||
columnIDName = tableName+"_ID";
|
|
||||||
sqlC = new StringBuffer ("UPDATE " + tableName
|
|
||||||
+ " SET IsActive = 'N'"
|
|
||||||
+ " WHERE " + columnIDName+" = "+ recordID);
|
|
||||||
|
|
||||||
// execute update
|
|
||||||
no = DB.executeUpdate(sqlC.toString(), null);
|
|
||||||
|
|
||||||
// Update uninstall field for record
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp_Detail"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_Detail_ID = "+ rs.getInt("AD_Package_Imp_Detail_ID"));
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "doIt", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{}
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
//Update uninstall field for package
|
|
||||||
sqlD = new StringBuffer ("UPDATE AD_Package_Imp"
|
|
||||||
+ " SET Uninstall = 'Y'"
|
|
||||||
+ " WHERE AD_Package_Imp_ID = "+ m_AD_Package_Imp_ID);
|
|
||||||
no = DB.executeUpdate(sqlD.toString(), null);
|
|
||||||
|
|
||||||
sqlB = new StringBuffer ("UPDATE AD_Package_Imp "
|
|
||||||
+ " SET PK_Status = 'Uninstalled'"
|
|
||||||
+ " WHERE AD_Package_Imp_ID = " + m_AD_Package_Imp_ID);
|
|
||||||
no = DB.executeUpdate (sqlB.toString(), get_TrxName());
|
|
||||||
|
|
||||||
|
|
||||||
log.info("Package Reversal Completed");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return "";
|
|
||||||
} // doIt
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open input file for processing
|
|
||||||
*
|
|
||||||
* @param String file with path
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public FileInputStream OpenInputfile (String filePath) {
|
|
||||||
|
|
||||||
FileInputStream fileTarget = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fileTarget = new FileInputStream(filePath);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e ) {
|
|
||||||
System.out.println("Can't find file ");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return fileTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open output file for processing
|
|
||||||
*
|
|
||||||
* @param String file with path
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public OutputStream OpenOutputfile (String filePath) {
|
|
||||||
|
|
||||||
OutputStream fileTarget = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fileTarget = new FileOutputStream(filePath);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e ) {
|
|
||||||
System.out.println("Can't find file ");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return fileTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyfile
|
|
||||||
*
|
|
||||||
* @param String file with path
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public int copyFile (String sourceFile,String targetFile) {
|
|
||||||
|
|
||||||
OutputStream target= OpenOutputfile ( targetFile);
|
|
||||||
InputStream source = OpenInputfile (sourceFile);
|
|
||||||
|
|
||||||
int byteCount = 0;
|
|
||||||
int success = 0;
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
int data = source.read();
|
|
||||||
if (data < 0)
|
|
||||||
break;
|
|
||||||
target.write(data);
|
|
||||||
byteCount++;
|
|
||||||
}
|
|
||||||
source.close();
|
|
||||||
target.close();
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("Successfully copied " + byteCount + " bytes.");
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.println("Error occurred while copying. "+ byteCount + " bytes copied.");
|
|
||||||
System.out.println(e.toString());
|
|
||||||
|
|
||||||
success = -1;
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // PackRoll
|
|
Loading…
Reference in New Issue