IDEMPIERE-4199 Clean up org.adempiere.extend (#29)

Remove org.adempiere.pipo.legacy project.
This commit is contained in:
hengsin 2020-05-05 02:36:59 +08:00 committed by GitHub
parent ed6470ea1d
commit 738b97ccaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 0 additions and 15206 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.adempiere.pipo.legacy</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
#Mon Sep 27 13:03:25 MYT 2010
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false

View File

@ -1,13 +0,0 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Old Pipo
Bundle-SymbolicName: org.adempiere.pipo.legacy
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.adempiere.base;bundle-version="1.0.0"
Export-Package: org.adempiere.pipo,
org.adempiere.pipo.exception,
org.adempiere.pipo.handler
Import-Package: junit.framework;version="3.8.2",
org.apache.tools.ant,
org.apache.tools.ant.taskdefs

View File

@ -1,4 +0,0 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View File

@ -1,399 +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. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
*****************************************************************************/
package org.adempiere.pipo;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_BUTTON;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_LIST;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_MEMO;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_STRING;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TEXT;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public abstract class AbstractElementHandler implements ElementHandler {
protected CLogger log = CLogger.getCLogger("PackIn");
/**
* Get ID from Name for a table.
* TODO: substitute with PO.getAllIDs
*
* @param tableName
* @param name
*
*/
public int get_ID (Properties ctx, String tableName, String name) {
return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx));
}
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param name
*/
public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) {
return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
}
/**
* Write results to log and records in history table
*
* @param success
* @param tableName
* @param objectType
* @param objectID
* @param objectStatus
* @throws SAXException
*
*/
public int record_log (Properties ctx, int success, String objectName,String objectType, int objectID,
int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{
StringBuffer recordLayout = new StringBuffer();
int id = 0;
TransformerHandler hd_document = getLogDocument(ctx);
AttributesImpl attsOut = new AttributesImpl();
String result = success == 1 ? "Success" : "Failure";
//hd_documemt.startElement("","","Successful",attsOut);
recordLayout.append("Type:")
.append(objectType)
.append(" - Name:")
.append(objectName)
.append(" - ID:")
.append(objectID)
.append(" - Action:")
.append(objectStatus)
.append(" - " + result);
hd_document.startElement("","",result,attsOut);
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
hd_document.endElement("","",result);
X_AD_Package_Imp_Detail detail = new X_AD_Package_Imp_Detail(ctx, 0, getTrxName(ctx));
detail.setAD_Package_Imp_ID(getPackageImpId(ctx));
detail.setAD_Org_ID(Env.getAD_Org_ID(ctx) );
detail.setType(objectType);
detail.setName(objectName);
detail.setAction(objectStatus);
detail.setSuccess(result);
detail.setRecord_ID(objectID);
detail.setAD_Backup_ID(objectIDBackup);
detail.setTableName(tableName);
detail.setAD_Table_ID(AD_Table_ID);
if ( !detail.save(getTrxName(ctx)) )
log.info("Insert to import detail failed");
id = detail.get_ID();
return id;
}
/**
* Get ID from Name for a table with a Master reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx));
}
/**
* Get ID from Name for a table with a Master reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int get_IDWithMasterAndColumn (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) {
return IDFinder.get_IDWithMasterAndColumn(tableName, columnName, name, tableNameMaster, masterID,
getTrxName(ctx));
}
/**
* Get ID from Name for a table with a Master reference ID.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
*/
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) {
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx));
}
/**
* Get ID from Name for a table.
* TODO: substitute with PO.getAllIDs
*
* @param tableName
* @param name
*/
public int getIDbyName (Properties ctx, String tableName, String name) {
return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx));
}
/**
* Get ID from Value for a table.
* TODO: substitute with PO.getAllIDs
*
* @param tableName
* @param name
*/
public int getIDbyValue (Properties ctx, String tableName, String value) {
return IDFinder.getIDbyValue(tableName, value, getClientId(ctx), getTrxName(ctx));
}
/**
* Make backup copy of record.
*
* @param tablename
*
*
*
*/
public int copyRecord(Properties ctx, String tableName,PO from){
// Create new record
int idBackup = 0;
String colValue=null;
int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx));
for (int i = 0; i < poInfo.getColumnCount(); i++){
colValue=null;
int columnID =get_IDWithMasterAndColumn (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID);
StringBuffer sqlD = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'");
int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString());
idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL");
int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1;
if (referenceID == REFERENCE_DATATYPE_STRING || referenceID == REFERENCE_DATATYPE_TEXT || referenceID == REFERENCE_DATATYPE_MEMO || referenceID == REFERENCE_DATATYPE_LIST)
if (from != null && from.get_Value(i)!= null)
colValue = from.get_Value(i).toString().replaceAll("'","''");
else if (referenceID == REFERENCE_DATATYPE_YES_NO|| referenceID == REFERENCE_DATATYPE_BUTTON)
if (from != null && from.get_Value(i)!= null)
colValue = from.get_Value(i).toString().replaceAll("'","''");
else
;//Ignore
StringBuffer sqlB = new StringBuffer ("INSERT INTO AD_Package_Imp_Backup")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
.append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + idBackup )
.append( ", " + idDetail )
.append( ", " + getPackageImpId(ctx) )
.append( ", " + tableID )
.append( ", " + (columnID == -1 ? "null" : columnID) )
.append( ", " + (referenceID == -1 ? "null" : referenceID) )
.append( ", '" + (colValue != null ? colValue : (from != null ? from.get_Value(i) : "null")) )
.append( "')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to import backup failed");
//}
}
return idBackup;
}
/**
* 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("File not found: " + filePath);
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("File not found: " + filePath);
return null;
}
return fileTarget;
}
/**
* Copyfile
*
* @param String file with path
*
*/
public int copyFile (InputStream source,OutputStream target) {
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.");
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
success = -1;
}
return success;
}
/**
* Get client id
* @param ctx
* @return int
*/
protected int getClientId(Properties ctx) {
return Env.getContextAsInt(ctx, "AD_Client_ID");
}
/**
* Get AD_Package_Imp_ID
* @param ctx
* @return int
*/
protected int getPackageImpId(Properties ctx) {
return Env.getContextAsInt(ctx, "AD_Package_Imp_ID");
}
/**
* Get update system maintained dictionary flag
* @param ctx
* @return update mode
*/
protected String getUpdateMode(Properties ctx) {
return Env.getContext(ctx, "UpdateMode");
}
/**
* Get current transaction name
* @param ctx
* @return transaction name
*/
protected String getTrxName(Properties ctx) {
return Env.getContext(ctx, "TrxName");
}
/**
* Get share document
* @param ctx
* @return TransformerHandler
*/
protected TransformerHandler getLogDocument(Properties ctx) {
return (TransformerHandler)ctx.get("LogDocument");
}
/**
* @param ctx
* @return package directory
*/
protected String getPackageDirectory(Properties ctx) {
return Env.getContext(ctx, "PackageDirectory");
}
/**
* Process element by entity type and user setting.
* @param ctx
* @param entityType
* @return boolean
*/
protected boolean isProcessElement(Properties ctx, String entityType) {
if ("D".equals(entityType) || "C".equals(entityType)) {
return "true".equalsIgnoreCase(getUpdateMode(ctx));
} else {
return true;
}
}
/**
* return null for empty string ("").
* @param atts
* @param qName
* @return string value
*/
protected String getStringValue(Attributes atts, String qName) {
String s = atts.getValue(qName);
return ("".equals(s) ? null : s);
}
}

View File

@ -1,112 +0,0 @@
package org.adempiere.pipo;
import org.compiere.model.PO;
import org.xml.sax.helpers.AttributesImpl;
public class AttributeFiller {
private AttributesImpl atts = null;
private PO po = null;
/**
* Will clear attributes !!!
* @param _atts
*/
public AttributeFiller(AttributesImpl attributes){
attributes.clear();
atts = attributes;
po = null;
}
/**
* Will clear attributes !!!
* @param _atts
*/
public AttributeFiller(AttributesImpl attributes, PO poToAutoFill){
attributes.clear();
atts = attributes;
po = poToAutoFill;
}
/**
*
* @param name
* @param value
*/
public void addUnchecked(String name, String value){
atts.addAttribute("", "", name, "CDATA", value);
}
/**
*
* @param name
* @param stringValue
*/
public void addString(String name, String stringValue){
atts.addAttribute("", "", name, "CDATA", stringValue != null ? stringValue : "");
}
/**
*
* @param name
* @param boolValue
*/
public void addBoolean(String name, boolean boolValue){
atts.addAttribute("", "", name, "CDATA", boolValue == true ? "true" : "false");
}
/**
*
* @param name
* @param stringValue
*/
public void add(String columnName){
Object value = po.get_Value(columnName);
if(value == null){
atts.addAttribute("", "", columnName, "CDATA", "");
return;
}
if(value instanceof String){
atts.addAttribute("", "", columnName, "CDATA", (String)value);
}else if(value instanceof Boolean) {
atts.addAttribute("", "", columnName, "CDATA", (Boolean)value == true ? "true" : "false");
}else if(value instanceof Integer) {
atts.addAttribute("", "", columnName, "CDATA", value.toString());
}else{
throw new IllegalArgumentException("Add your own type implementation here.");
}
}
/**
*
*
*/
public void addIsActive(){
atts.addAttribute("", "", "IsActive", "CDATA", (Boolean)po.isActive() == true ? "true" : "false");
}
/**
*
* @return
*/
public AttributesImpl getAttributes(){
return atts;
}
}

View File

@ -1,120 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* _____________________________________________
*****************************************************************************/
package org.adempiere.pipo;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.GZip;
import org.apache.tools.ant.taskdefs.Tar;
import org.apache.tools.ant.taskdefs.Zip;
/**
* 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)
{
try {
ZipFile zipFile = new ZipFile(zipFilepath);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry = 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

View File

@ -1,72 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo;
import org.xml.sax.Attributes;
/**
* XML element structure
* @author Low Heng Sin
*
*/
public class Element {
public String uri;
public String localName;
public String qName;
//element attributes
public Attributes attributes;
//defer for later reprocessing
public boolean defer = false;
//parent element
public Element parent;
//resolved db recordid, store for reference by child element
public int recordId = 0;
//unresolved dependency
public String unresolved = "";
//number of pass
public int pass = 1;
//skip this node
public boolean skip = false;
public boolean deferEnd = false;
/**
* @param uri
* @param localName
* @param qName
* @param attributes
*/
public Element(String uri, String localName, String qName, Attributes attributes) {
this.uri = uri;
this.localName = localName;
this.qName = qName;
this.attributes = attributes;
}
/**
* @return elementValue
*/
public String getElementValue() {
String elementValue = null;
if ("".equals (uri))
elementValue = qName;
else
elementValue = uri + localName;
return elementValue;
}
}

View File

@ -1,56 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.xml.sax.SAXException;
/**
* Interface for handling import and export of table data to xml
* @author Low Heng Sin
*
*/
public interface ElementHandler {
/**
* Handle start of xml element ( import ).
* @param ctx
* @param element
* @throws org.xml.sax.SAXException
*/
public void startElement (Properties ctx, Element element)
throws org.xml.sax.SAXException;
/**
* Handle closing of xml element ( import ).
* @param ctx
* @param element
* @throws SAXException
*/
public void endElement (Properties ctx, Element element) throws SAXException;
/**
* Create xml element ( export ).
* @param ctx
* @param document
* @throws SAXException
*/
public void create(Properties ctx, TransformerHandler document) throws SAXException;
}

View File

@ -1,385 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.adempiere.exceptions.DBException;
import org.adempiere.pipo.exception.NonUniqueIDLookupException;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
/**
* Utility class for the looking up of record id.
* @author Low Heng Sin
* @author Teo Sarca
*/
public final class IDFinder
{
private static CLogger log = CLogger.getCLogger(IDFinder.class);
private static Map<String, Integer> idCache = new HashMap<String, Integer>();
/**
* Get ID from Name for a table.
*
* @param tableName
* @param name
* @param AD_Client_ID
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int get_ID (String tableName, String name, int AD_Client_ID, String trxName)
{
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name);
if (!tableName.startsWith("AD_"))
key.append(" and AD_Client_ID=").append(AD_Client_ID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
.append(tableName)
.append(" where name=?");
params.add(name);
if (!tableName.startsWith("AD_"))
{
sqlB = sqlB.append(" and AD_Client_ID=?");
params.add(AD_Client_ID);
}
return getID(sqlB.toString(), params, key.toString(), true, trxName);
}
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param value
* @param AD_Client_ID
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int get_IDWithColumn (String tableName, String columnName, Object value, int AD_Client_ID, String trxName)
{
return get_IDWithColumn(tableName, columnName, value, AD_Client_ID, true, trxName);
}
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param value
* @param AD_Client_ID
* @param strict if true we throw NonUniqueIDLookupException on more then one result. Else we will return 0.
* @param trxName
* @return id or 0
* @throws NonUniqueIDLookupException if more then one result found for search criteria and strict is true
*/
public static int get_IDWithColumn (String tableName, String columnName, Object value, int AD_Client_ID, boolean strict, String trxName)
{
if (value == null)
return 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".")
.append(columnName)
.append("=")
.append(value.toString());
if (!tableName.startsWith("AD_"))
key.append(" and AD_Client_ID=").append(AD_Client_ID);
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
.append(tableName)
.append(" where ")
.append(columnName)
.append(" = ?");
params.add(value);
if (!tableName.startsWith("AD_"))
{
sqlB = sqlB.append(" and AD_Client_ID=?");
params.add(AD_Client_ID);
}
sqlB = sqlB.append(" Order By ")
.append(tableName)
.append("_ID");
return getID(sqlB.toString(), params, key.toString(), strict, trxName);
}
/**
* Get ID from Name for a table with a Master reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, String nameMaster, String trxName)
{
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name)
.append(" and ")
.append(tableNameMaster)
.append(".Name=")
.append(nameMaster);
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
.append(tableName)
.append(" where name = ? and ")
.append(tableNameMaster)
.append("_ID = (select ")
.append(tableNameMaster)
.append("_ID from ")
.append(tableNameMaster)
.append(" where name = ?)");
params.add(name);
params.add(nameMaster);
return getID(sqlB.toString(), params, key.toString(), true, trxName);
}
/**
* Get ID from Name for a table with a Master reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int get_IDWithMasterAndColumn (String tableName, String columnName, String name, String tableNameMaster, int masterID, String trxName)
{
String key = tableName + "." + columnName + "=" + name + tableNameMaster + "=" + masterID;
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
.append(tableName)
.append(" where ")
.append(columnName)
.append(" = ? and ")
.append(tableNameMaster+"_ID =?");
params.add(name);
params.add(masterID);
return getID(sqlB.toString(), params, key, true, trxName);
}
/**
* Get ID from Name for a table with a Master reference ID.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, int masterID, String trxName)
{
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name)
.append(" and ")
.append(tableNameMaster)
.append(".")
.append(tableNameMaster)
.append("_ID=")
.append(masterID);
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
.append(tableName)
.append(" where name=? and ")
.append(tableNameMaster)
.append("_ID=?");
params.add(name);
params.add(masterID);
return getID(sqlB.toString(), params, key.toString(), true, trxName);
}
/**
* Get ID from Column for a table.
*
* @param tableName
* @param column
* @param name
* @param AD_Client_ID
* @param trxName
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int getIDbyColumn (String tableName, String column, String name, int AD_Client_ID, String trxName)
{
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append("."+column+"=")
.append(name);
if (!tableName.startsWith("AD_"))
key.append(" AND AD_Client_ID=").append(AD_Client_ID);
ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sql = new StringBuffer("SELECT ")
.append(tableName)
.append("_ID ")
.append("FROM ")
.append(tableName)
.append(" ")
.append("WHERE "+column+"=?");
params.add(name);
if (!tableName.startsWith("AD_"))
{
sql.append(" AND AD_Client_ID=?");
params.add(AD_Client_ID);
}
return getID(sql.toString(), params, key.toString(), true, trxName);
}
/**
*
* @param tableName
* @param name
* @param AD_Client_ID
* @param trxName
* @return
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int getIDbyName (String tableName, String name, int AD_Client_ID, String trxName)
{
return getIDbyColumn(tableName, "Name", name, AD_Client_ID, trxName);
}
/**
*
* @param tableName
* @param name
* @param AD_Client_ID
* @param trxName
* @return
* @throws NonUniqueIDLookupException if more then one result found for search criteria
*/
public static int getIDbyValue (String tableName, String name, int AD_Client_ID, String trxName)
{
return getIDbyColumn(tableName, "Value", name, AD_Client_ID, trxName);
}
public static void clearIDCache()
{
idCache.clear();
}
/**
*
* @param sql
* @param params
* @param key
* @param strict if true we throw NonUniqueIDLookupException on more then one result. Else we will return 0.
* @param trxName
* @return id or 0
* @throws NonUniqueIDLookupException if more then one result found for search criteria and strict is true
*/
private static int getID(String sql, List<Object> params, String key, boolean strict, String trxName)
{
if (key != null && idCache.containsKey(key))
return idCache.get(key);
int id = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, trxName);
DB.setParameters(pstmt, params);
rs = pstmt.executeQuery();
if (rs.next())
{
id = rs.getInt(1);
}
if (rs.next())
{
if (strict)
{
throw new NonUniqueIDLookupException(key);
}
else
{
log.warning("Non Unique ID Lookup found for "+key);
}
}
}
catch (SQLException e)
{
throw new DBException(e, sql);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// update cache
if (key != null && id > 0)
{
idCache.put(key, id);
}
return id;
}
}

View File

@ -1,305 +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. *
*
* Copyright (C) 2005 Robert KLEIN. robeklein@hotmail.com
*
*****************************************************************************/
package org.adempiere.pipo;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.compiere.Adempiere;
import org.compiere.db.CConnection;
import org.compiere.model.X_AD_Package_Imp_Proc;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Trx;
/**
* IntPackIn Tool.
*
* @author: Robert KLEIN. robeklein@hotmail.com
*/
public class PackIn extends SvrProcess {
/** Logger */
private CLogger log = CLogger.getCLogger("PackIn");
//update system maintain dictionary, default to true
public static String m_UpdateMode = "true";
public static String m_Database = "Oracle";
public static String m_Package_Dir = null;
public int p_PackIn_ID = 0;
private Map<String,Integer> tableCache = new HashMap<String,Integer>();
private Map<String,Integer> columnCache = new HashMap<String,Integer>();
/**
* add to table id cache
* @param tableName
* @param tableId
*/
public void addTable(String tableName, int tableId) {
tableCache.put(tableName, tableId);
}
/**
* Find table id from cache
* @param tableName
* @return tableId
*/
public int getTableId(String tableName) {
if (tableCache.containsKey(tableName))
return tableCache.get(tableName).intValue();
else
return 0;
}
/**
* add to column id cache
* @param tableName
* @param columnName
* @param columnId
*/
public void addColumn(String tableName, String columnName, int columnId) {
columnCache.put(tableName+"."+columnName, columnId);
}
/**
* find column id from cache
* @param tableName
* @param columnName
* @return column id
*/
public int getColumnId(String tableName, String columnName) {
String key = tableName+"."+columnName;
if (columnCache.containsKey(key))
return columnCache.get(key).intValue();
else
return 0;
}
protected void prepare() {
p_PackIn_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) throws Exception {
if (log.isLoggable(Level.INFO)) log.info("importXML:" + fileName);
File in = new File(fileName);
if (!in.exists()) {
String msg = "File does not exist: " + fileName;
if (log.isLoggable(Level.INFO)) log.info("importXML:" + msg);
return msg;
}
try {
log.info("starting");
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
PackInHandler handler = new PackInHandler();
handler.set_TrxName(trxName);
handler.setCtx(ctx);
handler.setProcess(this);
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);
throw e;
}
}
/**
* Doit
*
* @return ""
*
*/
protected String doIt() throws Exception {
X_AD_Package_Imp_Proc adPackageImp = new X_AD_Package_Imp_Proc(getCtx(),
p_PackIn_ID, null);
// clear cache of previous runs
IDFinder.clearIDCache();
// Create Target directory if required
String packageDirectory = adPackageImp.getAD_Package_Dir();
if (packageDirectory == null || packageDirectory.trim().length() == 0) {
packageDirectory = Adempiere.getAdempiereHome();
}
File targetDir = new File( packageDirectory + File.separator
+ "packages");
if (!targetDir.exists()) {
boolean success = (new File(packageDirectory
+ File.separator + "packages")).mkdirs();
if (!success) {
log.info("Target directory creation failed");
}
}
// Unzip package
File zipFilepath = new File(adPackageImp.getAD_Package_Source());
if (log.isLoggable(Level.INFO)) log.info("zipFilepath->" + zipFilepath);
String PackageName = CreateZipFile.getParentDir(zipFilepath);
CreateZipFile.unpackFile(zipFilepath, targetDir);
String dict_file = packageDirectory + File.separator
+ "packages" + File.separator + PackageName + File.separator
+ "dict" + File.separator + "PackOut.xml";
if (log.isLoggable(Level.INFO)) log.info("dict file->" + dict_file);
PackIn packIn = new PackIn();
if (adPackageImp.isAD_Override_Dict() == true)
PackIn.m_UpdateMode = "true";
else
PackIn.m_UpdateMode = "false";
PackIn.m_Package_Dir = packageDirectory + File.separator
+ "packages" + File.separator + PackageName + File.separator;
if (DB.isOracle())
PackIn.m_Database = "Oracle";
else if (DB.isPostgreSQL())
PackIn.m_Database = "PostgreSQL";
// call XML Handler
String msg = packIn.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 msg;
} // doIt
/***************************************************************************
*
* @param args
* XMLfile host port db username password
*/
public static void main(String[] args) {
if (args.length < 1) {
System.out
.println("Please give the file name to read as first parameter.");
System.exit(1);
}
String file = args[0];
org.compiere.Adempiere.startup(true);
// globalqss - added argument 8 to generate system sequences
if (args.length > 8 && args[8].equals(Ini.P_ADEMPIERESYS)) {
System.out.println("**** WARNING: Working with system sequences "
+ Ini.P_ADEMPIERESYS + " ****");
Ini.setProperty(Ini.P_ADEMPIERESYS, true);
}
PackIn packIn = new PackIn();
// org.compiere.Compiere.startupEnvironment(true);
// Force connection if there are enough parameters. Else we work with
// Compiere.properties
if (args.length >= 6) {
// CConnection cc = CConnection.get("PostgreSQL", args[1],
// Integer.valueOf(args[2]).intValue(), args[5], args[3], args[4]);
CConnection cc = CConnection.get();
// System.out.println("DB Connect String1:"+cc.getDbName());
PackIn.m_Database = cc.getType();
DB.setDBTarget(cc);
}
// Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO,
// Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL
Level logLevel = Level.FINER;
switch (Integer.parseInt(args[6])) {
case 1:
logLevel = Level.OFF;
break;
case 2:
logLevel = Level.SEVERE;
break;
case 3:
logLevel = Level.WARNING;
break;
case 4:
logLevel = Level.INFO;
break;
case 5:
logLevel = Level.CONFIG;
break;
case 6:
logLevel = Level.FINE;
break;
case 7:
logLevel = Level.FINER;
break;
case 8:
logLevel = Level.FINEST;
break;
case 9:
logLevel = Level.ALL;
break;
}
CLogMgt.setLevel(logLevel);
CLogMgt.setLoggerLevel(logLevel, null);
if (args.length >= 8)
PackIn.m_UpdateMode = args[7];
String trxName = Trx.createTrxName("PackIn");
try {
packIn.importXML(file, Env.getCtx(), trxName);
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.commit(true);
} catch (Exception e) {
System.out.println("Import Failed: " + e.getLocalizedMessage());
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.rollback();
}
System.exit(0);
} // main
} // PackIn

View File

@ -1,856 +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. *
* *
* Copyright (C) 2004 Marco LOMBARDO. lombardo@mayking.com *
* Contributor: Robert KLEIN. robeklein@hotmail.com *
* Contributor: Tim Heath *
* Contributor: Low Heng Sin hengsin@avantz.com *
*****************************************************************************/
package org.adempiere.pipo;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Stack;
import java.util.logging.Level;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.adempiere.pipo.handler.AdElementHandler;
import org.adempiere.pipo.handler.CodeSnipitElementHandler;
import org.adempiere.pipo.handler.ColumnElementHandler;
import org.adempiere.pipo.handler.CommonTranslationHandler;
import org.adempiere.pipo.handler.DataElementHandler;
import org.adempiere.pipo.handler.DistFileElementHandler;
import org.adempiere.pipo.handler.DynValRuleElementHandler;
import org.adempiere.pipo.handler.EntityTypeElementHandler;
import org.adempiere.pipo.handler.FieldElementHandler;
import org.adempiere.pipo.handler.FieldGroupElementHandler;
import org.adempiere.pipo.handler.FormAccessElementHandler;
import org.adempiere.pipo.handler.FormElementHandler;
import org.adempiere.pipo.handler.ImpFormatElementHandler;
import org.adempiere.pipo.handler.ImpFormatRowElementHandler;
import org.adempiere.pipo.handler.MenuElementHandler;
import org.adempiere.pipo.handler.MessageElementHandler;
import org.adempiere.pipo.handler.ModelValidatorElementHandler;
import org.adempiere.pipo.handler.OrgRoleElementHandler;
import org.adempiere.pipo.handler.PreferenceElementHandler;
import org.adempiere.pipo.handler.PrintFormatElementHandler;
import org.adempiere.pipo.handler.PrintFormatItemElementHandler;
import org.adempiere.pipo.handler.PrintPaperElementHandler;
import org.adempiere.pipo.handler.ProcessAccessElementHandler;
import org.adempiere.pipo.handler.ProcessElementHandler;
import org.adempiere.pipo.handler.ProcessParaElementHandler;
import org.adempiere.pipo.handler.ReferenceElementHandler;
import org.adempiere.pipo.handler.ReferenceListElementHandler;
import org.adempiere.pipo.handler.ReferenceTableElementHandler;
import org.adempiere.pipo.handler.ReportViewColElementHandler;
import org.adempiere.pipo.handler.ReportViewElementHandler;
import org.adempiere.pipo.handler.RoleElementHandler;
import org.adempiere.pipo.handler.SQLStatementElementHandler;
import org.adempiere.pipo.handler.TabElementHandler;
import org.adempiere.pipo.handler.TableElementHandler;
import org.adempiere.pipo.handler.TaskAccessElementHandler;
import org.adempiere.pipo.handler.TaskElementHandler;
import org.adempiere.pipo.handler.UserRoleElementHandler;
import org.adempiere.pipo.handler.WindowAccessElementHandler;
import org.adempiere.pipo.handler.WindowElementHandler;
import org.adempiere.pipo.handler.WorkflowAccessElementHandler;
import org.adempiere.pipo.handler.WorkflowElementHandler;
import org.adempiere.pipo.handler.WorkflowNodeElementHandler;
import org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler;
import org.adempiere.pipo.handler.WorkflowNodeNextElementHandler;
import org.compiere.model.MSequence;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWorkflow;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
/**
* SAX Handler for parsing XML description of the GUI.
*
* @author Marco LOMBARDO, lombardo@mayking.com
* @author Robert KLEIN, robeklein@hotmail
*
* Contributor: William G. Heath - Import of workflows and dynamic validations
*/
public class PackInHandler extends DefaultHandler {
/**
* PackInHandler Handler
*/
public PackInHandler () {
setupHandlers();
} // PackInHandler
/** Set this if you want to update Dictionary */
private String m_UpdateMode = "true";
private String packageDirectory = null;
private String m_DatabaseType = "Oracle";
private int m_AD_Client_ID = 0;
private int AD_Package_Imp_ID=0;
private int AD_Package_Imp_Inst_ID=0;
private CLogger log = CLogger.getCLogger(PackInHandler.class);
private OutputStream fw_document = null;
private TransformerHandler logDocument = null;
private StreamResult streamResult_document = null;
private SAXTransformerFactory tf_document = null;
private Transformer serializer_document = null;
private int Start_Doc = 0;
private String logDate = null;
private String PK_Status = "Installing";
// transaction name
private String m_trxName = null;
private Properties m_ctx = null;
private Map<String, ElementHandler>handlers = null;
private List<Element> menus = new ArrayList<Element>();
private List<Element> workflow = new ArrayList<Element>();
private List<Element> nodes = new ArrayList<Element>();
private List<DeferEntry> defer = new ArrayList<DeferEntry>();
private Stack<Element> stack = new Stack<Element>();
private PackIn packIn;
private void init() throws SAXException {
if (packIn == null)
packIn = new PackIn();
packageDirectory = PackIn.m_Package_Dir;
m_UpdateMode = PackIn.m_UpdateMode;
m_DatabaseType = PackIn.m_Database;
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ");
SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
Date today = new Date();
String fileDate = formatter_file.format(today);
logDate = formatter_log.format(today);
String file_document = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml";
if (log.isLoggable(Level.INFO)) log.info("file_document="+file_document);
try {
fw_document = new FileOutputStream (file_document, false);
} catch (FileNotFoundException e1) {
log.warning ("Failed to create log file:"+e1);
}
streamResult_document = new StreamResult(fw_document);
tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try {
logDocument = tf_document.newTransformerHandler();
} catch (TransformerConfigurationException e2) {
if (log.isLoggable(Level.INFO)) log.info ("startElement:"+e2);
}
serializer_document = logDocument.getTransformer();
serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
serializer_document.setOutputProperty(OutputKeys.INDENT,"yes");
logDocument.setResult(streamResult_document);
logDocument.startDocument();
logDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
Properties tmp = new Properties();
if (m_ctx != null)
tmp.putAll(m_ctx);
else
tmp.putAll(Env.getCtx());
m_ctx = tmp;
if (m_trxName == null)
m_trxName = Trx.createTrxName("PackIn");
m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID");
Start_Doc=1;
}
private void setupHandlers() {
DataElementHandler dataHandler = new DataElementHandler();
handlers = new HashMap<String, ElementHandler>();
handlers.put("menu", new MenuElementHandler());
handlers.put("adempieredata", dataHandler);
handlers.put("data", dataHandler);
handlers.put("dtable", dataHandler);
handlers.put("drow", dataHandler);
handlers.put("dcolumn", dataHandler);
handlers.put("window", new WindowElementHandler());
handlers.put("windowaccess", new WindowAccessElementHandler());
handlers.put("preference", new PreferenceElementHandler());
handlers.put("tab", new TabElementHandler());
handlers.put("field", new FieldElementHandler());
handlers.put("process", new ProcessElementHandler());
handlers.put("processpara", new ProcessParaElementHandler());
handlers.put("processaccess", new ProcessAccessElementHandler());
handlers.put("message", new MessageElementHandler());
handlers.put("dynvalrule", new DynValRuleElementHandler());
handlers.put("workflow", new WorkflowElementHandler());
handlers.put("workflowNode", new WorkflowNodeElementHandler());
handlers.put("workflowNodeNext", new WorkflowNodeNextElementHandler());
handlers.put("workflowNodeNextCondition", new WorkflowNodeNextConditionElementHandler());
handlers.put("workflowaccess", new WorkflowAccessElementHandler());
handlers.put("table", new TableElementHandler());
handlers.put("column", new ColumnElementHandler());
handlers.put("role", new RoleElementHandler());
handlers.put("userrole", new UserRoleElementHandler());
handlers.put("orgrole", new OrgRoleElementHandler());
handlers.put("form", new FormElementHandler());
handlers.put("formaccess", new FormAccessElementHandler());
handlers.put("task", new TaskElementHandler());
handlers.put("taskaccess", new TaskAccessElementHandler());
handlers.put("impformat", new ImpFormatElementHandler());
handlers.put("impformatrow", new ImpFormatRowElementHandler());
handlers.put("codesnipit", new CodeSnipitElementHandler());
handlers.put("distfile", new DistFileElementHandler());
handlers.put("reportview", new ReportViewElementHandler());
handlers.put("reportviewcol", new ReportViewColElementHandler());
handlers.put("printformat", new PrintFormatElementHandler());
handlers.put("printformatitem", new PrintFormatItemElementHandler());
handlers.put("SQLStatement", new SQLStatementElementHandler());
handlers.put("reference", new ReferenceElementHandler());
handlers.put("referencelist", new ReferenceListElementHandler());
handlers.put("referencetable", new ReferenceTableElementHandler());
handlers.put("fieldgroup", new FieldGroupElementHandler());
handlers.put("element", new AdElementHandler());
handlers.put("trl", new CommonTranslationHandler());
handlers.put(ModelValidatorElementHandler.TAG_Name, new ModelValidatorElementHandler());
handlers.put(EntityTypeElementHandler.TAG_Name, new EntityTypeElementHandler());
handlers.put(PrintPaperElementHandler.TAG_Name, new PrintPaperElementHandler());
}
/**
* Receive notification of the start of an element.
*
* @param uri namespace
* @param localName simple name
* @param qName qualified name
* @param atts attributes
* @throws org.xml.sax.SAXException
*/
public void startElement (String uri, String localName, String qName, Attributes atts)
throws org.xml.sax.SAXException {
// Create the package log
if (Start_Doc==0){
init();
}
// Check namespace.
String elementValue = null;
if ("".equals (uri))
elementValue = qName;
else
elementValue = uri + localName;
// adempiereAD.
if (elementValue.equals("adempiereAD")) {
if (log.isLoggable(Level.INFO)) log.info("adempiereAD updateMode="+m_UpdateMode);
//Start package log
AttributesImpl attsOut = new AttributesImpl();
logDocument.startElement("","","adempiereDocument",attsOut);
logDocument.startElement("","","header",attsOut);
logDocument.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length());
logDocument.endElement("","","header");
logDocument.startElement("","","H3",attsOut);
logDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length());
logDocument.endElement("","","H3");
logDocument.startElement("","","packagename4log",attsOut);
logDocument.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length());
logDocument.endElement("","","packagename4log");
logDocument.startElement("","","H3",attsOut);
logDocument.characters(("Version:" ).toCharArray(),0,("Version:" ).length());
logDocument.endElement("","","H3");
logDocument.startElement("","","Version",attsOut);
logDocument.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length());
logDocument.endElement("","","Version");
logDocument.startElement("","","H3",attsOut);
logDocument.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length());
logDocument.endElement("","","H3");
logDocument.startElement("","","installDate",attsOut);
logDocument.characters(logDate.toCharArray(),0,logDate.length());
logDocument.endElement("","","installDate");
logDocument.startElement("","","H3",attsOut);
logDocument.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length());
logDocument.endElement("","","H3");
logDocument.startElement("","","CompVer",attsOut);
logDocument.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length());
logDocument.endElement("","","CompVer");
logDocument.startElement("","","H3",attsOut);
logDocument.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length());
logDocument.endElement("","","H3");
logDocument.startElement("","","DataBase",attsOut);
logDocument.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length());
logDocument.endElement("","","DataBase");
createImp_Sum_table ("AD_Package_Imp_Backup");
createImp_Sum_table ("AD_Package_Imp");
createImp_Sum_table ("AD_Package_Imp_Inst");
createImp_Sum_table ("AD_Package_Imp_Detail");
// Update Summary Package History Table
String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME ="
+ "'" + atts.getValue("Name")
+ "' AND PK_VERSION ='" + atts.getValue("Version") + "'";
int PK_preInstalled = DB.getSQLValue(m_trxName,sql2);
AD_Package_Imp_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null);
StringBuffer sqlB = new StringBuffer ("INSERT INTO AD_Package_Imp")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " )
.append( ", DESCRIPTION, NAME, CREATOR" )
.append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(m_ctx) )
.append( ", "+ Env.getAD_Org_ID(m_ctx) )
.append( ", "+ Env.getAD_User_ID(m_ctx) )
.append( ", "+ Env.getAD_User_ID(m_ctx) )
.append( ", " + AD_Package_Imp_ID )
.append( ", '" + atts.getValue("CompVer") )
.append( "', '" + atts.getValue("Version") )
.append( "', '" + atts.getValue("DataBase") )
.append( "', '" + atts.getValue("Description").replaceAll("'","''"))
.append( "', '" + atts.getValue("Name") )
.append( "', '" + atts.getValue("creator") )
.append( "', '" + atts.getValue("creatorcontact") )
.append( "', '" + atts.getValue("createddate") )
.append( "', '" + atts.getValue("updateddate") )
.append( "', '" + PK_Status )
.append( "')" );
Env.getAD_User_ID(m_ctx);
int no = DB.executeUpdate (sqlB.toString(), m_trxName);
if (no == -1)
log.info("Insert to Package import failed");
if ( PK_preInstalled == -1){
AD_Package_Imp_Inst_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null);
//Insert Package into package install log
sqlB = new StringBuffer ("INSERT INTO AD_Package_Imp_Inst")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " )
.append( ", DESCRIPTION, NAME, CREATOR" )
.append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(m_ctx) )
.append( ", "+ Env.getAD_Org_ID(m_ctx) )
.append( ", "+ Env.getAD_User_ID(m_ctx) )
.append( ", "+ Env.getAD_User_ID(m_ctx) )
.append( ", " + AD_Package_Imp_Inst_ID )
.append( ", '" + atts.getValue("CompVer") )
.append( "', '" + atts.getValue("Version") )
.append( "', '" + atts.getValue("DataBase") )
.append( "', '" + atts.getValue("Description").replaceAll("'","''"))
.append( "', '" + atts.getValue("Name") )
.append( "', '" + atts.getValue("creator") )
.append( "', '" + atts.getValue("creatorcontact") )
.append( "', '" + atts.getValue("createddate") )
.append( "', '" + atts.getValue("updateddate") )
.append( "', '" + PK_Status )
.append( "')" );
Env.getAD_User_ID(m_ctx);
no = DB.executeUpdate (sqlB.toString(), m_trxName);
if (no == -1)
log.info("Insert to Package List import failed");
}
else{
//Update package list with package status
AD_Package_Imp_Inst_ID = PK_preInstalled;
sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst "
+ "SET PK_Status = '" + PK_Status
+ "' WHERE AD_Package_Imp_Inst_ID = "+AD_Package_Imp_Inst_ID);
no = DB.executeUpdate (sqlB.toString(), m_trxName);
if (no == -1)
log.info("Update to package summary failed");
}
Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID);
Env.setContext(m_ctx, "UpdateMode", m_UpdateMode);
Env.setContext(m_ctx, "TrxName", m_trxName);
Env.setContext(m_ctx, "PackageDirectory", packageDirectory);
m_ctx.put("LogDocument", logDocument);
m_ctx.put("PackInProcess", packIn);
}
else if (elementValue.equals("menu")) {
//defer
Element e = new Element(uri, localName, qName, new AttributesImpl(atts));
if (stack.size() > 0)
e.parent = stack.peek();
stack.push(e);
menus.add(e);
}
else {
Element e = new Element(uri, localName, qName, new AttributesImpl(atts));
if (stack.size() > 0)
e.parent = stack.peek();
stack.push(e);
if (elementValue.equals("workflow"))
{
workflow.add(e);
}
if (elementValue.equals("workflowNode"))
{
nodes.add(e);
}
ElementHandler handler = handlers.get(elementValue);
if (handler != null)
handler.startElement(m_ctx, e);
if (e.defer) {
defer.add(new DeferEntry(e, true));
}
}
} // startElement
/**
* Check if Package History Table exists in database. If not create
*
* @param tablename
*
*/
public void createImp_Sum_table (String tablename){
// Check if table exists.
Connection conn = DB.getConnectionRW();
DatabaseMetaData dbm;
try {
dbm = conn.getMetaData();
// check if table is there
ResultSet tables = null;
if (m_DatabaseType.equals("Oracle"))
tables = dbm.getTables(null, null, tablename.toUpperCase(), null );
else if (m_DatabaseType.equals("PostgreSQL"))
tables = dbm.getTables(null, null, tablename.toLowerCase(), null );
if (tables.next()) {
log.info ("Table Found");
}
else {
if (tablename.equals("AD_Package_Imp")){
StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ")
.append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " )
.append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " )
.append( "AD_ORG_ID NUMBER(10) NOT NULL, " )
.append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " )
.append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "CREATEDBY NUMBER(10) NOT NULL, " )
.append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "UPDATEDBY NUMBER(10) NOT NULL, " )
.append( "NAME NVARCHAR2(60) NOT NULL, " )
.append( "PK_STATUS NVARCHAR2(22), " )
.append( "RELEASENO NVARCHAR2(20), " )
.append( "PK_VERSION NVARCHAR2(20), " )
.append( "VERSION NVARCHAR2(20), " )
.append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " )
.append( "EMAIL NVARCHAR2(60), " )
.append( "PROCESSED CHAR(1) DEFAULT 'N', " )
.append( "PROCESSING CHAR(1) DEFAULT 'N', " )
.append( "CREATOR VARCHAR2(60 ), " )
.append( "CREATORCONTACT VARCHAR2(255), " )
.append( " CREATEDDATE VARCHAR2(25), " )
.append( "UPDATEDDATE VARCHAR2(25), " )
.append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" );
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence (m_ctx, "AD_Package_Imp", m_trxName);
pstmt.close();
pstmt = null;
}
catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info ("createImp_Sum_table:"+e);
}
}
if (tablename.equals("AD_Package_Imp_Inst")){
StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ")
.append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " )
.append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " )
.append( "AD_ORG_ID NUMBER(10) NOT NULL, " )
.append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " )
.append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "CREATEDBY NUMBER(10) NOT NULL, " )
.append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "UPDATEDBY NUMBER(10) NOT NULL, " )
.append( "NAME NVARCHAR2(60) NOT NULL, " )
.append( "PK_STATUS NVARCHAR2(22), " )
.append( "RELEASENO NVARCHAR2(20), " )
.append( "PK_VERSION NVARCHAR2(20), " )
.append( "VERSION NVARCHAR2(20), " )
.append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " )
.append( "EMAIL NVARCHAR2(60), " )
.append( "PROCESSED CHAR(1) DEFAULT 'N', " )
.append( "PROCESSING CHAR(1) DEFAULT 'N', " )
.append( "CREATOR VARCHAR2(60 ), " )
.append( "CREATORCONTACT VARCHAR2(255), " )
.append( " CREATEDDATE VARCHAR2(25), " )
.append( "UPDATEDDATE VARCHAR2(25), " )
.append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" );
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Inst", m_trxName);
pstmt.close();
pstmt = null;
}
catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info ("createImp_Sum_table:"+e);
}
}
if (tablename.equals("AD_Package_Imp_Detail")){
StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ")
.append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " )
.append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " )
.append( "AD_ORG_ID NUMBER(10) NOT NULL, " )
.append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " )
.append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "CREATEDBY NUMBER(10) NOT NULL, " )
.append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "UPDATEDBY NUMBER(10) NOT NULL, " )
.append( "NAME NVARCHAR2(60), " )
.append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " )
.append( "AD_ORIGINAL_ID Number(10) NOT NULL, " )
.append( "AD_BACKUP_ID Number(10), " )
.append( "ACTION NVARCHAR2(20), " )
.append( "SUCCESS NVARCHAR2(20), " )
.append( "TYPE NVARCHAR2(60), " )
.append( "TABLENAME NVARCHAR2(60), " )
.append( "AD_TABLE_ID NUMBER(10), " )
.append( "UNINSTALL CHAR(1), " )
.append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" );
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Detail", m_trxName);
pstmt.close();
pstmt = null;
}
catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info ("createImp_Sum_table:"+e);
}
}
if (tablename.equals("AD_Package_Imp_Backup")){
StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ")
.append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " )
.append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " )
.append( "AD_ORG_ID NUMBER(10) NOT NULL, " )
.append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " )
.append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "CREATEDBY NUMBER(10) NOT NULL, " )
.append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " )
.append( "UPDATEDBY NUMBER(10) NOT NULL, " )
.append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " )
.append( "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " )
.append( "AD_TABLE_ID NUMBER(10), " )
.append( "AD_COLUMN_ID NUMBER(10), " )
.append( "AD_REFERENCE_ID NUMBER(10), " )
.append( "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " )
.append( "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " )
.append( "COLVALUE NVARCHAR2(2000), " )
.append( "UNINSTALL CHAR(1), " )
.append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" );
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Backup", m_trxName);
pstmt.close();
pstmt = null;
}
catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info ("createImp_Sum_table:"+e);
}
}
}
tables.close();
}
catch (SQLException e) {
if (log.isLoggable(Level.INFO)) log.info ("createImp_Sum_table:"+e);
}
finally
{
if( conn != null )
{
try
{
conn.close();
}
catch( Exception e ){}
}
}
}
/**
* Receive notification of the end of an element.
* @param uri namespace
* @param localName simple name
* @param qName qualified name
* @throws SAXException
*/
public void endElement (String uri, String localName, String qName) throws SAXException {
// Check namespace.
String elementValue = null;
if ("".equals (uri))
elementValue = qName;
else
elementValue = uri + localName;
if (elementValue.equals("adempiereAD")){
processDeferElements();
processMenuElements();
if (!PK_Status.equals("Completed with errors"))
PK_Status = "Completed successfully";
//Update package history log with package status
StringBuffer sqlB = new StringBuffer ("UPDATE AD_Package_Imp "
+ "SET PK_Status = '" + PK_Status
+ "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID);
int no = DB.executeUpdate (sqlB.toString(), m_trxName);
if (no == -1)
log.info("Update to package summary failed");
//Update package list with package status
sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst "
+ "SET PK_Status = '" + PK_Status
+ "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID);
no = DB.executeUpdate (sqlB.toString(), m_trxName);
if (no == -1)
log.info("Update to package list failed");
if(workflow.size() > 0)
{
for (Element e : workflow)
{
Attributes atts = e.attributes;
String workflowName = atts.getValue("Name");
MWorkflow wf = null;
int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName ,m_AD_Client_ID , m_trxName);
if(workflow_id > 0)
{
wf = new MWorkflow(m_ctx, workflow_id , m_trxName);
int node_id = 0;
String name = atts.getValue("ADWorkflowNodeNameID");
if (name != null && name.trim().length() > 0)
{
MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID);
for (MWFNode node : nodes)
{
if (node.getName().trim().equals(name.trim()))
{
node_id = node.getAD_WF_Node_ID();
wf.setAD_WF_Node_ID(node_id);
if (!wf.save())
System.out.println("Can not save Start Node "+ name +"to Workflow " + workflowName + " do not exist ");
break;
}
}
if(node_id == 0)
System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist ");
else
break;
}
}
}
}
if(nodes.size() > 0)
{
for (Element e : nodes)
{
Attributes atts = e.attributes;
String nodeName = atts.getValue("Name");
MWFNode node = null;
int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName, m_AD_Client_ID, false, m_trxName);
if(id > 0)
{
node = new MWFNode(m_ctx, id , m_trxName);
String workflowNodeName = atts.getValue("WorkflowNameID").trim();
if (workflowNodeName != null && workflowNodeName.trim().length() > 0)
{
int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name",workflowNodeName, m_AD_Client_ID, m_trxName);
if (workflow_id > 0)
{
node.setWorkflow_ID(workflow_id);
if(!node.save())
{
System.out.println("can not save Workflow " + workflowNodeName );
}
}
else
System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist ");
}
}
}
}
logDocument.endElement("","","adempiereDocument");
logDocument.endDocument();
try {
fw_document.close();
}
catch (Exception e)
{}
//reset
setupHandlers();
} else {
Element e = stack.pop();
if (e.defer) {
defer.add(new DeferEntry(e, false));
} else {
ElementHandler handler = handlers.get(elementValue);
if (handler != null)
handler.endElement(m_ctx, e);
if (e.defer || e.deferEnd)
defer.add(new DeferEntry(e, false));
else if (!e.skip) {
if (log.isLoggable(Level.INFO))
log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0));
}
}
}
} // endElement
private void processMenuElements() throws SAXException {
ElementHandler handler = handlers.get("menu");
if (menus.size() > 0 && handler != null) {
for (Element e : menus) {
handler.startElement(m_ctx, e);
handler.endElement(m_ctx, e);
}
}
}
private void processDeferElements() throws SAXException {
if (defer.isEmpty()) return;
do {
int startSize = defer.size();
List<DeferEntry> tmp = new ArrayList<DeferEntry>(defer);
defer.clear();
for (DeferEntry d : tmp) {
if (d.startElement) {
d.element.defer = false;
d.element.unresolved = "";
d.element.pass++;
} else {
if (d.element.deferEnd) {
d.element.deferEnd = false;
d.element.unresolved = "";
}
}
if (log.isLoggable(Level.INFO)) {
log.info("Processeing Defer Element: " + d.element.getElementValue() + " - "
+ d.element.attributes.getValue(0));
}
ElementHandler handler = handlers.get(d.element.getElementValue());
if (handler != null) {
if (d.startElement)
handler.startElement(m_ctx, d.element);
else
handler.endElement(m_ctx, d.element);
}
if (d.element.defer)
defer.add(d);
else if (!d.startElement) {
if (d.element.deferEnd)
defer.add(d);
else {
if (log.isLoggable(Level.INFO))
log.info("Imported Defer Element: " + d.element.getElementValue() + " - "
+ d.element.attributes.getValue(0));
}
}
}
int endSize = defer.size();
if (startSize == endSize) break;
} while (defer.size() > 0);
if (defer.size() > 0) {
int count = 0;
for (DeferEntry d : defer) {
if (!d.startElement) {
count++;
if (log.isLoggable(Level.SEVERE))
log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved);
}
}
throw new RuntimeException("Failed to resolve dependency for " + count + " elements.");
//System.err.println("Failed to resolve dependency for " + count + " elements.");
}
}
// globalqss - add support for trx in 3.1.2
public void set_TrxName(String trxName) {
m_trxName = trxName;
}
// globalqss - add support for trx in 3.1.2
public void setCtx(Properties ctx) {
m_ctx = ctx;
}
class DeferEntry {
Element element;
boolean startElement = false;
DeferEntry(Element e, boolean b) {
element = e;
startElement = b;
}
}
/**
* @param packIn
*/
public void setProcess(PackIn packIn) {
this.packIn = packIn;
}
} // PackInHandler

View File

@ -1,894 +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. *
* *
* Copyright (C) *
* 2004 Robert KLEIN. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
* Teo Sarca teo.sarca@arhipac.ro, SC ARHIPAC SERVICE SRL *
*****************************************************************************/
package org.adempiere.pipo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.adempiere.pipo.handler.AdElementHandler;
import org.adempiere.pipo.handler.CodeSnipitElementHandler;
import org.adempiere.pipo.handler.CommonTranslationHandler;
import org.adempiere.pipo.handler.DataElementHandler;
import org.adempiere.pipo.handler.DistFileElementHandler;
import org.adempiere.pipo.handler.DynValRuleElementHandler;
import org.adempiere.pipo.handler.EntityTypeElementHandler;
import org.adempiere.pipo.handler.FieldGroupElementHandler;
import org.adempiere.pipo.handler.FormElementHandler;
import org.adempiere.pipo.handler.ImpFormatElementHandler;
import org.adempiere.pipo.handler.MenuElementHandler;
import org.adempiere.pipo.handler.MessageElementHandler;
import org.adempiere.pipo.handler.ModelValidatorElementHandler;
import org.adempiere.pipo.handler.PrintFormatElementHandler;
import org.adempiere.pipo.handler.PrintPaperElementHandler;
import org.adempiere.pipo.handler.ProcessElementHandler;
import org.adempiere.pipo.handler.ReferenceElementHandler;
import org.adempiere.pipo.handler.ReportViewElementHandler;
import org.adempiere.pipo.handler.RoleElementHandler;
import org.adempiere.pipo.handler.SQLStatementElementHandler;
import org.adempiere.pipo.handler.TableElementHandler;
import org.adempiere.pipo.handler.TaskElementHandler;
import org.adempiere.pipo.handler.WindowElementHandler;
import org.adempiere.pipo.handler.WorkflowElementHandler;
import org.compiere.model.MSysConfig;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_FieldGroup;
import org.compiere.model.X_AD_Package_Exp;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_PrintPaper;
import org.compiere.model.X_AD_Reference;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* Convert AD to XML
*
* @author Robert Klein
* @version $Id: PackOut.java,v 1.0
*
* Contributor: William G. Heath - Export of workflows and dynamic validations
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1819315 ] PackOut: fix xml indentation not working
* <li>BF [ 1819319 ] PackOut: use just active AD_Package_Exp_Detail lines
* <li>--
* <li>FR [ 2847727 ] 2pack export all messages for a entity type functionality
* https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2847727&group_id=176962
*/
public class PackOut extends SvrProcess
{
/** Record ID */
private int p_PackOut_ID = 0;
private String PackOutVer = "005";
private String packagedir = null;
private String packagename = null;
private String includesdir = null;
public final static int MAX_OFFICIAL_ID = 999999;
private Properties localContext = null;
ProcessElementHandler processHandler = new ProcessElementHandler();
TaskElementHandler taskHandler = new TaskElementHandler();
FormElementHandler formHandler = new FormElementHandler();
WindowElementHandler windowHandler = new WindowElementHandler();
MenuElementHandler menuHandler = new MenuElementHandler();
ReportViewElementHandler reportViewHandler = new ReportViewElementHandler();
DataElementHandler dataHandler = new DataElementHandler();
TableElementHandler tableHandler = new TableElementHandler();
RoleElementHandler roleHandler = new RoleElementHandler();
SQLStatementElementHandler sqlHandler = new SQLStatementElementHandler();
ImpFormatElementHandler impFormtHandler = new ImpFormatElementHandler();
CodeSnipitElementHandler codeHandler = new CodeSnipitElementHandler();
WorkflowElementHandler workflowHandler = new WorkflowElementHandler();
DynValRuleElementHandler dynValRuleHandler = new DynValRuleElementHandler();
MessageElementHandler messageHandler = new MessageElementHandler();
PrintFormatElementHandler printFormatHandler = new PrintFormatElementHandler();
DistFileElementHandler distFileHandler = new DistFileElementHandler();
ReferenceElementHandler referenceHandler = new ReferenceElementHandler();
FieldGroupElementHandler fieldGroupHandler = new FieldGroupElementHandler();
AdElementHandler adElementHandler = new AdElementHandler();
CommonTranslationHandler translationHandler = new CommonTranslationHandler();
ModelValidatorElementHandler modelValidatorHandler = new ModelValidatorElementHandler();
EntityTypeElementHandler entitytypeHandler = new EntityTypeElementHandler();
PrintPaperElementHandler printPaperHandler = new PrintPaperElementHandler();
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
p_PackOut_ID = getRecord_ID();
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
}
} // prepare
/**
* Start the transformation to XML
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
initContext();
OutputStream packageDocStream = null;
OutputStream packOutDocStream = null;
if (log.isLoggable(Level.INFO)) log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID);
if (p_PackOut_ID == 0)
throw new IllegalArgumentException("No Record");
String sql1 = "SELECT * FROM AD_Package_Exp WHERE AD_Package_Exp_ID = "+p_PackOut_ID;
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement (sql1, get_TrxName());
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()){
//Create the package documentation
packagedir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory).trim();
if (!packagedir.endsWith("/") && !packagedir.endsWith("\\"))
packagedir += File.separator;
packagename = packagedir + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name);
includesdir = rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name) + File.separator +"**";
@SuppressWarnings("unused")
boolean success = (new File(packagename+File.separator+"doc"+File.separator)).mkdirs();
String file_document = packagename+File.separator+"doc"+File.separator+rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+"Doc.xml";
packageDocStream = new FileOutputStream (file_document, false);
StreamResult streamResult_document = new StreamResult(new OutputStreamWriter(packageDocStream,"ISO-8859-1"));
SAXTransformerFactory tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
tf_document.setAttribute("indent-number", new Integer(4));
TransformerHandler packageDocument = tf_document.newTransformerHandler();
Transformer serializer_document = packageDocument.getTransformer();
serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
serializer_document.setOutputProperty(OutputKeys.INDENT,"yes");
packageDocument.setResult(streamResult_document);
packageDocument.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.clear();
packageDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
packageDocument.startElement("","","adempiereDocument",atts);
packageDocument.startElement("","","header",atts);
packageDocument.characters((rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").toCharArray(),0,(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+" Package Description").length());
packageDocument.endElement("","","header");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","packagename",atts);
packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name).length());
packageDocument.endElement("","","packagename");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Creator:" ).toCharArray(),0,("Creator:").length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","creator",atts);
packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName).length());
packageDocument.endElement("","","creator");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Email Address:" ).toCharArray(),0,("Email Address:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","creatorcontact",atts);
packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail).length());
packageDocument.endElement("","","creatorcontact");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Created:" ).toCharArray(),0,("Created:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","createddate",atts);
packageDocument.characters(rs1.getString("Created").toString().toCharArray(),0,rs1.getString("Created").toString().length());
packageDocument.endElement("","","createddate");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Updated:" ).toCharArray(),0,("Updated:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","updateddate",atts);
packageDocument.characters(rs1.getString("Updated").toString().toCharArray(),0,rs1.getString("Updated".toString()).length());
packageDocument.endElement("","","updateddate");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Description:" ).toCharArray(),0,("Description:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","description",atts);
packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description).length());
packageDocument.endElement("","","description");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Instructions:" ).toCharArray(),0,("Instructions:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","instructions",atts);
packageDocument.characters(rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).toCharArray(),0,rs1.getString(X_AD_Package_Exp.COLUMNNAME_Instructions).length());
packageDocument.endElement("","","instructions");
packageDocument.startElement("","","H1",atts);
packageDocument.characters(("Files in Package:" ).toCharArray(),0,("Files in Package:" ).length());
packageDocument.endElement("","","H1");
packageDocument.startElement("","","file",atts);
packageDocument.characters(("File: PackOut.xml").toCharArray(),0,("File: PackOut.xml").length());
packageDocument.endElement("","","file");
packageDocument.startElement("","","filedirectory",atts);
packageDocument.characters("Directory: \\dict\\".toCharArray(),0,("Directory: \\dict\\").length());
packageDocument.endElement("","","filedirectory");
packageDocument.startElement("","","filenotes",atts);
packageDocument.characters("Notes: Contains all application/object settings for package".toCharArray(),0,"Notes: Contains all application/object settings for package".length());
packageDocument.endElement("","","filenotes");
success = (new File(packagename+File.separator+ "dict"+File.separator)).mkdirs();
String file_menu = packagename+File.separator+ "dict"+File.separator+"PackOut.xml";
packOutDocStream = new FileOutputStream (file_menu, false);
StreamResult streamResult_menu = new StreamResult(new OutputStreamWriter(packOutDocStream,"ISO-8859-1"));
SAXTransformerFactory tf_menu = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
tf_menu.setAttribute("indent-number", new Integer(4));
TransformerHandler packOutDocument = tf_menu.newTransformerHandler();
Transformer serializer_menu = packOutDocument.getTransformer();
serializer_menu.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
serializer_menu.setOutputProperty(OutputKeys.INDENT,"yes");
packOutDocument.setResult(streamResult_menu);
packOutDocument.startDocument();
atts.clear();
atts.addAttribute("","","Name","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name));
atts.addAttribute("","","Version","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_PK_Version));
atts.addAttribute("","","CompVer","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_ReleaseNo));
atts.addAttribute("","","DataBase","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_Version));
atts.addAttribute("","","Description","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_Description));
atts.addAttribute("","","creator","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_UserName));
atts.addAttribute("","","creatorcontact","CDATA",rs1.getString(X_AD_Package_Exp.COLUMNNAME_EMail));
atts.addAttribute("","","createddate","CDATA",rs1.getString("Created"));
atts.addAttribute("","","updateddate","CDATA",rs1.getString("Updated"));
atts.addAttribute("","","PackOutVer","CDATA",PackOutVer);
packOutDocument.startElement("","","adempiereAD",atts);
atts.clear();
final String sql = "SELECT * FROM AD_Package_Exp_Detail WHERE AD_Package_Exp_ID = "+p_PackOut_ID+" AND IsActive='Y' ORDER BY Line ASC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
rs = pstmt.executeQuery();
while (rs.next())
{
final String Type = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Type);
final int AD_EntityType_ID = rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID, AD_EntityType_ID);
//
if (log.isLoggable(Level.INFO)) log.info(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Line));
if (Type.compareTo("M") == 0){
createMenu(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID), packOutDocument );
}
else if (Type.compareTo("P") == 0)
createProcess ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID), packOutDocument );
else if (Type.compareTo("R") == 0)
createReportview ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID), packOutDocument );
else if (Type.compareTo("D") == 0)
createData ( rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), packOutDocument );
else if (Type.compareTo("T") == 0)
createTable (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID), packOutDocument);
else if (Type.compareTo("X") == 0)
createForm (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID), packOutDocument);
else if (Type.compareTo("W") == 0)
createWindow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID), packOutDocument);
else if (Type.compareTo("S") == 0)
createRoles (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID), packOutDocument);
else if (Type.compareTo("SQL") == 0)
createSQL (rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement), rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_DBType), packOutDocument);
else if (Type.compareTo("IMP") == 0)
createImpFormat (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID), packOutDocument);
else if (Type.compareTo("REF") == 0)
createReference (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID), packOutDocument);
else if (Type.compareTo("SNI") == 0)
createSnipit(
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_FileName),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo),
packOutDocument);
else if (Type.compareTo("F") == 0)
createWorkflow (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID), packOutDocument);
else if (Type.compareTo("V") == 0)
createDynamicRuleValidation(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID), packOutDocument);
else if (Type.compareTo("MSG") == 0)
createMessage(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID), packOutDocument);
else if (Type.compareTo("PFT") == 0)
createPrintFormat(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID), packOutDocument);
else if (Type.compareTo(X_AD_Package_Exp_Detail.TYPE_ModelValidator) == 0)
createModelValidator(rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ModelValidator_ID), packOutDocument);
else if (Type.compareTo(X_AD_Package_Exp_Detail.TYPE_EntityType) == 0)
createEntityType(AD_EntityType_ID, packOutDocument);
else if (Type.compareTo("C") == 0){
log.log(Level.INFO,"In PackOut.java handling Code or Other 2pack module creation");
String fullDirectory = rs1.getString(X_AD_Package_Exp.COLUMNNAME_File_Directory) + rs1.getString(X_AD_Package_Exp.COLUMNNAME_Name)+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
log.log(Level.INFO,"fullDirectory" + fullDirectory);
String targetDirectoryModified=null;
char fileseperator1 = '/';
char fileseperator2 = '\\';
//Correct package for proper file separator
if (File.separator.equals("/")){
targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1);
}
else
targetDirectoryModified = fullDirectory.replace(fileseperator1,fileseperator2);
String target_File = (targetDirectoryModified);
success = (new File(target_File).mkdirs());
fullDirectory = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
targetDirectoryModified=null;
//Correct package for proper file separator
if (File.separator.equals("/")){
targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1);
}
else
targetDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1);
copyCode(
targetDirectoryModified + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName),
target_File + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName));
atts.clear();
if(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory) != null){
fullDirectory = rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory);
String destinationDirectoryModified=null;
//Correct package for proper file separator
if (File.separator.equals("/")){
destinationDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1);
}
else
destinationDirectoryModified = fullDirectory.replace(fileseperator2,fileseperator1);
createDistributeFile(
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory),
rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo),
destinationDirectoryModified,
packOutDocument);
}
if(rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName) != null){
packageDocument.startElement("","","file",atts);
packageDocument.characters(("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).toCharArray(),0,("File: "+rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_FileName)).length());
packageDocument.endElement("","","file");
}
packageDocument.startElement("","","filedirectory",atts);
packageDocument.characters(
("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).toCharArray(),
0,
("Directory: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory)).length());
packageDocument.endElement("","","filedirectory");
packageDocument.startElement("","","filenotes",atts);
packageDocument.characters(
("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).toCharArray(),
0,
(("Notes: " + rs.getString(X_AD_Package_Exp_Detail.COLUMNNAME_Description)).length()));
packageDocument.endElement("","","filenotes");
}
}
//
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
atts.clear();
//no longer use
//packOutDocument.startElement("","","menuset",atts);
//packOutDocument.endElement("","","menuset");
packOutDocument.endElement("","","adempiereAD");
packOutDocument.endDocument();packageDocument.endElement("","","adempiereDocument");
packageDocument.endDocument();
//m_Exp.setProcessed(true);
//m_Exp.saveEx();
}
rs1.close();
pstmt1.close();
pstmt1 = null;
}
catch (Exception e)
{
log.log(Level.SEVERE,e.getLocalizedMessage(), e);
throw e;
}
finally
{
try
{
if (pstmt1 != null)
pstmt1.close ();
}
catch (Exception e)
{}
pstmt1 = null;
// Close streams - teo_sarca [ 1704762 ]
if (packageDocStream != null)
try {
packageDocStream.close();
} catch (Exception e) {}
if (packOutDocStream != null)
try {
packOutDocStream.close();
} catch (Exception e) {}
}
//create compressed packages
//set the files
File srcFolder = new File(packagedir);
File destZipFile = new File(packagename+".zip");
File destTarFile = new File(packagename+".tar");
File destGZipFile = new File(packagename+".tar.gz");
//delete the old packages if necessary
@SuppressWarnings("unused")
boolean success = destZipFile.delete();
success = destTarFile.delete();
success = destGZipFile.delete();
//create the compressed packages
CreateZipFile.zipFolder(srcFolder, destZipFile, includesdir);
CreateZipFile.tarFolder(srcFolder, destTarFile, includesdir);
CreateZipFile.gzipFile(destTarFile, destGZipFile);
//Clean .tar file up
success = destTarFile.delete();
return "Finish Process";
} // doIt
private void initContext() {
Properties tmp = new Properties();
if (getCtx() != null)
tmp.putAll(getCtx());
tmp.put("TrxName", get_TrxName());
tmp.put("PackOutProcess", this);
localContext = tmp;
}
private void copyCode (String sourceName, String copyName)
{
copyFile (sourceName, copyName );
}
/**
*
* @param AD_Menu_ID
* @param packOutDocument
* @throws Exception
*/
public void createMenu(int AD_Menu_ID, TransformerHandler packOutDocument) throws SAXException {
Env.setContext(getCtx(), "AD_Menu_ID", AD_Menu_ID);
menuHandler.create(getCtx(), packOutDocument);
getCtx().remove("AD_Menu_ID");
}
/**
*
* @param AD_PrintFormat_ID
* @param packOutDocument
* @throws Exception
*/
public void createPrintFormat (int AD_PrintFormat_ID, TransformerHandler packOutDocument) throws Exception
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID, AD_PrintFormat_ID);
printFormatHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID);
}
/**
*
* @param AD_Message_ID
* @param packOutDocument
* @throws Exception
*/
public void createMessage (int AD_Message_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID, AD_Message_ID);
messageHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID);
}
/**
*
* @param AD_Val_Rule_ID
* @param packOutDocument
* @throws Exception
*/
public void createDynamicRuleValidation (int AD_Val_Rule_ID,
TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID, AD_Val_Rule_ID);
dynValRuleHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID);
}
/**
*
* @param AD_Workflow_ID
* @param packOutDocument
* @throws SAXException
*/
public void createWorkflow (int AD_Workflow_ID, TransformerHandler packOutDocument)
throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID);
workflowHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID);
}
/**
*
* @param FileName
* @param Source_Directory
* @param ReleaseNo
* @param Target_Directory
* @param atts
* @param packOutDocument
* @throws SAXException
*/
public void createDistributeFile (String FileName, String Source_Directory, String ReleaseNo,String Target_Directory, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, FileName);
Env.setContext(getCtx(), "Source_Directory", Source_Directory);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, ReleaseNo);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, Target_Directory);
distFileHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
getCtx().remove("Source_Directory");
}
/**
*
* @param AD_Form_ID
* @param packOutDocument
* @throws SAXException
*/
public void createForm (int AD_Form_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), "AD_Form_ID", AD_Form_ID);
formHandler.create(getCtx(), packOutDocument);
getCtx().remove("AD_Form_ID");
}
/**
*
* @param AD_Task_ID
* @param packOutDocument
* @throws SAXException
*/
public void createTask (int AD_Task_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), "AD_Task_ID", AD_Task_ID);
taskHandler.create(getCtx(), packOutDocument);
getCtx().remove("AD_Task_ID");
}
/**
*
* @param AD_Process_ID
* @param packOutDocument
* @throws SAXException
*/
public void createProcess (int AD_Process_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), "AD_Process_ID", AD_Process_ID);
processHandler.create(getCtx(), packOutDocument);
getCtx().remove("AD_Process_ID");
}
/**
*
* @param AD_Window_ID
* @param packOutDocument
* @throws SAXException
*/
public void createWindow (int AD_Window_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), "AD_Window_ID", AD_Window_ID);
windowHandler.create(getCtx(), packOutDocument);
getCtx().remove("AD_Window_ID");
}
/**
*
* @param table_id
* @param sql
* @param packOutDocument
* @throws SAXException
*/
public void createData (int table_id, String sql, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, table_id);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, sql);
dataHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
}
/**
*
* @param Reportview_id
* @param packOutDocument
* @throws SAXException
*/
public void createReportview (int Reportview_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID, Reportview_id);
reportViewHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID);
}
/**
*
* @param SQLStatement
* @param DBType
* @param packOutDocument
* @throws SAXException
*/
public void createSQL (String SQLStatement, String DBType, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, SQLStatement);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_DBType, DBType);
sqlHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
}
/**
*
* @param FileDir
* @param FileName
* @param OldCode
* @param NewCode
* @param ReleaseNo
* @param atts
* @param packOutDocument
* @throws SAXException
*/
public void createSnipit (String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory, FileDir);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, FileName);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old, OldCode);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New, NewCode);
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, ReleaseNo);
codeHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
}
/**
*
* @param Role_id
* @param packOutDocument
* @throws SAXException
*/
public void createRoles (int Role_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID, Role_id);
roleHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
}
/**
*
* @param Reference_id
* @param packOutDocument
* @throws SAXException
*/
public void createReference (int Reference_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Reference.COLUMNNAME_AD_Reference_ID, Reference_id);
referenceHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Reference.COLUMNNAME_AD_Reference_ID);
}
/**
*
* @param import_id
* @param packOutDocument
* @throws SAXException
*/
public void createImpFormat (int import_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID, import_id);
impFormtHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID);
}
/**
*
* @param table_id
* @param packOutDocument
* @throws SAXException
*/
public void createTable (int table_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, table_id);
tableHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
}
/**
*
* @param FieldGroup_id
* @param packOutDocument
* @throws SAXException
*/
public void createFieldGroupElement (int FieldGroup_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, FieldGroup_id);
fieldGroupHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
}
/**
*
* @param Reference_id
* @param packOutDocument
* @throws SAXException
*/
public void createAdElement (int Ad_Element_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Element.COLUMNNAME_AD_Element_ID, Ad_Element_id);
adElementHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Element.COLUMNNAME_AD_Element_ID);
}
/**
*
* @param parentTableName
* @param parentID
* @param packOutDocument
* @throws SAXException
*/
public void createTranslations (String parentTableName, int parentID, TransformerHandler packOutDocument) throws SAXException
{
if (MSysConfig.getBooleanValue(MSysConfig.TWOPACK_HANDLE_TRANSLATIONS, false)) {
Env.setContext(getCtx(), CommonTranslationHandler.CONTEXT_KEY__PARENT_TABLE,
parentTableName);
Env.setContext(getCtx(), CommonTranslationHandler.CONTEXT_KEY__PARENT_RECORD_ID,
parentID);
translationHandler.create(getCtx(), packOutDocument);
getCtx().remove(CommonTranslationHandler.CONTEXT_KEY__PARENT_TABLE);
getCtx().remove(CommonTranslationHandler.CONTEXT_KEY__PARENT_RECORD_ID);
}
}
/**
*
* @param AD_ModelValidator_ID
* @param packOutDocument
* @throws Exception
*/
public void createModelValidator (int AD_ModelValidator_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ModelValidator_ID, AD_ModelValidator_ID);
modelValidatorHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ModelValidator_ID);
}
/**
*
* @param AD_EntityType_ID
* @param packOutDocument
* @throws Exception
*/
public void createEntityType (int AD_EntityType_ID, TransformerHandler packOutDocument) throws Exception
{
//Env.setContext(getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID, AD_EntityType_ID);
entitytypeHandler.create(getCtx(), packOutDocument);
//getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
}
public void createPrintPaper (int AD_PrintPaper_ID, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID, AD_PrintPaper_ID);
printPaperHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID);
}
public void copyFile (String sourceName, String copyName ) {
InputStream source; // Stream for reading from the source file.
OutputStream copy; // Stream for writing the copy.
boolean force; // This is set to true if the "-f" option
// is specified on the command line.
int byteCount; // Number of bytes copied from the source file.
force = true;
try {
source = new FileInputStream(sourceName);
}
catch (FileNotFoundException e) {
System.out.println("Can't find file \"" + sourceName + "\".");
return;
}
File file = new File(copyName);
if (file.exists() && force == false) {
System.out.println(
"Output file exists. Use the -f option to replace it.");
return;
}
try {
copy = new FileOutputStream(copyName, false);
}
catch (IOException e) {
System.out.println("Can't open output file \""
+ copyName + "\".");
return;
}
byteCount = 0;
try {
while (true) {
int data = source.read();
if (data < 0)
break;
copy.write(data);
byteCount++;
}
source.close();
copy.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());
}
}
@Override
public Properties getCtx() {
return localContext != null ? localContext : super.getCtx();
}
} // PackOut

View File

@ -1,546 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Carlos Ruiz - globalqss
*****************************************************************************/
package org.adempiere.pipo;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_ACCOUNT;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_AMOUNT;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_BUTTON;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_COLOR;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_DATE;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_DATETIME;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_INTEGER;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_LIST;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_LOCATION;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_LOCATOR;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_MEMO;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_NUMBER;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_PRODUCTATTRIBUTE;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_QUANTITY;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_SEARCH;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TABLE;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TABLEDIR;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TEXT;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO;
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.util.logging.Level;
import org.compiere.model.SystemIDs;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Reverse Package Install.
*
* @author Robert Klein
*
*/
public class PackRoll extends SvrProcess {
/** Package from Record */
private int m_AD_Package_Imp_ID = 0;
@SuppressWarnings("unused")
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);
@SuppressWarnings("unused")
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");
if (log.isLoggable(Level.INFO)) log.info(sql.toString());
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);
// 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 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
sqlC = new StringBuffer("UPDATE "
+ tableName + " SET " + columnName
+ " = SYSDATE 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");
// Update columns that are Strings adjusting
// for single quotes
if (v_AD_Reference_ID == 10
|| v_AD_Reference_ID == REFERENCE_DATATYPE_TEXT
|| v_AD_Reference_ID == REFERENCE_DATATYPE_MEMO
|| v_AD_Reference_ID == REFERENCE_DATATYPE_LIST
// Carlos Ruiz globalqss, special
// treatment for EntityType
// it's a Table reference but must
// be treated as String
|| (v_AD_Reference_ID == SystemIDs.REFERENCE_DATATYPE_TABLE && 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 == REFERENCE_DATATYPE_YES_NO
|| v_AD_Reference_ID == REFERENCE_DATATYPE_BUTTON) {
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 == SystemIDs.REFERENCE_DATATYPE_ID
|| v_AD_Reference_ID == REFERENCE_DATATYPE_TABLE
|| v_AD_Reference_ID == REFERENCE_DATATYPE_TABLEDIR
|| v_AD_Reference_ID == REFERENCE_DATATYPE_LOCATION
|| v_AD_Reference_ID == REFERENCE_DATATYPE_ACCOUNT
|| v_AD_Reference_ID == REFERENCE_DATATYPE_COLOR
|| v_AD_Reference_ID == REFERENCE_DATATYPE_SEARCH
|| v_AD_Reference_ID == REFERENCE_DATATYPE_LOCATOR
|| v_AD_Reference_ID == REFERENCE_DATATYPE_PRODUCTATTRIBUTE)
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 == REFERENCE_DATATYPE_INTEGER
|| v_AD_Reference_ID == REFERENCE_DATATYPE_AMOUNT
|| v_AD_Reference_ID == REFERENCE_DATATYPE_NUMBER
|| v_AD_Reference_ID == REFERENCE_DATATYPE_QUANTITY)
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 == REFERENCE_DATATYPE_DATE
|| v_AD_Reference_ID == REFERENCE_DATATYPE_DATETIME)
// 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(), get_TrxName());
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

View File

@ -1,36 +0,0 @@
package org.adempiere.pipo;
import org.compiere.model.PO;
import org.xml.sax.Attributes;
public class PoFiller{
PO po = null;
Attributes atts = null;
public PoFiller(PO po, Attributes atts){
this.po = po;
this.atts = atts;
}
public void setString(String columnName){
String value = atts.getValue(columnName);
value = "".equals(value) ? null : value;
po.set_ValueOfColumn(columnName, value);
}
public void setBoolean(String columnName){
String value = atts.getValue(columnName);
boolean bool = "true".equals(value) ? true : false;
po.set_ValueOfColumn(columnName, bool);
}
}

View File

@ -1,26 +0,0 @@
package org.adempiere.pipo.exception;
public class DatabaseAccessException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = -8834711100842625706L;
public DatabaseAccessException() {
super();
}
public DatabaseAccessException(String message, Throwable cause) {
super(message, cause);
}
public DatabaseAccessException(String message) {
super(message);
}
public DatabaseAccessException(Throwable cause) {
super(cause);
}
}

View File

@ -1,24 +0,0 @@
/**
*
*/
package org.adempiere.pipo.exception;
import org.adempiere.exceptions.AdempiereException;
/**
* Throws when IDFinder methods have found more then one id (result) for search criteria
* @author Teo Sarca, teo.sarca@gmail.com
*
*/
public class NonUniqueIDLookupException extends AdempiereException
{
/**
*
*/
private static final long serialVersionUID = 3523717056935105698L;
public NonUniqueIDLookupException(String what)
{
super("Non Unique ID Lookup found for "+what);
}
}

View File

@ -1,25 +0,0 @@
package org.adempiere.pipo.exception;
public class POSaveFailedException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 8325708851137221459L;
public POSaveFailedException() {
super();
}
public POSaveFailedException(String message, Throwable cause) {
super(message, cause);
}
public POSaveFailedException(String message) {
super(message);
}
public POSaveFailedException(Throwable cause) {
super(cause);
}
}

View File

@ -1,170 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.PoFiller;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Element;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class AdElementHandler extends AbstractElementHandler {
private List<Integer> processedElements = new ArrayList<Integer>();
private final String AD_ELEMENT = "AD_Element";
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ColumnName"));
String entitytype = atts.getValue("EntityType");
String ColumnName = atts.getValue("ColumnName");
if (isProcessElement(ctx, entitytype)) {
int id = get_IDWithColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
X_AD_Element m_AdElement = new X_AD_Element(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Element_ID") != null && Integer.parseInt(atts.getValue("AD_Element_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_AdElement.setAD_Element_ID(Integer.parseInt(atts.getValue("AD_Element_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, AD_ELEMENT, m_AdElement);
Object_Status = "Update";
if (processedElements.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
PoFiller pf = new PoFiller(m_AdElement, atts);
pf.setBoolean("IsActive");
pf.setString(X_AD_Element.COLUMNNAME_ColumnName);
pf.setString(X_AD_Element.COLUMNNAME_Description);
pf.setString(X_AD_Element.COLUMNNAME_EntityType);
pf.setString(X_AD_Element.COLUMNNAME_Help);
pf.setString(X_AD_Element.COLUMNNAME_Name);
pf.setString(X_AD_Element.COLUMNNAME_PrintName);
pf.setString(X_AD_Element.COLUMNNAME_PO_Description);
pf.setString(X_AD_Element.COLUMNNAME_PO_Name);
pf.setString(X_AD_Element.COLUMNNAME_PO_Help);
pf.setString(X_AD_Element.COLUMNNAME_PO_PrintName);
if (m_AdElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_AdElement.getName(), "Element",
m_AdElement.get_ID(), AD_Backup_ID, Object_Status,
AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table",
"TableName", AD_ELEMENT));
element.recordId = m_AdElement.getAD_Element_ID();
processedElements.add(m_AdElement.getAD_Element_ID());
} else {
record_log(ctx, 0, m_AdElement.getName(), "Element",
m_AdElement.get_ID(), AD_Backup_ID, Object_Status,
AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table",
"TableName", AD_ELEMENT));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int adElement_id = Env.getContextAsInt(ctx,
X_AD_Element.COLUMNNAME_AD_Element_ID);
if (processedElements.contains(adElement_id))
return;
processedElements.add(adElement_id);
X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null);
AttributesImpl atts = new AttributesImpl();
createAdElementBinding(atts, m_AdElement);
document.startElement("", "", "element", atts);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
packOut.createTranslations(X_AD_Element.Table_Name,
m_AdElement.get_ID(), document);
document.endElement("", "", "element");
}
private AttributesImpl createAdElementBinding(AttributesImpl atts,
X_AD_Element m_AdElement) {
AttributeFiller filler = new AttributeFiller(atts, m_AdElement);
if (m_AdElement.getAD_Element_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add(X_AD_Element.COLUMNNAME_AD_Element_ID);
filler.add("IsActive");
filler.add(X_AD_Element.COLUMNNAME_ColumnName);
filler.add(X_AD_Element.COLUMNNAME_Description);
filler.add(X_AD_Element.COLUMNNAME_EntityType);
filler.add(X_AD_Element.COLUMNNAME_Help);
filler.add(X_AD_Element.COLUMNNAME_Name);
filler.add(X_AD_Element.COLUMNNAME_PrintName);
filler.add(X_AD_Element.COLUMNNAME_PO_Description);
filler.add(X_AD_Element.COLUMNNAME_PO_Name);
filler.add(X_AD_Element.COLUMNNAME_PO_Help);
filler.add(X_AD_Element.COLUMNNAME_PO_PrintName);
return atts;
}
}

View File

@ -1,244 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.Adempiere;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class CodeSnipitElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
String Object_Status = null;
log.info(elementValue);
Object_Status = "Update";
Attributes atts = element.attributes;
String releaseNumber = atts.getValue("ReleaseNo");
//Check Release Number
if(Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){
String sourceName = atts.getValue("filename");
String targetDirectory = atts.getValue("filedir");
String oldCode = atts.getValue("oldcode");
String newCode = atts.getValue("newcode");
int idDetail=0;
InputStream source; // Stream for reading from the source file.
OutputStream copy; // Stream for writing the copy.
@SuppressWarnings("unused")
File currentDirectory = new File(".");
String packagePath=null;
String sourcePath=null;
//get adempiere-all directory
try {
packagePath = getPackageDirectory(ctx);
File parentDirectory = new File(packagePath);
while (!parentDirectory.getName().equals("packages")){
parentDirectory = parentDirectory.getParentFile();
}
parentDirectory = parentDirectory.getParentFile();
sourcePath = parentDirectory.getCanonicalPath();
} catch (IOException e1) {
System.out.println("Can't find adempiere-all directory.");
}
// Create backup directory if required
File backupDir = new File(packagePath+File.separator+"backup"+File.separator);
if (!backupDir.exists()){
boolean success = (new File(packagePath+File.separator+"backup"+File.separator)).mkdirs();
if (!success) {
log.info("Backup directory creation failed");
}
}
//Correct target directory for proper file separator
String fullDirectory = sourcePath+targetDirectory;
String targetDirectoryModified=null;
String fileDate = null;
char slash1 = '\\';
char slash2 = '/';
if (File.separator.equals("/"))
targetDirectoryModified = fullDirectory.replace(slash1,slash2);
else
targetDirectoryModified = fullDirectory.replace(slash2,slash1);
File file = new File(targetDirectoryModified+sourceName);
if (log.isLoggable(Level.INFO)) log.info(targetDirectoryModified+sourceName);
//TODO: derived force from user parameter
boolean force = true;
// check to see if overwrites are allowed
if (file.exists() && force == false) {
System.out.println(
"Output file exists. Use the -f option to replace it.");
return;
}
//backup file to package directory
else if (file.exists() && force == true) {
Object_Status = "Update";
if (log.isLoggable(Level.INFO)) log.info("Target Backup:"+targetDirectoryModified+sourceName);
source = OpenInputfile(targetDirectoryModified+sourceName);
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ");
Date today = new Date();
fileDate = formatter_file.format(today);
copy = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName);
if (log.isLoggable(Level.INFO)) log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName);
copyFile (source,copy);
if (log.isLoggable(Level.INFO)) log.info("Backup Complete");
}
int success = readReplace(targetDirectoryModified+sourceName, oldCode, newCode);
// Record in log
int idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
if (success != -1){
try {
idDetail = record_log (ctx, 1, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0);
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info ("setfile:"+e);
}
}
else{
try {
idDetail = record_log (ctx, 0, sourceName,"codesnipit", 0,0, Object_Status,sourceName,0);
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info ("setfile:"+e);
}
}
//Record in transaction file
StringBuffer sqlB = new StringBuffer ("INSERT INTO AD_Package_Imp_Backup")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
.append( " AD_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + idBackup )
.append( ", " + idDetail )
.append( ", " + getPackageImpId(ctx) )
.append( ", '" + targetDirectoryModified+sourceName )
.append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName )
.append( "')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to import backup failed");
}
}
/**
* Find and replace code
*
* @param file name
* @param old string
* @param new string
*
*/
public static int readReplace(String fname, String oldPattern, String replPattern){
String line;
StringBuffer sb = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(fname);
BufferedReader reader=new BufferedReader ( new InputStreamReader(fis));
while((line = reader.readLine()) != null) {
line = line.replaceAll(oldPattern, replPattern);
System.err.println(line);
sb.append(line+"\n");
}
reader.close();
BufferedWriter out=new BufferedWriter ( new FileWriter(fname));
out.write(sb.toString());
out.close();
}
catch (Throwable e) {
System.err.println("error replacing codesnipit "+e);
return -1;
}
return 0;
}
public void endElement(Properties ctx, Element element)
throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
String FileDir = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
String OldCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old);
String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl();
createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo);
document.startElement("","","codesnipit",atts);
document.endElement("","","codesnipit");
}
private AttributesImpl createSnipitBinding( AttributesImpl atts, String FileDir, String FileName, String OldCode, String NewCode, String ReleaseNo)
{
atts.clear();
atts.addAttribute("","","filedir","CDATA",FileDir);
atts.addAttribute("","","filename","CDATA",FileName);
String preOldCode = OldCode.toString();
String preNewCode = NewCode.toString();
String modOldCode = preOldCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.")
.replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)")
.replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+")
.replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|");
String modNewCode = preNewCode.replaceAll("\\$","\\\\\\$").replaceAll("\\.","\\\\.")
.replaceAll("\\^","\\\\^").replaceAll("\\(","\\\\(").replaceAll("\\)","\\\\)")
.replaceAll("\\[","\\\\[").replaceAll("\\/","\\\\/").replaceAll("\\+","\\\\+")
.replaceAll("\\*","\\\\*").replaceAll("\\|","\\\\|");
atts.addAttribute("","","oldcode","CDATA",modOldCode);
atts.addAttribute("","","newcode","CDATA",modNewCode);
atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo);
return atts;
}
}

View File

@ -1,527 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackIn;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MColumn;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_Column;
import org.compiere.model.X_AD_Element;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ColumnElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
PackIn packIn = (PackIn)ctx.get("PackInProcess");
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ColumnName"));
int success = 0;
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("table") &&
element.parent.defer) {
element.defer = true;
return;
}
String columnName = atts.getValue("ColumnName");
String tableName = atts.getValue("ADTableNameID");
int tableid = 0;
if (element.parent != null && element.parent.getElementValue().equals("table") &&
element.parent.recordId > 0) {
tableid = element.parent.recordId;
} else {
tableid = packIn.getTableId(tableName);
}
if (tableid <= 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
packIn.addTable(tableName, tableid);
}
int id = packIn.getColumnId(tableName, columnName);
if (id <= 0) {
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName",
columnName, "AD_Table", tableid);
if (id > 0) {
packIn.addColumn(tableName, columnName, id);
}
}
MColumn m_Column = new MColumn(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Column_ID") != null && Integer.parseInt(atts.getValue("AD_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Column.setAD_Column_ID(Integer.parseInt(atts.getValue("AD_Column_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Column", m_Column);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Column.setColumnName(columnName);
// Process
String processName = atts.getValue("ADProcessNameID");
int AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Value", processName);
if (AD_Process_ID <= 0 /** TODO PackOut version check 005 */)
{
AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Name", processName);
}
m_Column.setAD_Process_ID(AD_Process_ID);
//
String Name = atts.getValue("ADReferenceNameID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Column.setAD_Reference_ID(id);
// log.info("Column ID ->"+id);
Name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
m_Column.setAD_Table_ID(id);
Name = atts.getValue("ADValRuleNameID");
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
m_Column.setAD_Val_Rule_ID(id);
Name = atts.getValue("ADReferenceNameValueID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Column.setAD_Reference_Value_ID(id);
m_Column.setCallout(getStringValue(atts, "Callout"));
m_Column.setColumnSQL(getStringValue(atts, "ColumnSQL"));
m_Column.setColumnName(atts.getValue("ColumnName"));
m_Column.setDefaultValue(getStringValue(atts, "DefaultValue"));
m_Column.setDescription(getStringValue(atts, "Description"));
m_Column.setEntityType(atts.getValue("EntityType"));
if (Integer.parseInt(atts.getValue("FieldLength")) > 0)
m_Column.setFieldLength(Integer.parseInt(atts
.getValue("FieldLength")));
m_Column.setHelp(getStringValue(atts, "Help"));
m_Column.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Column.setIsAlwaysUpdateable((Boolean.valueOf(atts
.getValue("isAlwaysUpdateable")).booleanValue()));
// m_Column.setIsEncrypted(atts.getValue("isEncrypted"));
m_Column.setIsIdentifier((Boolean.valueOf(atts
.getValue("isIdentifier")).booleanValue()));
m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey"))
.booleanValue()));
m_Column.setIsMandatory((Boolean.valueOf(atts
.getValue("isMandatory")).booleanValue()));
m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent"))
.booleanValue()));
m_Column.setIsSelectionColumn((Boolean.valueOf(atts
.getValue("isSelectionColumn")).booleanValue()));
m_Column.setIsSyncDatabase(atts.getValue("getIsSyncDatabase"));
m_Column.setIsTranslated((Boolean.valueOf(atts
.getValue("isTranslated")).booleanValue()));
m_Column.setIsUpdateable((Boolean.valueOf(atts
.getValue("isUpdateable")).booleanValue()));
m_Column.setName(atts.getValue("Name"));
m_Column.setReadOnlyLogic(getStringValue(atts, "ReadOnlyLogic"));
if (Integer.parseInt(atts.getValue("SeqNo")) > 0)
m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Column.setVFormat(getStringValue(atts, "VFormat"));
if (getStringValue(atts, "ValueMax") != null)
m_Column.setValueMax(atts.getValue("ValueMax"));
if (getStringValue(atts, "ValueMin") != null)
m_Column.setValueMin(atts.getValue("ValueMin"));
if (getStringValue(atts, "Version") != null)
m_Column.setVersion(new BigDecimal(atts.getValue("Version")));
//m_Column.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
// Setup Element.
id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", m_Column
.getColumnName());
X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
String Object_Status_col = Object_Status;
if (adElement.getAD_Element_ID() == 0) {
// Object_Status = "New";
adElement.setColumnName(m_Column.getColumnName());
adElement.setEntityType(m_Column.getEntityType());
adElement.setPrintName(m_Column.getColumnName());
adElement.setName(m_Column.getColumnName());
if (adElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
} else {
record_log(ctx, 0, m_Column.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
}
}
Object_Status = Object_Status_col;
m_Column.setAD_Element_ID(adElement.getAD_Element_ID());
boolean recreateColumn = (m_Column.is_new()
|| m_Column.is_ValueChanged("AD_Reference_ID")
|| m_Column.is_ValueChanged("FieldLength")
|| m_Column.is_ValueChanged("ColumnName") || m_Column
.is_ValueChanged("IsMandatory"));
//ignore fieldlength change for clob and lob
if (!m_Column.is_ValueChanged("AD_Reference_ID") && m_Column.is_ValueChanged("FieldLength")) {
if (DisplayType.isLOB(m_Column.getAD_Reference_ID())) {
recreateColumn = false;
}
}
// changed default ??
// m_Column.is_ValueChanged("DefaultValue") doesn't work well with
// nulls
if (!recreateColumn) {
String oldDefault = (String) m_Column
.get_ValueOld("DefaultValue");
String newDefault = m_Column.getDefaultValue();
if (oldDefault != null && oldDefault.length() == 0)
oldDefault = null;
if (newDefault != null && newDefault.length() == 0)
newDefault = null;
if ((oldDefault == null && newDefault != null)
|| (oldDefault != null && newDefault == null)) {
recreateColumn = true;
} else if (oldDefault != null && newDefault != null) {
if (!oldDefault.equals(newDefault))
recreateColumn = true;
}
}
// Don't create database column for virtual columns
boolean syncDatabase = "Y".equalsIgnoreCase(atts.getValue("getIsSyncDatabase"));
if (recreateColumn) {
if (m_Column.isVirtualColumn() || !syncDatabase)
recreateColumn = false;
}
if (m_Column.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Column", m_Column
.get_ID(), AD_Backup_ID, Object_Status, "AD_Column",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Column"));
element.recordId = m_Column.getAD_Column_ID();
} else {
record_log(ctx, 0, m_Column.getName(), "Column", m_Column
.get_ID(), AD_Backup_ID, Object_Status, "AD_Column",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Column"));
throw new POSaveFailedException("Failed to import column.");
}
if (recreateColumn || syncDatabase) {
MTable table = new MTable(ctx, m_Column.getAD_Table_ID(), getTrxName(ctx));
if (!table.isView() && !m_Column.isVirtualColumn()) {
success = createColumn(ctx, table, m_Column, recreateColumn);
if (success == 1) {
record_log(ctx, 1, m_Column.getColumnName(), "dbColumn",
m_Column.get_ID(), 0, Object_Status, atts.getValue(
"ADTableNameID").toUpperCase(),
get_IDWithColumn(ctx, "AD_Table", "TableName", atts
.getValue("ADTableNameID").toUpperCase()));
} else {
record_log(ctx, 0, m_Column.getColumnName(), "dbColumn",
m_Column.get_ID(), 0, Object_Status, atts.getValue(
"ADTableNameID").toUpperCase(),
get_IDWithColumn(ctx, "AD_Table", "TableName", atts
.getValue("ADTableNameID").toUpperCase()));
throw new DatabaseAccessException("Failed to create column or related constraint for " + m_Column.getColumnName());
}
}
}
} else {
element.skip = true;
}
}
/**
* Check if column exists in database and modify. If not create column.
*
* @param tablename
* @param columnname
* @param v_AD_Reference_ID
* @param v_FieldLength
* @param v_DefaultValue
* @param v_IsMandatory
*
*/
private int createColumn(Properties ctx, MTable table, MColumn column, boolean doAlter) {
int no = 0;
String sql = null;
ResultSet rst = null;
ResultSet rsc = null;
Connection conn = null;
Trx trx = Trx.get(getTrxName(ctx), true);
if (!trx.commit())
return 0;
try {
// Find Column in Database
conn = trx.getConnection();
DatabaseMetaData md = conn.getMetaData();
String catalog = DB.getDatabase().getCatalog();
String schema = DB.getDatabase().getSchema();
String tableName = table.getTableName();
String columnName = column.getColumnName();
if (md.storesUpperCaseIdentifiers()) {
tableName = tableName.toUpperCase();
columnName = columnName.toUpperCase();
} else if (md.storesLowerCaseIdentifiers()) {
tableName = tableName.toLowerCase();
columnName = columnName.toLowerCase();
}
rst = md.getTables(catalog, schema, tableName,
new String[] { "TABLE" });
if (!rst.next()) {
// table doesn't exist
sql = table.getSQLCreate();
} else {
//
rsc = md.getColumns(catalog, schema, tableName, columnName);
if (rsc.next()) {
if (doAlter) {
// update existing column
boolean notNull = DatabaseMetaData.columnNoNulls == rsc
.getInt("NULLABLE");
sql = column.getSQLModify(table,
column.isMandatory() != notNull);
}
} else {
// No existing column
sql = column.getSQLAdd(table);
}
rsc.close();
rsc = null;
}
rst.close();
rst = null;
//execute modify or add if needed
if (sql != null && sql.trim().length() > 0) {
log.info(sql);
if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) {
no = DB.executeUpdate(sql, false, trx.getTrxName());
if (no == -1)
return 0;
} else {
String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR);
for (int i = 0; i < statements.length; i++) {
int count = DB.executeUpdate(statements[i], false,
trx.getTrxName());
if (count == -1) {
return 0;
}
no += count;
}
}
}
trx.commit(true);
} catch (SQLException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (rsc != null) {
try {
rsc.close();
} catch (SQLException e1) {
}
rsc = null;
}
if (rst != null) {
try {
rst.close();
} catch (SQLException e1) {
}
rst = null;
}
trx.rollback();
return 0;
}
return 1;
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Column_ID = Env.getContextAsInt(ctx,
X_AD_Column.COLUMNNAME_AD_Column_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID,
getTrxName(ctx));
createColumnBinding(atts, m_Column);
document.startElement("", "", "column", atts);
document.endElement("", "", "column");
}
private AttributesImpl createColumnBinding(AttributesImpl atts,
X_AD_Column m_Column) {
String sql = null;
String name = null;
atts.clear();
if (m_Column.getAD_Column_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Column_ID", "CDATA", Integer.toString(m_Column.getAD_Column_ID()));
if (m_Column.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_Column.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
//
if (m_Column.getAD_Process_ID() > 0)
{
sql = "SELECT Value FROM AD_Process WHERE AD_Process_ID=?";
name = DB.getSQLValueStringEx(null, sql, m_Column.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessNameID", "CDATA", name);
}
else
{
atts.addAttribute("", "", "ADProcessNameID", "CDATA", "");
}
// Element - this info is not needed since we search for element based on ColumnName
if (m_Column.getAD_Element_ID() > 0)
{
sql = "SELECT ColumnName FROM AD_Element WHERE AD_Element_ID=?";
name = DB.getSQLValueStringEx(null, sql, m_Column.getAD_Element_ID());
atts.addAttribute("", "", "ADElementNameID", "CDATA", name);
}
else
{
atts.addAttribute("", "", "ADElementNameID", "CDATA", "");
}
//
if (m_Column.getAD_Reference_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Column
.getAD_Reference_ID());
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
if (m_Column.getAD_Reference_Value_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Column
.getAD_Reference_Value_ID());
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", "");
if (m_Column.getAD_Table_ID() > 0) {
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, m_Column.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (m_Column.getAD_Val_Rule_ID() > 0) {
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
name = DB
.getSQLValueString(null, sql, m_Column.getAD_Val_Rule_ID());
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
atts.addAttribute("", "", "Callout", "CDATA",
(m_Column.getCallout() != null ? m_Column.getCallout() : ""));
atts.addAttribute("", "", "ColumnSQL", "CDATA", (m_Column
.getColumnSQL() != null ? m_Column.getColumnSQL() : ""));
atts.addAttribute("", "", "ColumnName", "CDATA", (m_Column
.getColumnName() != null ? m_Column.getColumnName() : ""));
atts.addAttribute("", "", "DefaultValue", "CDATA", (m_Column
.getDefaultValue() != null ? m_Column.getDefaultValue() : ""));
atts.addAttribute("", "", "Description", "CDATA", (m_Column
.getDescription() != null ? m_Column.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Column
.getEntityType() != null ? m_Column.getEntityType() : ""));
atts.addAttribute("", "", "FieldLength", "CDATA", (m_Column
.getFieldLength() > 0 ? "" + m_Column.getFieldLength() : "0"));
atts.addAttribute("", "", "Help", "CDATA",
(m_Column.getHelp() != null ? m_Column.getHelp() : ""));
atts.addAttribute("", "", "isAlwaysUpdateable", "CDATA", (m_Column
.isAlwaysUpdateable() == true ? "true" : "false"));
// atts.addAttribute("","","isEncrypted","CDATA",(m_Column.getIsEncrypted()==
// true ? "true":"false"));
atts.addAttribute("", "", "isIdentifier", "CDATA", (m_Column
.isIdentifier() == true ? "true" : "false"));
atts.addAttribute("", "", "isKey", "CDATA",
(m_Column.isKey() == true ? "true" : "false"));
atts.addAttribute("", "", "isMandatory", "CDATA", (m_Column
.isMandatory() == true ? "true" : "false"));
atts.addAttribute("", "", "isParent", "CDATA",
(m_Column.isParent() == true ? "true" : "false"));
atts.addAttribute("", "", "isSelectionColumn", "CDATA", (m_Column
.isSelectionColumn() == true ? "true" : "false"));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Column.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isTranslated", "CDATA", (m_Column
.isTranslated() == true ? "true" : "false"));
atts.addAttribute("", "", "isUpdateable", "CDATA", (m_Column
.isUpdateable() == true ? "true" : "false"));
atts.addAttribute("", "", "Name", "CDATA",
(m_Column.getName() != null ? m_Column.getName() : ""));
atts.addAttribute("", "", "getIsSyncDatabase", "CDATA", "Y");
atts
.addAttribute("", "", "ReadOnlyLogic", "CDATA", (m_Column
.getReadOnlyLogic() != null ? m_Column
.getReadOnlyLogic() : ""));
atts.addAttribute("", "", "SeqNo", "CDATA",
(m_Column.getSeqNo() > 0 ? "" + m_Column.getSeqNo() : "0"));
atts.addAttribute("", "", "VFormat", "CDATA",
(m_Column.getVFormat() != null ? m_Column.getVFormat() : ""));
atts.addAttribute("", "", "ValueMax", "CDATA",
(m_Column.getValueMax() != null ? m_Column.getValueMax() : ""));
atts.addAttribute("", "", "ValueMin", "CDATA",
(m_Column.getValueMin() != null ? m_Column.getValueMin() : ""));
atts.addAttribute("", "", "Version", "CDATA",
(m_Column.getVersion() != null ? "" + m_Column.getVersion()
: "0.0"));
//atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Column.getInfoFactoryClass() != null
// ? m_Column.getInfoFactoryClass() : ""));
return atts;
}
}

View File

@ -1,319 +0,0 @@
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.ElementHandler;
import org.compiere.model.MSysConfig;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class CommonTranslationHandler extends AbstractElementHandler implements ElementHandler{
public static final String CONTEXT_KEY__PARENT_TABLE = "currentParentTableForTranslation";
public static final String CONTEXT_KEY__PARENT_RECORD_ID = "currentParentTableRecordID_ForTranslation";
public static final String SPECIAL_ATRRIBUTE__TABLE_NAME = "ParentTable";
private HashMap<String, ArrayList<String>> cached_PIPO_ColumnsByTable = new HashMap<String, ArrayList<String>>();//Key: table name. Value: set of PIPO columns
public void startElement(Properties ctx, Element element) throws SAXException {
if(! MSysConfig.getBooleanValue(MSysConfig.TWOPACK_HANDLE_TRANSLATIONS, false)){
return;//translation import option is disabled
}
if(element.parent.skip){
return;
}
if(element.parent.defer){
element.defer = true;
return;
}
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
int parentID = element.parent.recordId;
if(parentID ==0)
throw new SAXException();
String parentTable = atts.getValue(SPECIAL_ATRRIBUTE__TABLE_NAME);
String language = atts.getValue("AD_Language");
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+parentTable+" "+atts.getValue("Name"));
if(isRecordExists(parentTable, parentID, language, ctx)){
updateTranslation(parentTable, parentID, ctx, atts);
}else{
insertTranslation(parentTable, parentID, ctx, atts);
}
}
private boolean isRecordExists(String parentTable, int parentID,
String language, Properties ctx) {
String sql =
"select ad_client_id from "+parentTable +"_trl where "+
parentTable+"_ID="+parentID+" and ad_language = '"+language+"'";
if(DB.getSQLValue(getTrxName(ctx), sql) == -1){
return false;
}else{
return true;
}
}
private void insertTranslation(String parentTable, int parentID,
Properties ctx, Attributes atts) throws SAXException{
ArrayList<String> pipoColumns = getExportableColumns(parentTable);
StringBuffer sql = new StringBuffer(
"INSERT INTO "+parentTable+"_trl ("+parentTable+"_ID, "+
" ad_client_ID, ad_org_id, CreatedBy, UpdatedBy, "+cast(pipoColumns)+
") VALUES ( ?, ?, ?, ?, ? ");
for (int i = 0; i<pipoColumns.size(); i++) {
sql.append(",?");
}
sql.append(")");
PreparedStatement pstm = DB.prepareStatement(sql.toString(), getTrxName(ctx));
try {
pstm.setInt(1, parentID);
pstm.setInt(2, 0);
pstm.setInt(3, 0);
pstm.setInt(4, 0);
pstm.setInt(5, 0);
int i = 5;
for (String columnName : pipoColumns) {
i++;
String value = atts.getValue(columnName);
if(columnName.equalsIgnoreCase("IsActive") ||
columnName.equalsIgnoreCase("IsTranslated")){
value = "true".equals(value) ? "Y" : "N";
}
pstm.setString(i, value);
}
if(pstm.executeUpdate()<0){
throw new SAXException();
}
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
private void updateTranslation(String parentTable, int parentID,
Properties ctx, Attributes atts) throws SAXException{
ArrayList<String> pipoColumns = getExportableColumns(parentTable);
StringBuffer sqlBuf = new StringBuffer("UPDATE "+parentTable+"_trl SET ");
for (String columnName : pipoColumns) {
sqlBuf.append(columnName).append("=?,");
}
String sql = sqlBuf.substring(0, sqlBuf.length()-1);
sql += " WHERE ad_language = '"+atts.getValue("AD_Language")+
"' AND "+parentTable+"_ID="+parentID;
try {
PreparedStatement pstm = DB.prepareStatement(sql,
getTrxName(ctx));
int i=0;
for (String columnName : pipoColumns) {
String value = atts.getValue(columnName);
i++;
if(columnName.equalsIgnoreCase("IsActive") ||
columnName.equalsIgnoreCase("IsTranslated")){
value = "true".equals(value) ? "Y" : "N";
}
pstm.setString(i, value);
}
if(pstm.executeUpdate()<0){
throw new SAXException();
}
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document) throws SAXException {
String parenTableName = Env.getContext(ctx, CONTEXT_KEY__PARENT_TABLE);
int parentRecordID = Env.getContextAsInt(ctx, CONTEXT_KEY__PARENT_RECORD_ID);
createTranslationTags(parenTableName, parentRecordID, document);
}
private void createTranslationTags(String parentTable,
int parentRecordID, TransformerHandler document) throws SAXException {
ArrayList<String> exportableColumns = getExportableColumns(parentTable);
String sql =
"select "+cast(exportableColumns)+" from "+parentTable+"_trl where "+
parentTable+"_ID="+parentRecordID;
PreparedStatement pstm = DB.prepareStatement(sql, null);
try {
ResultSet rs = pstm.executeQuery();
while(rs.next()){
AttributesImpl atts = getAttsForOneTrlRow(exportableColumns, rs);
atts.addAttribute("", "", SPECIAL_ATRRIBUTE__TABLE_NAME, "CDATA", parentTable);
document.startElement("", "", "trl", atts);
document.endElement("", "", "trl");
}
rs.close();
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
private AttributesImpl getAttsForOneTrlRow(ArrayList<String> exportableColumns,
ResultSet rs) throws Exception {
AttributesImpl atts = new AttributesImpl();
AttributeFiller af = new AttributeFiller(atts);
for (String columnName : exportableColumns) {
if(columnName.equalsIgnoreCase("IsActive")||
columnName.equalsIgnoreCase("IsTranslated")){
af.addBoolean(columnName, rs.getString(columnName).equalsIgnoreCase("Y"));
}else{
af.addString(columnName, rs.getString(columnName));
}
}
return atts;
}
/**
*
* @param parentTable
* @return
* @throws SAXException
*/
@SuppressWarnings("unchecked")
private ArrayList<String> getExportableColumns(String parentTable) throws SAXException {
Object pipolColumns = cached_PIPO_ColumnsByTable.get(parentTable);
if(pipolColumns != null){
return (ArrayList<String>)pipolColumns;
}
ArrayList<String> new_PIPO_Columns = new ArrayList<String>();
String sql = "select * from ad_column where ad_table_id = " +
"(select ad_table_id from ad_table where tableName = ?)" +
"and isTranslated='Y'"
+" ORDER BY AD_Column_ID";
PreparedStatement pstm = DB.prepareStatement(sql, null);
try {
pstm.setString(1, parentTable);
ResultSet rs = pstm.executeQuery();
while(rs.next()){
new_PIPO_Columns.add(rs.getString("columnName"));
}
pstm.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
throw new SAXException();
}
new_PIPO_Columns.add("AD_Language");
new_PIPO_Columns.add("IsActive");
new_PIPO_Columns.add("IsTranslated");
//Putting in cache
cached_PIPO_ColumnsByTable.put(parentTable, new_PIPO_Columns);
return (ArrayList<String>)new_PIPO_Columns;
}
private String cast(ArrayList<String> arg){
return arg.toString().substring(1, arg.toString().length()-1);
}
}

View File

@ -1,415 +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. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.IDFinder;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
*
* @author Robert Klein.
* @author Low Heng Sin
*
*/
public class DataElementHandler extends AbstractElementHandler {
private PO genericPO = null;
int AD_Backup_ID = -1;
String objectStatus = null;
String d_tablename = null;
private DataRowElementHandler rowHandler = new DataRowElementHandler();
private DataColumnElementHandler columnHandler = new DataColumnElementHandler();
public DataElementHandler() {
}
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (elementValue.equals("adempieredata") || elementValue.equals("data")) {
log.info(elementValue);
if (atts.getValue("clientname") != null) {
int AD_Client_ID = IDFinder.get_ID("AD_Client", atts.getValue("clientname"), getClientId(ctx), getTrxName(ctx));
Env.setContext(ctx, "AD_Client_ID", AD_Client_ID);
if (log.isLoggable(Level.INFO)) log.info("adempieredata: client set to "+AD_Client_ID+" "+atts.getValue("clientname"));
}
}
else if (elementValue.equals("dtable")) {
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("name"));
d_tablename = atts.getValue("name");
}
// row element, adempieredata
else if (elementValue.equals("drow")) {
rowHandler.startElement(ctx, element);
}
// column element, adempieredata
else if (elementValue.equals("dcolumn")) {
columnHandler.startElement(ctx, element);
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
if (elementValue.equals("drow")) {
rowHandler.endElement(ctx, element);
}
}
class DataRowElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("name"));
MTable table = MTable.get(ctx, d_tablename);
String d_rowname = atts.getValue("name");
// name can be null if there are keyXname attributes.
if (d_rowname != null && !d_rowname.equals("")){
int id = get_ID(ctx, d_tablename, d_rowname);
genericPO = table.getPO(id, getTrxName(ctx));
if (id > 0){
if (genericPO == null || genericPO.get_ID() != id)
throw new SAXException("id not found");
AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO);
objectStatus = "Update";
}
else{
objectStatus = "New";
AD_Backup_ID =0;
}
}
// keyXname and lookupkeyXname.
else {
String sql = "select * from "+d_tablename;
String whereand = " where";
String CURRENT_KEY = "key1name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
whereand = " and";
}
CURRENT_KEY = "key2name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
whereand = " and";
}
if (whereand.equals(" where"))
log.warning("no name or keyXname attribute defined.");
sql = sql+whereand+" AD_Client_ID="+getClientId(ctx);
// Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value
try {
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
objectStatus = "Update";
genericPO = table.getPO(rs, getTrxName(ctx));
rs.close();
pstmt.close();
pstmt = null;
}
else {
rs.close();
rs = null;
pstmt.close();
pstmt = null;
objectStatus = "New";
genericPO = table.getPO(0, getTrxName(ctx));
// set keyXname.
CURRENT_KEY = "key1name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
String colName = atts.getValue(CURRENT_KEY);
String valueObject = atts.getValue("lookup"+CURRENT_KEY);
if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject);
genericPO.set_ValueOfColumn(colName, valueObject);
}
CURRENT_KEY = "key2name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
String colName = atts.getValue(CURRENT_KEY);
String valueObject = atts.getValue("lookup"+CURRENT_KEY);
if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject);
genericPO.set_ValueOfColumn(colName, valueObject);
}
}
}
catch (Exception e) {
log.warning ("keyXname attribute. init from rs error."+e);
throw new SAXException(e.getMessage());
}
}
// for debug GenericPO.
/*if (false) {
POInfo poInfo = POInfo.getPOInfo(ctx, get_ID(ctx, "AD_Table", d_tablename), getTrxName(ctx));
if (poInfo == null)
log.info("poInfo is null.");
for (int i = 0; i < poInfo.getColumnCount(); i++) {
log.info(d_tablename+" column: "+poInfo.getColumnName(i));
}
}*/
// globalqss: set AD_Client_ID to the client setted in adempieredata
if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx))
genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx));
// if new. TODO: no defaults for keyXname.
if (d_rowname != null && !d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) {
if (log.isLoggable(Level.INFO)) log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname);
genericPO.set_ValueOfColumn("Name", d_rowname);
// Set defaults.
//TODO: get defaults from configuration
HashMap<Object, Object> defaults = new HashMap<Object, Object>();
HashMap<?, ?> thisDefault = (HashMap<?, ?>)defaults.get(d_tablename);
if (thisDefault != null) {
Iterator<?> iter = thisDefault.values().iterator();
ArrayList<?> thisValue = null;
while (iter.hasNext()) {
thisValue = (ArrayList<?>)iter.next();
if (((String)(thisValue.get(2))).equals("String"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), (String)thisValue.get(1));
else if (((String)(thisValue.get(2))).equals("Integer"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1)));
else if (((String)(thisValue.get(2))).equals("Boolean"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false));
}
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
if (genericPO != null) {
if (genericPO.save(getTrxName(ctx))== true)
record_log (ctx, 1, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, objectStatus,d_tablename,get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename));
else {
record_log (ctx, 0, genericPO.get_TableName(),"Data", genericPO.get_ID(),AD_Backup_ID, objectStatus,d_tablename,get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename));
throw new POSaveFailedException("GenericPO");
}
genericPO = null;
}
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
}
}
class DataColumnElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("name"));
String columnName = atts.getValue("name");
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename);
int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid);
StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?");
String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id);
sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?");
String isKey = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id);
if (("New".equals(objectStatus)) || (isKey.equals("N") &&
isUpdateable.equals("Y") &&
(!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) {
if (atts.getValue("value") != null && !atts.getValue("value").equals("null")) {
if (atts.getValue("class").equals("String") || atts.getValue("class").equals("Text")
|| atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No")
|| atts.getValue("class").equals("Button")
|| atts.getValue("class").equals("Memo")|| atts.getValue("class").equals("Text Long")
|| atts.getValue("name").equals("AD_Language") || atts.getValue("name").equals("EntityType")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), atts.getValue("value").toString());
}
else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount")
|| atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), new BigDecimal(atts.getValue("value")));
}
else if (atts.getValue("class").equals("Integer") || atts.getValue("class").equals("ID")
|| atts.getValue("class").equals("Table Direct")|| atts.getValue("class").equals("Table")
|| atts.getValue("class").equals("Location (Address)")|| atts.getValue("class").equals("Account")
|| atts.getValue("class").equals("Color)")|| atts.getValue("class").equals("Search")
|| atts.getValue("class").equals("Locator (WH)")|| atts.getValue("class").equals("Product Attribute")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value")));
}
else if (atts.getValue("class").equals("Boolean")) {
genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false));
}
else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time")
|| atts.getValue("class").equals("Time")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("value")));
}//Binary, Radio, RowID, Image not supported
} else { // value is null
if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) {
// globalqss - bring support from XML2AD to lookupname
String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3);
genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname"))));
} else if (atts.getValue("lookupvalue") != null && !"".equals(atts.getValue("lookupvalue"))) {
// globalqss - bring support from XML2AD to lookupvalue
String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3);
genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyValue(ctx, m_tablename, atts.getValue("lookupvalue"))));
}
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
}
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
int table_id = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
Statement stmt = DB.createStatement();
AttributesImpl atts = new AttributesImpl();
document.startElement("","","data",atts);
try {
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
int i = 1;
String col_Name = null;
String sql1 = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
String table_Name = DB.getSQLValueString(null,sql1,table_id);
atts.clear();
atts.addAttribute("","","name","CDATA",table_Name);
document.startElement("","","dtable",atts);
while (rs.next()){
atts.clear();
int key1 = 0;
String nameatts = "";
for (i=1 ;i <= columns;i++){
col_Name = meta.getColumnName(i).toUpperCase();
if (col_Name.equals("NAME") && rs.getObject("name") != null)
nameatts = ""+rs.getObject("name");
String sql2 = "SELECT ColumnName FROM AD_Column "
+ "WHERE isKey = 'Y' AND "
+ "AD_Table_ID = ? AND "
+ "Upper(ColumnName)= '"+col_Name+"'";
String cName = DB.getSQLValueString(null,sql2,table_id);
if (cName != null){
if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){
atts.addAttribute("","","key1name","CDATA",cName);
atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name));
key1 = 1;
}
else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){
atts.addAttribute("","","key2name","CDATA",cName);
atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name));
key1 = 2;
}
}
}
atts.addAttribute("","","name","CDATA",nameatts);
if ( key1 == 0 ){
atts.addAttribute("","","key1name","CDATA","");
atts.addAttribute("","","lookupkey1name","CDATA","");
key1 = 1;
}
if ( key1 == 1 ){
atts.addAttribute("","","key2name","CDATA","");
atts.addAttribute("","","lookupkey2name","CDATA","");
}
document.startElement("","","drow",atts);
for (i=1 ;i <= columns;i++){
atts.clear();
col_Name = meta.getColumnName(i).toUpperCase();
String sql2 = "Select A.ColumnName, B.Name "
+ "From AD_Column A, AD_Reference B "
+ "Where Upper(A.columnname) = ? and "
+ "A.AD_TABLE_ID = ? and "
+ "A.AD_Reference_ID = B.AD_Reference_ID";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql2, getTrxName(ctx));
pstmt.setString(1, col_Name);
pstmt.setInt(2, table_id);
ResultSet rs1 = pstmt.executeQuery();
while (rs1.next()){
//added 9/3/05
atts.clear();
atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName"));
atts.addAttribute("","","class","CDATA", rs1.getString("Name"));
if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time"))
atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i));
else
atts.addAttribute("","","value","CDATA", "" + rs.getObject(i));
if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&&
!rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){
document.startElement("","","dcolumn",atts);
document.endElement("","","dcolumn");
}
}
rs1.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE,"getData", e);
}
}
document.endElement("","","drow");
}
rs.close();
stmt.close();
stmt = null;
document.endElement("","","dtable");
}
catch (Exception e) {
log.log(Level.SEVERE,"getData", e);
}
document.endElement("","","data");
}
}

View File

@ -1,200 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.Adempiere;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class DistFileElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("name"));
String releaseNumber = atts.getValue("ReleaseNo");
//log.info(atts.getValue("ReleaseNo"));
//log.info(Compiere.MAIN_VERSION);
//Check Release Number
if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){
String fileName = atts.getValue("name");
String sourceDirectory = atts.getValue("sourceDirectory");
String targetDirectory = atts.getValue("targetDirectory");
Object_Status = "New";
int idDetail=0;
InputStream inputStream; // Stream for reading from the source file.
OutputStream outputStream; // Stream for writing the copy.
String packagePath=null;
String adempiereSourcePath=null;
//get adempiere-all directory
try {
packagePath = getPackageDirectory(ctx);
File parentDirectory = new File(packagePath);
while (!parentDirectory.getName().equals("packages")){
parentDirectory = parentDirectory.getParentFile();
}
parentDirectory = parentDirectory.getParentFile();
adempiereSourcePath = parentDirectory.getCanonicalPath();
} catch (IOException e1) {
System.out.println("Can't find adempiere-all directory.");
}
// Create backup directory if required
File backupDir = new File(packagePath+File.separator+"backup"+File.separator);
if (!backupDir.exists()){
boolean success = (new File(packagePath+File.separator+"backup"+File.separator)).mkdirs();
if (!success) {
log.info("Backup directory creation failed");
}
}
//Correct target directory for proper file separator
String fullTargetPath = adempiereSourcePath+targetDirectory;
char slash1 = '\\';
char slash2 = '/';
if (File.separator.equals("/"))
fullTargetPath = fullTargetPath.replace(slash1,slash2);
else
fullTargetPath = fullTargetPath.replace(slash2,slash1);
File file = new File(fullTargetPath+fileName);
//TODO: derive force from user parameter
boolean force = true;
String fileDate = null;
//check to see if overwrites are allowed
if (file.exists() && force == false) {
System.out.println(
"Output file exists. Use the -f option to replace it.");
return;
}
//backup file to package directory
else if (file.exists() && force == true) {
Object_Status = "Update";
if (log.isLoggable(Level.INFO)) log.info("Target Backup:"+fullTargetPath+fileName);
inputStream = OpenInputfile(fullTargetPath+fileName);
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssSSSSZ");
Date today = new Date();
fileDate = formatter_file.format(today);
outputStream = OpenOutputfile(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName);
if (log.isLoggable(Level.INFO)) log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName);
copyFile (inputStream, outputStream);
log.info("Backup Complete");
}
// Correct dist directory for proper file separator
String fullSourcePath=null;
if (File.separator.equals("/"))
fullSourcePath = sourceDirectory.replace(slash1,slash2);
else
fullSourcePath = sourceDirectory.replace(slash2,slash1);
inputStream = OpenInputfile(packagePath+fullSourcePath+fileName);
// Create Target directory if required
File targetDir = new File(fullTargetPath);
if (!targetDir.exists()){
boolean success = (new File(fullTargetPath)).mkdirs();
if (!success) {
log.info("Target directory creation failed");
}
}
outputStream = OpenOutputfile(fullTargetPath+fileName);
//Copy File
int success = copyFile (inputStream,outputStream);
//Record in log
int idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
if (success != -1){
try {
idDetail = record_log (ctx, 1, fileName,"file", 0,0, Object_Status,fileName,0);
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info ("setfile:"+e);
}
}
else{
try {
idDetail = record_log (ctx, 0, fileName,"file", 0,0, Object_Status,fileName,0);
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info ("setfile:"+e);
}
}
//Record in transaction file
StringBuffer sqlB = new StringBuffer ("INSERT INTO AD_Package_Imp_Backup" )
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
.append( " AD_PACKAGE_IMP_ORG_DIR, AD_PACKAGE_IMP_BCK_DIR)" )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + idBackup )
.append( ", " + idDetail )
.append( ", " + getPackageImpId(ctx) )
.append( ", '" + fullTargetPath+fileName )
.append( "', '" + packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName )
.append( "')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to import backup failed");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
String Source_Directory = Env.getContext(ctx, "Source_Directory");
String Target_Directory = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("","","name","CDATA",FileName);
atts.addAttribute("","","sourceDirectory","CDATA",Source_Directory);
atts.addAttribute("","","targetDirectory","CDATA",Target_Directory);
atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo);
document.startElement("","","distfile",atts);
document.endElement("","","distfile");
}
}

View File

@ -1,139 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Val_Rule;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class DynValRuleElementHandler extends AbstractElementHandler {
private List<Integer> rules = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_Val_Rule", "name", name);
X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Val_Rule_ID") != null && Integer.parseInt(atts.getValue("AD_Val_Rule_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_ValRule.setAD_Val_Rule_ID(Integer.parseInt(atts.getValue("AD_Val_Rule_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_Val_Rule",m_ValRule);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
m_ValRule.setDescription(getStringValue(atts, "Description"));
m_ValRule.setEntityType(atts.getValue("EntityType"));
m_ValRule.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_ValRule.setName(name);
m_ValRule.setType(atts.getValue("Type"));
m_ValRule.setCode(atts.getValue("Code"));
if (m_ValRule.save(getTrxName(ctx)) == true){
record_log (ctx, 1, m_ValRule.getName(),"ValRule", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Val_Rule"));
}
else{
record_log (ctx, 0, m_ValRule.getName(),"ValRule", m_ValRule.get_ID(),AD_Backup_ID, Object_Status,"AD_Val_Rule",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Val_Rule"));
throw new POSaveFailedException("Failed to save dynamic validation rule.");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Val_Rule_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID);
if (rules.contains(AD_Val_Rule_ID))
return;
rules.add(AD_Val_Rule_ID);
String sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID= " + AD_Val_Rule_ID;
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
try {
rs = pstmt.executeQuery();
while (rs.next())
{
X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null);
createDynamicValidationRuleBinding(atts,m_ValRule);
document.startElement("","","dynvalrule",atts);
document.endElement("","","dynvalrule");
}
}
catch (Exception e){
log.log(Level.SEVERE,"getProcess", e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
}
private AttributesImpl createDynamicValidationRuleBinding( AttributesImpl atts, X_AD_Val_Rule m_ValRule)
{
atts.clear();
if (m_ValRule.getAD_Val_Rule_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Val_Rule_ID","CDATA",Integer.toString(m_ValRule.getAD_Val_Rule_ID()));
atts.addAttribute("","","Name","CDATA",(m_ValRule.getName () != null ? m_ValRule.getName ():""));
//FIXME: may not need this I guess
//atts.addAttribute("","","AccessLevel","CDATA",(m_ValRule.getAccessLevel () != null ? m_ValRule.getAccessLevel ():""));
atts.addAttribute("","","Code","CDATA",(m_ValRule.getCode() != null ? m_ValRule.getCode ():""));
atts.addAttribute("","","Description","CDATA",(m_ValRule.getDescription () != null ? m_ValRule.getDescription ():""));
atts.addAttribute("","","EntityType","CDATA",(m_ValRule.getEntityType () != null ? m_ValRule.getEntityType ():""));
atts.addAttribute("","","Type","CDATA",(m_ValRule.getType () != null ? m_ValRule.getType ():""));
atts.addAttribute("","","isActive","CDATA",(m_ValRule.isActive()== true ? "true":"false"));
return atts;
}
}

View File

@ -1,162 +0,0 @@
/**
*
*/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.I_AD_EntityType;
import org.compiere.model.MEntityType;
import org.compiere.model.PO;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* @author Teo Sarca
* <li>FR [ 2847694 ] 2pack import/export AD_EntityType functionality
* https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2847694&group_id=176962
*/
public class EntityTypeElementHandler extends AbstractElementHandler
{
public static final String TAG_Name = "entitytype";
private final List<Integer> entityTypes = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException
{
final String elementValue = element.getElementValue();
final Attributes atts = element.attributes;
final String entitytype = atts.getValue(I_AD_EntityType.COLUMNNAME_EntityType);
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+entitytype);
if (isProcessElement(ctx, entitytype))
{
int id = get_IDWithColumn(ctx, I_AD_EntityType.Table_Name, I_AD_EntityType.COLUMNNAME_EntityType, entitytype);
final MEntityType entity = new MEntityType(ctx, id, getTrxName(ctx));
final int AD_Backup_ID;
final String Object_Status;
if (id <= 0 && getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0) <= PackOut.MAX_OFFICIAL_ID)
{
entity.setAD_EntityType_ID(getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0));
}
if (id > 0)
{
AD_Backup_ID = copyRecord(ctx, I_AD_EntityType.Table_Name, entity);
Object_Status = "Update";
}
else
{
Object_Status = "New";
AD_Backup_ID = 0;
}
entity.setName(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Name));
entity.setDescription(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Description));
entity.setHelp(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Help));
entity.setEntityType(getStringValue(atts, I_AD_EntityType.COLUMNNAME_EntityType));
entity.setVersion(atts.getValue(I_AD_EntityType.COLUMNNAME_Version));
entity.setIsActive(getBooleanValue(atts, I_AD_EntityType.COLUMNNAME_IsActive, true));
entity.setModelPackage(getStringValue(atts, I_AD_EntityType.COLUMNNAME_ModelPackage));
entity.setClasspath(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Classpath));
if (entity.save(getTrxName(ctx)) == true)
{
record_log (ctx, 1, entity.getEntityType(), TAG_Name, entity.get_ID(),
AD_Backup_ID, Object_Status,
I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
}
else
{
record_log (ctx, 0, entity.getEntityType(), TAG_Name, entity.get_ID(),
AD_Backup_ID, Object_Status,
I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
throw new POSaveFailedException("Failed to save message.");
}
}
else
{
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException
{
}
public void create(Properties ctx, TransformerHandler document) throws SAXException
{
// TODO
final int AD_EntityType_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
if (entityTypes.contains(AD_EntityType_ID))
return;
entityTypes.add(AD_EntityType_ID);
final MEntityType entity = new MEntityType(ctx, AD_EntityType_ID, null);
AttributesImpl atts = new AttributesImpl();
createMessageBinding(atts, entity);
document.startElement("", "", TAG_Name, atts);
document.endElement("", "", TAG_Name);
}
private AttributesImpl createMessageBinding(AttributesImpl atts, MEntityType entity)
{
atts.clear();
if (entity.getAD_EntityType_ID() <= PackOut.MAX_OFFICIAL_ID)
{
addAttribute(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, entity);
}
addAttribute(atts, I_AD_EntityType.COLUMNNAME_Name, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_Description, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_Help, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_EntityType, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_Version, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_IsActive, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_ModelPackage, entity);
addAttribute(atts, I_AD_EntityType.COLUMNNAME_Classpath, entity);
return atts;
}
protected boolean getBooleanValue(Attributes atts, String qName, boolean defaultValue)
{
String s = atts.getValue(qName);
return s != null ? Boolean.valueOf(s) : defaultValue;
}
protected int getIntValue(Attributes atts, String qName, int defaultValue)
{
Object o = atts.getValue(qName);
if (o == null)
return defaultValue;
if (o instanceof Number)
return ((Number)o).intValue();
return Integer.parseInt(o.toString());
}
private final void addAttribute(AttributesImpl atts, String name, PO po)
{
Object value = po.get_Value(name);
atts.addAttribute("", "", name, "CDATA", toStringAttribute(value));
}
private final String toStringAttribute(Object value)
{
if (value == null)
return "";
if (value instanceof Boolean)
return ((Boolean)value).booleanValue() == true ? "true" : "false";
return value.toString();
}
}

View File

@ -1,386 +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. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
* Teo Sarca teo.sarca@gmail.com *
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackIn;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MField;
import org.compiere.model.X_AD_Field;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FieldElementHandler extends AbstractElementHandler
{
public void startElement(Properties ctx, Element element) throws SAXException
{
final String include_tabname = element.attributes.getValue("ADIncludeTabNameID");
// Set Included Tab ID if this task was previously postponed
if (element.defer && element.recordId > 0 && include_tabname != null)
{
MField field = new MField(ctx, element.recordId, getTrxName(ctx));
setIncluded_Tab_ID(ctx, field, include_tabname);
field.saveEx();
return;
}
PackIn packIn = (PackIn)ctx.get("PackInProcess");
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("Name");
String tabname = atts.getValue("ADTabNameID");
String colname = atts.getValue("ADColumnNameID");
String tableName = atts.getValue("ADTableNameID");
int tableid = packIn.getTableId(tableName);
if (tableid <= 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
packIn.addTable(tableName, tableid);
}
if (tableid <= 0) {
element.defer = true;
return;
}
int windowid = get_ID(ctx, "AD_Window", atts
.getValue("ADWindowNameID"));
if (windowid <= 0) {
element.defer = true;
return;
}
int columnid = packIn.getColumnId(tableName, colname);
if (columnid <= 0) {
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column",
"ColumnName", colname, "AD_Table", tableid);
if (columnid > 0)
packIn.addColumn(tableName, colname, columnid);
}
if (columnid <= 0) {
element.defer = true;
return;
}
int tabid = 0;
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
element.parent.recordId > 0) {
tabid = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer(
"select AD_Tab_ID from AD_Tab where AD_Window_ID = "
+ windowid).append(" and Name = '" + tabname + "'")
.append(" and AD_Table_ID = ?");
tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
tableid);
if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
element.parent.recordId = tabid;
}
}
if (tabid > 0) {
StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(columnid)
.append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
final MField m_Field = new MField(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Field_ID") != null && Integer.parseInt(atts.getValue("AD_Field_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Field.setAD_Field_ID(Integer.parseInt(atts.getValue("AD_Field_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Field.setName(atts.getValue("Name"));
m_Field.setAD_Column_ID(columnid);
name = atts.getValue("ADFieldGroupNameID");
id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
m_Field.setAD_FieldGroup_ID(id);
m_Field.setAD_Tab_ID(tabid);
m_Field.setEntityType(atts.getValue("EntityType"));
m_Field.setIsSameLine(Boolean
.valueOf(atts.getValue("SameLine")).booleanValue());
m_Field.setIsCentrallyMaintained(Boolean.valueOf(
atts.getValue("isCentrallyMaintained")).booleanValue());
m_Field.setIsDisplayed(Boolean.valueOf(
atts.getValue("Displayed")).booleanValue());
// m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
m_Field.setIsFieldOnly(Boolean.valueOf(
atts.getValue("isFieldOnly")).booleanValue());
m_Field.setIsHeading(Boolean
.valueOf(atts.getValue("isHeading")).booleanValue());
m_Field.setIsReadOnly(Boolean.valueOf(
atts.getValue("isReadOnly")).booleanValue());
m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Field.setDisplayLength(Integer.parseInt(atts
.getValue("DisplayLength")));
m_Field.setDescription(getStringValue(atts, "Description"));
m_Field.setHelp(getStringValue(atts, "Help"));
m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
String sortNo = getStringValue(atts, "SortNo");
if (sortNo != null)
m_Field.setSortNo(new BigDecimal(sortNo));
m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
String Name = atts.getValue("ADReferenceNameID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Field.setAD_Reference_ID(id);
Name = atts.getValue("ADValRuleNameID");
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
m_Field.setAD_Val_Rule_ID(id);
Name = atts.getValue("ADReferenceNameValueID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Field.setAD_Reference_Value_ID(id);
//m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
setIncluded_Tab_ID(ctx, m_Field, include_tabname);
if (m_Field.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Field.getName(), "Field", m_Field
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Field"));
element.recordId = m_Field.getAD_Field_ID();
} else {
record_log(ctx, 0, m_Field.getName(), "Field", m_Field
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Field"));
throw new POSaveFailedException("Failed to save field definition.");
}
// If Included Tab not found, then postpone this task for later processing
if (m_Field.getAD_Field_ID() > 0 && include_tabname != null && m_Field.getIncluded_Tab_ID() <= 0)
{
element.defer = true;
}
} else {
element.defer = true;
return;
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Field_ID = Env.getContextAsInt(ctx,
X_AD_Field.COLUMNNAME_AD_Field_ID);
X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null);
AttributesImpl atts = new AttributesImpl();
createFieldBinding(atts, m_Field);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
if(m_Field.getAD_FieldGroup_ID() > 0){
packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document);
}
if(m_Field.getAD_Reference_ID() > 0) {
packOut.createReference(m_Field.getAD_Reference_ID(), document);
}
if (m_Field.getAD_Reference_Value_ID() > 0) {
packOut.createReference(m_Field.getAD_Reference_Value_ID(), document);
}
if (m_Field.getAD_Val_Rule_ID() > 0) {
packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document);
}
document.startElement("", "", "field", atts);
document.endElement("", "", "field");
}
private AttributesImpl createFieldBinding(AttributesImpl atts,
X_AD_Field m_Field) {
String sql = null;
String name = null;
atts.clear();
if (m_Field.getAD_Field_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Field_ID", "CDATA", Integer.toString(m_Field.getAD_Field_ID()));
if (m_Field.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
if (m_Field.getAD_Column_ID() > 0) {
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID());
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, idTable);
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (m_Field.getAD_FieldGroup_ID() > 0) {
sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?";
name = DB.getSQLValueString(null, sql, m_Field
.getAD_FieldGroup_ID());
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", "");
if (m_Field.getAD_Field_ID() > 0) {
sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?";
name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID());
atts.addAttribute("", "", "ADFieldNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADFieldNameID", "CDATA", "");
if (m_Field.getAD_Tab_ID() > 0) {
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID());
atts.addAttribute("", "", "ADTabNameID", "CDATA", name);
sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?";
int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID());
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, windowid);
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTabNameID", "CDATA", "");
if (m_Field.getIncluded_Tab_ID() > 0) {
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
name = DB.getSQLValueString(null, sql, m_Field.getIncluded_Tab_ID());
atts.addAttribute("", "", "ADIncludeTabNameID", "CDATA", name);
}
atts.addAttribute("", "", "EntityType", "CDATA", (m_Field
.getEntityType() != null ? m_Field.getEntityType() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Field.getName() != null ? m_Field.getName() : ""));
atts.addAttribute("", "", "SameLine", "CDATA",
(m_Field.isSameLine() == true ? "true" : "false"));
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field
.isCentrallyMaintained() == true ? "true" : "false"));
atts.addAttribute("", "", "Displayed", "CDATA",
(m_Field.isDisplayed() == true ? "true" : "false"));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Field.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field
.isEncrypted() == true ? "true" : "false"));
atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field
.isFieldOnly() == true ? "true" : "false"));
atts.addAttribute("", "", "isHeading", "CDATA",
(m_Field.isHeading() == true ? "true" : "false"));
atts.addAttribute("", "", "isReadOnly", "CDATA",
(m_Field.isReadOnly() == true ? "true" : "false"));
atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo()));
atts.addAttribute("", "", "DisplayLength", "CDATA",
(m_Field.getDisplayLength() > 0 ? ""
+ m_Field.getDisplayLength() : "0"));
atts.addAttribute("", "", "Description", "CDATA", (m_Field
.getDescription() != null ? m_Field.getDescription() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Field.getHelp() != null ? m_Field.getHelp() : ""));
atts.addAttribute("", "", "SortNo", "CDATA",
(m_Field.getSortNo() != null ? m_Field.getSortNo().toString()
: ""));
atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field
.getDisplayLogic() != null ? m_Field.getDisplayLogic() : ""));
atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field
.getObscureType() != null ? m_Field.getObscureType() : ""));
//atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null
// ? m_Field.getInfoFactoryClass() : ""));
if (m_Field.getAD_Reference_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Field
.getAD_Reference_ID());
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
if (m_Field.getAD_Reference_Value_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Field
.getAD_Reference_Value_ID());
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", "");
if (m_Field.getAD_Val_Rule_ID() > 0) {
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
name = DB
.getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID());
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
return atts;
}
/**
* Set Included_Tab_ID (if needed)
* @param ctx
* @param field
* @param includedTabName
*/
private void setIncluded_Tab_ID(Properties ctx, MField field, String includedTabName)
{
if (includedTabName == null)
return;
//
final String trxName = getTrxName(ctx);
final int AD_Tab_ID = field.getAD_Tab_ID();
if (AD_Tab_ID <= 0)
{
log.warning("AD_Tab_ID=0 ("+field+")");
return;
}
final int AD_Window_ID = DB.getSQLValueEx(trxName,
"SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?",
AD_Tab_ID);
final int included_Tab_ID = DB.getSQLValueEx(trxName,
"SELECT AD_Tab_ID FROM AD_Tab WHERE Name=? AND AD_Window_ID=? AND AD_Tab_ID<>?",
includedTabName, AD_Window_ID, AD_Tab_ID);
if(included_Tab_ID > 0)
{
field.setIncluded_Tab_ID(included_Tab_ID);
}
}
}

View File

@ -1,155 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Igor G. - progerpro@gmail.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.PoFiller;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_FieldGroup;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FieldGroupElementHandler extends AbstractElementHandler {
private List<Integer> processedFieldGroups = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("Name");
if (isProcessElement(ctx, entitytype)) {
int id = get_IDWithColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_FieldGroup_ID") != null && Integer.parseInt(atts.getValue("AD_FieldGroup_ID")) <= PackOut.MAX_OFFICIAL_ID)
fieldGroup.setAD_FieldGroup_ID(Integer.parseInt(atts.getValue("AD_FieldGroup_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, X_AD_FieldGroup.Table_Name, fieldGroup);
Object_Status = "Update";
if (processedFieldGroups.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
PoFiller pf = new PoFiller(fieldGroup, atts);
pf.setBoolean(X_AD_FieldGroup.COLUMNNAME_IsActive);
pf.setString(X_AD_FieldGroup.COLUMNNAME_Name);
pf.setString(X_AD_FieldGroup.COLUMNNAME_EntityType);
pf.setString(X_AD_FieldGroup.COLUMNNAME_FieldGroupType);
pf.setBoolean(X_AD_FieldGroup.COLUMNNAME_IsCollapsedByDefault);
if (fieldGroup.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, fieldGroup.getName(), "FieldGroup",
fieldGroup.get_ID(), AD_Backup_ID, Object_Status,
X_AD_FieldGroup.Table_Name, get_IDWithColumn(ctx, "AD_Table",
"TableName", X_AD_FieldGroup.Table_Name));
element.recordId = fieldGroup.getAD_FieldGroup_ID();
processedFieldGroups.add(fieldGroup.getAD_FieldGroup_ID());
} else {
record_log(ctx, 0, fieldGroup.getName(), "FieldGroup",
fieldGroup.get_ID(), AD_Backup_ID, Object_Status,
X_AD_FieldGroup.Table_Name, get_IDWithColumn(ctx, "AD_Table",
"TableName", X_AD_FieldGroup.Table_Name));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int fieldGroup_id = Env.getContextAsInt(ctx,
X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
if (processedFieldGroups.contains(fieldGroup_id))
return;
processedFieldGroups.add(fieldGroup_id);
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, fieldGroup_id, null);
AttributesImpl atts = new AttributesImpl();
createFieldGroupBinding(atts, fieldGroup);
document.startElement("", "", "fieldgroup", atts);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
packOut.createTranslations(X_AD_FieldGroup.Table_Name,
fieldGroup.get_ID(), document);
document.endElement("", "", "fieldgroup");
}
private AttributesImpl createFieldGroupBinding(AttributesImpl atts, X_AD_FieldGroup fieldGroup)
{
AttributeFiller filler = new AttributeFiller(atts, fieldGroup);
if (fieldGroup.getAD_FieldGroup_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
filler.add(X_AD_FieldGroup.COLUMNNAME_IsActive);
filler.add(X_AD_FieldGroup.COLUMNNAME_Name);
filler.add(X_AD_FieldGroup.COLUMNNAME_EntityType);
filler.add(X_AD_FieldGroup.COLUMNNAME_FieldGroupType);
filler.add(X_AD_FieldGroup.COLUMNNAME_IsCollapsedByDefault);
return atts;
}
}

View File

@ -1,139 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FormAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int formid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (atts.getValue("formname")!=null){
String name = atts.getValue("formname");
sqlB = new StringBuffer ("SELECT AD_Form_ID FROM AD_Form WHERE Name= ?");
formid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Form_Access WHERE AD_Role_ID=? and AD_Form_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,formid);
@SuppressWarnings("unused")
String Object_Status = null;
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Form_Access ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadWrite = '" + atts.getValue("isReadWrite") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Form_ID = " + formid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to form access failed");
throw new DatabaseAccessException("Update to form access failed");
}
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Form_Access"
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
+ "AD_Role_ID, AD_Form_ID, isActive, isReadWrite) "
+ "VALUES("
+ " "+ Env.getAD_Client_ID(ctx)
+ ", "+ Env.getAD_Org_ID(ctx)
+ ", "+ Env.getAD_User_ID(ctx)
+ ", "+ Env.getAD_User_ID(ctx)
+ ", " + roleid
+ ", " + formid
+ ", '" + atts.getValue("isActive")
+ "', '" + atts.getValue("isReadWrite")+"')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to form access failed");
throw new DatabaseAccessException("Insert to form access failed");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Form_ID = Env.getContextAsInt(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createFormAccessBinding(atts, AD_Form_ID, AD_Role_ID);
document.startElement("", "", "formaccess", atts);
document.endElement("", "", "formaccess");
}
private AttributesImpl createFormAccessBinding(AttributesImpl atts,
int form_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?";
name = DB.getSQLValueString(null, sql, form_id);
atts.addAttribute("", "", "formname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Form_Access WHERE AD_Form_ID=" + form_id
+ " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadWrite FROM AD_Form_Access WHERE AD_Form_ID="
+ form_id + " and AD_Role_ID=?";
String isReadWrite = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite);
return atts;
}
}

View File

@ -1,130 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MForm;
import org.compiere.model.X_AD_Form;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FormElementHandler extends AbstractElementHandler {
private List<Integer> forms = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("ADFormNameID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADFormNameID");
int id = get_ID(ctx, "AD_Form", name);
MForm m_Form = new MForm(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Form_ID") != null && Integer.parseInt(atts.getValue("AD_Form_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Form.setAD_Form_ID(Integer.parseInt(atts.getValue("AD_Form_ID")));
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_Form",m_Form);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
m_Form.setClassname (atts.getValue("Classname"));
m_Form.setIsBetaFunctionality (Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
m_Form.setAccessLevel(atts.getValue("AccessLevel"));
m_Form.setDescription(getStringValue(atts, "Description"));
m_Form.setEntityType(atts.getValue("EntityType"));
m_Form.setHelp(getStringValue(atts, "Help"));
m_Form.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_Form.setName(atts.getValue("Name"));
if (m_Form.save(getTrxName(ctx)) == true){
record_log (ctx, 1, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
}
else{
record_log (ctx, 0, m_Form.getName(),"Form", m_Form.get_ID(),AD_Backup_ID, Object_Status,"AD_Form",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Form"));
throw new POSaveFailedException("Failed to save form definition");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Form_ID = Env.getContextAsInt(ctx, "AD_Form_ID");
if (forms.contains(AD_Form_ID)) return;
forms.add(AD_Form_ID);
X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null);
AttributesImpl atts = new AttributesImpl();
createFormBinding(atts,m_Form);
document.startElement("","","form",atts);
document.endElement("","","form");
}
private AttributesImpl createFormBinding( AttributesImpl atts, X_AD_Form m_Form)
{
String sql = null;
String name = null;
atts.clear();
if (m_Form.getAD_Form_ID()> 0 ){
sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?";
name = DB.getSQLValueString(null,sql,m_Form.getAD_Form_ID());
if (name != null )
atts.addAttribute("","","ADFormNameID","CDATA",name);
else
atts.addAttribute("","","ADFormNameID","CDATA","");
} else {
atts.addAttribute("","","ADFormNameID","CDATA","");
}
if (m_Form.getAD_Form_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Form_ID","CDATA",Integer.toString(m_Form.getAD_Form_ID()));
atts.addAttribute("","","Classname","CDATA",(m_Form.getClassname () != null ? m_Form.getClassname ():""));
atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Form.isBetaFunctionality()== true ? "true":"false"));
atts.addAttribute("","","AccessLevel","CDATA",(m_Form.getAccessLevel () != null ? m_Form.getAccessLevel ():""));
atts.addAttribute("","","Description","CDATA",(m_Form.getDescription () != null ? m_Form.getDescription ():""));
atts.addAttribute("","","isActive","CDATA",(m_Form.isActive()== true ? "true":"false"));
atts.addAttribute("","","EntityType","CDATA",(m_Form.getEntityType () != null ? m_Form.getEntityType ():""));
atts.addAttribute("","","Help","CDATA",(m_Form.getHelp() != null ? m_Form.getHelp():""));
atts.addAttribute("","","Name","CDATA",(m_Form.getName() != null ? m_Form.getName():""));
return atts;
}
}

View File

@ -1,183 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_ImpFormat;
import org.compiere.model.X_AD_ImpFormat_Row;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ImpFormatElementHandler extends AbstractElementHandler {
private ImpFormatRowElementHandler rowHandler = new ImpFormatRowElementHandler();
private List<Integer> formats = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
int id = get_ID(ctx, "AD_ImpFormat", atts.getValue("Name"));
X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_ImpFormat_ID") != null && Integer.parseInt(atts.getValue("AD_ImpFormat_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_ImpFormat.setAD_ImpFormat_ID(Integer.parseInt(atts.getValue("AD_ImpFormat_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_ImpFormat", m_ImpFormat);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_ImpFormat.setName(atts.getValue("Name"));
String name = atts.getValue("ADTableNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (id <= 0) {
element.defer = true;
return;
}
m_ImpFormat.setAD_Table_ID(id);
}
m_ImpFormat.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_ImpFormat
.setProcessing(atts.getValue("isProcessing") != null ? Boolean
.valueOf(atts.getValue("isProcessing")).booleanValue()
: true);
m_ImpFormat.setName(atts.getValue("Name"));
m_ImpFormat.setDescription(getStringValue(atts,"Description"));
m_ImpFormat.setFormatType(atts.getValue("FormatType"));
if (m_ImpFormat.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat
.get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_ImpFormat"));
} else {
record_log(ctx, 0, m_ImpFormat.getName(), "ImpFormat", m_ImpFormat
.get_ID(), AD_Backup_ID, Object_Status, "AD_ImpFormat",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_ImpFormat"));
throw new POSaveFailedException("Failed to save Import Format.");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int import_id = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID);
if (formats.contains(import_id))
return;
formats.add(import_id);
AttributesImpl atts = new AttributesImpl();
X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null);
atts = createImpFormatBinding(atts, m_ImpFormat);
document.startElement("", "", "impformat", atts);
String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= " + import_id
+" ORDER BY "+X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createImpFormatRow(ctx, document, rs
.getInt("AD_ImpFormat_Row_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "ImpFormat", e);
throw new DatabaseAccessException("Failed to export Import Format.", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
document.endElement("", "", "impformat");
}
private void createImpFormatRow(Properties ctx,
TransformerHandler document, int AD_ImpFormat_Row_ID)
throws SAXException {
Env.setContext(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID,
AD_ImpFormat_Row_ID);
rowHandler.create(ctx, document);
ctx.remove(X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID);
}
private AttributesImpl createImpFormatBinding(AttributesImpl atts,
X_AD_ImpFormat m_ImpFormat) {
atts.clear();
if (m_ImpFormat.getAD_ImpFormat_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_ImpFormat_ID","CDATA",Integer.toString(m_ImpFormat.getAD_ImpFormat_ID()));
if (m_ImpFormat.getAD_Table_ID() > 0) {
String sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
String name = DB.getSQLValueString(null, sql, m_ImpFormat
.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
atts.addAttribute("", "", "Name", "CDATA",
(m_ImpFormat.getName() != null ? m_ImpFormat.getName() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_ImpFormat.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isProcessing", "CDATA", (m_ImpFormat
.isProcessing() == true ? "true" : "false"));
atts.addAttribute("", "", "Description", "CDATA", (m_ImpFormat
.getDescription() != null ? m_ImpFormat.getDescription() : ""));
atts.addAttribute("", "", "FormatType", "CDATA", (m_ImpFormat
.getFormatType() != null ? m_ImpFormat.getFormatType() : ""));
return atts;
}
}

View File

@ -1,169 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_ImpFormat_Row;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ImpFormatRowElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("Name"));
int impformid = get_ID(ctx, "AD_ImpFormat", atts.getValue("ADImpFormatNameID"));
if (impformid <= 0) {
element.defer = true;
return;
}
String name = atts.getValue("ADTableNameID");
int tableid = 0;
if (name != null && name.trim().length() > 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (tableid <= 0) {
element.defer = true;
return;
}
}
name = atts.getValue("ADColumnNameID");
int columnid = 0;
if (name != null && name.trim().length() > 0) {
columnid = get_IDWithMasterAndColumn (ctx, "AD_Column","ColumnName", name, "AD_Table", tableid);
if (columnid <= 0) {
element.defer = true;
return;
}
}
StringBuffer sqlB = new StringBuffer ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? and AD_ImpFormat_ID=?");
int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnid,impformid);
X_AD_ImpFormat_Row m_ImpFormat_row = new X_AD_ImpFormat_Row(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_ImpFormat_Row_ID") != null && Integer.parseInt(atts.getValue("AD_ImpFormat_Row_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_ImpFormat_row.setAD_ImpFormat_Row_ID(Integer.parseInt(atts.getValue("AD_ImpFormat_Row_ID")));
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_ImpFormat",m_ImpFormat_row);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
m_ImpFormat_row.setName(atts.getValue("Name"));
m_ImpFormat_row.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
if (columnid > 0)
m_ImpFormat_row.setAD_Column_ID(columnid);
m_ImpFormat_row.setAD_ImpFormat_ID(impformid);
m_ImpFormat_row.setDataFormat(atts.getValue("DataFormat"));
m_ImpFormat_row.setDataType(atts.getValue("DataType"));
m_ImpFormat_row.setDecimalPoint(atts.getValue("DecimalPoint"));
m_ImpFormat_row.setDivideBy100(atts.getValue("isDivideBy100") != null ? Boolean.valueOf(atts.getValue("isDivideBy100")).booleanValue():true);
m_ImpFormat_row.setConstantValue(atts.getValue("ConstantValue"));
m_ImpFormat_row.setCallout(atts.getValue("Callout"));
m_ImpFormat_row.setEndNo(Integer.parseInt(atts.getValue("EndNo")));
m_ImpFormat_row.setScript(atts.getValue("Script"));
m_ImpFormat_row.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_ImpFormat_row.setStartNo(Integer.parseInt(atts.getValue("StartNo")));
if (m_ImpFormat_row.save(getTrxName(ctx)) == true){
record_log (ctx, 1, m_ImpFormat_row.getName(),"ImpFormatRow", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn(ctx, "AD_Table", "TableName", "m_ImpFormat_row"));
}
else{
record_log (ctx, 0, m_ImpFormat_row.getName(),"ImpFormatRow", m_ImpFormat_row.get_ID(),AD_Backup_ID, Object_Status,"AD_ImpFormat",get_IDWithColumn(ctx, "AD_Table", "TableName", "m_ImpFormat_row"));
throw new POSaveFailedException("Failed to import Import Format Row.");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_ImpFormat_Row_ID = Env.getContextAsInt(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID);
X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx, AD_ImpFormat_Row_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createImpFormatRowBinding(atts,m_ImpFormat_Row);
document.startElement("","","impformatrow",atts);
document.endElement("","","impformatrow");
}
private AttributesImpl createImpFormatRowBinding( AttributesImpl atts, X_AD_ImpFormat_Row m_ImpFormat_Row)
{
String sql = null;
String name = null;
atts.clear();
if (m_ImpFormat_Row.getAD_ImpFormat_ID()> 0 ){
sql = "SELECT Name FROM AD_ImpFormat WHERE AD_ImpFormat_ID=?";
name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_ImpFormat_ID());
atts.addAttribute("","","ADImpFormatNameID","CDATA",name);
}
else
atts.addAttribute("","","ADImpFormatNameID","CDATA","");
if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_Column_ID());
atts.addAttribute("","","ADColumnNameID","CDATA",name);
}
else
atts.addAttribute("","","ADColumnNameID","CDATA","");
if (m_ImpFormat_Row.getAD_Column_ID()> 0 ){
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int idTable = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID());
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null,sql,idTable);
atts.addAttribute("","","ADTableNameID","CDATA",name);
}
else
atts.addAttribute("","","ADTableNameID","CDATA","");
if (m_ImpFormat_Row.getAD_ImpFormat_Row_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_ImpFormat_Row_ID","CDATA",Integer.toString(m_ImpFormat_Row.getAD_ImpFormat_Row_ID()));
atts.addAttribute("","","Name","CDATA",(m_ImpFormat_Row.getName () != null ? m_ImpFormat_Row.getName ():""));
atts.addAttribute("","","SeqNo","CDATA",""+m_ImpFormat_Row.getSeqNo());
atts.addAttribute("","","StartNo","CDATA",""+m_ImpFormat_Row.getStartNo());
atts.addAttribute("","","EndNo","CDATA",""+m_ImpFormat_Row.getEndNo());
atts.addAttribute("","","DataType","CDATA",(m_ImpFormat_Row.getDataType () != null ? m_ImpFormat_Row.getDataType():""));
atts.addAttribute("","","DataFormat","CDATA",(m_ImpFormat_Row.getDataFormat () != null ? m_ImpFormat_Row.getDataFormat():""));
atts.addAttribute("","","DecimalPoint","CDATA",(m_ImpFormat_Row.getDecimalPoint () != null ? m_ImpFormat_Row.getDecimalPoint():""));
atts.addAttribute("","","isDivideBy100","CDATA",(m_ImpFormat_Row.isDivideBy100 ()== true ? "true":"false"));
atts.addAttribute("","","ConstantValue","CDATA",(m_ImpFormat_Row.getConstantValue() != null ? m_ImpFormat_Row.getConstantValue():""));
atts.addAttribute("","","Callout","CDATA",(m_ImpFormat_Row.getCallout() != null ? m_ImpFormat_Row.getCallout():""));
atts.addAttribute("","","Script","CDATA",(m_ImpFormat_Row.getScript() != null ? m_ImpFormat_Row.getScript():""));
atts.addAttribute("","","isActive","CDATA",(m_ImpFormat_Row.isActive()== true ? "true":"false"));
return atts;
}
}

View File

@ -1,503 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_BUTTON;
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.compiere.model.X_AD_Menu;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class MenuElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ADMenuNameID"));
// String entitytype = atts.getValue("EntityType");
// if (entitytype.compareTo("U") == 0 || entitytype.compareTo("D") == 0
// && m_UpdateMode == true ) {
String name = null;
int idDetail = 0;
StringBuffer sqlB = null;
name = atts.getValue("ADMenuNameID");
int menuid = get_IDWithColumn(ctx, "AD_Menu", "Name", name);
X_AD_Menu m_Menu = new X_AD_Menu(ctx, menuid, getTrxName(ctx));
if (menuid <= 0 && atts.getValue("AD_Menu_ID") != null && Integer.parseInt(atts.getValue("AD_Menu_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Menu.setAD_Menu_ID(Integer.parseInt(atts.getValue("AD_Menu_ID")));
if (menuid > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Menu", m_Menu);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Menu.setName(name);
name = atts.getValue("ADWindowNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Window_ID(id);
}
name = atts.getValue("ADProcessNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Process_ID(id);
}
name = atts.getValue("ADFormNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Form_ID(id);
}
name = atts.getValue("ADTaskNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Task", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Task_ID(id);
}
/*name = atts.getValue("ADWorkbenchNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Workbench", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Workbench_ID(id);
}*/
name = atts.getValue("ADWorkflowNameID");
if (name != null && name.trim().length() > 0) {
int id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Menu.setAD_Workflow_ID(id);
}
String action = (atts.getValue("Action") != null ? atts
.getValue("Action") : " ");
if (action.compareTo(" ") > -1)
m_Menu.setAction(action);
m_Menu.setDescription(getStringValue(atts, "Description"));
m_Menu.setEntityType(atts.getValue("EntityType"));
m_Menu.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly"))
.booleanValue());
m_Menu.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx"))
.booleanValue());
m_Menu.setIsSummary(Boolean.valueOf(atts.getValue("isSummary"))
.booleanValue());
m_Menu.setIsActive(Boolean.valueOf(atts.getValue("isActive"))
.booleanValue());
if (m_Menu.save(getTrxName(ctx)) == true) {
try {
idDetail = record_log(ctx, 1, m_Menu.getName(), "Menu", m_Menu
.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Menu"));
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info("setmenu:" + e);
}
} else {
try {
idDetail = record_log(ctx, 0, m_Menu.getName(), "Menu", m_Menu
.get_ID(), AD_Backup_ID, Object_Status, "AD_Menu",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Menu"));
} catch (SAXException e) {
if (log.isLoggable(Level.INFO)) log.info("setmenu:" + e);
}
}
name = atts.getValue("ADParentMenuNameID");
int id = get_ID(ctx, "AD_Menu", name);
String sql2 = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10"
+ " AND Node_ID = " + menuid;
int countRecords = DB.getSQLValue(getTrxName(ctx), sql2);
if (countRecords > 0) {
StringBuffer sqlC = new StringBuffer(
"select * from AD_TREENODEMM where AD_Tree_ID = 10 and "
+ " Node_ID =?");
try {
PreparedStatement pstmt1 = DB.prepareStatement(sqlC.toString(),
getTrxName(ctx));
pstmt1.setInt(1, menuid);
ResultSet rs1 = pstmt1.executeQuery();
if (rs1.next()) {
String colValue = null;
ResultSetMetaData meta = rs1.getMetaData();
int columns = meta.getColumnCount();
int tableID = get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_TreeNodeMM");
for (int q = 1; q <= columns; q++) {
String col_Name = meta.getColumnName(q);
StringBuffer sql = new StringBuffer(
"SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = '"
+ col_Name + "' AND AD_Table_ID = ?");
int columnID = DB.getSQLValue(getTrxName(ctx), sql
.toString(), tableID);
sql = new StringBuffer(
"SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = "
+ (columnID == -1 ? "null" : columnID));
int referenceID = DB.getSQLValue(getTrxName(ctx), sql
.toString());
int idBackup = DB.getNextID(Env
.getAD_Client_ID(ctx), "AD_Package_Imp_Backup",
getTrxName(ctx));
if (referenceID == REFERENCE_DATATYPE_YES_NO || referenceID == REFERENCE_DATATYPE_BUTTON)
if (rs1.getObject(q).equals("Y"))
colValue = "true";
else
colValue = "false";
else
colValue = rs1.getObject(q).toString();
StringBuffer sqlD = new StringBuffer(
"INSERT INTO AD_Package_Imp_Backup"
+ "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, "
+ "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID,"
+ " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)"
+ "VALUES(" + " "
+ Env.getAD_Client_ID(ctx)
+ ", "
+ Env.getAD_Org_ID(ctx)
+ ", "
+ Env.getAD_User_ID(ctx)
+ ", "
+ Env.getAD_User_ID(ctx)
+ ", "
+ idBackup
+ ", "
+ idDetail
+ ", "
+ getPackageImpId(ctx)
+ ", "
+ tableID
+ ", "
+ (columnID == -1 ? "null" : columnID)
+ ", "
+ (referenceID == -1 ? "null" : referenceID)
+ ", '" + colValue + "')");
int no = DB.executeUpdate(sqlD.toString(),
getTrxName(ctx));
if (no == -1)
log.info("Insert to import backup failed");
}
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info("get_IDWithMasterID:" + e);
}
sqlB = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + id).append(
" , SeqNo = " + atts.getValue("ADParentSeqno")).append(
" WHERE AD_Tree_ID = 10").append(
" AND Node_ID = " + m_Menu.getAD_Menu_ID());
} else {
sqlB = new StringBuffer("INSERT INTO AD_TREENODEMM").append(
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append(
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append(
"VALUES(0, 0, 0, 0, ").append(
id + "," + atts.getValue("ADParentSeqno") + ", 10, "
+ m_Menu.getAD_Menu_ID() + ")");
}
DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Menu_ID = Env.getContextAsInt(ctx, "AD_Menu_ID");
X_AD_Menu m_Menu = new X_AD_Menu(ctx, AD_Menu_ID, null);
if (m_Menu.isSummary() == false) {
createApplication(ctx, document, AD_Menu_ID);
} else {
AttributesImpl atts = new AttributesImpl();
createMenuBinding(atts, m_Menu);
document.startElement("", "", "menu", atts);
createModule(ctx, document, AD_Menu_ID);
document.endElement("", "", "menu");
}
}
private AttributesImpl createMenuBinding(AttributesImpl atts,
X_AD_Menu m_Menu) {
String sql = null;
String name = null;
atts.clear();
if (m_Menu.getAD_Menu_ID() > 0) {
sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Menu_ID());
atts.addAttribute("", "", "ADMenuNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADMenuNameID", "CDATA", "");
if (m_Menu.getAD_Window_ID() > 0) {
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Window_ID());
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
if (m_Menu.getAD_Process_ID() > 0) {
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADProcessNameID", "CDATA", "");
if (m_Menu.getAD_Form_ID() > 0) {
sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Form_ID());
atts.addAttribute("", "", "ADFormNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADFormNameID", "CDATA", "");
if (m_Menu.getAD_Task_ID() > 0) {
sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Task_ID());
atts.addAttribute("", "", "ADTaskNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
/*if (m_Menu.getAD_Workbench_ID() > 0) {
sql = "SELECT Name FROM AD_Workbench WHERE AD_Workbench_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Workbench_ID());
atts.addAttribute("", "", "ADWorkbenchNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADWorkbenchNameID", "CDATA", "");*/
if (m_Menu.getAD_Workflow_ID() > 0) {
sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?";
name = DB.getSQLValueString(null, sql, m_Menu.getAD_Workflow_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", "");
sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
if (id > 0) {
sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?";
name = DB.getSQLValueString(null, sql, id);
atts.addAttribute("", "", "ADParentMenuNameID", "CDATA", name);
}
sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Menu_ID","CDATA",Integer.toString(m_Menu.getAD_Menu_ID()));
atts.addAttribute("", "", "ADParentSeqno", "CDATA", "" + id);
atts.addAttribute("", "", "Action", "CDATA",
(m_Menu.getAction() != null ? m_Menu.getAction() : ""));
atts.addAttribute("", "", "Description", "CDATA", (m_Menu
.getDescription() != null ? m_Menu.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Menu
.getEntityType() != null ? m_Menu.getEntityType() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Menu.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isReadOnly", "CDATA",
(m_Menu.isReadOnly() == true ? "true" : "false"));
atts.addAttribute("", "", "isSOTrx", "CDATA",
(m_Menu.isSOTrx() == true ? "true" : "false"));
atts.addAttribute("", "", "isSummary", "CDATA",
(m_Menu.isSummary() == true ? "true" : "false"));
return atts;
}
private void createApplication(Properties ctx, TransformerHandler document,
int AD_Menu_ID) throws SAXException {
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
String sql = null;
// int x = 0;
sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, "
+ "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID "
+ "FROM AD_TreeNoDemm A, AD_Menu B "
+ "WHERE A.Node_ID = "
+ AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID";
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null);
atts = createMenuBinding(atts, m_Menu);
document.startElement("", "", "menu", atts);
if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0
|| rs.getInt("AD_TASK_ID") > 0
|| rs.getInt("AD_PROCESS_ID") > 0
|| rs.getInt("AD_FORM_ID") > 0
|| rs.getInt("AD_WORKBENCH_ID") > 0) {
// Call CreateWindow.
if (rs.getInt("AD_WINDOW_ID") > 0) {
packOut.createWindow(rs.getInt("AD_WINDOW_ID"), document);
}
// Call CreateProcess.
else if (rs.getInt("AD_PROCESS_ID") > 0) {
packOut.createProcess(rs.getInt("AD_PROCESS_ID"), document);
}
// Call CreateTask.
else if (rs.getInt("AD_TASK_ID") > 0) {
packOut.createTask(rs.getInt("AD_TASK_ID"), document);
}
// Call CreateForm.
else if (rs.getInt("AD_FORM_ID") > 0) {
packOut.createForm(rs.getInt("AD_FORM_ID"), document);
}
// Call CreateWorkflow
else if (rs.getInt("AD_Workflow_ID") > 0) {
packOut.createWorkflow(rs.getInt("AD_Workflow_ID"),
document);
}
// Call CreateModule because entry is a summary menu
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", "menu");
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
public void createModule(Properties ctx, TransformerHandler document,
int menu_id) throws SAXException {
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
String sql = null;
sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, "
+ "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID "
+ "FROM AD_TreeNoDemm A, AD_Menu B "
+ "WHERE A.Parent_ID = "
+ menu_id + " AND A.Node_ID = B.AD_Menu_ID";
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
// Menu tag Start.
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null);
atts = createMenuBinding(atts, m_Menu);
document.startElement("", "", "menu", atts);
if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0
|| rs.getInt("AD_TASK_ID") > 0
|| rs.getInt("AD_PROCESS_ID") > 0
|| rs.getInt("AD_FORM_ID") > 0
|| rs.getInt("AD_WORKBENCH_ID") > 0) {
// Call CreateWindow.
if (rs.getInt("AD_WINDOW_ID") > 0) {
packOut.createWindow(rs.getInt("AD_WINDOW_ID"), document);
}
// Call CreateProcess.
else if (rs.getInt("AD_PROCESS_ID") > 0) {
packOut.createProcess(rs.getInt("AD_PROCESS_ID"),
document);
}
// Call CreateTask.
else if (rs.getInt("AD_TASK_ID") > 0) {
packOut.createTask(rs.getInt("AD_TASK_ID"), document);
}
// Call CreateForm.
else if (rs.getInt("AD_FORM_ID") > 0) {
packOut.createForm(rs.getInt("AD_FORM_ID"), document);
}
// Call CreateWorkflow
else if (rs.getInt("AD_Workflow_ID") > 0) {
packOut.createWorkflow(rs.getInt("AD_Workflow_ID"),
document);
}
// Call CreateModule because entry is a summary menu
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", "menu");
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
}

View File

@ -1,147 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MMessage;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Message;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class MessageElementHandler extends AbstractElementHandler {
private List<Integer> messages = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("Value"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String value = atts.getValue("Value");
int id = get_IDWithColumn(ctx, "AD_Message", "value", value);
MMessage m_Message = new MMessage(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Message_ID") != null && Integer.parseInt(atts.getValue("AD_Message_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Message.setAD_Message_ID(Integer.parseInt(atts.getValue("AD_Message_ID")));
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_Message",m_Message);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
m_Message.setMsgText(getStringValue(atts, "MsgText"));
m_Message.setMsgTip(getStringValue(atts, "MsgTip"));
m_Message.setEntityType(atts.getValue("EntityType"));
m_Message.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_Message.setValue(value);
m_Message.setMsgType(atts.getValue("MsgType"));
if (m_Message.save(getTrxName(ctx)) == true){
record_log (ctx, 1, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Message"));
}
else{
record_log (ctx, 0, m_Message.getValue(),"Message", m_Message.get_ID(),AD_Backup_ID, Object_Status,"AD_Message",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Message"));
throw new POSaveFailedException("Failed to save message.");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document) throws SAXException
{
for (X_AD_Message message : getMessages(ctx))
{
if (messages.contains(message.getAD_Message_ID()))
continue;
messages.add(message.getAD_Message_ID());
//
AttributesImpl atts = new AttributesImpl();
createMessageBinding(atts, message);
document.startElement("","","message",atts);
document.endElement("","","message");
}
}
private List<X_AD_Message> getMessages(Properties ctx)
{
int AD_Message_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID);
int AD_EntityType_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
String whereClause;
Object[] params;
if (AD_Message_ID > 0)
{
whereClause = X_AD_Message.COLUMNNAME_AD_Message_ID+"=?";
params = new Object[]{AD_Message_ID};
}
else if (AD_EntityType_ID > 0)
{
whereClause = " EXISTS (SELECT 1 FROM AD_EntityType et"
+" WHERE et.AD_EntityType_ID=? AND et.EntityType=AD_Message.EntityType)";
params = new Object[]{AD_EntityType_ID};
}
else
{
throw new IllegalArgumentException("AD_Message_ID and AD_EntityType_ID not found");
}
List<X_AD_Message> list = new Query(ctx, X_AD_Message.Table_Name, whereClause, null)
.setParameters(params)
.setOrderBy(X_AD_Message.COLUMNNAME_AD_Message_ID)
.list();
return list;
}
private AttributesImpl createMessageBinding( AttributesImpl atts, X_AD_Message m_Message)
{
atts.clear();
if (m_Message.getAD_Message_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Message_ID","CDATA",Integer.toString(m_Message.getAD_Message_ID()));
//FIXME: may not need this I guess
//atts.addAttribute("","","AccessLevel","CDATA",(m_Message.getAccessLevel () != null ? m_Message.getAccessLevel ():""));
atts.addAttribute("","","MsgText","CDATA",(m_Message.getMsgText() != null ? m_Message.getMsgText():""));
atts.addAttribute("","","MsgType","CDATA",(m_Message.getMsgType() != null ? m_Message.getMsgType ():""));
atts.addAttribute("","","MsgTip","CDATA",(m_Message.getMsgTip() != null ? m_Message.getMsgTip ():""));
atts.addAttribute("","","Value","CDATA",(m_Message.getValue() != null ? m_Message.getValue ():""));
atts.addAttribute("","","EntityType","CDATA",(m_Message.getEntityType () != null ? m_Message.getEntityType ():""));
atts.addAttribute("","","isActive","CDATA",(m_Message.isActive()== true ? "true":"false"));
return atts;
}
}

View File

@ -1,172 +0,0 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2009 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. *
* *
* Copyright (C) 2009 Teo Sarca, teo.sarca@gmail.com *
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.I_AD_ModelValidator;
import org.compiere.model.PO;
import org.compiere.model.X_AD_ModelValidator;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* @author Teo Sarca, teo.sarca@gmail.com
* <li>FR [ 2847669 ] 2pack export model validator functionality
* https://sourceforge.net/tracker/?func=detail&aid=2847669&group_id=176962&atid=879335
*/
public class ModelValidatorElementHandler extends AbstractElementHandler
{
public static final String TAG_Name = "modelvalidator";
private final List<Integer> validators = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException
{
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue(I_AD_ModelValidator.COLUMNNAME_Name));
String entitytype = atts.getValue(I_AD_ModelValidator.COLUMNNAME_EntityType);
if (isProcessElement(ctx, entitytype))
{
String name = atts.getValue(I_AD_ModelValidator.COLUMNNAME_Name);
int id = get_IDWithColumn(ctx, I_AD_ModelValidator.Table_Name, I_AD_ModelValidator.COLUMNNAME_Name, name);
final X_AD_ModelValidator validator = new X_AD_ModelValidator(ctx, id, getTrxName(ctx));
final int AD_Backup_ID;
final String Object_Status;
if (id <= 0 && getIntValue(atts, I_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID, 0) <= PackOut.MAX_OFFICIAL_ID)
{
validator.setAD_ModelValidator_ID(getIntValue(atts, I_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID, 0));
}
if (id > 0)
{
AD_Backup_ID = copyRecord(ctx, I_AD_ModelValidator.Table_Name, validator);
Object_Status = "Update";
}
else
{
Object_Status = "New";
AD_Backup_ID = 0;
}
validator.setName(name);
validator.setDescription(getStringValue(atts, I_AD_ModelValidator.COLUMNNAME_Description));
validator.setHelp(getStringValue(atts, I_AD_ModelValidator.COLUMNNAME_Help));
validator.setEntityType(atts.getValue(I_AD_ModelValidator.COLUMNNAME_EntityType));
validator.setModelValidationClass(atts.getValue(I_AD_ModelValidator.COLUMNNAME_ModelValidationClass));
validator.setIsActive(getBooleanValue(atts, I_AD_ModelValidator.COLUMNNAME_IsActive, true));
validator.setSeqNo(getIntValue(atts, I_AD_ModelValidator.COLUMNNAME_SeqNo, 0));
if (validator.save(getTrxName(ctx)) == true)
{
record_log (ctx, 1, validator.getName(),TAG_Name, validator.get_ID(),
AD_Backup_ID, Object_Status,
I_AD_ModelValidator.Table_Name, I_AD_ModelValidator.Table_ID);
}
else
{
record_log (ctx, 0, validator.getName(),TAG_Name, validator.get_ID(),
AD_Backup_ID, Object_Status,
I_AD_ModelValidator.Table_Name, I_AD_ModelValidator.Table_ID);
throw new POSaveFailedException("Failed to save message.");
}
}
else
{
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException
{
}
public void create(Properties ctx, TransformerHandler document) throws SAXException
{
final int AD_ModelValidator_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_ModelValidator_ID);
if (validators.contains(AD_ModelValidator_ID))
return;
validators.add(AD_ModelValidator_ID);
final X_AD_ModelValidator validator = new X_AD_ModelValidator(ctx, AD_ModelValidator_ID, null);
AttributesImpl atts = new AttributesImpl();
createMessageBinding(atts, validator);
document.startElement("", "", TAG_Name, atts);
document.endElement("", "", TAG_Name);
}
private AttributesImpl createMessageBinding(AttributesImpl atts, X_AD_ModelValidator validator)
{
atts.clear();
if (validator.getAD_ModelValidator_ID() <= PackOut.MAX_OFFICIAL_ID)
{
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_AD_ModelValidator_ID, validator);
}
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_Name, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_Description, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_Help, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_ModelValidationClass, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_EntityType, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_IsActive, validator);
addAttribute(atts, X_AD_ModelValidator.COLUMNNAME_SeqNo, validator);
return atts;
}
protected boolean getBooleanValue(Attributes atts, String qName, boolean defaultValue)
{
String s = atts.getValue(qName);
return s != null ? Boolean.valueOf(s) : defaultValue;
}
protected int getIntValue(Attributes atts, String qName, int defaultValue)
{
Object o = atts.getValue(qName);
if (o == null)
return defaultValue;
if (o instanceof Number)
return ((Number)o).intValue();
return Integer.parseInt(o.toString());
}
private final void addAttribute(AttributesImpl atts, String name, PO po)
{
Object value = po.get_Value(name);
atts.addAttribute("", "", name, "CDATA", toStringAttribute(value));
}
private final String toStringAttribute(Object value)
{
if (value == null)
return "";
if (value instanceof Boolean)
return ((Boolean)value).booleanValue() == true ? "true" : "false";
return value.toString();
}
}

View File

@ -1,132 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class OrgRoleElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int orgid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (atts.getValue("orgname")!=null){
String name = atts.getValue("orgname");
sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?");
orgid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Role_OrgAccess WHERE AD_Role_ID=? and AD_Org_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,orgid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Role_OrgAccess ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadOnly = '" + atts.getValue("isReadOnly") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Org_ID = " + orgid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Update to org access failed");
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Role_OrgAccess")
.append( "(AD_Client_ID, CreatedBy, UpdatedBy, " )
.append( "AD_Role_ID, AD_Org_ID, isActive, isReadOnly) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + roleid )
.append( ", " + orgid )
.append( ", '" + atts.getValue("isActive") )
.append( "', '" + atts.getValue("isReadOnly")+"')");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to org access failed");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createOrgAccessBinding(atts, AD_Org_ID, AD_Role_ID);
document.startElement("", "", "OrgAccess", atts);
document.endElement("", "", "OrgAccess");
}
private AttributesImpl createOrgAccessBinding(AttributesImpl atts,
int org_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
name = DB.getSQLValueString(null, sql, org_id);
atts.addAttribute("", "", "orgname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Role_OrgAccess WHERE AD_Org_ID="
+ org_id + " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadOnly FROM AD_Role_OrgAccess WHERE AD_Org_ID="
+ org_id + " and AD_Role_ID=?";
String isReadOnly = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadOnly", "CDATA", isReadOnly);
return atts;
}
}

View File

@ -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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MPreference;
import org.compiere.model.X_AD_Preference;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PreferenceElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
// TODO Add User_ID
Attributes atts = element.attributes;
int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
if (windowid <= 0) {
element.defer = true;
return;
}
StringBuffer sqlB = new StringBuffer(
"select AD_Preference_ID from AD_Preference where ").append(
" Attribute = '" + atts.getValue("Attribute") + "'").append(
" and AD_Window_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), windowid);
MPreference m_Preference = new MPreference(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Preference_ID") != null && Integer.parseInt(atts.getValue("AD_Preference_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Preference.setAD_Preference_ID(Integer.parseInt(atts.getValue("AD_Preference_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Preference", m_Preference);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
sqlB = null;
m_Preference.setAD_Window_ID(windowid);
m_Preference.setAttribute(atts.getValue("Attribute"));
m_Preference.setValue(atts.getValue("Value"));
if (m_Preference.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Preference.getAttribute(), "Preference",
m_Preference.get_ID(), AD_Backup_ID, Object_Status,
"AD_Preference", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Preference"));
} else {
record_log(ctx, 0, m_Preference.getAttribute(), "Preference",
m_Preference.get_ID(), AD_Backup_ID, Object_Status,
"AD_Preference", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Preference"));
throw new POSaveFailedException("Failed to save Preference");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Preference_ID = Env.getContextAsInt(ctx,
X_AD_Preference.COLUMNNAME_AD_Preference_ID);
X_AD_Preference m_Preference = new X_AD_Preference(ctx,
AD_Preference_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createPreferenceBinding(atts, m_Preference);
document.startElement("", "", "preference", atts);
document.endElement("", "", "preference");
}
private AttributesImpl createPreferenceBinding(AttributesImpl atts,
X_AD_Preference m_Preference) {
String sql = null;
String name = null;
atts.clear();
if (m_Preference.getAD_Preference_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Preference_ID","CDATA",Integer.toString(m_Preference.getAD_Preference_ID()));
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, m_Preference.getAD_Window_ID());
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
name = DB.getSQLValueString(null, sql, m_Preference.getAD_User_ID());
atts.addAttribute("", "", "ADUserNameID", "CDATA", name);
atts.addAttribute("", "", "Attribute", "CDATA", m_Preference
.getAttribute());
atts.addAttribute("", "", "Value", "CDATA", m_Preference.getValue());
return atts;
}
}

View File

@ -1,355 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, SC ARHIPAC SERVICE SRL
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_PrintFormat;
import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PrintFormatElementHandler extends AbstractElementHandler {
private PrintFormatItemElementHandler itemHandler = new PrintFormatItemElementHandler();
private List<Integer> formats = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String name = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
X_AD_PrintFormat m_PrintFormat = new X_AD_PrintFormat(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_PrintFormat_ID") != null && Integer.parseInt(atts.getValue("AD_PrintFormat_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_PrintFormat.setAD_PrintFormat_ID(Integer.parseInt(atts.getValue("AD_PrintFormat_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_PrintFormat", m_PrintFormat);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
name = atts.getValue("ADReportviewnameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormat.setAD_ReportView_ID(id);
}
name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (id == 0) {
MTable m_Table = new MTable(ctx, 0, getTrxName(ctx));
m_Table.setAccessLevel("3");
m_Table.setName(name);
m_Table.setTableName(name);
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table",
m_Table.get_ID(), 0, "New", "AD_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Table"));
} else {
record_log(ctx, 0, m_Table.getName(), "Table",
m_Table.get_ID(), 0, "New", "AD_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Table"));
}
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
}
m_PrintFormat.setAD_Table_ID(id);
name = atts.getValue("ADPrintTableFormatID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintTableFormat", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormat.setAD_PrintTableFormat_ID(id);
}
name = atts.getValue("ADPrintColorID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintColor", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormat.setAD_PrintColor_ID(id);
}
name = atts.getValue("ADPrintFontID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintFont", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormat.setAD_PrintFont_ID(id);
}
name = atts.getValue("ADPrintPaperID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintPaper", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormat.setAD_PrintPaper_ID(id);
}
m_PrintFormat.setDescription(getStringValue(atts, "Description"));
m_PrintFormat.setName(atts.getValue("Name"));
m_PrintFormat.setPrinterName(getStringValue(atts, "PrinterName"));
m_PrintFormat.setFooterMargin(Integer.parseInt(atts
.getValue("FooterMargin")));
m_PrintFormat.setHeaderMargin(Integer.parseInt(atts
.getValue("HeaderMargin")));
m_PrintFormat.setCreateCopy(atts.getValue("CreateCopy"));
m_PrintFormat.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_PrintFormat.setIsTableBased(Boolean.valueOf(
atts.getValue("isTableBased")).booleanValue());
m_PrintFormat.setIsForm(Boolean.valueOf(atts.getValue("isForm"))
.booleanValue());
m_PrintFormat.setIsStandardHeaderFooter(Boolean.valueOf(
atts.getValue("isStandardHeader")).booleanValue());
m_PrintFormat.setIsDefault(Boolean.valueOf(atts.getValue("isDefault"))
.booleanValue());
if (m_PrintFormat.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_PrintFormat.getName(), "PrintFormat",
m_PrintFormat.get_ID(), AD_Backup_ID, Object_Status,
"AD_PrintFormat", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_PrintFormat"));
element.recordId = m_PrintFormat.getAD_PrintFormat_ID();
} else {
record_log(ctx, 0, m_PrintFormat.getName(), "PrintFormat",
m_PrintFormat.get_ID(), AD_Backup_ID, Object_Status,
"AD_PrintFormat", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_PrintFormat"));
throw new POSaveFailedException("Failed to save Print Format");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_PrintFormat_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID);
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
if (formats.contains(AD_PrintFormat_ID))
return;
formats.add(AD_PrintFormat_ID);
AttributesImpl atts = new AttributesImpl();
String sql = null;
sql = "SELECT AD_PrintFormat_ID "
+ "FROM AD_PrintFormat "
+ "WHERE (AD_PrintFormat_ID IN "
+ "(SELECT AD_PrintFormatChild_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID = "
+ AD_PrintFormat_ID + " AND PrintFormatType = 'P' GROUP BY AD_PrintFormatChild_ID) OR AD_PrintFormat_ID = "
+ AD_PrintFormat_ID + ")";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_PrintFormat m_Printformat = new X_AD_PrintFormat(ctx, rs.getInt("AD_PrintFormat_ID"), null);
if (m_Printformat.getAD_PrintPaper_ID() > 0)
packOut.createPrintPaper(m_Printformat.getAD_PrintPaper_ID(), document);
createPrintFormatBinding(atts, m_Printformat);
document.startElement("", "", "printformat", atts);
String sql2 = "SELECT * FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= "
+ m_Printformat.getAD_PrintFormat_ID()
+ " ORDER BY "+X_AD_PrintFormatItem.COLUMNNAME_SeqNo+","+X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID;
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement(sql2, getTrxName(ctx));
try {
ResultSet rs2 = pstmt2.executeQuery();
while (rs2.next()) {
createItem(ctx, document, rs2
.getInt("AD_PrintFormatItem_ID"));
}
rs2.close();
pstmt2.close();
pstmt2 = null;
} finally {
try {
if (pstmt2 != null)
pstmt2.close();
} catch (Exception e) {
}
pstmt2 = null;
}
document.endElement("", "", "printformat");
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export print format.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export print format.", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
private void createItem(Properties ctx, TransformerHandler document,
int AD_PrintFormatItem_ID) throws SAXException {
Env.setContext(ctx,
X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID,
AD_PrintFormatItem_ID);
itemHandler.create(ctx, document);
ctx.remove(X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID);
}
private AttributesImpl createPrintFormatBinding(AttributesImpl atts,
X_AD_PrintFormat m_Printformat) {
String sql = null;
String name = null;
atts.clear();
if (m_Printformat.getAD_PrintFormat_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_PrintFormat_ID","CDATA",Integer.toString(m_Printformat.getAD_PrintFormat_ID()));
if (m_Printformat.getAD_ReportView_ID() > 0) {
sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_ReportView_ID());
atts.addAttribute("", "", "ADReportviewnameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReportviewnameID", "CDATA", "");
if (m_Printformat.getAD_Table_ID() > 0) {
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (m_Printformat.getAD_PrintTableFormat_ID() > 0) {
sql = "SELECT Name FROM AD_PrintTableFormat WHERE AD_PrintTableFormat_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_PrintTableFormat_ID());
atts.addAttribute("", "", "ADPrintTableFormatID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintTableFormatID", "CDATA", "");
if (m_Printformat.getAD_PrintColor_ID() > 0) {
sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_PrintColor_ID());
atts.addAttribute("", "", "ADPrintColorID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintColorID", "CDATA", "");
if (m_Printformat.getAD_PrintFont_ID() > 0) {
sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_PrintFont_ID());
atts.addAttribute("", "", "ADPrintFontID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintFontID", "CDATA", "");
if (m_Printformat.getAD_PrintPaper_ID() > 0) {
sql = "SELECT Name FROM AD_PrintPaper WHERE AD_PrintPaper_ID=?";
name = DB.getSQLValueString(null, sql, m_Printformat
.getAD_PrintPaper_ID());
atts.addAttribute("", "", "ADPrintPaperID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintPaperID", "CDATA", "");
atts.addAttribute("", "", "Description", "CDATA",
(m_Printformat.getDescription() != null ? m_Printformat
.getDescription() : ""));
atts
.addAttribute("", "", "Name", "CDATA",
(m_Printformat.getName() != null ? m_Printformat
.getName() : ""));
atts.addAttribute("", "", "PrinterName", "CDATA",
(m_Printformat.getPrinterName() != null ? m_Printformat
.getPrinterName() : ""));
atts.addAttribute("", "", "FooterMargin", "CDATA", ""
+ m_Printformat.getFooterMargin());
atts.addAttribute("", "", "HeaderMargin", "CDATA", ""
+ m_Printformat.getHeaderMargin());
atts.addAttribute("", "", "CreateCopy", "CDATA", (m_Printformat
.getCreateCopy() != null ? m_Printformat.getCreateCopy() : ""));
atts.addAttribute("", "", "isActive", "CDATA", (m_Printformat
.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isTableBased", "CDATA", (m_Printformat
.isTableBased() == true ? "true" : "false"));
atts.addAttribute("", "", "isForm", "CDATA",
(m_Printformat.isForm() == true ? "true" : "false"));
atts.addAttribute("", "", "isStandardHeader", "CDATA", (m_Printformat
.isStandardHeaderFooter() == true ? "true" : "false"));
atts.addAttribute("", "", "isDefault", "CDATA", (m_Printformat
.isDefault() == true ? "true" : "false"));
return atts;
}
}

View File

@ -1,455 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, SC ARHIPAC SERVICE SRL
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PrintFormatItemElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
if (element.parent != null && element.parent.getElementValue().equals("printformat") &&
element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("Name");
int id = get_IDWithMaster(ctx, "AD_PrintFormatItem", name,
"AD_PrintFormat", atts.getValue("ADPrintFormatNameID"));
X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx,
id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_PrintFormatItem_ID") != null && Integer.parseInt(atts.getValue("AD_PrintFormatItem_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_PrintFormatItem.setAD_PrintFormatItem_ID(Integer.parseInt(atts.getValue("AD_PrintFormatItem_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_PrintFormatItem",
m_PrintFormatItem);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_PrintFormatItem.setName(name);
name = atts.getValue("ADPrintFormatNameID");
if (element.parent != null && element.parent.getElementValue().equals("printformat") &&
element.parent.recordId != 0) {
id = element.parent.recordId;
} else {
id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
if (element.parent != null && element.parent.getElementValue().equals("printformat") &&
id > 0) {
element.parent.recordId = id;
}
}
if (id <= 0) {
element.defer = true;
return;
}
m_PrintFormatItem.setAD_PrintFormat_ID(id);
name = atts.getValue("ADTableNameID");
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
name = atts.getValue("ADColumnNameID");
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name,
"AD_Table", tableid);
if (id > 0)
m_PrintFormatItem.setAD_Column_ID(id);
name = atts.getValue("ADPrintFormatChildNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_PrintFormat: " + name;
return;
}
m_PrintFormatItem.setAD_PrintFormatChild_ID(id);
}
name = atts.getValue("ADPrintGraphID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintGraph", "Name", name);
//TODO: export and import of ad_printgraph
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_PrintFormatItem.setAD_PrintGraph_ID(id);
}
name = atts.getValue("ADPrintColorID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintColor", "Name", name);
//TODO: export and import of ad_printcolor
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_PrintFormatItem.setAD_PrintColor_ID(id);
}
name = atts.getValue("ADPrintFontID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintFont", "Name", name);
//TODO: export and import of print font
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_PrintFormatItem.setAD_PrintFont_ID(id);
}
m_PrintFormatItem.setPrintName(getStringValue(atts, "PrintName"));
m_PrintFormatItem.setName(atts.getValue("Name"));
m_PrintFormatItem.setPrintAreaType(getStringValue(atts,"PrintAreaType"));
m_PrintFormatItem.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_PrintFormatItem.setPrintFormatType(getStringValue(atts,"PrintFormatType"));
m_PrintFormatItem.setXSpace(Integer.parseInt(atts.getValue("XSpace")));
m_PrintFormatItem.setYSpace(Integer.parseInt(atts.getValue("YSpace")));
m_PrintFormatItem.setXPosition(Integer.parseInt(atts
.getValue("Xposition")));
m_PrintFormatItem.setYPosition(Integer.parseInt(atts
.getValue("Yposition")));
m_PrintFormatItem.setMaxWidth(Integer.parseInt(atts
.getValue("MaxWidth")));
m_PrintFormatItem.setMaxHeight(Integer.parseInt(atts
.getValue("MaxHieght")));
m_PrintFormatItem.setSortNo(Integer.parseInt(atts.getValue("SortNo")));
m_PrintFormatItem.setFieldAlignmentType(getStringValue(atts
,"FieldAlignmentType"));
m_PrintFormatItem.setLineAlignmentType(getStringValue(atts
,"LineAlignmentType"));
m_PrintFormatItem.setImageURL(getStringValue(atts,"ImageURL"));
m_PrintFormatItem.setArcDiameter(Integer.parseInt(atts
.getValue("ArcDiameter")));
m_PrintFormatItem.setLineWidth(Integer.parseInt(atts
.getValue("LineWidth")));
m_PrintFormatItem.setShapeType(getStringValue(atts,"ShapeType"));
m_PrintFormatItem.setBelowColumn(Integer.parseInt(atts
.getValue("BelowColumn")));
m_PrintFormatItem.setPrintNameSuffix(getStringValue(atts,"PrintNameSuffix"));
m_PrintFormatItem.setRunningTotalLines(Integer.parseInt(atts
.getValue("RunningTotalLines")));
m_PrintFormatItem
.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
m_PrintFormatItem.setIsPrinted(Boolean.valueOf(
atts.getValue("isPrinted")).booleanValue());
m_PrintFormatItem.setIsRelativePosition(Boolean.valueOf(
atts.getValue("isRelativePosition")).booleanValue());
m_PrintFormatItem.setIsNextLine(Boolean.valueOf(
atts.getValue("isNextLine")).booleanValue());
m_PrintFormatItem.setIsHeightOneLine(Boolean.valueOf(
atts.getValue("isHeightOneLine")).booleanValue());
m_PrintFormatItem.setIsOrderBy(Boolean.valueOf(
atts.getValue("isOrderBy")).booleanValue());
m_PrintFormatItem.setIsGroupBy(Boolean.valueOf(
atts.getValue("isGroupBy")).booleanValue());
m_PrintFormatItem.setIsPageBreak(Boolean.valueOf(
atts.getValue("isPageBreak")).booleanValue());
m_PrintFormatItem.setIsSummarized(Boolean.valueOf(
atts.getValue("isSummarized")).booleanValue());
m_PrintFormatItem.setImageIsAttached(Boolean.valueOf(
atts.getValue("isImageIsAttached")).booleanValue());
m_PrintFormatItem.setIsAveraged(Boolean.valueOf(
atts.getValue("isAveraged")).booleanValue());
m_PrintFormatItem.setIsCounted(Boolean.valueOf(
atts.getValue("isCounted")).booleanValue());
m_PrintFormatItem.setIsSetNLPosition(Boolean.valueOf(
atts.getValue("isSetNLPosition")).booleanValue());
m_PrintFormatItem.setIsSuppressNull(Boolean.valueOf(
atts.getValue("isSuppressNull")).booleanValue());
m_PrintFormatItem.setIsFixedWidth(Boolean.valueOf(
atts.getValue("isFixedWidth")).booleanValue());
m_PrintFormatItem.setIsNextPage(Boolean.valueOf(
atts.getValue("isNextPage")).booleanValue());
m_PrintFormatItem.setIsMaxCalc(Boolean.valueOf(
atts.getValue("isMaxCalc")).booleanValue());
m_PrintFormatItem.setIsMinCalc(Boolean.valueOf(
atts.getValue("isMinCalc")).booleanValue());
m_PrintFormatItem.setIsRunningTotal(Boolean.valueOf(
atts.getValue("isRunningTotal")).booleanValue());
m_PrintFormatItem.setIsVarianceCalc(Boolean.valueOf(
atts.getValue("isVarianceCalc")).booleanValue());
m_PrintFormatItem.setIsDeviationCalc(Boolean.valueOf(
atts.getValue("isDeviationCalc")).booleanValue());
// BarCode Type
String barCodeType = atts.getValue(X_AD_PrintFormatItem.COLUMNNAME_BarcodeType);
m_PrintFormatItem.setBarcodeType(barCodeType);
if (m_PrintFormatItem.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_PrintFormatItem.getName(), "PrintFormatItem",
m_PrintFormatItem.get_ID(), AD_Backup_ID, Object_Status,
"AD_PrintFormatItem", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_PrintFormatItem"));
} else {
record_log(ctx, 0, m_PrintFormatItem.getName(), "PrintFormatItem",
m_PrintFormatItem.get_ID(), AD_Backup_ID, Object_Status,
"AD_PrintFormatItem", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_PrintFormatItem"));
throw new POSaveFailedException("PrintFormatItem");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_PrintFormatItem_ID = Env.getContextAsInt(ctx,
X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID);
X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx,
AD_PrintFormatItem_ID, null);
AttributesImpl atts = new AttributesImpl();
createPrintFormatItemBinding(atts, m_PrintFormatItem);
document.startElement("", "", "printformatitem", atts);
document.endElement("", "", "printformatitem");
}
private AttributesImpl createPrintFormatItemBinding(AttributesImpl atts,
X_AD_PrintFormatItem m_PrintformatItem) {
String sql = null;
String name = null;
atts.clear();
if (m_PrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_PrintFormatItem_ID","CDATA",Integer.toString(m_PrintformatItem.getAD_PrintFormatItem_ID()));
if (m_PrintformatItem.getAD_PrintFormat_ID() > 0) {
sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_PrintFormat_ID());
atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", "");
if (m_PrintformatItem.getAD_PrintFormatChild_ID() > 0) {
sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_PrintFormatChild_ID());
atts
.addAttribute("", "", "ADPrintFormatChildNameID", "CDATA",
name);
} else
atts.addAttribute("", "", "ADPrintFormatChildNameID", "CDATA", "");
if (m_PrintformatItem.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
if (m_PrintformatItem.getAD_Column_ID() > 0) {
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableID = DB.getSQLValue(null, sql, m_PrintformatItem
.getAD_Column_ID());
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, tableID);
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (m_PrintformatItem.getAD_PrintGraph_ID() > 0) {
sql = "SELECT Name FROM AD_PrintGraph WHERE AD_PrintGraph_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_PrintGraph_ID());
atts.addAttribute("", "", "ADPrintGraphID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintGraphID", "CDATA", "");
if (m_PrintformatItem.getAD_PrintColor_ID() > 0) {
sql = "SELECT Name FROM AD_PrintColor WHERE AD_PrintColor_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_PrintColor_ID());
atts.addAttribute("", "", "ADPrintColorID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintColorID", "CDATA", "");
if (m_PrintformatItem.getAD_PrintFont_ID() > 0) {
sql = "SELECT Name FROM AD_PrintFont WHERE AD_PrintFont_ID=?";
name = DB.getSQLValueString(null, sql, m_PrintformatItem
.getAD_PrintFont_ID());
atts.addAttribute("", "", "ADPrintFontID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintFontID", "CDATA", "");
atts.addAttribute("", "", "PrintName", "CDATA",
(m_PrintformatItem.getPrintName() != null ? m_PrintformatItem
.getPrintName() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_PrintformatItem.getName() != null ? m_PrintformatItem
.getName() : ""));
atts.addAttribute("", "", "PrintAreaType", "CDATA", (m_PrintformatItem
.getPrintAreaType() != null ? m_PrintformatItem
.getPrintAreaType() : ""));
atts.addAttribute("", "", "SeqNo", "CDATA", ""
+ m_PrintformatItem.getSeqNo());
atts.addAttribute("", "", "PrintFormatType", "CDATA", m_PrintformatItem
.getPrintFormatType());
atts.addAttribute("", "", "XSpace", "CDATA", ("" + m_PrintformatItem
.getXSpace()));
atts.addAttribute("", "", "YSpace", "CDATA", ("" + m_PrintformatItem
.getYSpace()));
atts.addAttribute("", "", "Xposition", "CDATA", ("" + m_PrintformatItem
.getXPosition()));
atts.addAttribute("", "", "Yposition", "CDATA", ("" + m_PrintformatItem
.getYPosition()));
atts.addAttribute("", "", "MaxWidth", "CDATA", ("" + m_PrintformatItem
.getMaxWidth()));
atts.addAttribute("", "", "MaxHieght", "CDATA", ("" + m_PrintformatItem
.getMaxHeight()));
atts.addAttribute("", "", "SortNo", "CDATA", ("" + m_PrintformatItem
.getSortNo()));
atts
.addAttribute(
"",
"",
"FieldAlignmentType",
"CDATA",
(m_PrintformatItem.getFieldAlignmentType() != null ? m_PrintformatItem
.getFieldAlignmentType()
: ""));
atts
.addAttribute(
"",
"",
"LineAlignmentType",
"CDATA",
(m_PrintformatItem.getLineAlignmentType() != null ? m_PrintformatItem
.getLineAlignmentType()
: ""));
atts.addAttribute("", "", "ImageURL", "CDATA", (m_PrintformatItem
.getImageURL() != null ? m_PrintformatItem.getImageURL() : ""));
atts.addAttribute("", "", "BelowColumn", "CDATA",
("" + m_PrintformatItem.getBelowColumn()));
atts.addAttribute("", "", "RunningTotalLines", "CDATA",
("" + m_PrintformatItem.getRunningTotalLines()));
atts
.addAttribute(
"",
"",
"PrintNameSuffix",
"CDATA",
(m_PrintformatItem.getPrintNameSuffix() != null ? m_PrintformatItem
.getPrintNameSuffix()
: ""));
atts.addAttribute("", "", "ArcDiameter", "CDATA", ""
+ m_PrintformatItem.getArcDiameter());
atts.addAttribute("", "", "LineWidth", "CDATA", ""
+ m_PrintformatItem.getLineWidth());
atts
.addAttribute("", "", "ShapeType", "CDATA", m_PrintformatItem
.getShapeType() != null ? m_PrintformatItem
.getShapeType() : "");
atts.addAttribute("", "", "isActive", "CDATA", (m_PrintformatItem
.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isPrinted", "CDATA", (m_PrintformatItem
.isPrinted() == true ? "true" : "false"));
atts.addAttribute("", "", "isRelativePosition", "CDATA",
(m_PrintformatItem.isRelativePosition() == true ? "true"
: "false"));
atts.addAttribute("", "", "isNextLine", "CDATA", (m_PrintformatItem
.isNextLine() == true ? "true" : "false"));
atts
.addAttribute("", "", "isHeightOneLine", "CDATA",
(m_PrintformatItem.isHeightOneLine() == true ? "true"
: "false"));
atts.addAttribute("", "", "isOrderBy", "CDATA", (m_PrintformatItem
.isOrderBy() == true ? "true" : "false"));
atts.addAttribute("", "", "isGroupBy", "CDATA", (m_PrintformatItem
.isGroupBy() == true ? "true" : "false"));
atts.addAttribute("", "", "isPageBreak", "CDATA", (m_PrintformatItem
.isPageBreak() == true ? "true" : "false"));
atts.addAttribute("", "", "isSummarized", "CDATA", (m_PrintformatItem
.isSummarized() == true ? "true" : "false"));
atts.addAttribute("", "", "isImageIsAttached", "CDATA",
(m_PrintformatItem.isImageIsAttached() == true ? "true"
: "false"));
atts.addAttribute("", "", "isAveraged", "CDATA", (m_PrintformatItem
.isAveraged() == true ? "true" : "false"));
atts.addAttribute("", "", "isCounted", "CDATA", (m_PrintformatItem
.isCounted() == true ? "true" : "false"));
atts
.addAttribute("", "", "isSetNLPosition", "CDATA",
(m_PrintformatItem.isSetNLPosition() == true ? "true"
: "false"));
atts.addAttribute("", "", "isSuppressNull", "CDATA", (m_PrintformatItem
.isSuppressNull() == true ? "true" : "false"));
atts.addAttribute("", "", "isFixedWidth", "CDATA", (m_PrintformatItem
.isFixedWidth() == true ? "true" : "false"));
atts.addAttribute("", "", "isNextPage", "CDATA", (m_PrintformatItem
.isNextPage() == true ? "true" : "false"));
atts.addAttribute("", "", "isMaxCalc", "CDATA", (m_PrintformatItem
.isMaxCalc() == true ? "true" : "false"));
atts.addAttribute("", "", "isMinCalc", "CDATA", (m_PrintformatItem
.isMinCalc() == true ? "true" : "false"));
atts.addAttribute("", "", "isRunningTotal", "CDATA", (m_PrintformatItem
.isRunningTotal() == true ? "true" : "false"));
atts.addAttribute("", "", "isVarianceCalc", "CDATA", (m_PrintformatItem
.isVarianceCalc() == true ? "true" : "false"));
atts
.addAttribute("", "", "isDeviationCalc", "CDATA",
(m_PrintformatItem.isDeviationCalc() == true ? "true"
: "false"));
// BarCode Type
if (m_PrintformatItem.getBarcodeType() != null)
atts.addAttribute("", "", X_AD_PrintFormatItem.COLUMNNAME_BarcodeType, "CDATA",
m_PrintformatItem.getBarcodeType());
return atts;
}
}

View File

@ -1,256 +0,0 @@
/**
*
*/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintPaper;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* @author teo.sarca@gmail.com
* <li>FR [ 2867966 ] Export PrintPaper
* https://sourceforge.net/tracker/?func=detail&aid=2867966&group_id=176962&atid=879335
*/
public class PrintPaperElementHandler extends AbstractElementHandler
{
public static final String TAG_Name = "printpaper";
private final List<Integer> list = new ArrayList<Integer>();
protected String getTagName()
{
return TAG_Name;
}
protected String getTableName()
{
return I_AD_PrintPaper.Table_Name;
}
protected final int getTable_ID()
{
return MTable.getTable_ID(getTableName());
}
protected String getKeyColumnName()
{
return I_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID;
}
protected String getIdentifierColumnName()
{
return I_AD_PrintPaper.COLUMNNAME_Name;
}
protected String[] getAttributeNames()
{
final String[] attributeNames = new String[]{
I_AD_PrintPaper.COLUMNNAME_Name,
I_AD_PrintPaper.COLUMNNAME_Description,
I_AD_PrintPaper.COLUMNNAME_IsActive,
I_AD_PrintPaper.COLUMNNAME_IsDefault,
I_AD_PrintPaper.COLUMNNAME_IsLandscape,
I_AD_PrintPaper.COLUMNNAME_Code,
I_AD_PrintPaper.COLUMNNAME_MarginTop,
I_AD_PrintPaper.COLUMNNAME_MarginLeft,
I_AD_PrintPaper.COLUMNNAME_MarginRight,
I_AD_PrintPaper.COLUMNNAME_MarginBottom,
I_AD_PrintPaper.COLUMNNAME_SizeX,
I_AD_PrintPaper.COLUMNNAME_SizeY,
I_AD_PrintPaper.COLUMNNAME_DimensionUnits,
};
return attributeNames;
}
protected int getExportItem_ID(Properties ctx)
{
final int id = Env.getContextAsInt(ctx, getKeyColumnName());
return id;
}
protected PO getCreatePO(Properties ctx, int id, String trxName)
{
return MTable.get(ctx, getTableName()).getPO(id, trxName);
}
public void startElement(Properties ctx, Element element) throws SAXException
{
final String elementValue = element.getElementValue();
final Attributes atts = element.attributes;
final String strIdentifier = atts.getValue(getIdentifierColumnName());
final int id = get_IDWithColumn(ctx, getTableName(), getIdentifierColumnName(), strIdentifier);
final PO po = getCreatePO(ctx, id, getTrxName(ctx));
final String keyColumnName = getKeyColumnName();
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+strIdentifier+"["+id+"]");
if (id <= 0 && keyColumnName != null && getIntValue(atts, keyColumnName, 0) <= PackOut.MAX_OFFICIAL_ID)
{
po.set_ValueOfColumn(keyColumnName, getIntValue(atts, keyColumnName, 0));
}
final int AD_Backup_ID;
final String Object_Status;
if (id > 0)
{
AD_Backup_ID = copyRecord(ctx, getTableName(), po);
Object_Status = "Update";
}
else
{
Object_Status = "New";
AD_Backup_ID = 0;
}
for (String attributeName : getAttributeNames())
{
loadAttribute(atts, attributeName, po);
}
if (po.save(getTrxName(ctx)) == true)
{
record_log (ctx, 1, strIdentifier, getTagName(), po.get_ID(),
AD_Backup_ID, Object_Status,
getTableName(), getTable_ID());
}
else
{
record_log (ctx, 0, strIdentifier, getTagName(), po.get_ID(),
AD_Backup_ID, Object_Status,
getTableName(), getTable_ID());
throw new POSaveFailedException("Failed to save message.");
}
}
public void endElement(Properties ctx, Element element) throws SAXException
{
}
public void create(Properties ctx, TransformerHandler document) throws SAXException
{
final int id = getExportItem_ID(ctx);
if (list.contains(id))
return;
list.add(id);
final PO po = getCreatePO(ctx, id, null);
final AttributesImpl atts = new AttributesImpl();
createMessageBinding(atts, po);
document.startElement("", "", getTagName(), atts);
document.endElement("", "", getTagName());
}
private AttributesImpl createMessageBinding(AttributesImpl atts, PO po)
{
atts.clear();
// Add ID if it's official
String keyColumnName = getKeyColumnName();
if (keyColumnName != null && po.get_ID() <= PackOut.MAX_OFFICIAL_ID)
{
addAttribute(atts, keyColumnName, po);
}
for (String name : getAttributeNames())
{
addAttribute(atts, name, po);
}
return atts;
}
protected void loadAttribute(Attributes atts, String name, PO po)
{
final String strValueExact = atts.getValue(name);
String strValue = strValueExact;
if (Util.isEmpty(strValue, true))
{
strValue = null;
}
else
{
strValue = strValue.trim();
}
final POInfo poInfo = POInfo.getPOInfo(po.getCtx(), getTable_ID());
final Class<?> clazz = poInfo.getColumnClass(poInfo.getColumnIndex(name));
if (strValue == null)
{
po.set_ValueOfColumn(name, null);
}
else if (clazz == BigDecimal.class)
{
po.set_ValueOfColumn(name, new BigDecimal(strValue));
}
else if (clazz == Integer.class)
{
po.set_ValueOfColumn(name, new BigDecimal(strValue).intValueExact());
}
else if (clazz == String.class)
{
po.set_ValueOfColumn(name, strValueExact);
}
else if (clazz == Boolean.class)
{
po.set_ValueOfColumn(name, Boolean.valueOf(strValue));
}
else if (clazz == Timestamp.class)
{
Timestamp ts = Timestamp.valueOf(strValue);
po.set_ValueOfColumn(name, ts);
}
else
{
throw new AdempiereException("Class not supported - "+clazz);
}
}
protected boolean getBooleanValue(Attributes atts, String qName, boolean defaultValue)
{
String s = atts.getValue(qName);
return s != null ? Boolean.valueOf(s) : defaultValue;
}
protected int getIntValue(Attributes atts, String qName, int defaultValue)
{
Object o = atts.getValue(qName);
if (o == null)
return defaultValue;
if (o instanceof Number)
return ((Number)o).intValue();
return Integer.parseInt(o.toString());
}
private final void addAttribute(AttributesImpl atts, String name, PO po)
{
Object value = po.get_Value(name);
atts.addAttribute("", "", name, "CDATA", toStringAttribute(value));
}
private final String toStringAttribute(Object value)
{
if (value == null)
return "";
if (value instanceof Boolean)
return ((Boolean)value).booleanValue() == true ? "true" : "false";
return value.toString();
}
}

View File

@ -1,140 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ProcessAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int processid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (atts.getValue("processname")!=null){
String name = atts.getValue("processname");
sqlB = new StringBuffer ("SELECT AD_Process_ID FROM AD_Process WHERE Name= ?");
processid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Process_Access WHERE AD_Role_ID=? and AD_Process_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,processid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Process_Access ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadWrite = '" + atts.getValue("isReadWrite") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Process_ID = " + processid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to process access failed");
throw new DatabaseAccessException("Update to process access failed");
}
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Process_Access")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_Role_ID, AD_Process_ID, isActive, isReadWrite) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + roleid )
.append( ", " + processid )
.append( ", '" + atts.getValue("isActive") )
.append( "', '" + atts.getValue("isReadWrite")+"')" );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to process access failed");
throw new DatabaseAccessException("Insert to process access failed");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Process_ID = Env.getContextAsInt(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createProcessAccessBinding(atts, AD_Process_ID, AD_Role_ID);
document.startElement("", "", "processaccess", atts);
document.endElement("", "", "processaccess");
}
private AttributesImpl createProcessAccessBinding(AttributesImpl atts,
int process_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB.getSQLValueString(null, sql, process_id);
atts.addAttribute("", "", "processname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Process_Access WHERE AD_Process_ID="
+ process_id + " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadWrite FROM AD_Process_Access WHERE AD_Process_ID="
+ process_id + " and AD_Role_ID=?";
String isReadWrite = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite);
return atts;
}
}

View File

@ -1,344 +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. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ProcessElementHandler extends AbstractElementHandler {
private ProcessParaElementHandler paraHandler = new ProcessParaElementHandler();
private List<Integer> processes = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
int id = 0;
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String value = atts.getValue("Value");
// Get New process.
id = get_IDWithColumn(ctx, "AD_Process", "Value", value);
X_AD_Process m_Process = null;
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
AD_Backup_ID = copyRecord(ctx, "AD_Process", m_Process);
Object_Status = "Update";
} else {
m_Process = new X_AD_Process(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Process_ID") != null && Integer.parseInt(atts.getValue("AD_Process_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Process.setAD_Process_ID(Integer.parseInt(atts.getValue("AD_Process_ID")));
Object_Status = "New";
AD_Backup_ID = 0;
}
String name = atts.getValue("Name");
m_Process.setName(name);
name = atts.getValue("ADWorkflowNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + name;
return;
}
m_Process.setAD_Workflow_ID(id);
}
name = atts.getValue("ADPrintFormatNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_PrintFormat", "Name", name);
if (id <= 0) {
if (element.pass == 1) {
element.defer = true;
element.unresolved = "AD_PrintFormat: " + name;
return;
} else {
log.warning("AD_PrintFormat: " + name + " not found for Process: " + m_Process.getName());
}
}
if (id > 0)
m_Process.setAD_PrintFormat_ID(id);
}
name = atts.getValue("ADReportViewNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
if (id <= 0) {
if (element.pass == 1) {
element.defer = true;
element.unresolved = "AD_ReportView: " + name;
return;
} else {
log.warning("AD_ReportView: " + name + " not found for Process: " + m_Process.getName());
}
}
if (id > 0)
m_Process.setAD_ReportView_ID(id);
}
m_Process.setAccessLevel(atts.getValue("AccessLevel"));
m_Process.setClassname(getStringValue(atts, "Classname"));
m_Process.setDescription(getStringValue(atts, "Description"));
m_Process.setEntityType(atts.getValue("EntityType"));
m_Process.setHelp(getStringValue(atts, "Help"));
m_Process.setIsBetaFunctionality(Boolean.valueOf(
atts.getValue("isBetaFunctionality")).booleanValue());
m_Process.setIsDirectPrint(Boolean.valueOf(
atts.getValue("isDirectPrint")).booleanValue());
m_Process.setIsReport(Boolean.valueOf(atts.getValue("isReport"))
.booleanValue());
m_Process.setName(atts.getValue("Name"));
m_Process.setProcedureName(getStringValue(atts, "ProcedureName"));
m_Process.setStatistic_Count(0);
m_Process.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Process.setStatistic_Seconds(0);
m_Process.setValue(atts.getValue("Value"));
m_Process.setWorkflowValue(atts.getValue("WorkflowValue"));
m_Process.setShowHelp((getStringValue(atts, "ShowHelp")));
m_Process.setJasperReport(getStringValue(atts, "JasperReport"));
if (m_Process.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Process.getName(), "Process", m_Process
.get_ID(), AD_Backup_ID, Object_Status, "AD_Process",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Process"));
element.recordId = m_Process.getAD_Process_ID();
} else {
record_log(ctx, 0, m_Process.getName(), "Process", m_Process
.get_ID(), AD_Backup_ID, Object_Status, "AD_Process",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Process"));
throw new POSaveFailedException("Process");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID");
if (processes.contains(AD_Process_ID))
return;
processes.add(AD_Process_ID);
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
String sqlW = "SELECT AD_Process_ID FROM AD_PROCESS WHERE AD_PROCESS_ID = "
+ AD_Process_ID;
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sqlW, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
X_AD_Process m_Process = new X_AD_Process(ctx, rs1
.getInt("AD_Process_ID"), null);
log.log(Level.INFO, "AD_ReportView_ID: "
+ m_Process.getAD_Process_ID());
if (m_Process.isReport() && m_Process.getAD_ReportView_ID() > 0) {
packOut.createReportview(m_Process.getAD_ReportView_ID(),
document);
}
if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0) {
packOut.createPrintFormat(m_Process.getAD_PrintFormat_ID(),
document);
}
if (m_Process.getAD_Workflow_ID() > 0) {
packOut.createWorkflow(m_Process.getAD_Workflow_ID(),
document);
}
createProcessBinding(atts, m_Process);
document.startElement("", "", "process", atts);
// processpara tags
String sqlP = "SELECT * FROM AD_PROCESS_PARA WHERE AD_PROCESS_ID = "+ AD_Process_ID
+" ORDER BY "+X_AD_Process_Para.COLUMNNAME_SeqNo+","+X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID;
PreparedStatement pstmtP = null;
pstmtP = DB.prepareStatement(sqlP, getTrxName(ctx));
try {
ResultSet rsP = pstmtP.executeQuery();
while (rsP.next()) {
if (rsP.getInt("AD_Reference_ID") > 0)
packOut.createReference(rsP
.getInt("AD_Reference_ID"), document);
if (rsP.getInt("AD_Reference_Value_ID") > 0)
packOut.createReference(rsP
.getInt("AD_Reference_Value_ID"),
document);
if (rsP.getInt("AD_Val_Rule_ID") > 0)
packOut.createDynamicRuleValidation (rsP.getInt("AD_Val_Rule_ID"), document);
createProcessPara(ctx, document, rsP
.getInt("AD_Process_Para_ID"));
}
rsP.close();
pstmtP.close();
pstmtP = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getProcess_Para", e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export process.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export process.", e);
} finally {
try {
if (pstmtP != null)
pstmtP.close();
} catch (Exception e) {
}
pstmtP = null;
}
document.endElement("", "", "process");
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getProcess", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
private void createProcessPara(Properties ctx, TransformerHandler document,
int AD_Process_Para_ID) throws SAXException {
Env.setContext(ctx, X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID,
AD_Process_Para_ID);
paraHandler.create(ctx, document);
ctx.remove(X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID);
}
private AttributesImpl createProcessBinding(AttributesImpl atts,
X_AD_Process m_Process) {
String sql = null;
String name = null;
atts.clear();
if (m_Process.getAD_Process_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Process_ID","CDATA",Integer.toString(m_Process.getAD_Process_ID()));
atts.addAttribute("", "", "Name", "CDATA",
(m_Process.getName() != null ? m_Process.getName() : ""));
if (m_Process.getAD_Workflow_ID() > 0) {
sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?";
name = DB.getSQLValueString(null, sql, m_Process
.getAD_Workflow_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", "");
if (m_Process.getAD_Process_ID() > 0) {
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB
.getSQLValueString(null, sql, m_Process.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADProcessNameID", "CDATA", "");
if (m_Process.getAD_PrintFormat_ID() > 0) {
sql = "SELECT Name FROM AD_PrintFormat WHERE AD_PrintFormat_ID=?";
name = DB.getSQLValueString(null, sql, m_Process
.getAD_PrintFormat_ID());
atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADPrintFormatNameID", "CDATA", "");
if (m_Process.getAD_ReportView_ID() > 0) {
sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?";
name = DB.getSQLValueString(null, sql, m_Process
.getAD_ReportView_ID());
atts.addAttribute("", "", "ADReportViewNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReportViewNameID", "CDATA", "");
atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Process
.getAccessLevel() != null ? m_Process.getAccessLevel() : ""));
atts.addAttribute("", "", "Classname", "CDATA", (m_Process
.getClassname() != null ? m_Process.getClassname() : ""));
atts.addAttribute("", "", "Description", "CDATA", (m_Process
.getDescription() != null ? m_Process.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Process
.getEntityType() != null ? m_Process.getEntityType() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Process.getHelp() != null ? m_Process.getHelp() : ""));
atts.addAttribute("", "", "isBetaFunctionality", "CDATA", (m_Process
.isBetaFunctionality() == true ? "true" : "false"));
atts.addAttribute("", "", "isDirectPrint", "CDATA", (m_Process
.isDirectPrint() == true ? "true" : "false"));
atts.addAttribute("", "", "isReport", "CDATA",
(m_Process.isReport() == true ? "true" : "false"));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Process.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "ProcedureName", "CDATA",
(m_Process.getProcedureName() != null ? m_Process
.getProcedureName() : ""));
atts.addAttribute("", "", "StatisticCount", "CDATA", "0");
atts.addAttribute("", "", "StatisticSeconds", "CDATA", "0");
atts.addAttribute("", "", "Value", "CDATA",
(m_Process.getValue() != null ? m_Process.getValue() : ""));
atts.addAttribute("", "", "WorkflowValue", "CDATA",
(m_Process.getWorkflowValue() != null ? m_Process
.getWorkflowValue() : ""));
atts.addAttribute("", "", "ShowHelp", "CDATA",
(m_Process.getShowHelp() != null ? m_Process.getShowHelp() : ""));
atts.addAttribute("", "", "JasperReport", "CDATA",
(m_Process.getJasperReport() != null ? m_Process.getJasperReport() : ""));
return atts;
}
}

View File

@ -1,314 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ProcessParaElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("process") &&
element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("Name");
int id = 0;
int masterId = 0;
String processValue = "";
if (element.parent != null && element.parent.getElementValue().equals("process") &&
element.parent.recordId > 0) {
masterId = element.parent.recordId;
} else {
processValue = atts.getValue("ADProcessValueID");
if (processValue != null && processValue.trim().length() > 0) {
masterId = get_IDWithColumn(ctx, "AD_Process", "Value", processValue);
} else {
//for backward compatibility
processValue = atts.getValue("ADProcessNameID");
masterId = get_IDWithColumn(ctx, "AD_Process", "Name", processValue);
}
}
if (masterId <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + processValue;
return;
}
id = get_IDWithMasterAndColumn(ctx, "AD_Process_Para", "Name",
name, "AD_Process", masterId);
X_AD_Process_Para m_Process_para = new X_AD_Process_Para(ctx, id,
getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Process_Para_ID") != null && Integer.parseInt(atts.getValue("AD_Process_Para_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Process_para.setAD_Process_Para_ID(Integer.parseInt(atts.getValue("AD_Process_Para_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Process_Para",
m_Process_para);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Process_para.setName(atts.getValue("Name"));
m_Process_para.setAD_Process_ID(masterId);
m_Process_para.setColumnName(atts.getValue("ColumnName"));
m_Process_para.setEntityType(atts.getValue("EntityType"));
name = atts.getValue("ADElementNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", name);
if (id <= 0 /** Check Packout version - 005 */)
{
id = get_IDWithColumn(ctx, "AD_Element", "Name", name);
}
// Setup Element
X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
if (adElement.getAD_Element_ID() == 0) {
String columnName = m_Process_para.getColumnName();
id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", columnName);
if ( id > 0 ) {
adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
} else {
adElement.setColumnName(columnName);
adElement.setEntityType(m_Process_para.getEntityType());
adElement.setPrintName(name);
adElement.setName(m_Process_para.getName());
if (adElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Process_para.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
} else {
record_log(ctx, 0, m_Process_para.getName(), "Element", adElement
.getAD_Element_ID(), AD_Backup_ID, "New",
"AD_Element", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Element"));
}
}
}
m_Process_para.setAD_Element_ID(adElement.getAD_Element_ID());
}
name = atts.getValue("ADReferenceNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Reference: " + name;
return;
}
m_Process_para.setAD_Reference_ID(id);
}
name = atts.getValue("ADReferenceValueNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Reference", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Reference: " + name;
return;
}
m_Process_para.setAD_Reference_Value_ID(id);
}
name = atts.getValue("ADValRuleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Val_Rule: " +name;
return;
}
m_Process_para.setAD_Val_Rule_ID(id);
}
m_Process_para.setDefaultValue(getStringValue(atts, "DefaultValue"));
m_Process_para.setDefaultValue2(getStringValue(atts, "DefaultValue2"));
m_Process_para.setDescription(getStringValue(atts,"Description"));
m_Process_para.setHelp(getStringValue(atts,"Help"));
m_Process_para
.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
m_Process_para.setVFormat(getStringValue(atts,"VFormat"));
m_Process_para.setValueMax(getStringValue(atts,"ValueMax"));
m_Process_para.setValueMin(getStringValue(atts,"ValueMin"));
m_Process_para.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Process_para.setFieldLength(Integer.parseInt(atts
.getValue("FieldLength")));
m_Process_para.setIsCentrallyMaintained(Boolean.valueOf(
atts.getValue("isCentrallyMaintained")).booleanValue());
m_Process_para.setIsMandatory(Boolean.valueOf(
atts.getValue("isMandatory")).booleanValue());
m_Process_para.setIsRange(Boolean.valueOf(atts.getValue("isRange"))
.booleanValue());
if (m_Process_para.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Process_para.getName(), "Process_para",
m_Process_para.get_ID(), AD_Backup_ID, Object_Status,
"AD_Process_para", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Process_para"));
} else {
record_log(ctx, 0, m_Process_para.getName(), "Process_para",
m_Process_para.get_ID(), AD_Backup_ID, Object_Status,
"AD_Process_para", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Process_para"));
throw new POSaveFailedException("ProcessPara");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Process_Para_ID = Env.getContextAsInt(ctx,
X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID);
X_AD_Process_Para m_Processpara = new X_AD_Process_Para(ctx,
AD_Process_Para_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createProcessParaBinding(atts, m_Processpara);
document.startElement("", "", "processpara", atts);
document.endElement("", "", "processpara");
}
private AttributesImpl createProcessParaBinding(AttributesImpl atts,
X_AD_Process_Para m_Processpara) {
String sql = null;
String name = null;
atts.clear();
if (m_Processpara.getAD_Process_Para_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Process_Para_ID","CDATA",Integer.toString(m_Processpara.getAD_Process_Para_ID()));
atts
.addAttribute("", "", "Name", "CDATA",
(m_Processpara.getName() != null ? m_Processpara
.getName() : ""));
if (m_Processpara.getAD_Process_ID() > 0) {
sql = "SELECT Value FROM AD_Process WHERE AD_Process_ID=?";
name = DB.getSQLValueString(null, sql, m_Processpara
.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessValueID", "CDATA", name);
} else
atts.addAttribute("", "", "ADProcessValueID", "CDATA", "");
if (m_Processpara.getAD_Process_Para_ID() > 0) {
sql = "SELECT Name FROM AD_Process_Para WHERE AD_Process_Para_ID=?";
name = DB.getSQLValueString(null, sql, m_Processpara
.getAD_Process_Para_ID());
atts.addAttribute("", "", "ADProcessParaNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADProcessParaNameID", "CDATA", "");
if (m_Processpara.getAD_Element_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Element WHERE AD_Element_ID=?";
name = DB.getSQLValueStringEx(null, sql, m_Processpara.getAD_Element_ID());
atts.addAttribute("", "", "ADElementNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADElementNameID", "CDATA", "");
if (m_Processpara.getAD_Reference_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Processpara
.getAD_Reference_ID());
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
if (m_Processpara.getAD_Reference_Value_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Processpara
.getAD_Reference_Value_ID());
atts.addAttribute("", "", "ADReferenceValueNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReferenceValueNameID", "CDATA", "");
if (m_Processpara.getAD_Val_Rule_ID() > 0) {
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
name = DB.getSQLValueString(null, sql, m_Processpara
.getAD_Val_Rule_ID());
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
atts.addAttribute("", "", "ColumnName", "CDATA", (m_Processpara
.getColumnName() != null ? m_Processpara.getColumnName() : ""));
atts.addAttribute("", "", "DefaultValue", "CDATA", (m_Processpara
.getDefaultValue() != null ? m_Processpara.getDefaultValue()
: ""));
atts.addAttribute("", "", "DefaultValue2", "CDATA", (m_Processpara
.getDefaultValue2() != null ? m_Processpara.getDefaultValue2()
: ""));
atts.addAttribute("", "", "Description", "CDATA",
(m_Processpara.getDescription() != null ? m_Processpara
.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Processpara
.getEntityType() != null ? m_Processpara.getEntityType() : ""));
atts
.addAttribute("", "", "Help", "CDATA",
(m_Processpara.getHelp() != null ? m_Processpara
.getHelp() : ""));
atts.addAttribute("", "", "isActive", "CDATA", (m_Processpara
.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "VFormat", "CDATA", (m_Processpara
.getVFormat() != null ? m_Processpara.getVFormat() : ""));
atts.addAttribute("", "", "ValueMax", "CDATA", (m_Processpara
.getValueMax() != null ? m_Processpara.getValueMax() : ""));
atts.addAttribute("", "", "ValueMin", "CDATA", (m_Processpara
.getValueMin() != null ? m_Processpara.getValueMin() : ""));
atts.addAttribute("", "", "SeqNo", "CDATA",
(m_Processpara.getSeqNo() > 0 ? "" + m_Processpara.getSeqNo()
: "0"));
atts.addAttribute("", "", "FieldLength", "CDATA", (m_Processpara
.getFieldLength() > 0 ? "" + m_Processpara.getFieldLength()
: "0"));
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA",
(m_Processpara.isCentrallyMaintained() == true ? "true"
: "false"));
atts.addAttribute("", "", "isMandatory", "CDATA", (m_Processpara
.isMandatory() == true ? "true" : "false"));
atts.addAttribute("", "", "isRange", "CDATA",
(m_Processpara.isRange() == true ? "true" : "false"));
return atts;
}
}

View File

@ -1,279 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Ref_List;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.model.X_AD_Reference;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ReferenceElementHandler extends AbstractElementHandler {
private ReferenceListElementHandler listHandler = new ReferenceListElementHandler();
private ReferenceTableElementHandler tableHandler = new ReferenceTableElementHandler();
private List<Integer> references = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("name"));
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("name");
if (isProcessElement(ctx, entitytype)) {
int id = get_ID(ctx, "AD_Reference", name);
X_AD_Reference m_Reference = new X_AD_Reference(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Reference_ID") != null && Integer.parseInt(atts.getValue("AD_Reference_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Reference.setAD_Reference_ID(Integer.parseInt(atts.getValue("AD_Reference_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Reference", m_Reference);
Object_Status = "Update";
if (references.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Reference.setDescription(getStringValue(atts,"Description"));
m_Reference.setEntityType(atts.getValue("EntityType"));
m_Reference.setHelp(getStringValue(atts,"Help"));
m_Reference.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Reference.setName(atts.getValue("name"));
// m_Reference.setVFormat(atts.getValue("VFormat"));
m_Reference.setValidationType(atts.getValue("ValidationType"));
if (m_Reference.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Reference.getName(), "Reference",
m_Reference.get_ID(), AD_Backup_ID, Object_Status,
"AD_Reference", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Reference"));
references.add(m_Reference.getAD_Reference_ID());
element.recordId = m_Reference.getAD_Reference_ID();
} else {
record_log(ctx, 0, m_Reference.getName(), "Reference",
m_Reference.get_ID(), AD_Backup_ID, Object_Status,
"AD_Reference", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Reference"));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int Reference_id = Env.getContextAsInt(ctx,
X_AD_Reference.COLUMNNAME_AD_Reference_ID);
if (references.contains(Reference_id))
return;
references.add(Reference_id);
AttributesImpl atts = new AttributesImpl();
String sql = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= "
+ Reference_id;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Reference m_Reference = new X_AD_Reference(ctx, rs
.getInt("AD_Reference_ID"), null);
createReferenceBinding(atts, m_Reference);
document.startElement("", "", "reference", atts);
if (m_Reference.getValidationType().compareTo("L") == 0) {
String sql1 = "SELECT * FROM AD_Ref_List WHERE AD_Reference_ID= " + Reference_id
+ " ORDER BY Value, AD_Ref_List_ID";
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceList(ctx, document, rs1
.getInt("AD_REF_LIST_ID"));
}
rs1.close();
pstmt1.close();
pstmt1 = null;
}
catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export Reference.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export Reference.", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
} else if (m_Reference.getValidationType().compareTo("T") == 0) {
String sql1 = "SELECT AD_Reference_ID FROM AD_Ref_Table WHERE AD_Reference_ID = "
+ Reference_id;
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceTable(ctx, document, Reference_id);
}
rs1.close();
pstmt1.close();
pstmt1 = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "getRef_Table", e);
}
finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
document.endElement("", "", "reference");
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "getRefence", e);
}
finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
private void createReferenceTable(Properties ctx, TransformerHandler document,
int reference_id) throws SAXException {
Env.setContext(ctx, X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, reference_id);
tableHandler.create(ctx, document);
ctx.remove(X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
}
private void createReferenceList(Properties ctx,
TransformerHandler document, int AD_Ref_List_ID)
throws SAXException {
Env.setContext(ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID,
AD_Ref_List_ID);
listHandler.create(ctx, document);
ctx.remove(X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID);
}
private AttributesImpl createReferenceBinding(AttributesImpl atts,
X_AD_Reference m_Reference) {
String sql = null;
String name = null;
atts.clear();
if (m_Reference.getAD_Reference_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Reference_ID", "CDATA", Integer.toString(m_Reference.getAD_Reference_ID()));
if (m_Reference.getAD_Reference_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Reference
.getAD_Reference_ID());
atts.addAttribute("", "", "name", "CDATA", name);
} else
atts.addAttribute("", "", "name", "CDATA", "");
atts.addAttribute("", "", "Description", "CDATA", (m_Reference
.getDescription() != null ? m_Reference.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Reference
.getEntityType() != null ? m_Reference.getEntityType() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Reference.getHelp() != null ? m_Reference.getHelp() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Reference.getName() != null ? m_Reference.getName() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Reference.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "VFormat", "CDATA",
(m_Reference.getVFormat() != null ? m_Reference.getVFormat()
: ""));
atts.addAttribute("", "", "ValidationType", "CDATA", (m_Reference
.getValidationType() != null ? m_Reference.getValidationType()
: ""));
return atts;
}
}

View File

@ -1,165 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Ref_List;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ReferenceListElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
// TODO: Solve for date issues with valuefrom valueto
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
@SuppressWarnings("unused")
String name = atts.getValue("Name");
String value = atts.getValue("Value");
int AD_Reference_ID = 0;
if (element.parent != null && element.parent.getElementValue().equals("reference") &&
element.parent.recordId > 0) {
AD_Reference_ID = element.parent.recordId;
} else {
AD_Reference_ID = get_IDWithColumn(ctx, "AD_Reference", "Name",
atts.getValue("ADRefenceNameID"));
}
int AD_Ref_List_ID = get_IDWithMasterAndColumn(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID,
getTrxName(ctx));
if (AD_Ref_List_ID <= 0 && atts.getValue("AD_Ref_List_ID") != null && Integer.parseInt(atts.getValue("AD_Ref_List_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Ref_List.setAD_Ref_List_ID(Integer.parseInt(atts.getValue("AD_Ref_List_ID")));
if (AD_Ref_List_ID > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Ref_List", m_Ref_List);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Ref_List.setAD_Reference_ID(AD_Reference_ID);
m_Ref_List.setDescription(getStringValue(atts,"Description"));
m_Ref_List.setEntityType(atts.getValue("EntityType"));
m_Ref_List.setName(atts.getValue("Name"));
m_Ref_List.setValue(value);
m_Ref_List.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
if (m_Ref_List.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Ref_List.getName(), "Reference List",
m_Ref_List.get_ID(), AD_Backup_ID, Object_Status,
"AD_Ref_List", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Ref_List"));
} else {
record_log(ctx, 0, m_Ref_List.getName(), "Reference List",
m_Ref_List.get_ID(), AD_Backup_ID, Object_Status,
"AD_Ref_List", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Ref_List"));
throw new POSaveFailedException("ReferenceList");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Ref_List_ID = Env.getContextAsInt(ctx,
X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID);
X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID,
getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createRefListBinding(atts, m_Ref_List);
document.startElement("", "", "referencelist", atts);
document.endElement("", "", "referencelist");
}
private AttributesImpl createRefListBinding(AttributesImpl atts,
X_AD_Ref_List m_Ref_List) {
String sql = null;
String name = null;
atts.clear();
if (m_Ref_List.getAD_Ref_List_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Ref_List_ID", "CDATA", Integer.toString(m_Ref_List.getAD_Ref_List_ID()));
if (m_Ref_List.getAD_Ref_List_ID() > 0) {
sql = "SELECT Name FROM AD_Ref_List WHERE AD_Ref_List_ID=?";
name = DB.getSQLValueString(null, sql, m_Ref_List
.getAD_Ref_List_ID());
if (name != null)
atts.addAttribute("", "", "ADReflistNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADReflistNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADReflistNameID", "CDATA", "");
}
if (m_Ref_List.getAD_Reference_ID() > 0) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Ref_List
.getAD_Reference_ID());
if (name != null)
atts.addAttribute("", "", "ADRefenceNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADRefenceNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADRefenceNameID", "CDATA", "");
}
atts.addAttribute("", "", "Description", "CDATA", (m_Ref_List
.getDescription() != null ? m_Ref_List.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Ref_List
.getEntityType() != null ? m_Ref_List.getEntityType() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Ref_List.getName() != null ? m_Ref_List.getName() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Ref_List.isActive() == true ? "true" : "false"));
// atts.addAttribute("","","ValidFrom","CDATA",(m_Ref_List.getValidFrom
// ().toGMTString() != null ?
// m_Ref_List.getValidFrom().toGMTString():""));
// atts.addAttribute("","","ValidTo","CDATA",(m_Ref_List.getValidTo
// ().toGMTString() != null ?
// m_Ref_List.getValidTo().toGMTString():""));
atts.addAttribute("", "", "Value", "CDATA",
(m_Ref_List.getValue() != null ? m_Ref_List.getValue() : ""));
return atts;
}
}

View File

@ -1,293 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MColumn;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ReferenceTableElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
log.info(elementValue);
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADRefenceNameID");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
int AD_Reference_ID = 0;
if (element.parent != null && element.parent.getElementValue().equals("reference") &&
element.parent.recordId > 0) {
AD_Reference_ID = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer(
"SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?");
AD_Reference_ID = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (AD_Reference_ID <= 0 && atts.getValue("AD_Reference_ID") != null && Integer.parseInt(atts.getValue("AD_Reference_ID")) <= PackOut.MAX_OFFICIAL_ID)
AD_Reference_ID = Integer.parseInt(atts.getValue("AD_Reference_ID"));
StringBuffer sqlB = new StringBuffer(
"SELECT Count(*) FROM AD_Ref_Table WHERE AD_Reference_ID= ?");
int count = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), AD_Reference_ID);
int tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts
.getValue("ADTableNameID"));
if (tableId == 0) {
MTable m_Table = new MTable(ctx, 0, getTrxName(ctx));
m_Table.setAccessLevel("3");
m_Table.setName(atts.getValue("ADTableNameID"));
m_Table.setTableName(atts.getValue("ADTableNameID"));
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table", m_Table
.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Table"));
} else {
record_log(ctx, 0, m_Table.getName(), "Table", m_Table
.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Table"));
}
tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts
.getValue("ADTableNameID"));
}
name = atts.getValue("ADDisplay");
int DisplayId = get_IDWithMasterAndColumn(ctx, "AD_Column",
"ColumnName", name, "AD_Table", tableId);
if (DisplayId == 0) {
MColumn m_Column = new MColumn(ctx, 0, getTrxName(ctx));
m_Column.setAD_Table_ID(tableId);
// m_Column.setVersion(new BigDecimal("1")); // use constructor
// value
m_Column.setColumnName(name);
m_Column.setName(name);
m_Column.setAD_Reference_ID(30);
if (m_Column.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Column", m_Column
.get_ID(), 0, "New", "AD_Column", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Column"));
} else {
record_log(ctx, 0, m_Column.getName(), "Column", m_Column
.get_ID(), 0, "New", "AD_Column", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Column"));
}
}
name = atts.getValue("Key");
int keyId = get_IDWithMasterAndColumn(ctx, "AD_Column",
"ColumnName", name, "AD_Table", tableId);
if (keyId == 0) {
MColumn m_Column = new MColumn(ctx, 0, getTrxName(ctx));
m_Column.setAD_Table_ID(tableId);
// m_Column.setVersion(new BigDecimal("1")); // use constructor
// value
m_Column.setColumnName(name);
m_Column.setName(name);
m_Column.setAD_Reference_ID(30);
if (m_Column.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Column", m_Column
.get_ID(), 0, "New", "AD_Column", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Column"));
} else {
record_log(ctx, 0, m_Column.getName(), "Column", m_Column
.get_ID(), 0, "New", "AD_Column", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Column"));
}
}
name = atts.getValue("ADDisplay");
DisplayId = get_IDWithMasterAndColumn(ctx, "AD_Column",
"ColumnName", name, "AD_Table", tableId);
name = atts.getValue("Key");
keyId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName",
name, "AD_Table", tableId);
String entityType = atts.getValue("EntityType");
String isValueDisplayed = atts.getValue("IsValueDisplayed");
String OrderByClause = atts.getValue("OrderByClause").replaceAll("'", "''");
String WhereClause = atts.getValue("WhereClause").replaceAll("'","''");
if (count > 0) {
sqlB = new StringBuffer("UPDATE AD_Ref_Table ").append(
"SET AD_Table_ID = " + tableId).append(
", AD_Display = " + DisplayId).append(
", AD_Key = " + keyId).append(
", isValueDisplayed = '" + isValueDisplayed).append(
"', OrderByClause = '" + OrderByClause).append(
"', EntityType ='" + entityType).append(
"', WhereClause = '" + WhereClause).append(
"' WHERE AD_Reference_ID = " + AD_Reference_ID);
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no > 0) {
record_log(ctx, 1, atts.getValue("ADRefenceNameID"),
"Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Ref_Table"));
} else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"),
"Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
} else {
sqlB = new StringBuffer("INSERT INTO AD_Ref_Table")
.append(
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ")
.append(
"AD_Reference_ID, AD_Table_ID, AD_Display, AD_Key ")
.append(
",entityType, isValueDisplayed, OrderByClause, ")
.append(" WhereClause )").append(
"VALUES(0, 0, 0, 0, " + AD_Reference_ID).append(
", " + tableId).append(", " + DisplayId)
.append(", " + keyId).append(", '" + entityType)
.append("', '" + isValueDisplayed).append(
"', '" + OrderByClause).append(
"', '" + WhereClause + "')");
int no = DB.executeUpdate(sqlB.toString(), getTrxName(ctx));
if (no > 0) {
record_log(ctx, 1, atts.getValue("ADRefenceNameID"),
"Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Ref_Table"));
} else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"),
"Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int Reference_id = Env.getContextAsInt(ctx,
X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AttributesImpl atts = new AttributesImpl();
createReferenceTableBinding(ctx, atts, Reference_id);
document.startElement("", "", "referencetable", atts);
document.endElement("", "", "referencetable");
}
private AttributesImpl createReferenceTableBinding(Properties ctx,
AttributesImpl atts, int reference_ID) {
atts.clear();
if (reference_ID <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Reference_ID", "CDATA", Integer.toString(reference_ID));
String name = null;
String sql = null;
String sql1 = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= "
+ reference_ID;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, reference_ID);
atts.addAttribute("", "", "ADRefenceNameID", "CDATA", name);
if (rs.getInt("AD_Table_ID") > 0) {
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, rs
.getInt("AD_Table_ID"));
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (rs.getInt("AD_Display") > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, rs
.getInt("AD_Display"));
atts.addAttribute("", "", "ADDisplay", "CDATA", name);
} else
atts.addAttribute("", "", "ADDisplay", "CDATA", "");
if (rs.getInt("AD_Key") > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, rs.getInt("AD_Key"));
atts.addAttribute("", "", "Key", "CDATA", name);
} else
atts.addAttribute("", "", "Key", "CDATA", "");
atts.addAttribute("", "", "EntityType", "CDATA", (rs
.getString("EntityType") != null ? rs
.getString("EntityType") : ""));
atts
.addAttribute("", "", "IsValueDisplayed", "CDATA",
(rs.getString("IsValueDisplayed")
.compareTo("Y") == 0 ? "Y" : "N"));
atts.addAttribute("", "", "OrderByClause", "CDATA", (rs
.getString("OrderByClause") != null ? rs
.getString("OrderByClause") : ""));
atts.addAttribute("", "", "isActive", "CDATA", (rs.getString(
"isActive").compareTo("Y") == 0 ? "Y" : "N"));
atts.addAttribute("", "", "WhereClause", "CDATA", (rs
.getString("WhereClause") != null ? rs
.getString("WhereClause") : ""));
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new DatabaseAccessException("Failed to export Reference Table", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
return atts;
}
}

View File

@ -1,177 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ReportViewColElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ADReportViewColID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADReportviewNameID");
int AD_ReportView_ID = 0;
if (element.parent != null && element.parent.getElementValue().equals("reportview") &&
element.parent.recordId > 0) {
AD_ReportView_ID = element.parent.recordId;
} else {
AD_ReportView_ID = get_IDWithColumn(ctx, "AD_ReportView", "Name", name);
}
if (AD_ReportView_ID <= 0) {
element.defer = true;
return;
}
name = atts.getValue("ADColumnNameID");
int AD_Column_ID = 0;
if (name != null && name.trim().length() > 0) {
AD_Column_ID = get_IDWithColumn(ctx, "AD_Column", "Name", name);
if (AD_Column_ID <= 0) {
element.defer = true;
return;
}
}
String functionColumn = getStringValue(atts, "FunctionColumn");
StringBuffer sql = new StringBuffer("SELECT AD_Reportview_Col_ID FROM AD_Reportview_Col ")
.append(" WHERE AD_Column_ID ");
if (AD_Column_ID > 0)
sql.append(" = " + AD_Column_ID);
else
sql.append(" IS NULL ");
sql.append(" AND FunctionColumn = ?");
int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn);
if (id < 0) id = 0;
X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx,
id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_ReportView_Col_ID") != null && Integer.parseInt(atts.getValue("AD_ReportView_Col_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Reportview_Col.setAD_ReportView_Col_ID(Integer.parseInt(atts.getValue("AD_ReportView_Col_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Reportview_Col",
m_Reportview_Col);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
boolean isGroupFunction = Boolean.valueOf(
atts.getValue("isGroupFunction")).booleanValue();
m_Reportview_Col.setAD_ReportView_ID(AD_ReportView_ID);
if (AD_Column_ID > 0) {
m_Reportview_Col.setAD_Column_ID(id);
}
m_Reportview_Col.setFunctionColumn(functionColumn);
m_Reportview_Col
.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
m_Reportview_Col.setIsGroupFunction(isGroupFunction);
if (m_Reportview_Col.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, "" + m_Reportview_Col.getAD_ReportView_ID(),
"Reportview_Col", m_Reportview_Col.get_ID(),
AD_Backup_ID, Object_Status, "AD_Reportview_Col",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Reportview_Col"));
} else {
record_log(ctx, 0, "" + m_Reportview_Col.getAD_ReportView_ID(),
"Reportview_Col", m_Reportview_Col.get_ID(),
AD_Backup_ID, Object_Status, "AD_Reportview_Col",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Reportview_Col"));
throw new POSaveFailedException("ReportViewCol");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_ReportView_Col_ID = Env.getContextAsInt(ctx,
X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID);
X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx,
AD_ReportView_Col_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createReportViewColBinding(atts, m_Reportview_Col);
document.startElement("", "", "reportviewcol", atts);
document.endElement("", "", "reportviewcol");
}
private AttributesImpl createReportViewColBinding(AttributesImpl atts,
X_AD_ReportView_Col m_Reportview_Col) {
String sql = null;
String name = null;
atts.clear();
if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_ReportView_Col_ID","CDATA",Integer.toString(m_Reportview_Col.getAD_ReportView_Col_ID()));
if (m_Reportview_Col.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_Reportview_Col
.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
if (m_Reportview_Col.getAD_ReportView_ID() > 0) {
sql = "SELECT Name FROM AD_Reportview WHERE AD_Reportview_ID=?";
name = DB.getSQLValueString(null, sql, m_Reportview_Col
.getAD_ReportView_ID());
atts.addAttribute("", "", "ADReportviewNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReportviewNameID", "CDATA", "");
atts.addAttribute("", "", "FunctionColumn", "CDATA", (m_Reportview_Col
.getFunctionColumn() != null ? m_Reportview_Col
.getFunctionColumn() : ""));
atts.addAttribute("", "", "isActive", "CDATA", (m_Reportview_Col
.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isGroupFunction", "CDATA", (m_Reportview_Col
.isGroupFunction() == true ? "true" : "false"));
return atts;
}
}

View File

@ -1,269 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_PrintFormat;
import org.compiere.model.X_AD_ReportView;
import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class ReportViewElementHandler extends AbstractElementHandler {
private ReportViewColElementHandler columnHandler = new ReportViewColElementHandler();
private List<Integer> views = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ADReportviewnameID"));
//String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADReportviewnameID");
int id = get_ID(ctx, "AD_ReportView", name);
X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, id,
getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_ReportView_ID") != null && Integer.parseInt(atts.getValue("AD_ReportView_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Reportview.setAD_ReportView_ID(Integer.parseInt(atts.getValue("AD_ReportView_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Reportview", m_Reportview);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
String Name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
MTable m_Table = null;
if (id == 0) {
m_Table = new MTable(ctx, 0, getTrxName(ctx));
m_Table.setAccessLevel("3");
m_Table.setName(Name);
m_Table.setTableName(Name);
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table",
m_Table.get_ID(), 0, "New", "AD_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Table"));
} else {
record_log(ctx, 0, m_Table.getName(), "Table",
m_Table.get_ID(), 0, "New", "AD_Table",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Table"));
}
id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
}
m_Reportview.setAD_Table_ID(id);
m_Reportview.setDescription(getStringValue(atts,"Description"));
m_Reportview.setEntityType(atts.getValue("EntityType"));
m_Reportview.setName(atts.getValue("Name"));
m_Reportview.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Reportview.setOrderByClause(getStringValue(atts,"OrderByClause"));
m_Reportview.setWhereClause(getStringValue(atts,"WhereClause"));
if (m_Reportview.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Reportview.getName(), "Reportview",
m_Reportview.get_ID(), AD_Backup_ID, Object_Status,
"AD_Reportview", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Reportview"));
element.recordId = m_Reportview.getAD_ReportView_ID();
} else {
record_log(ctx, 0, m_Reportview.getName(), "Reportview",
m_Reportview.get_ID(), AD_Backup_ID, Object_Status,
"AD_Reportview", get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_Reportview"));
throw new POSaveFailedException("ReportView");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID");
if (views.contains(AD_ReportView_ID))
return;
views.add(AD_ReportView_ID);
String sql = "SELECT * FROM AD_ReportView WHERE AD_ReportView_ID= " + AD_ReportView_ID;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, rs
.getInt("AD_Reportview_ID"), null);
atts = createReportViewBinding(atts, m_Reportview);
document.startElement("", "", "reportview", atts);
document.endElement("", "", "reportview");
String sql1 = "SELECT * FROM AD_Printformat WHERE AD_Reportview_ID="+AD_ReportView_ID
+" AND AD_Client_ID="+Env.getAD_Client_ID(ctx)
+" ORDER BY "+X_AD_PrintFormat.COLUMNNAME_AD_PrintFormat_ID
;
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
// Export Table if neccessary
packOut.createTable(rs1.getInt("AD_Table_ID"),
document);
packOut.createPrintFormat(rs1
.getInt("AD_Printformat_ID"), document);
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
atts.clear();
sql1 = "SELECT * FROM AD_ReportView_Col WHERE AD_Reportview_ID= "
+ AD_ReportView_ID;
pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReportViewCol(ctx, document, rs1
.getInt("AD_ReportView_Col_ID"));
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "reportview", e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export report view.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export report view.", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
private void createReportViewCol(Properties ctx,
TransformerHandler document, int AD_ReportView_Col_ID)
throws SAXException {
Env.setContext(ctx,
X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID,
AD_ReportView_Col_ID);
columnHandler.create(ctx, document);
ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID);
}
private AttributesImpl createReportViewBinding(AttributesImpl atts,
X_AD_ReportView m_Reportview) {
String sql = null;
String name = null;
atts.clear();
if (m_Reportview.getAD_ReportView_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_ReportView_ID","CDATA",Integer.toString(m_Reportview.getAD_ReportView_ID()));
if (m_Reportview.getAD_ReportView_ID() > 0) {
sql = "SELECT Name FROM AD_ReportView WHERE AD_ReportView_ID=?";
name = DB.getSQLValueString(null, sql, m_Reportview
.getAD_ReportView_ID());
atts.addAttribute("", "", "ADReportviewnameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADReportviewnameID", "CDATA", "");
if (m_Reportview.getAD_Table_ID() > 0) {
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, m_Reportview
.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
atts
.addAttribute("", "", "Description", "CDATA", (m_Reportview
.getDescription() != null ? m_Reportview
.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Reportview
.getEntityType() != null ? m_Reportview.getEntityType() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Reportview.getName() != null ? m_Reportview.getName() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Reportview.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "OrderByClause", "CDATA", (m_Reportview
.getOrderByClause() != null ? m_Reportview.getOrderByClause()
: ""));
atts
.addAttribute("", "", "WhereClause", "CDATA", (m_Reportview
.getWhereClause() != null ? m_Reportview
.getWhereClause() : ""));
return atts;
}
}

View File

@ -1,520 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MRole;
import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Task;
import org.compiere.model.X_AD_User;
import org.compiere.model.X_AD_Window;
import org.compiere.model.X_AD_Workflow;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class RoleElementHandler extends AbstractElementHandler {
private List<Integer> roles = new ArrayList<Integer>();
private OrgRoleElementHandler orgHandler = new OrgRoleElementHandler();
private ProcessAccessElementHandler processHandler = new ProcessAccessElementHandler();
private UserRoleElementHandler userHandler = new UserRoleElementHandler();
private WindowAccessElementHandler windowHandler = new WindowAccessElementHandler();
private FormAccessElementHandler formHandler = new FormAccessElementHandler();
private TaskAccessElementHandler taskHandler = new TaskAccessElementHandler();
private WorkflowAccessElementHandler workflowHandler = new WorkflowAccessElementHandler();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String name = atts.getValue("Name");
int id = get_ID(ctx, "AD_Role", name);
MRole m_Role = new MRole(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Role_ID") != null && Integer.parseInt(atts.getValue("AD_Role_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Role.setAD_Role_ID(Integer.parseInt(atts.getValue("AD_Role_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Role", m_Role);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Role.setName(name);
name = atts.getValue("treemenuname");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Tree", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Role.setAD_Tree_Menu_ID(id);
}
name = atts.getValue("treeorgname");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Tree", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Role.setAD_Tree_Org_ID(id);
}
name = atts.getValue("currencycode");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "C_Currency", "ISO_Code", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Role.setC_Currency_ID(id);
}
name = atts.getValue("supervisorid");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_User", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
m_Role.setC_Currency_ID(id);
}
m_Role.setDescription(getStringValue(atts,"Description"));
String amtApproval = getStringValue(atts,"AmtApproval");
if (amtApproval != null)
m_Role.setAmtApproval(new BigDecimal(amtApproval));
m_Role.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(
atts.getValue("isActive")).booleanValue() : true);
m_Role
.setIsAccessAllOrgs(atts.getValue("isAccessAllOrgs") != null ? Boolean
.valueOf(atts.getValue("isAccessAllOrgs"))
.booleanValue()
: true);
m_Role
.setIsCanApproveOwnDoc(atts.getValue("isCanApproveOwnDoc") != null ? Boolean
.valueOf(atts.getValue("isCanApproveOwnDoc"))
.booleanValue()
: true);
m_Role.setIsCanExport(atts.getValue("isCanExport") != null ? Boolean
.valueOf(atts.getValue("isCanExport")).booleanValue() : true);
m_Role.setIsCanReport(atts.getValue("isCanReport") != null ? Boolean
.valueOf(atts.getValue("isCanReport")).booleanValue() : true);
m_Role.setIsChangeLog(atts.getValue("isChangeLog") != null ? Boolean
.valueOf(atts.getValue("isChangeLog")).booleanValue() : true);
m_Role.setIsManual(atts.getValue("isManual") != null ? Boolean.valueOf(
atts.getValue("isManual")).booleanValue() : true);
m_Role
.setIsPersonalAccess(atts.getValue("isPersonalAccess") != null ? Boolean
.valueOf(atts.getValue("isPersonalAccess"))
.booleanValue()
: true);
m_Role
.setIsPersonalLock(atts.getValue("isPersonalLock") != null ? Boolean
.valueOf(atts.getValue("isPersonalLock"))
.booleanValue()
: true);
m_Role.setIsShowAcct(atts.getValue("isShowAcct") != null ? Boolean
.valueOf(atts.getValue("isShowAcct")).booleanValue() : true);
m_Role
.setIsUseUserOrgAccess(atts.getValue("isUseUserOrgAccess") != null ? Boolean
.valueOf(atts.getValue("isUseUserOrgAccess"))
.booleanValue()
: true);
m_Role
.setOverwritePriceLimit(atts.getValue("isOverwritePriceLimit") != null ? Boolean
.valueOf(atts.getValue("isOverwritePriceLimit"))
.booleanValue()
: true);
m_Role.setPreferenceType(atts.getValue("PreferenceType"));
m_Role.setUserLevel(atts.getValue("UserLevel"));
m_Role.setAllow_Info_Account(Boolean.valueOf(atts.getValue("AllowInfoAccount")));
m_Role.setAllow_Info_Asset(Boolean.valueOf(atts.getValue("AllowInfoAsset")));
m_Role.setAllow_Info_BPartner(Boolean.valueOf(atts.getValue("AllowInfoBPartner")));
// m_Role.setAllow_Info_CashJournal(Boolean.valueOf(atts.getValue("AllowInfoCashJournal")));
m_Role.setAllow_Info_InOut(Boolean.valueOf(atts.getValue("AllowInfoInOut")));
m_Role.setAllow_Info_Invoice(Boolean.valueOf(atts.getValue("AllowInfoInvoice")));
m_Role.setAllow_Info_Order(Boolean.valueOf(atts.getValue("AllowInfoOrder")));
m_Role.setAllow_Info_Payment(Boolean.valueOf(atts.getValue("AllowInfoPayment")));
m_Role.setAllow_Info_Product(Boolean.valueOf(atts.getValue("AllowInfoProduct")));
m_Role.setAllow_Info_Resource(Boolean.valueOf(atts.getValue("AllowInfoResource")));
m_Role.setAllow_Info_Schedule(Boolean.valueOf(atts.getValue("AllowInfoSchedule")));
//m_Role.setAllow_Info_CRP(Boolean.valueOf(atts.getValue("AllowInfoCRP")));
//m_Role.setAllow_Info_MRP(Boolean.valueOf(atts.getValue("AllowInfoMRP")));
if (m_Role.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Role.getName(), "Role", m_Role.get_ID(),
AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Role"));
} else {
record_log(ctx, 0, m_Role.getName(), "Role", m_Role.get_ID(),
AD_Backup_ID, Object_Status, "AD_Role", get_IDWithColumn(
ctx, "AD_Table", "TableName", "AD_Role"));
throw new POSaveFailedException("Role");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int Role_id = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
if (roles.contains(Role_id))
return;
roles.add(Role_id);
X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
AttributesImpl atts = new AttributesImpl();
createRoleBinding(atts, m_Role);
document.startElement("", "", "role", atts);
// Process org access
String sql = "SELECT * FROM AD_Role_OrgAccess WHERE AD_Role_ID= "
+ Role_id;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createOrgAccess(ctx, document, rs.getInt("AD_Org_ID"), rs
.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Role_OrgAccess", e);
throw new DatabaseAccessException("Failed to export organization role access.");
}
// Process user assignment access
sql = "SELECT * FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createUserRole(ctx, document, rs.getInt("AD_User_ID"),
rs.getInt("AD_Role_ID"), rs.getInt("AD_Org_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_User_Roles", e);
throw new DatabaseAccessException("Failed to export user role assignment.");
}
// Process AD_Window_Access Values
sql = "SELECT * FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createWindowAccess(ctx, document, rs
.getInt("AD_Window_ID"), rs.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Window_Access", e);
throw new DatabaseAccessException("Failed to export window access.");
}
// Process AD_Process_Access Values
sql = "SELECT * FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createProcessAccess(ctx, document, rs
.getInt("AD_Process_ID"), rs.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Process_Access", e);
throw new DatabaseAccessException("Failed to export process access.");
}
// Process AD_Form_Access Values
sql = "SELECT * FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createFormAccess(ctx, document, rs.getInt("AD_Form_ID"),
rs.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Form_Access", e);
throw new DatabaseAccessException("Failed to export form access.");
}
// Process AD_Workflow_Access Values
sql = "SELECT * FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createWorkflowAccess(ctx, document, rs
.getInt("AD_Workflow_ID"), rs.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Workflow_Access", e);
throw new DatabaseAccessException("Failed to export workflow access.");
}
// Process AD_Task_Access Values
sql = "SELECT * FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createTaskAccess(ctx, document, rs.getInt("AD_Task_ID"), rs
.getInt("AD_Role_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
log.log(Level.SEVERE, "AD_Task_Access", e);
throw new DatabaseAccessException("Failed to export task access.");
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
document.endElement("", "", "role");
}
private void createTaskAccess(Properties ctx, TransformerHandler document,
int AD_Task_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID, AD_Task_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
taskHandler.create(ctx, document);
ctx.remove(X_AD_Task.COLUMNNAME_AD_Task_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private void createWorkflowAccess(Properties ctx,
TransformerHandler document, int AD_Workflow_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
workflowHandler.create(ctx, document);
ctx.remove(X_AD_Workflow.COLUMNNAME_AD_Workflow_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private void createFormAccess(Properties ctx, TransformerHandler document,
int AD_Form_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID, AD_Form_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
formHandler.create(ctx, document);
ctx.remove(X_AD_Form.COLUMNNAME_AD_Form_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private void createProcessAccess(Properties ctx,
TransformerHandler document, int AD_Process_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID, AD_Process_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
processHandler.create(ctx, document);
ctx.remove(X_AD_Process.COLUMNNAME_AD_Process_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private void createWindowAccess(Properties ctx,
TransformerHandler document, int AD_Window_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID, AD_Window_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
windowHandler.create(ctx, document);
ctx.remove(X_AD_Window.COLUMNNAME_AD_Window_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private void createUserRole(Properties ctx, TransformerHandler document,
int AD_User_ID, int AD_Role_ID, int AD_Org_ID) throws SAXException {
Env.setContext(ctx, X_AD_User.COLUMNNAME_AD_User_ID, AD_User_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
Env.setContext(ctx, "AD_Org_ID", AD_Org_ID);
userHandler.create(ctx, document);
ctx.remove(X_AD_User.COLUMNNAME_AD_User_ID);
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
ctx.remove("AD_Org_ID");
}
private void createOrgAccess(Properties ctx, TransformerHandler document,
int AD_Org_ID, int AD_Role_ID) throws SAXException {
Env.setContext(ctx, "AD_Org_ID", AD_Org_ID);
Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID);
orgHandler.create(ctx, document);
ctx.remove("AD_Org_ID");
ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID);
}
private AttributesImpl createRoleBinding(AttributesImpl atts,
X_AD_Role m_Role) {
String sql = null;
String name = null;
atts.clear();
if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Role_ID","CDATA",Integer.toString(m_Role.getAD_Role_ID()));
if (m_Role.getAD_Tree_Menu_ID() > 0) {
sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='MM'";
name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Menu_ID());
atts.addAttribute("", "", "treemenuname", "CDATA", name);
} else
atts.addAttribute("", "", "treemenuname", "CDATA", "");
if (m_Role.getAD_Tree_Org_ID() > 0) {
sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='OO'";
name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Org_ID());
atts.addAttribute("", "", "treeorgname", "CDATA", name);
} else
atts.addAttribute("", "", "treeorgname", "CDATA", "");
if (m_Role.getC_Currency_ID() > 0) {
sql = "SELECT ISO_Code FROM C_Currency WHERE C_Currency_ID=?";
name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID());
atts.addAttribute("", "", "currencycode", "CDATA", name);
} else
atts.addAttribute("", "", "currencycode", "CDATA", "");
if (m_Role.getSupervisor_ID() > 0) {
sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID());
atts.addAttribute("", "", "supervisorid", "CDATA", name);
} else
atts.addAttribute("", "", "supervisorid", "CDATA", "");
atts.addAttribute("", "", "Description", "CDATA", (m_Role
.getDescription() != null ? m_Role.getDescription() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Role.getName() != null ? m_Role.getName() : ""));
atts.addAttribute("", "", "AmtApproval", "CDATA", ("" + m_Role
.getAmtApproval()));
atts.addAttribute("", "", "isAccessAllOrgs", "CDATA", (m_Role
.isAccessAllOrgs() == true ? "true" : "false"));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Role.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "isCanApproveOwnDoc", "CDATA", (m_Role
.isCanApproveOwnDoc() == true ? "true" : "false"));
atts.addAttribute("", "", "isCanExport", "CDATA",
(m_Role.isCanExport() == true ? "true" : "false"));
atts.addAttribute("", "", "isCanReport", "CDATA",
(m_Role.isCanReport() == true ? "true" : "false"));
atts.addAttribute("", "", "isChangeLog", "CDATA",
(m_Role.isChangeLog() == true ? "true" : "false"));
atts.addAttribute("", "", "isManual", "CDATA",
(m_Role.isManual() == true ? "true" : "false"));
atts.addAttribute("", "", "isPersonalAccess", "CDATA", (m_Role
.isPersonalAccess() == true ? "true" : "false"));
atts.addAttribute("", "", "isPersonalLock", "CDATA", (m_Role
.isPersonalLock() == true ? "true" : "false"));
atts.addAttribute("", "", "isShowAcct", "CDATA",
(m_Role.isShowAcct() == true ? "true" : "false"));
atts.addAttribute("", "", "isUseUserOrgAccess", "CDATA", (m_Role
.isUseUserOrgAccess() == true ? "true" : "false"));
atts.addAttribute("", "", "isOverwritePriceLimit", "CDATA", (m_Role
.isOverwritePriceLimit() == true ? "true" : "false"));
atts
.addAttribute("", "", "PreferenceType", "CDATA", (m_Role
.getPreferenceType() != null ? m_Role
.getPreferenceType() : ""));
atts.addAttribute("", "", "UserLevel", "CDATA",
(m_Role.getUserLevel() != null ? m_Role.getUserLevel() : ""));
atts.addAttribute("", "", "AllowInfoAccount", "CDATA", Boolean.toString(m_Role.isAllow_Info_Account()));
atts.addAttribute("", "", "AllowInfoAsset", "CDATA", Boolean.toString(m_Role.isAllow_Info_Asset()));
atts.addAttribute("", "", "AllowInfoBPartner", "CDATA", Boolean.toString(m_Role.isAllow_Info_BPartner()));
// atts.addAttribute("", "", "AllowInfoCashJournal", "CDATA", Boolean.toString(m_Role.isAllow_Info_CashJournal()));
atts.addAttribute("", "", "AllowInfoInOut", "CDATA", Boolean.toString(m_Role.isAllow_Info_InOut()));
atts.addAttribute("", "", "AllowInfoInvoice", "CDATA", Boolean.toString(m_Role.isAllow_Info_Invoice()));
atts.addAttribute("", "", "AllowInfoOrder", "CDATA", Boolean.toString(m_Role.isAllow_Info_Order()));
atts.addAttribute("", "", "AllowInfoPayment", "CDATA", Boolean.toString(m_Role.isAllow_Info_Payment()));
atts.addAttribute("", "", "AllowInfoProduct", "CDATA", Boolean.toString(m_Role.isAllow_Info_Product()));
atts.addAttribute("", "", "AllowInfoResource", "CDATA", Boolean.toString(m_Role.isAllow_Info_Resource()));
atts.addAttribute("", "", "AllowInfoSchedule", "CDATA", Boolean.toString(m_Role.isAllow_Info_Schedule()));
// atts.addAttribute("", "", "AllowInfoCRP", "CDATA", Boolean.toString(m_Role.isAllow_Info_CRP()));
// atts.addAttribute("", "", "AllowInfoMRP", "CDATA", Boolean.toString(m_Role.isAllow_Info_MRP()));
return atts;
}
}

View File

@ -1,113 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class SQLStatementElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
log.info(elementValue);
Attributes atts = element.attributes;
String DBType = atts.getValue("DBType");
String sql = atts.getValue("statement").trim();
if (sql.endsWith(";"))
sql = sql.substring(0, sql.length() - 1);
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
if(DBType.equals("ALL")) {
@SuppressWarnings("unused")
int n = pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ atts.getValue("statement"));
}
else if(DB.isOracle() == true && DBType.equals("Oracle")) {
pstmt.executeUpdate();
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ atts.getValue("statement"));
}
else if ( DB.isPostgreSQL()
&& ( DBType.equals("Postgres")
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
)
) {
// Avoid convert layer - command specific for postgresql
//
// pstmt = DB.prepareStatement(sql, null);
// pstmt.executeUpdate();
//
Connection m_con = DB.getConnectionRW(true);
try {
Statement stmt = m_con.createStatement();
@SuppressWarnings("unused")
int n = stmt.executeUpdate (atts.getValue("statement"));
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ atts.getValue("statement"));
// Postgres needs to commit DDL statements
if (m_con != null && !m_con.getAutoCommit())
m_con.commit();
stmt.close();
} finally {
m_con.close();
}
}
pstmt.close();
} catch (Exception e) {
log.log(Level.SEVERE,"SQLSatement", e);
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
AttributesImpl atts = new AttributesImpl();
createSQLStatmentBinding(atts, SQLStatement, DBType);
document.startElement("","","SQLStatement",atts);
document.endElement("","","SQLStatement");
}
private AttributesImpl createSQLStatmentBinding( AttributesImpl atts, String SqlStatement, String DBType)
{
atts.clear();
atts.addAttribute("","","DBType","CDATA",DBType);
atts.addAttribute("","","statement","CDATA",SqlStatement);
return atts;
}
}

View File

@ -1,333 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTab;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Tab;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class TabElementHandler extends AbstractElementHandler
{
private FieldElementHandler fieldHandler = new FieldElementHandler();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("ADTabNameID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("window")
&& element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("ADTabNameID");
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
if (tableid <= 0) {
element.defer = true;
return;
}
int windowid = 0;
if (element.parent != null && element.parent.getElementValue().equals("window")
&& element.parent.recordId > 0) {
windowid = element.parent.recordId;
} else {
windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
if (element.parent != null && element.parent.getElementValue().equals("window")
&& windowid > 0) {
element.parent.recordId = windowid;
}
}
if (windowid <= 0) {
element.defer = true;
return;
}
StringBuffer sqlB = new StringBuffer ("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid
+ " and Name = '"+name +"'"
+ " and AD_Table_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString (), tableid);
MTab m_Tab = new MTab(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Tab_ID") != null && Integer.parseInt(atts.getValue("AD_Tab_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Tab.setAD_Tab_ID(Integer.parseInt(atts.getValue("AD_Tab_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_Tab",m_Tab);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
sqlB = null;
m_Tab.setName(name);
id = 0;
if (getStringValue(atts,"ADColumnSortYesNoNameID")!= null){
name = atts.getValue("ADColumnSortYesNoNameID");
id = get_IDWithMasterAndColumn (ctx, "AD_Column","Name", name, MTable.Table_Name, get_IDWithColumn(ctx,MTable.Table_Name, MTable.COLUMNNAME_TableName, atts.getValue("ADTableNameID")));
m_Tab.setAD_ColumnSortYesNo_ID(id);
}
if (getStringValue(atts,"ADColumnSortOrderNameID")!= null){
name = atts.getValue("ADColumnSortOrderNameID");
id = get_IDWithMasterAndColumn (ctx, "AD_Column","Name", name, MTable.Table_Name, get_IDWithColumn(ctx,MTable.Table_Name, MTable.COLUMNNAME_TableName, atts.getValue("ADTableNameID")));
m_Tab.setAD_ColumnSortOrder_ID(id);
}
if (getStringValue(atts,"ADImageNameID")!= null){
name = atts.getValue("ADImageNameID");
id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
m_Tab.setAD_Image_ID(id);
}
if (getStringValue(atts,"ADProcessNameID")!= null){
name = atts.getValue("ADProcessNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + name;
return;
}
m_Tab.setAD_Process_ID(id);
}
}
if (getStringValue(atts,"ADTableNameID")!= null){
name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
m_Tab.setAD_Table_ID(id);
}
if (getStringValue(atts,"ADColumnNameID")!= null) {
name = atts.getValue("ADColumnNameID");
id = get_IDWithMasterAndColumn(ctx, "AD_Column","ColumnName", atts.getValue("ADColumnNameID"), "AD_Table", m_Tab.getAD_Table_ID());
if (id <= 0 /** TODO Check PackOut Version -- 005 */)
{
id = get_IDWithMasterAndColumn(ctx, "AD_Column","Name", atts.getValue("ADColumnNameID"), "AD_Table", m_Tab.getAD_Table_ID());
}
m_Tab.setAD_Column_ID(id);
if (id <= 0)
{
log.warning("@NotFound@ @AD_Column_ID@ - @Name@:"+name+", @AD_Table_ID@:"+atts.getValue("ADTableNameID"));
}
}
m_Tab.setAD_Window_ID(windowid);
if (getStringValue(atts,"IncludedTabNameID")!= null){
name = atts.getValue("IncludedTabNameID");
id = get_IDWithColumn(ctx, "AD_Tab", "Name", name);
m_Tab.setIncluded_Tab_ID(id);
}
m_Tab.setCommitWarning(atts.getValue("CommitWarning"));
m_Tab.setDescription(getStringValue(atts,"Description"));
m_Tab.setEntityType (atts.getValue("EntityType"));
m_Tab.setHasTree(Boolean.valueOf(atts.getValue("isHasTree")).booleanValue());
m_Tab.setHelp (getStringValue(atts,"Help"));
m_Tab.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_Tab.setImportFields (atts.getValue("ImportFields"));
m_Tab.setIsInfoTab (Boolean.valueOf(atts.getValue("isInfoTab")).booleanValue());
m_Tab.setIsReadOnly (Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
m_Tab.setIsSingleRow (Boolean.valueOf(atts.getValue("isSingleRow")).booleanValue());
m_Tab.setIsSortTab (Boolean.valueOf(atts.getValue("isSortTab")).booleanValue());
m_Tab.setIsTranslationTab (Boolean.valueOf(atts.getValue("IsTranslationTab")).booleanValue());
m_Tab.setName (atts.getValue("Name"));
m_Tab.setOrderByClause (getStringValue(atts,"OrderByClause"));
m_Tab.setProcessing(false);
m_Tab.setSeqNo (Integer.parseInt(atts.getValue("SeqNo")));
m_Tab.setTabLevel (Integer.parseInt(atts.getValue("TabLevel")));
m_Tab.setWhereClause (getStringValue(atts,"WhereClause"));
if (getStringValue(atts,"ReadOnlyLogic") != null) {
m_Tab.setReadOnlyLogic(atts.getValue("ReadOnlyLogic"));
}
if (getStringValue(atts,"DisplayLogic") != null) {
m_Tab.setDisplayLogic(atts.getValue("DisplayLogic"));
}
if (getStringValue(atts,"isInsertRecord") != null) {
m_Tab.setIsInsertRecord(Boolean.valueOf(atts.getValue("isInsertRecord")).booleanValue());
}
if (getStringValue(atts,"isAdvancedTab") != null) {
m_Tab.setIsAdvancedTab(Boolean.valueOf(atts.getValue("isAdvancedTab")).booleanValue());
}
if (m_Tab.save(getTrxName(ctx)) == true){
record_log (ctx, 1, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab"));
element.recordId = m_Tab.getAD_Tab_ID();
} else {
record_log (ctx, 0, m_Tab.getName(),"Tab", m_Tab.get_ID(),AD_Backup_ID, Object_Status,"AD_Tab",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Tab"));
throw new POSaveFailedException("Tab");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document) throws SAXException
{
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
int AD_Tab_ID = Env.getContextAsInt(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID);
X_AD_Tab m_Tab = new X_AD_Tab (ctx, AD_Tab_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
createTabBinding(atts,m_Tab);
document.startElement("","","tab",atts);
//Fields tags.
String sql = "SELECT * FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID
+ "ORDER BY SEQNO asc, "+X_AD_Field.COLUMNNAME_AD_Field_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next())
{
createField(ctx, document, rs.getInt("AD_Field_ID"));
}
}
catch (Exception e)
{
log.log(Level.SEVERE,e.getLocalizedMessage(), e);
throw new DatabaseAccessException("Failed to export window tab", e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
document.endElement("","","tab");
if(m_Tab.getAD_Process_ID() > 0 )
{
packOut.createProcess(m_Tab.getAD_Process_ID(), document);
}
}
private void createField(Properties ctx, TransformerHandler document,
int AD_Field_ID) throws SAXException {
Env.setContext(ctx, X_AD_Field.COLUMNNAME_AD_Field_ID, AD_Field_ID);
fieldHandler.create(ctx, document);
ctx.remove(X_AD_Field.COLUMNNAME_AD_Field_ID);
}
private AttributesImpl createTabBinding( AttributesImpl atts, X_AD_Tab m_Tab)
{
String sql = null;
String name = null;
atts.clear();
if (m_Tab.getAD_Tab_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Tab_ID", "CDATA", Integer.toString(m_Tab.getAD_Tab_ID()));
atts.addAttribute("","","Name","CDATA",(m_Tab.getName () != null ? m_Tab.getName ():""));
if (m_Tab.getAD_ColumnSortOrder_ID()>0){
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortOrder_ID());
atts.addAttribute("","","ADColumnSortOrderNameID","CDATA",name);
}
else
atts.addAttribute("","","ADColumnSortOrderNameID","CDATA","");
if (m_Tab.getAD_ColumnSortYesNo_ID()>0 ){
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_ColumnSortYesNo_ID());
atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA",name);
}
else
atts.addAttribute("","","ADColumnSortYesNoNameID","CDATA","");
if (m_Tab.getAD_Column_ID()>0 ){
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Column_ID());
atts.addAttribute("","","ADColumnNameID","CDATA",name);
}
else
atts.addAttribute("","","ADColumnNameID","CDATA","");
if (m_Tab.getAD_Image_ID() >0 ){
sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Image_ID());
atts.addAttribute("","","ADImageNameID","CDATA",name);
}
else
atts.addAttribute("","","ADImageNameID","CDATA","");
if (m_Tab.getAD_Process_ID() >0 ){
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Process_ID());
atts.addAttribute("","","ADProcessNameID","CDATA",name);
}
else
atts.addAttribute("","","ADProcessNameID","CDATA","");
if (m_Tab.getAD_Tab_ID() >0 ){
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Tab_ID());
atts.addAttribute("","","ADTabNameID","CDATA",name);
}
else
atts.addAttribute("","","ADTabNameID","CDATA","");
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Table_ID());
atts.addAttribute("","","ADTableNameID","CDATA",name);
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getAD_Window_ID());
atts.addAttribute("","","ADWindowNameID","CDATA",name);
if (m_Tab.getIncluded_Tab_ID() > 0 ){
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
name = DB.getSQLValueString(null,sql,m_Tab.getIncluded_Tab_ID());
atts.addAttribute("","","IncludedTabNameID","CDATA",name);
}
else
atts.addAttribute("","","IncludedTabNameID","CDATA","");
atts.addAttribute("","","CommitWarning","CDATA",(m_Tab.getCommitWarning () != null ? m_Tab.getCommitWarning ():""));
atts.addAttribute("","","Description","CDATA",(m_Tab.getDescription () != null ? m_Tab.getDescription ():""));
atts.addAttribute("","","EntityType","CDATA",(m_Tab.getEntityType () != null ? m_Tab.getEntityType ():""));
atts.addAttribute("","","isHasTree","CDATA",(m_Tab.isHasTree()== true ? "true":"false"));
atts.addAttribute("","","Help","CDATA",(m_Tab.getHelp () != null ? m_Tab.getHelp ():""));
atts.addAttribute("","","isInfoTab","CDATA",(m_Tab.isInfoTab()== true ? "true":"false"));
atts.addAttribute("","","isReadOnly","CDATA",(m_Tab.isReadOnly()== true ? "true":"false"));
atts.addAttribute("","","isSingleRow","CDATA",(m_Tab.isSingleRow()== true ? "true":"false"));
atts.addAttribute("","","isSortTab","CDATA",(m_Tab.isSortTab()== true ? "true":"false"));
atts.addAttribute("","","isActive","CDATA",(m_Tab.isActive()== true ? "true":"false"));
atts.addAttribute("","","IsTranslationTab","CDATA",(m_Tab.isTranslationTab()== true ? "true":"false"));
atts.addAttribute("","","OrderByClause","CDATA",(m_Tab.getOrderByClause () != null ? m_Tab.getOrderByClause ():""));
atts.addAttribute("","","isProcessing","CDATA",(m_Tab.isProcessing()== true ? "true":"false"));
atts.addAttribute("","","SeqNo","CDATA",(m_Tab.getSeqNo () >= 0 ? "" + m_Tab.getSeqNo ():"0"));
atts.addAttribute("","","TabLevel","CDATA",(m_Tab.getTabLevel () >= 0 ? "" + m_Tab.getTabLevel ():""));
atts.addAttribute("","","WhereClause","CDATA",(m_Tab.getWhereClause () != null ? m_Tab.getWhereClause ():""));
atts.addAttribute("","","ReadOnlyLogic","CDATA",(m_Tab.getReadOnlyLogic() != null ? m_Tab.getReadOnlyLogic ():""));
atts.addAttribute("","","DisplayLogic","CDATA",(m_Tab.getDisplayLogic() != null ? m_Tab.getDisplayLogic ():""));
atts.addAttribute("","","isInsertRecord","CDATA",(m_Tab.isInsertRecord()== true ? "true":"false"));
atts.addAttribute("","","isAdvancedTab","CDATA",(m_Tab.isAdvancedTab()== true ? "true":"false"));
atts.addAttribute("","","Syncfields","CDATA","false");
return atts;
}
}

View File

@ -1,342 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackIn;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTable;
import org.compiere.model.X_AD_Column;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Table;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class TableElementHandler extends AbstractElementHandler {
private ColumnElementHandler columnHandler = new ColumnElementHandler();
private List<Integer>tables = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException
{
final PackIn packIn = (PackIn)ctx.get("PackInProcess");
final String elementValue = element.getElementValue();
final Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue+" "+atts.getValue("ADTableNameID"));
final String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype))
{
final String tableName = atts.getValue("ADTableNameID");
int id = packIn.getTableId(tableName);
if (id <= 0)
{
id = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
}
if (id > 0 && isTableProcess(ctx, id) && element.pass == 1)
{
return;
}
MTable m_Table = new MTable(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Table_ID") != null && Integer.parseInt(atts.getValue("AD_Table_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Table.setAD_Table_ID(Integer.parseInt(atts.getValue("AD_Table_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0)
{
AD_Backup_ID = copyRecord(ctx, "AD_Table",m_Table);
Object_Status = "Update";
}
else
{
Object_Status = "New";
AD_Backup_ID =0;
}
m_Table.setTableName(tableName);
//
// Window
final String windowName = atts.getValue("ADWindowNameID");
if (!Util.isEmpty(windowName, true))
{
id = get_IDWithColumn(ctx, "AD_Window", "Name", windowName);
if (id > 0)
{
m_Table.setAD_Window_ID(id);
}
else if (!element.defer)
{
element.defer = true;
element.unresolved = "Window:"+windowName;
}
else
{
log.warning("@NotFound@ @AD_Window_ID@:"+windowName);
}
}
//
// PO Window
final String poWindowName = getStringValue(atts,"POWindowNameID");
if (!Util.isEmpty(poWindowName, true))
{
id = get_IDWithColumn(ctx, "AD_Window", "Name", poWindowName);
if (id > 0)
{
m_Table.setPO_Window_ID(id);
}
else if (!element.defer)
{
element.defer = true;
element.unresolved = "POWindow:"+poWindowName;
}
else
{
log.warning("@NotFound@ @PO_Window_ID@:"+poWindowName);
}
}
//
// Validation Rule
final String valRuleName = getStringValue(atts,"ADValRuleNameID");
if (!Util.isEmpty(valRuleName, true))
{
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", valRuleName);
if (id > 0)
{
m_Table.setAD_Val_Rule_ID(id);
}
else
{
element.defer = true;
element.unresolved = "ValRule:"+valRuleName;
}
}
//
m_Table.setAccessLevel (atts.getValue("AccessLevel"));
m_Table.setDescription(getStringValue(atts,"Description"));
m_Table.setEntityType(atts.getValue("EntityType"));
m_Table.setHelp(getStringValue(atts,"Help"));
m_Table.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_Table.setImportTable(getStringValue(atts,"ImportTable"));
m_Table.setIsChangeLog(Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue());
m_Table.setIsDeleteable(Boolean.valueOf(atts.getValue("isDeleteable")).booleanValue());
m_Table.setIsHighVolume(Boolean.valueOf(atts.getValue("isHighVolume")).booleanValue());
m_Table.setIsSecurityEnabled(Boolean.valueOf(atts.getValue("isSecurityEnabled")).booleanValue());
m_Table.setIsView(Boolean.valueOf(atts.getValue("isView")).booleanValue());
//m_Table.setLoadSeq(Integer.parseInt(atts.getValue("LoadSeq")));
m_Table.setName(atts.getValue("Name"));
m_Table.setReplicationType(getStringValue(atts,"ReplicationType"));
m_Table.setTableName(atts.getValue("TableName"));
if (m_Table.save(getTrxName(ctx)) == true)
{
record_log (ctx, 1, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
tables.add(m_Table.getAD_Table_ID());
packIn.addTable(tableName, m_Table.getAD_Table_ID());
element.recordId = m_Table.getAD_Table_ID();
}
else
{
record_log (ctx, 0, m_Table.getName(),"Table", m_Table.get_ID(),AD_Backup_ID, Object_Status,"AD_Table",get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
throw new POSaveFailedException("Table");
}
}
else
{
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Table_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
boolean exported = isTableProcess(ctx, AD_Table_ID);
AttributesImpl atts = new AttributesImpl();
//Export table if not already done so
if (!exported){
String sql = "SELECT Name FROM AD_Table WHERE AD_Table_ID= " + AD_Table_ID;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null);
createTableBinding(atts,m_Table);
document.startElement("","","table",atts);
String sql1 = "SELECT * FROM AD_Column WHERE AD_Table_ID = " + AD_Table_ID
+ " ORDER BY IsKey DESC, AD_Column_ID"; // Export key column as the first one
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement (sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()){
packOut.createAdElement(rs1.getInt("AD_Element_ID"), document);
if (rs1.getInt("AD_Reference_ID")>0)
packOut.createReference (rs1.getInt("AD_Reference_ID"), document);
if (rs1.getInt("AD_Reference_Value_ID")>0)
packOut.createReference (rs1.getInt("AD_Reference_Value_ID"), document);
if (rs1.getInt("AD_Process_ID")>0)
packOut.createProcess (rs1.getInt("AD_Process_ID"), document);
if (rs1.getInt("AD_Val_Rule_ID")>0)
packOut.createDynamicRuleValidation (rs1.getInt("AD_Val_Rule_ID"), document);
createColumn(ctx, document, rs1.getInt("AD_Column_ID"));
}
rs1.close();
pstmt1.close();
pstmt1 = null;
}
catch (Exception e) {
log.log(Level.SEVERE,"getProcess", e);
}
finally {
try {
if (pstmt1 != null)
pstmt1.close ();
}
catch (Exception e){}
pstmt1 = null;
}
document.endElement("","","table");
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e){
log.log(Level.SEVERE,"getProcess", e);
}
finally{
try {
if (pstmt != null)
pstmt.close ();
}
catch (Exception e){}
pstmt = null;
}
}
}
private void createColumn(Properties ctx, TransformerHandler document, int AD_Column_ID) throws SAXException {
Env.setContext(ctx, X_AD_Column.COLUMNNAME_AD_Column_ID, AD_Column_ID);
columnHandler.create(ctx, document);
ctx.remove(X_AD_Column.COLUMNNAME_AD_Column_ID);
}
private boolean isTableProcess(Properties ctx, int AD_Table_ID)
{
if (tables.contains(AD_Table_ID))
return true;
else {
tables.add(AD_Table_ID);
return false;
}
}
private AttributesImpl createTableBinding( AttributesImpl atts, X_AD_Table m_Table)
{
String sql = null;
String name = null;
atts.clear();
if (m_Table.getAD_Table_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Table_ID", "CDATA", Integer.toString(m_Table.getAD_Table_ID()));
atts.addAttribute("","","Name","CDATA",(m_Table.getName () != null ? m_Table.getName ():""));
if (m_Table.getAD_Table_ID()> 0 ){
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null,sql,m_Table.getAD_Table_ID());
atts.addAttribute("","","ADTableNameID","CDATA",name);
}
else
atts.addAttribute("","","ADTableNameID","CDATA","");
if (m_Table.getAD_Window_ID()> 0 ){
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null,sql,m_Table.getAD_Window_ID());
atts.addAttribute("","","ADWindowNameID","CDATA",name);
}
else
atts.addAttribute("","","ADWindowNameID","CDATA","");
if (m_Table.getPO_Window_ID()> 0 ){
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null,sql,m_Table.getPO_Window_ID());
atts.addAttribute("","","POWindowNameID","CDATA",name);
}
else
atts.addAttribute("","","POWindowNameID","CDATA","");
if (m_Table.getAD_Val_Rule_ID()> 0 ){
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
name = DB.getSQLValueString(null,sql,m_Table.getAD_Val_Rule_ID());
atts.addAttribute("","","ADValRuleNameID","CDATA",name);
}
else
atts.addAttribute("","","ADValRuleNameID","CDATA","");
atts.addAttribute("","","AccessLevel","CDATA",(m_Table.getAccessLevel () != null ? m_Table.getAccessLevel ():""));
atts.addAttribute("","","Description","CDATA",(m_Table.getDescription () != null ? m_Table.getDescription ():""));
atts.addAttribute("","","EntityType","CDATA",(m_Table.getEntityType () != null ? m_Table.getEntityType ():""));
atts.addAttribute("","","Help","CDATA",(m_Table.getHelp() != null ? m_Table.getHelp ():""));
atts.addAttribute("","","ImportTable","CDATA",(m_Table.getImportTable () != null ? m_Table.getImportTable ():""));
atts.addAttribute("","","isChangeLog","CDATA",(m_Table.isChangeLog()== true ? "true":"false"));
atts.addAttribute("","","isActive","CDATA",(m_Table.isActive()== true ? "true":"false"));
atts.addAttribute("","","isDeleteable","CDATA",(m_Table.isDeleteable()== true ? "true":"false"));
atts.addAttribute("","","isHighVolume","CDATA",(m_Table.isHighVolume()== true ? "true":"false"));
atts.addAttribute("","","isSecurityEnabled","CDATA",(m_Table.isSecurityEnabled()== true ? "true":"false"));
atts.addAttribute("","","isView","CDATA",(m_Table.isView()== true ? "true":"false"));
atts.addAttribute("","","LoadSeq","CDATA",(m_Table.getLoadSeq ()> 0 ? "" + m_Table.getLoadSeq ():""));
atts.addAttribute("","","ReplicationType","CDATA",(m_Table.getReplicationType () != null ? m_Table.getReplicationType ():""));
atts.addAttribute("","","TableName","CDATA",(m_Table.getTableName () != null ? m_Table.getTableName ():""));
return atts;
}
}

View File

@ -1,137 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Task;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class TaskAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int taskid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (getStringValue(atts,"rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (getStringValue(atts,"taskname")!=null){
String name = atts.getValue("taskname");
sqlB = new StringBuffer ("SELECT AD_Task_ID FROM AD_Task WHERE Name= ?");
taskid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Task_Access WHERE AD_Role_ID=? and AD_Task_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,taskid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Task_Access ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadWrite = '" + atts.getValue("isReadWrite") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Task_ID = " + taskid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to task access failed");
throw new DatabaseAccessException("Update to task access failed");
}
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Task_Access")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_Role_ID, AD_Task_ID, isActive, isReadWrite) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + roleid )
.append( ", " + taskid )
.append( ", '" + atts.getValue("isActive") )
.append( "', '" + atts.getValue("isReadWrite")+"')" );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to task access failed");
throw new DatabaseAccessException("Insert to task access failed");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Task_ID = Env.getContextAsInt(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createTaskAccessBinding(atts, AD_Task_ID, AD_Role_ID);
document.startElement("", "", "taskaccess", atts);
document.endElement("", "", "taskaccess");
}
private AttributesImpl createTaskAccessBinding(AttributesImpl atts,
int task_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?";
name = DB.getSQLValueString(null, sql, task_id);
atts.addAttribute("", "", "taskname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Task_Access WHERE AD_Task_ID=" + task_id
+ " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadWrite FROM AD_Task_Access WHERE AD_Task_ID="
+ task_id + " and AD_Role_ID=?";
String isReadWrite = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite);
return atts;
}
}

View File

@ -1,140 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MTask;
import org.compiere.model.X_AD_Task;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class TaskElementHandler extends AbstractElementHandler {
private List<Integer> tasks = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("ADTaskNameID"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("ADTaskNameID");
int id = get_ID(ctx, "AD_Task", name);
MTask m_Task = new MTask(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Task_ID") != null && Integer.parseInt(atts.getValue("AD_Task_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Task.setAD_Task_ID(Integer.parseInt(atts.getValue("AD_Task_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Task", m_Task);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Task.setAccessLevel(atts.getValue("AccessLevel"));
m_Task.setDescription(getStringValue(atts,"Description"));
m_Task.setEntityType(atts.getValue("EntityType"));
m_Task.setHelp(getStringValue(atts,"Help"));
m_Task.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Task.setName(name);
m_Task.setOS_Command(getStringValue(atts,"OS_Command"));
if (m_Task.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Task.getName(), "Task", m_Task.get_ID(),
AD_Backup_ID, Object_Status, "AD_Task",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Task"));
} else {
record_log(ctx, 0, m_Task.getName(), "Task", m_Task.get_ID(),
AD_Backup_ID, Object_Status, "AD_Task",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Task"));
throw new POSaveFailedException("Task");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Task_ID = Env.getContextAsInt(ctx, "AD_Task_ID");
if (tasks.contains(AD_Task_ID))
return;
tasks.add(AD_Task_ID);
X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null);
AttributesImpl atts = new AttributesImpl();
createTaskBinding(atts, m_Task);
document.startElement("", "", "task", atts);
document.endElement("", "", "task");
}
private static AttributesImpl createTaskBinding(AttributesImpl atts,
X_AD_Task m_Task) {
String sql = null;
String name = null;
atts.clear();
if (m_Task.getAD_Task_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Task_ID","CDATA",Integer.toString(m_Task.getAD_Task_ID()));
if (m_Task.getAD_Task_ID() > 0) {
sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?";
name = DB.getSQLValueString(null, sql, m_Task.getAD_Task_ID());
if (name != null)
atts.addAttribute("", "", "ADTaskNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
}
atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Task
.getAccessLevel() != null ? m_Task.getAccessLevel() : ""));
atts.addAttribute("", "", "Description", "CDATA", (m_Task
.getDescription() != null ? m_Task.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Task
.getEntityType() != null ? m_Task.getEntityType() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Task.getHelp() != null ? m_Task.getHelp() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Task.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "Name", "CDATA",
(m_Task.getName() != null ? m_Task.getName() : ""));
atts.addAttribute("", "", "OS_Command", "CDATA", (m_Task
.getOS_Command() != null ? m_Task.getOS_Command() : ""));
return atts;
}
}

View File

@ -1,141 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_User;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class UserRoleElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int userid =0;
int orgid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("username")!=null){
String name = atts.getValue("username");
sqlB = new StringBuffer ("SELECT AD_User_ID FROM AD_User WHERE Name= ?");
userid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (atts.getValue("rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (atts.getValue("orgname")!=null){
String name = atts.getValue("orgname");
sqlB = new StringBuffer ("SELECT AD_Org_ID FROM AD_Org WHERE Name= ?");
orgid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_User_Roles WHERE AD_User_ID = ? and AD_Role_ID = ?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),userid,roleid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
//AD_Backup_ID = copyRecord("AD_Role",m_Role);
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_User_Roles ")
.append( "SET isActive = '" + atts.getValue("isActive")+"'" )
.append( " WHERE AD_User_ID = " + userid )
.append( " and AD_Role_ID = " + roleid )
.append( " and AD_Org_ID = " + orgid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Update to user roles failed");
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_User_Roles")
.append( "(AD_Client_ID, CreatedBy, UpdatedBy, " )
.append( "AD_User_ID, AD_Role_ID, AD_Org_ID, isActive) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " +userid )
.append( ", " + roleid )
.append( ", " + orgid )
.append( ", '" + atts.getValue("isActive")+"')" );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to user roles failed");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_User_ID = Env.getContextAsInt(ctx, X_AD_User.COLUMNNAME_AD_User_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
AttributesImpl atts = new AttributesImpl();
createUserAssignBinding(atts, AD_User_ID,AD_Role_ID, AD_Org_ID);
document.startElement("", "", "userrole", atts);
document.endElement("", "", "userrole");
}
private AttributesImpl createUserAssignBinding(AttributesImpl atts,
int user_id, int role_id, int org_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
name = DB.getSQLValueString(null, sql, user_id);
atts.addAttribute("", "", "username", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_User_Roles WHERE AD_User_ID=" + user_id
+ " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
name = DB.getSQLValueString(null, sql, org_id);
atts.addAttribute("", "", "orgname", "CDATA", name);
return atts;
}
}

View File

@ -1,142 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Window;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WindowAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int windowid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (atts.getValue("rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
if (roleid <= 0) {
element.defer = true;
return;
}
}
if (atts.getValue("windowname")!=null){
String name = atts.getValue("windowname");
sqlB = new StringBuffer ("SELECT AD_Window_ID FROM AD_Window WHERE Name= ?");
windowid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
if (windowid <= 0) {
element.defer = true;
return;
}
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Window_Access WHERE AD_Role_ID=? and AD_Window_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,windowid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Window_Access ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadWrite = '" + atts.getValue("isReadWrite") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Window_ID = " + windowid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Update to window access failed");
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Window_Access")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_Role_ID, AD_Window_ID, isActive, isReadWrite) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + roleid )
.append( ", " + windowid )
.append( ", '" + atts.getValue("isActive") )
.append( "', '" + atts.getValue("isReadWrite")+"')" );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1)
log.info("Insert to window access failed");
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Window_ID = Env.getContextAsInt(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createWindowAccessBinding(atts, AD_Window_ID, AD_Role_ID);
document.startElement("", "", "windowaccess", atts);
document.endElement("", "", "windowaccess");
}
private AttributesImpl createWindowAccessBinding(AttributesImpl atts,
int window_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, window_id);
atts.addAttribute("", "", "windowname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Window_Access WHERE AD_Window_ID="
+ window_id + " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadWrite FROM AD_Window_Access WHERE AD_Window_ID="
+ window_id + " and AD_Role_ID=?";
String isReadWrite = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite);
return atts;
}
}

View File

@ -1,309 +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. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com *
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MWindow;
import org.compiere.model.X_AD_Preference;
import org.compiere.model.X_AD_Tab;
import org.compiere.model.X_AD_Window;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WindowElementHandler extends AbstractElementHandler {
private TabElementHandler tabHandler = new TabElementHandler();
private PreferenceElementHandler preferenceHandler = new PreferenceElementHandler();
private List<Integer> windows = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
// Check namespace.
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = atts.getValue("Name");
int id = get_ID(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
return;
}
MWindow m_Window = new MWindow(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Window_ID") != null && Integer.parseInt(atts.getValue("AD_Window_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Window.setAD_Window_ID(Integer.parseInt(atts.getValue("AD_Window_ID")));
String Object_Status = null;
int AD_Backup_ID = -1;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Window", m_Window);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Window.setName(name);
name = atts.getValue("ADImageNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
//TODO: export and import of ad_image
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_Window.setAD_Image_ID(id);
}
name = atts.getValue("ADColorNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Color", "Name", name);
//TODO: export and import of ad_color
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_Window.setAD_Color_ID(id);
}
m_Window.setDescription(getStringValue(atts,"Description"));
m_Window.setEntityType(atts.getValue("EntityType"));
m_Window.setHelp(getStringValue(atts,"Help"));
m_Window.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Window.setIsBetaFunctionality(Boolean.valueOf(
atts.getValue("isBetaFunctionality")).booleanValue());
m_Window.setIsDefault(Boolean.valueOf(atts.getValue("isDefault"))
.booleanValue());
m_Window.setIsSOTrx(Boolean.valueOf(atts.getValue("isSOTrx"))
.booleanValue());
m_Window.setName(atts.getValue("Name"));
m_Window.setProcessing(false);
if (!Util.isEmpty(atts.getValue("WinHeight"), true))
m_Window.setWinWidth(getValueInt(atts, "WinWidth", 0));
if (!Util.isEmpty(atts.getValue("WinHeight"), true))
m_Window.setWinHeight(getValueInt(atts, "WinHeight", 0));
m_Window.setWindowType(atts.getValue("WindowType"));
if (m_Window.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Window.getName(), "Window", m_Window
.get_ID(), AD_Backup_ID, Object_Status, "AD_Window",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Window"));
element.recordId = m_Window.getAD_Window_ID();
windows.add(m_Window.getAD_Window_ID());
} else {
record_log(ctx, 0, m_Window.getName(), "Window", m_Window
.get_ID(), AD_Backup_ID, Object_Status, "AD_Window",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Window"));
throw new POSaveFailedException("Window");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Window_ID = Env.getContextAsInt(ctx, "AD_Window_ID");
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null);
AttributesImpl atts = new AttributesImpl();
createWindowBinding(atts, m_Window);
document.startElement("", "", "window", atts);
// Tab Tag
String sql = "SELECT * FROM AD_TAB WHERE AD_WINDOW_ID = "
+ AD_Window_ID
+" ORDER BY "+X_AD_Tab.COLUMNNAME_SeqNo+","+X_AD_Tab.COLUMNNAME_AD_Tab_ID
;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
packOut.createTable(rs.getInt("AD_Table_ID"), document);
createTab(ctx, document, rs.getInt("AD_Tab_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export window.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export window.", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
//TODO: export of ad_image and ad_color use
// Loop tags.
document.endElement("", "", "window");
// Preference Tag
sql = "SELECT * FROM AD_PREFERENCE WHERE AD_WINDOW_ID = " + AD_Window_ID
+" ORDER BY "+X_AD_Preference.COLUMNNAME_AD_Preference_ID;
pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
createPreference(ctx, document, rs.getInt("AD_Preference_ID"));
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export window preference.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export window preference.", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
private void createPreference(Properties ctx, TransformerHandler document,
int AD_Preference_ID) throws SAXException {
Env.setContext(ctx, X_AD_Preference.COLUMNNAME_AD_Preference_ID,
AD_Preference_ID);
preferenceHandler.create(ctx, document);
ctx.remove(X_AD_Preference.COLUMNNAME_AD_Preference_ID);
}
private void createTab(Properties ctx, TransformerHandler document,
int AD_Tab_ID) throws SAXException {
Env.setContext(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID, AD_Tab_ID);
tabHandler.create(ctx, document);
ctx.remove(X_AD_Tab.COLUMNNAME_AD_Tab_ID);
}
private AttributesImpl createWindowBinding(AttributesImpl atts,
X_AD_Window m_Window) {
atts.clear();
if (m_Window.getAD_Window_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Window_ID", "CDATA", Integer.toString(m_Window.getAD_Window_ID()));
String sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
String name = DB.getSQLValueString(null, sql, m_Window
.getAD_Window_ID());
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
if (m_Window.getAD_Image_ID() > 0) {
sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?";
name = DB.getSQLValueString(null, sql, m_Window.getAD_Image_ID());
if (name != null)
atts.addAttribute("", "", "ADImageNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
}
else {
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
}
if (m_Window.getAD_Color_ID() > 0) {
sql = "SELECT Name FROM AD_Color WHERE AD_Color_ID=?";
name = DB.getSQLValueString(null, sql, m_Window.getAD_Color_ID());
if (name != null)
atts.addAttribute("", "", "ADColorNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADColorNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADColorNameID", "CDATA", "");
}
atts.addAttribute("", "", "Description", "CDATA", (m_Window
.getDescription() != null ? m_Window.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Window
.getEntityType() != null ? m_Window.getEntityType() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Window.getHelp() != null ? m_Window.getHelp() : ""));
atts.addAttribute("", "", "isBetaFunctionality", "CDATA", (m_Window
.isBetaFunctionality() == true ? "true" : "false"));
atts.addAttribute("", "", "isDefault", "CDATA",
(m_Window.isDefault() == true ? "true" : "false"));
atts.addAttribute("", "", "isSOTrx", "CDATA",
(m_Window.isSOTrx() == true ? "true" : "false"));
atts.addAttribute("", "", "isActive", "CDATA",
(m_Window.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "Name", "CDATA",
(m_Window.getName() != null ? m_Window.getName() : ""));
atts.addAttribute("", "", "isProcessing", "CDATA", (m_Window
.isProcessing() == true ? "true" : "false"));
atts.addAttribute("", "", "WinHeight", "CDATA", (m_Window
.getWinHeight() > 0 ? "" + m_Window.getWinHeight() : ""));
atts.addAttribute("", "", "WinWidth", "CDATA", (m_Window
.getWinWidth() > 0 ? "" + m_Window.getWinWidth() : ""));
atts.addAttribute("", "", "WindowType", "CDATA", (m_Window
.getWindowType() != null ? m_Window.getWindowType() : ""));
return atts;
}
protected int getValueInt(Attributes atts, String name, int defaultValue)
{
String value = atts.getValue(name);
if (Util.isEmpty(value, true))
return defaultValue;
int i = Integer.parseInt(value.trim());
return i;
}
}

View File

@ -1,138 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Workflow;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
int roleid =0;
int workflowid =0;
StringBuffer sqlB = null;
Attributes atts = element.attributes;
if (getStringValue(atts,"rolename")!=null){
String name = atts.getValue("rolename");
sqlB = new StringBuffer ("SELECT AD_Role_ID FROM AD_Role WHERE Name= ?");
roleid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
if (getStringValue(atts,"workflowname")!=null){
String name = atts.getValue("workflowname");
sqlB = new StringBuffer ("SELECT AD_Workflow_ID FROM AD_Workflow WHERE Name= ?");
workflowid = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),name);
}
sqlB = new StringBuffer ("SELECT count(*) FROM AD_Workflow_Access WHERE AD_Role_ID=? and AD_Workflow_ID=?");
int count = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),roleid,workflowid);
@SuppressWarnings("unused")
int AD_Backup_ID = -1;
@SuppressWarnings("unused")
String Object_Status = null;
if (count>0){
Object_Status = "Update";
sqlB = new StringBuffer ("UPDATE AD_Workflow_Access ")
.append( "SET isActive = '" + atts.getValue("isActive") )
.append( "', isReadWrite = '" + atts.getValue("isReadWrite") )
.append( "' WHERE AD_Role_ID = " + roleid )
.append( " and AD_Workflow_ID = " + workflowid );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Update to workflow access failed");
throw new DatabaseAccessException("Update to workflow access failed");
}
}
else{
Object_Status = "New";
AD_Backup_ID =0;
sqlB = new StringBuffer ("INSERT INTO AD_Workflow_Access")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_Role_ID, AD_Workflow_ID, isActive, isReadWrite) " )
.append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + roleid )
.append( ", " + workflowid )
.append( ", '" + atts.getValue("isActive") )
.append( "', '" + atts.getValue("isReadWrite")+"')" );
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
if (no == -1) {
log.info("Insert to workflow access failed");
throw new DatabaseAccessException("Insert to workflow access failed");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
createWorkflowAccessBinding(atts, AD_Workflow_ID, AD_Role_ID);
document.startElement("", "", "workflowaccess", atts);
document.endElement("", "", "workflowaccess");
}
private AttributesImpl createWorkflowAccessBinding(AttributesImpl atts,
int workflow_id, int role_id) {
String sql = null;
String name = null;
atts.clear();
sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?";
name = DB.getSQLValueString(null, sql, workflow_id);
atts.addAttribute("", "", "workflowname", "CDATA", name);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "rolename", "CDATA", name);
sql = "SELECT isActive FROM AD_Workflow_Access WHERE AD_Workflow_ID="
+ workflow_id + " and AD_Role_ID=?";
String TrueFalse = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isActive", "CDATA", TrueFalse);
sql = "SELECT isReadWrite FROM AD_Workflow_Access WHERE AD_Workflow_ID="
+ workflow_id + " and AD_Role_ID=?";
String isReadWrite = DB.getSQLValueString(null, sql, role_id);
atts.addAttribute("", "", "isReadWrite", "CDATA", isReadWrite);
return atts;
}
}

View File

@ -1,453 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, teo.sarca@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.DatabaseAccessException;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.model.X_AD_WF_NodeNext;
import org.compiere.model.X_AD_Workflow;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWorkflow;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowElementHandler extends AbstractElementHandler {
private WorkflowNodeElementHandler nodeHandler = new WorkflowNodeElementHandler();
private WorkflowNodeNextElementHandler nodeNextHandler = new WorkflowNodeNextElementHandler();
private WorkflowNodeNextConditionElementHandler nextConditionHandler = new WorkflowNodeNextConditionElementHandler();
private List<Integer> workflows = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
Attributes atts = element.attributes;
String elementValue = element.getElementValue();
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (log.isLoggable(Level.INFO)) log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
String workflowName = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
MWorkflow m_Workflow = new MWorkflow(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Workflow_ID") != null && Integer.parseInt(atts.getValue("AD_Workflow_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Workflow.setAD_Workflow_ID(Integer.parseInt(atts.getValue("AD_Workflow_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Workflow", m_Workflow);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
String name = atts.getValue("ADWorkflowResponsibleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Responsible: " + name;
return;
}
m_Workflow.setAD_WF_Responsible_ID(id);
}
name = atts.getValue("ADTableNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Table: " + name;
return;
}
m_Workflow.setAD_Table_ID(id);
}
name = atts.getValue("ADWorkflowProcessorNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WorkflowProcessor", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WorkflowProcessor: " + name;
return;
}
m_Workflow.setAD_WorkflowProcessor_ID(id);
}
m_Workflow.setValue(atts.getValue("Value"));
m_Workflow.setName(workflowName);
m_Workflow.setIsBetaFunctionality (Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
m_Workflow.setAccessLevel(atts.getValue("AccessLevel"));
m_Workflow.setDescription(getStringValue(atts,"Description"));
m_Workflow.setHelp(getStringValue(atts,"Help"));
m_Workflow.setDurationUnit(getStringValue(atts,"DurationUnit"));
m_Workflow.setAuthor(getStringValue(atts,"Author"));
if(getStringValue(atts, "Version") != null)
m_Workflow.setVersion(Integer.valueOf(atts.getValue("Version")));
if(getStringValue(atts, "Priority") != null)
m_Workflow.setPriority(Integer.valueOf(atts.getValue("Priority")));
if(getStringValue(atts, "Limit") != null)
m_Workflow.setLimit(Integer.valueOf(atts.getValue("Limit")));
if(getStringValue(atts, "Duration") != null)
m_Workflow.setDuration(Integer.valueOf(atts.getValue("Duration")));
if(getStringValue(atts, "Cost") != null)
m_Workflow.setCost(new BigDecimal(atts.getValue("Cost")));
m_Workflow.setWorkingTime(Integer.valueOf(atts
.getValue("WorkingTime")));
m_Workflow.setWaitingTime(Integer.valueOf(atts
.getValue("WaitingTime")));
m_Workflow.setPublishStatus(atts.getValue("PublishStatus"));
m_Workflow.setWorkflowType(atts.getValue("WorkflowType"));
m_Workflow.setDocValueLogic(getStringValue(atts,"DocValueLogic"));
m_Workflow.setIsValid(atts.getValue("isValid") != null ? Boolean
.valueOf(atts.getValue("isValid")).booleanValue() : true);
m_Workflow.setEntityType(atts.getValue("EntityType"));
m_Workflow.setAD_WF_Node_ID(-1);
log.info("about to execute m_Workflow.save");
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow
.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow
.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
} else {
element.skip = true;
}
}
/**
* @param ctx
* @param element
*/
public void endElement(Properties ctx, Element element) throws SAXException {
if (!element.defer && !element.skip && element.recordId > 0) {
Attributes atts = element.attributes;
//set start node
String name = atts.getValue("ADWorkflowNodeNameID");
if (name != null && name.trim().length() > 0) {
MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx));
int id = get_IDWithMasterAndColumn(ctx, "AD_WF_Node", "Name", name, "AD_Workflow", m_Workflow.getAD_Workflow_ID());
if (id <= 0) {
log.warning("Failed to resolve start node reference for workflow element. Workflow="
+ m_Workflow.getName() + " StartNode=" + name);
return;
}
m_Workflow.setAD_WF_Node_ID(id);
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow update success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow
.get_ID(), 0, "Update", "AD_Workflow",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow update fail");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow
.get_ID(), 0, "Update", "AD_Workflow",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
}
}
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Workflow_ID = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID);
if (workflows.contains(AD_Workflow_ID))
return;
workflows.add(AD_Workflow_ID);
String sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID= "
+ AD_Workflow_ID;
int ad_wf_nodenext_id = 0;
int ad_wf_nodenextcondition_id = 0;
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Workflow m_Workflow = new X_AD_Workflow(ctx,
AD_Workflow_ID, null);
createWorkflowBinding(atts, m_Workflow);
document.startElement("", "", "workflow", atts);
String sql1 = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = "
+ AD_Workflow_ID
+ " ORDER BY "+X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID
;
PreparedStatement pstmt1 = null;
ResultSet rs1 = null;
try {
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
// Generated workflowNodeNext(s) and
// workflowNodeNextCondition(s)
rs1 = pstmt1.executeQuery();
while (rs1.next()) {
int nodeId = rs1.getInt("AD_WF_Node_ID");
createNode(ctx, document, nodeId);
ad_wf_nodenext_id = 0;
String sqlnn = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID = ?"
+ " ORDER BY "+X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID;
PreparedStatement pstmtnn = null;
ResultSet rsnn = null;
try {
pstmtnn = DB.prepareStatement(sqlnn, getTrxName(ctx));
pstmtnn.setInt(1, nodeId);
rsnn = pstmtnn.executeQuery();
while (rsnn.next()) {
ad_wf_nodenext_id = rsnn.getInt("AD_WF_NodeNext_ID");
if (ad_wf_nodenext_id > 0) {
createNodeNext(ctx, document, ad_wf_nodenext_id);
ad_wf_nodenextcondition_id = 0;
String sqlnnc = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID = ?"
+ " ORDER BY "+X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID;
PreparedStatement pstmtnnc = null;
ResultSet rsnnc = null;
try {
pstmtnnc = DB.prepareStatement(sqlnnc, getTrxName(ctx));
pstmtnnc.setInt(1, ad_wf_nodenext_id);
rsnnc = pstmtnnc.executeQuery();
while (rsnnc.next()) {
ad_wf_nodenextcondition_id = rsnnc.getInt("AD_WF_NextCondition_ID");
if (log.isLoggable(Level.INFO)) log.info("ad_wf_nodenextcondition_id: " + String.valueOf(ad_wf_nodenextcondition_id));
if (ad_wf_nodenextcondition_id > 0) {
createNodeNextCondition(ctx, document, ad_wf_nodenextcondition_id);
}
}
} finally {
DB.close(rsnnc, pstmtnnc);
rsnnc = null;
pstmtnnc = null;
}
}
}
} finally {
DB.close(rsnn, pstmtnn);
rsnn = null;
pstmtnn = null;
}
}
} finally {
DB.close(rs1, pstmt1);
rs1 = null;
pstmt1 = null;
document.endElement("", "", "workflow");
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "Workflow", e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export workflow.", e);
else
throw new RuntimeException("Failed to export workflow.", e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
private void createNodeNextCondition(Properties ctx,
TransformerHandler document, int ad_wf_nodenextcondition_id)
throws SAXException {
Env.setContext(ctx,
X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID,
ad_wf_nodenextcondition_id);
nextConditionHandler.create(ctx, document);
ctx.remove(X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID);
}
private void createNodeNext(Properties ctx, TransformerHandler document,
int ad_wf_nodenext_id) throws SAXException {
Env.setContext(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID,
ad_wf_nodenext_id);
nodeNextHandler.create(ctx, document);
ctx.remove(X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID);
}
private void createNode(Properties ctx, TransformerHandler document,
int AD_WF_Node_ID) throws SAXException {
Env.setContext(ctx, X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID,
AD_WF_Node_ID);
nodeHandler.create(ctx, document);
ctx.remove(X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID);
}
private AttributesImpl createWorkflowBinding(AttributesImpl atts,
X_AD_Workflow m_Workflow) {
String sql = null;
String name = null;
atts.clear();
if (m_Workflow.getAD_Workflow_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_Workflow_ID","CDATA",Integer.toString(m_Workflow.getAD_Workflow_ID()));
atts.addAttribute("", "", "Value", "CDATA", (m_Workflow.getValue() != null ? m_Workflow.getValue() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_Workflow.getName() != null ? m_Workflow.getName() : ""));
if (m_Workflow.getAD_Table_ID() > 0) {
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow.getAD_Table_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (m_Workflow.getAD_WF_Node_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WF_Node_ID());
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", "");
if (m_Workflow.getAD_WF_Responsible_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WF_Responsible_ID());
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
"");
if (m_Workflow.getAD_WorkflowProcessor_ID() > 0) {
sql = "SELECT Name FROM AD_WorkflowProcessor_ID WHERE AD_WorkflowProcessor_ID=?";
name = DB.getSQLValueString(null, sql, m_Workflow
.getAD_WorkflowProcessor_ID());
atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowProcessorNameID", "CDATA", "");
atts.addAttribute("","","isBetaFunctionality","CDATA",(m_Workflow.isBetaFunctionality()== true ? "true":"false"));
atts.addAttribute("", "", "AccessLevel", "CDATA", (m_Workflow
.getAccessLevel() != null ? m_Workflow.getAccessLevel() : ""));
atts
.addAttribute("", "", "DurationUnit", "CDATA", (m_Workflow
.getDurationUnit() != null ? m_Workflow
.getDurationUnit() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_Workflow.getHelp() != null ? m_Workflow.getHelp() : ""));
atts.addAttribute("", "", "Description", "CDATA", (m_Workflow
.getDescription() != null ? m_Workflow.getDescription() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_Workflow
.getEntityType() != null ? m_Workflow.getEntityType() : ""));
atts.addAttribute("", "", "Author", "CDATA",
(m_Workflow.getAuthor() != null ? m_Workflow.getAuthor() : ""));
atts.addAttribute("", "", "Version", "CDATA", (""
+ m_Workflow.getVersion() != null ? ""
+ m_Workflow.getVersion() : ""));
// FIXME: Handle dates
// atts.addAttribute("","","ValidFrom","CDATA",(m_Workflow.getValidFrom
// ().toGMTString() != null ?
// m_Workflow.getValidFrom().toGMTString():""));
// atts.addAttribute("","","ValidTo","CDATA",(m_Workflow.getValidTo
// ().toGMTString() != null ?
// m_Workflow.getValidTo().toGMTString():""));
atts.addAttribute("", "", "Priority", "CDATA", ("" + m_Workflow
.getPriority()));
atts.addAttribute("", "", "Limit", "CDATA",
("" + m_Workflow.getLimit()));
atts.addAttribute("", "", "Duration", "CDATA", ("" + m_Workflow
.getDuration()));
atts.addAttribute("", "", "Cost", "CDATA", ("" + m_Workflow.getCost()));
atts.addAttribute("", "", "WorkingTime", "CDATA", ("" + m_Workflow
.getWorkingTime()));
atts.addAttribute("", "", "WaitingTime", "CDATA", ("" + m_Workflow
.getWaitingTime()));
atts.addAttribute("", "", "PublishStatus", "CDATA", (m_Workflow
.getPublishStatus() != null ? m_Workflow.getPublishStatus()
: ""));
atts
.addAttribute("", "", "WorkflowType", "CDATA", (m_Workflow
.getWorkflowType() != null ? m_Workflow
.getWorkflowType() : ""));
atts.addAttribute("", "", "DocValueLogic", "CDATA", (m_Workflow
.getDocValueLogic() != null ? m_Workflow.getDocValueLogic()
: ""));
atts.addAttribute("", "", "isValid", "CDATA",
(m_Workflow.isValid() == true ? "true" : "false"));
// Doesn't appear to be necessary
// atts.addAttribute("","","SetupTime","CDATA",(""+m_Workflow.getSetupTime()
// != null ? ""+m_Workflow.getSetupTime():""));
return atts;
}
}

View File

@ -1,435 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Contributor(s): Victor Perez. victor.perez@e-evolution.com [Bugs-1789058 ]
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowNodeElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
Attributes atts = element.attributes;
String elementValue = element.getElementValue();
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (log.isLoggable(Level.INFO)) log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
if (element.parent != null && element.parent.getElementValue().equals("workflow")
&& element.parent.defer) {
element.unresolved = "Parent element mark as defer: " + atts.getValue("ADWorkflowNameID");
element.defer = true;
return;
}
int workflowId = 0;
String workflowName = atts.getValue("ADWorkflowNameID");
if (element.parent != null && element.parent.getElementValue().equals("workflow")
&& element.parent.recordId > 0)
workflowId = element.parent.recordId;
else {
workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name",
workflowName);
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowName;
return;
}
else if (element.parent != null && element.parent.getElementValue().equals("workflow"))
element.parent.recordId = workflowId;
}
String workflowNodeName = atts.getValue("Name").trim();
StringBuffer sqlB = new StringBuffer(
"SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
workflowId, workflowNodeName);
X_AD_WF_Node m_WFNode = new X_AD_WF_Node(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_WF_Node_ID") != null && Integer.parseInt(atts.getValue("AD_WF_Node_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_WFNode.setAD_WF_Node_ID(Integer.parseInt(atts.getValue("AD_WF_Node_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_WF_Node", m_WFNode);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_WFNode.setValue(atts.getValue("Value"));
m_WFNode.setName(workflowNodeName);
m_WFNode.setAD_Workflow_ID(workflowId);
String name = atts.getValue("ADProcessNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Process", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + name;
return;
}
m_WFNode.setAD_Process_ID(id);
}
name = atts.getValue("ADFormNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Form", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Form: " + name;
return;
}
m_WFNode.setAD_Form_ID(id);
}
name = atts.getValue("ADWorkflowResponsibleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
//TODO: export and import of ad_wf_responsible
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_WFNode.setAD_WF_Responsible_ID(id);
}
name = atts.getValue("ADWindowNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Window", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Window: " + name;
return;
}
m_WFNode.setAD_Window_ID(id);
}
name = atts.getValue("ADImageNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Image", "Name", name);
//TODO: export and import of ad_image
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_WFNode.setAD_Image_ID(id);
}
name = atts.getValue("ADWorkflowBlockNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Block", "Name", name);
//TODO: export and import of ad_workflow_block
/*
if (id <= 0) {
element.defer = true;
return;
}*/
if (id > 0)
m_WFNode.setAD_WF_Block_ID(id);
}
//[Bugs-1789058 ]
/*
name = atts.getValue("WorkflowNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Workflow", "Name", name);
//TODO: export and import of ad_workflow
if (id <= 0) {
element.defer = true;
element.unresolved = "Sub Workflow: " + name;
return;
}
if (id > 0)
m_WFNode.setWorkflow_ID(id);
}*/
/*
* FIXME: Do we need TaskName ? if
* (atts.getValue("ADTaskNameID")!=null){ String name =
* atts.getValue("ADTaskNameID"); sqlB = new StringBuffer ("SELECT
* AD_Task_ID FROM AD_Task WHERE Name= ?"); taskid =
* DB.getSQLValue(m_trxName,sqlB.toString(),name); }
*/
m_WFNode.setValue(atts.getValue("Value"));
m_WFNode.setEntityType(atts.getValue("EntityType"));
m_WFNode.setAction(getStringValue(atts,"Action"));
m_WFNode.setDocAction(getStringValue(atts, "DocAction"));
m_WFNode.setDescription(getStringValue(atts,"Description"));
m_WFNode.setJoinElement(atts.getValue("JoinElement"));
m_WFNode.setSplitElement(atts.getValue("SplitElement"));
if (getStringValue(atts, "XPosition") != null)
m_WFNode.setXPosition(Integer.valueOf(atts.getValue("XPosition")));
if (getStringValue(atts, "YPosition") != null)
m_WFNode.setYPosition(Integer.valueOf(atts.getValue("YPosition")));
m_WFNode.setWaitingTime(Integer.valueOf(atts
.getValue("WaitingTime")));
if (getStringValue(atts, "WaitTime") != null)
m_WFNode.setWaitTime(Integer.valueOf(atts.getValue("WaitTime")));
m_WFNode.setWorkingTime(Integer.valueOf(atts
.getValue("WorkingTime")));
if (getStringValue(atts, "Cost") != null)
m_WFNode.setCost(new BigDecimal(atts.getValue("Cost")));
if (getStringValue(atts, "Duration") != null)
m_WFNode.setDuration(Integer.valueOf(atts.getValue("Duration")));
if (getStringValue(atts, "Priority") != null)
m_WFNode.setPriority(Integer.valueOf(atts.getValue("Priority")));
m_WFNode.setStartMode(getStringValue(atts, "StartMode"));
m_WFNode.setSubflowExecution(getStringValue(atts,"SubflowExecution"));
m_WFNode.setIsCentrallyMaintained(Boolean.valueOf(
atts.getValue("IsCentrallyMaintained")).booleanValue());
if (getStringValue(atts,"DynPriorityChange") != null)
m_WFNode.setDynPriorityChange(new BigDecimal(atts
.getValue("DynPriorityChange")));
// m_WFNode.setAccessLevel (atts.getValue("AccessLevel"));
m_WFNode.setDynPriorityUnit (getStringValue(atts,"DynPriorityUnit"));
m_WFNode.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_WFNode.setValue(atts.getValue("Value"));
log.info("about to execute m_WFNode.save");
if (m_WFNode.save(getTrxName(ctx)) == true) {
log.info("m_WFNode save success");
record_log(ctx, 1, m_WFNode.getName(), "WFNode", m_WFNode
.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_WF_Node"));
} else {
log.info("m_WFNode save failure");
record_log(ctx, 0, m_WFNode.getName(), "WFNode", m_WFNode
.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_Node",
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_WF_Node"));
throw new POSaveFailedException("WorkflowNode");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_WF_Node_ID = Env.getContextAsInt(ctx,
X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_WF_Node m_WF_Node = new X_AD_WF_Node(ctx, AD_WF_Node_ID,
getTrxName(ctx));
createWorkflowNodeBinding(atts, m_WF_Node);
document.startElement("", "", "workflowNode", atts);
document.endElement("", "", "workflowNode");
}
private AttributesImpl createWorkflowNodeBinding(AttributesImpl atts,
X_AD_WF_Node m_WF_Node) {
String sql = null;
String name = null;
atts.clear();
if (m_WF_Node.getAD_WF_Node_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_WF_Node_ID","CDATA",Integer.toString(m_WF_Node.getAD_WF_Node_ID()));
atts.addAttribute("", "", "Value", "CDATA", (m_WF_Node.getValue() != null ? m_WF_Node.getValue() : ""));
atts.addAttribute("", "", "Name", "CDATA",
(m_WF_Node.getName() != null ? m_WF_Node.getName() : ""));
if (m_WF_Node.getAD_Workflow_ID() > 0) {
sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node
.getAD_Workflow_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
} else
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", "");
if (m_WF_Node.getAD_Window_ID() > 0) {
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Window_ID());
if (name != null)
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Task_ID() > 0) {
sql = "SELECT Name FROM AD_Task WHERE AD_Task_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Task_ID());
if (name != null)
atts.addAttribute("", "", "ADTaskNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADTaskNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Process_ID() > 0) {
sql = "SELECT Name FROM AD_Process WHERE AD_Process_ID=?";
name = DB
.getSQLValueString(null, sql, m_WF_Node.getAD_Process_ID());
atts.addAttribute("", "", "ADProcessNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADProcessNameID", "CDATA", "");
if (m_WF_Node.getAD_Form_ID() > 0) {
sql = "SELECT Name FROM AD_Form WHERE AD_Form_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Form_ID());
atts.addAttribute("", "", "ADFormNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADFormNameID", "CDATA", "");
if (m_WF_Node.getAD_WF_Block_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Block WHERE AD_WF_Block_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node
.getAD_WF_Block_ID());
atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowBlockNameID", "CDATA", "");
if (m_WF_Node.getAD_WF_Responsible_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Responsible WHERE AD_WF_Responsible_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node
.getAD_WF_Responsible_ID());
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADWorkflowResponsibleNameID", "CDATA",
"");
if (m_WF_Node.getAD_Image_ID() > 0) {
sql = "SELECT Name FROM AD_Image WHERE AD_Image_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Image_ID());
if (name != null)
atts.addAttribute("", "", "ADImageNameID", "CDATA", name);
else
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "ADImageNameID", "CDATA", "");
}
//[Bugs-1789058 ]
if (m_WF_Node.getWorkflow_ID() > 0) {
sql = "SELECT Name FROM AD_Workflow WHERE AD_Workflow_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getWorkflow_ID());
if (name != null)
atts.addAttribute("", "", "WorkflowNameID", "CDATA", name);
else
atts.addAttribute("", "", "WorkflowNameID", "CDATA", "");
} else {
atts.addAttribute("", "", "WorkflowNameID", "CDATA", "");
}
if (m_WF_Node.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_Node.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA",
(name != null ? name : ""));
} else
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
atts.addAttribute("", "", "Value", "CDATA", (m_WF_Node
.getValue() != null ? m_WF_Node.getValue() : ""));
atts.addAttribute("", "", "Value", "CDATA", (m_WF_Node
.getValue() != null ? m_WF_Node.getValue() : ""));
atts.addAttribute("", "", "isActive", "CDATA",
(m_WF_Node.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "Description", "CDATA", (m_WF_Node
.getDescription() != null ? m_WF_Node.getDescription() : ""));
atts.addAttribute("", "", "Help", "CDATA",
(m_WF_Node.getHelp() != null ? m_WF_Node.getHelp() : ""));
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_WF_Node
.isCentrallyMaintained() == true ? "true" : "false"));
atts.addAttribute("", "", "Action", "CDATA",
(m_WF_Node.getAction() != null ? m_WF_Node.getAction() : ""));
atts.addAttribute("", "", "EntityType", "CDATA", (m_WF_Node
.getEntityType() != null ? m_WF_Node.getEntityType() : ""));
atts.addAttribute("", "", "XPosition", "CDATA", ("" + m_WF_Node
.getXPosition()));
atts.addAttribute("", "", "YPosition", "CDATA", ("" + m_WF_Node
.getYPosition()));
atts.addAttribute("", "", "SubflowExecution", "CDATA", (m_WF_Node
.getSubflowExecution() != null ? m_WF_Node
.getSubflowExecution() : ""));
atts.addAttribute("", "", "StartMode", "CDATA", (m_WF_Node
.getStartMode() != null ? m_WF_Node.getStartMode() : ""));
atts.addAttribute("", "", "Priority", "CDATA", ("" + m_WF_Node
.getPriority()));
atts.addAttribute("", "", "Duration", "CDATA", ("" + m_WF_Node
.getDuration()));
atts.addAttribute("", "", "Cost", "CDATA", ("" + m_WF_Node.getCost()));
atts.addAttribute("", "", "WorkingTime", "CDATA", ("" + m_WF_Node
.getWorkingTime()));
atts.addAttribute("", "", "WaitingTime", "CDATA", ("" + m_WF_Node
.getWaitingTime()));
atts.addAttribute("", "", "JoinElement", "CDATA", (m_WF_Node
.getJoinElement() != null ? m_WF_Node.getJoinElement() : ""));
atts.addAttribute("", "", "SplitElement", "CDATA", (m_WF_Node
.getSplitElement() != null ? m_WF_Node.getSplitElement() : ""));
atts.addAttribute("", "", "WaitTime", "CDATA", ("" + m_WF_Node
.getWaitTime()));
atts.addAttribute("", "", "AttributeName", "CDATA",
(m_WF_Node.getAttributeName() != null ? m_WF_Node
.getAttributeName() : ""));
atts.addAttribute("", "", "AttributeValue", "CDATA", (m_WF_Node
.getAttributeValue() != null ? m_WF_Node.getAttributeValue()
: ""));
atts.addAttribute("", "", "DocAction", "CDATA", (m_WF_Node
.getDocAction() != null ? m_WF_Node.getDocAction() : ""));
atts.addAttribute("", "", "DynPriorityUnit", "CDATA", (m_WF_Node
.getDynPriorityUnit() != null ? m_WF_Node.getDynPriorityUnit()
: ""));
atts.addAttribute("", "", "DynPriorityChange", "CDATA", ("" + m_WF_Node
.getDynPriorityChange()));
return atts;
}
}

View File

@ -1,270 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNextCondition;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowNodeNextConditionElementHandler extends
AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
if (log.isLoggable(Level.INFO)) log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
String workflowName = atts.getValue("ADWorkflowNameID");
int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name",
workflowName);
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowName;
return;
}
String workflowNodeName = atts.getValue("ADWorkflowNodeNameID");
String workflowNodeNextName = atts
.getValue("ADWorkflowNodeNextNameID");
StringBuffer sqlB = new StringBuffer(
"SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
int wfNodeId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
workflowId, workflowNodeName);
if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeName;
element.defer = true;
return;
}
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
workflowId, workflowNodeNextName);
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeNextName;
element.defer = true;
return;
}
sqlB = new StringBuffer(
"SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?");
int wfNodeNextTablePKId = DB.getSQLValue(getTrxName(ctx), sqlB
.toString(), wfNodeId, wfNodeNextId);
sqlB = new StringBuffer(
"SELECT ad_wf_nextcondition_id FROM AD_WF_NextCondition WHERE ad_wf_nodenext_id =?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
wfNodeNextTablePKId);
MWFNextCondition m_WFNodeNextCondition = new MWFNextCondition(ctx,
id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_WF_NextCondition_ID") != null && Integer.parseInt(atts.getValue("AD_WF_NextCondition_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_WFNodeNextCondition.setAD_WF_NextCondition_ID(Integer.parseInt(atts.getValue("AD_WF_NextCondition_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_WF_NextCondition",
m_WFNodeNextCondition);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
sqlB = new StringBuffer(
"SELECT AD_Column.ad_column_id FROM AD_Column, AD_Table WHERE AD_Column.ad_table_id = AD_Table.ad_table_id and AD_Table.name = '"
+ atts.getValue("ADTableNameID")
+ "' and AD_Column.name = ?");
// int columnId =
// DB.getSQLValue(m_trxName,sqlB.toString(),atts.getValue("ADTableNameID"),
// atts.getValue("ADColumnNameID"));
int columnId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
atts.getValue("ADColumnNameID"));
m_WFNodeNextCondition.setAD_Column_ID(columnId);
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId);
m_WFNodeNextCondition
.setIsActive(atts.getValue("isActive") != null ? Boolean
.valueOf(atts.getValue("isActive")).booleanValue()
: true);
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextTablePKId);
m_WFNodeNextCondition.setSeqNo(Integer.valueOf(atts
.getValue("SeqNo")));
m_WFNodeNextCondition.setEntityType(atts.getValue("EntityType"));
m_WFNodeNextCondition.setAndOr(atts.getValue("AndOr"));
m_WFNodeNextCondition.setOperation(atts.getValue("Operation"));
m_WFNodeNextCondition.setValue(atts.getValue("Value"));
m_WFNodeNextCondition.setValue2(atts.getValue("Value2"));
log.info("about to execute m_WFNodeNextCondition.save");
if (m_WFNodeNextCondition.save(getTrxName(ctx)) == true) {
log.info("m_WFNodeNextCondition save success");
record_log(
ctx,
1,
String.valueOf(m_WFNodeNextCondition.get_ID()),
"WFNextCondition",
m_WFNodeNextCondition.get_ID(),
AD_Backup_ID,
Object_Status,
"AD_WF_NextCondition",
get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_WF_NextCondition"));
} else {
log.info("m_WFNodeNextCondition save failure");
record_log(
ctx,
0,
String.valueOf(m_WFNodeNextCondition.get_ID()),
"WFNextCondition",
m_WFNodeNextCondition.get_ID(),
AD_Backup_ID,
Object_Status,
"AD_WF_NextCondition",
get_IDWithColumn(ctx, "AD_Table",
"TableName", "AD_WF_NextCondition"));
throw new POSaveFailedException("WorkflowNodeNextCondition");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int ad_wf_nodenextcondition_id = Env.getContextAsInt(ctx,
X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID);
X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition(
ctx, ad_wf_nodenextcondition_id, null);
AttributesImpl atts = new AttributesImpl();
createWorkflowNodeNextConditionBinding(atts, m_WF_NodeNextCondition);
document.startElement("", "", "workflowNodeNextCondition", atts);
document.endElement("", "", "workflowNodeNextCondition");
}
private AttributesImpl createWorkflowNodeNextConditionBinding(
AttributesImpl atts, X_AD_WF_NextCondition m_WF_NodeNextCondition) {
String sql = null;
String name = null;
atts.clear();
if (m_WF_NodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_WF_NextCondition_ID","CDATA",Integer.toString(m_WF_NodeNextCondition.getAD_WF_NextCondition_ID()));
if (m_WF_NodeNextCondition.getAD_WF_NodeNext_ID() > 0) {
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_Workflow.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name);
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
// log.log(Level.INFO,"node next name: ", name);
atts
.addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA",
name);
}
if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) {
sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_Column_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else {
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
}
// FIXME: don't know if I need org_id or not
// sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
// name = DB.getSQLValueString(null,sql,org_id);
// atts.addAttribute("","","orgname","CDATA",name);
atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNextCondition
.isActive() == true ? "true" : "false"));
atts
.addAttribute(
"",
"",
"EntityType",
"CDATA",
(m_WF_NodeNextCondition.getEntityType() != null ? m_WF_NodeNextCondition
.getEntityType()
: ""));
atts.addAttribute("", "", "AndOr", "CDATA", (m_WF_NodeNextCondition
.getAndOr() != null ? m_WF_NodeNextCondition.getAndOr() : ""));
atts.addAttribute("", "", "Operation", "CDATA", (m_WF_NodeNextCondition
.getOperation() != null ? m_WF_NodeNextCondition.getOperation()
: ""));
atts.addAttribute("", "", "Value", "CDATA", (m_WF_NodeNextCondition
.getValue() != null ? m_WF_NodeNextCondition.getValue() : ""));
atts
.addAttribute(
"",
"",
"Value2",
"CDATA",
(m_WF_NodeNextCondition.getValue2() != null ? m_WF_NodeNextCondition
.getValue2()
: ""));
atts.addAttribute("", "", "SeqNo", "CDATA", (String
.valueOf(m_WF_NodeNextCondition.getSeqNo()) != null ? String
.valueOf(m_WF_NodeNextCondition.getSeqNo()) : ""));
return atts;
}
}

View File

@ -1,276 +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. *
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_WF_NodeNext;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNodeNext;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
if (log.isLoggable(Level.INFO)) log.info("entitytype "+atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
String workflowName = atts.getValue("ADWorkflowNameID");
int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowName;
return;
}
String workflowNodeName = atts.getValue("ADWorkflowNodeNameID").trim();
String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID").trim();
StringBuffer sqlB = new StringBuffer ("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
int wfNodeId = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),workflowId,workflowNodeName);
if (wfNodeId <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeName;
return;
}
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),workflowId,workflowNodeNextName);
if (wfNodeNextId <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeNextName;
return;
}
sqlB = new StringBuffer ("SELECT ad_wf_nodenext_id FROM AD_WF_NodeNext WHERE ad_wf_node_id =? and ad_wf_next_id =?");
int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),wfNodeId,wfNodeNextId);
MWFNodeNext m_WFNodeNext = new MWFNodeNext(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_WF_NodeNext_ID") != null && Integer.parseInt(atts.getValue("AD_WF_NodeNext_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_WFNodeNext.setAD_WF_NodeNext_ID(Integer.parseInt(atts.getValue("AD_WF_NodeNext_ID")));
if (id > 0){
AD_Backup_ID = copyRecord(ctx, "AD_WF_NodeNext",m_WFNodeNext);
Object_Status = "Update";
}
else{
Object_Status = "New";
AD_Backup_ID =0;
}
m_WFNodeNext.setAD_WF_Node_ID(wfNodeId);
m_WFNodeNext.setAD_WF_Next_ID(wfNodeNextId);
m_WFNodeNext.setEntityType(atts.getValue("EntityType"));
m_WFNodeNext.setSeqNo(Integer.valueOf(atts.getValue("SeqNo")));
m_WFNodeNext.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue():true);
m_WFNodeNext.setIsStdUserWorkflow(atts.getValue("IsStdUserWorkflow") != null ? Boolean.valueOf(atts.getValue("IsStdUserWorkflow")).booleanValue():true);
log.info("about to execute m_WFNodeNext.save");
if (m_WFNodeNext.save(getTrxName(ctx)) == true){
log.info("m_WFNodeNext save success");
record_log (ctx, 1, String.valueOf(m_WFNodeNext.get_ID()),"WFNodeNext", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",
get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NodeNext"));
}
else{
log.info("m_WFNodeNext save failure");
record_log (ctx, 0, String.valueOf(m_WFNodeNext.get_ID()),"WFNodeNext", m_WFNodeNext.get_ID(),AD_Backup_ID, Object_Status,"AD_WF_NodeNext",
get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NodeNext"));
throw new POSaveFailedException("WorkflowNodeNext");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int ad_wf_nodenext_id = Env.getContextAsInt(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID);
X_AD_WF_NodeNext m_WF_NodeNext = new X_AD_WF_NodeNext(
ctx, ad_wf_nodenext_id, null);
AttributesImpl atts = new AttributesImpl();
createWorkflowNodeNextBinding(atts, m_WF_NodeNext);
document.startElement("", "", "workflowNodeNext",
atts);
document.endElement("", "", "workflowNodeNext");
}
private AttributesImpl createWorkflowNodeNextBinding(AttributesImpl atts,
X_AD_WF_NodeNext m_WF_NodeNext)
// public AttributesImpl createwf_nodenextBinding( AttributesImpl atts,
// X_AD_WF_NodeNext m_WF_NodeNext, X_AD_WF_Node m_WF_Node)
{
String sql = null;
String name = null;
atts.clear();
if (m_WF_NodeNext.getAD_WF_NodeNext_ID() <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("","","AD_WF_NodeNext_ID","CDATA",Integer.toString(m_WF_NodeNext.getAD_WF_NodeNext_ID()));
// log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Node_ID: ",
// m_WF_NodeNext.getAD_WF_Node_ID());
// log.log(Level.INFO,"m_WF_NodeNext.getAD_WF_Next_ID: ",
// m_WF_NodeNext.getAD_WF_Next_ID());
if (m_WF_NodeNext.getAD_WF_Node_ID() > 0) {
sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID =?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNext
.getAD_WF_Node_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNext
.getAD_WF_Node_ID());
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name);
}
if (m_WF_NodeNext.getAD_WF_Next_ID() > 0) {
sql = "SELECT Name FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNext
.getAD_WF_Next_ID());
// log.log(Level.INFO,"node next name: ", name);
atts
.addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA",
name);
}
// FIXME: don't know if I need org_id or not
// sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
// name = DB.getSQLValueString(null,sql,org_id);
// atts.addAttribute("","","orgname","CDATA",name);
atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNext
.isActive() == true ? "true" : "false"));
atts.addAttribute("", "", "EntityType", "CDATA", (m_WF_NodeNext
.getEntityType() != null ? m_WF_NodeNext.getEntityType() : ""));
atts.addAttribute("", "", "Description", "CDATA",
(m_WF_NodeNext.getDescription() != null ? m_WF_NodeNext
.getDescription() : ""));
atts.addAttribute("", "", "SeqNo", "CDATA", (String
.valueOf(m_WF_NodeNext.getSeqNo()) != null ? String
.valueOf(m_WF_NodeNext.getSeqNo()) : ""));
atts.addAttribute("", "", "IsStdUserWorkflow", "CDATA", (String
.valueOf(m_WF_NodeNext.isStdUserWorkflow()) != null ? String
.valueOf(m_WF_NodeNext.isStdUserWorkflow()) : ""));
return atts;
}
/*
private AttributesImpl createWorkflowNodeNextConditionBinding(
AttributesImpl atts, X_AD_WF_NextCondition m_WF_NodeNextCondition) {
String sql = null;
String name = null;
atts.clear();
if (m_WF_NodeNextCondition.getAD_WF_NodeNext_ID() > 0) {
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_Workflow.Name FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_Workflow.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
atts.addAttribute("", "", "ADWorkflowNameID", "CDATA", name);
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
atts.addAttribute("", "", "ADWorkflowNodeNameID", "CDATA", name);
// FIXME: it appears nodes point back to themselves
// so a group by is necessary
sql = "SELECT AD_WF_Node.Name FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
// log.log(Level.INFO,"node next name: ", name);
atts
.addAttribute("", "", "ADWorkflowNodeNextNameID", "CDATA",
name);
}
if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) {
sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_Column_ID());
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_Column_ID());
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
} else {
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
}
// FIXME: don't know if I need org_id or not
// sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
// name = DB.getSQLValueString(null,sql,org_id);
// atts.addAttribute("","","orgname","CDATA",name);
atts.addAttribute("", "", "isActive", "CDATA", (m_WF_NodeNextCondition
.isActive() == true ? "true" : "false"));
atts
.addAttribute(
"",
"",
"EntityType",
"CDATA",
(m_WF_NodeNextCondition.getEntityType() != null ? m_WF_NodeNextCondition
.getEntityType()
: ""));
atts.addAttribute("", "", "AndOr", "CDATA", (m_WF_NodeNextCondition
.getAndOr() != null ? m_WF_NodeNextCondition.getAndOr() : ""));
atts.addAttribute("", "", "Operation", "CDATA", (m_WF_NodeNextCondition
.getOperation() != null ? m_WF_NodeNextCondition.getOperation()
: ""));
atts.addAttribute("", "", "Value", "CDATA", (m_WF_NodeNextCondition
.getValue() != null ? m_WF_NodeNextCondition.getValue() : ""));
atts
.addAttribute(
"",
"",
"Value2",
"CDATA",
(m_WF_NodeNextCondition.getValue2() != null ? m_WF_NodeNextCondition
.getValue2()
: ""));
atts.addAttribute("", "", "SeqNo", "CDATA", (String
.valueOf(m_WF_NodeNextCondition.getSeqNo()) != null ? String
.valueOf(m_WF_NodeNextCondition.getSeqNo()) : ""));
return atts;
}
*/
}

View File

@ -1,88 +0,0 @@
//PackOutTest.java
package test.functional;
import org.adempiere.pipo.IDFinder;
import org.adempiere.pipo.PackInHandler;
import org.adempiere.pipo.PackOut;
import org.compiere.model.MLocation;
import org.compiere.model.MPackageExp;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.process.ProcessInfo;
import org.compiere.util.Trx;
import test.AdempiereTestCase;
public class PackOutTest extends AdempiereTestCase {
// Test: Specific variables
@SuppressWarnings("unused")
private MLocation location = null;
public void testPackOut() {
PackOut m_PackOut = new PackOut();
@SuppressWarnings("unused")
PackInHandler m_PackInHandler = new PackInHandler();
Trx m_trx = Trx.get(getTrxName(), true);
int m_ad_process_id = IDFinder.get_IDWithColumn("ad_process", "Name", "PackOut", getAD_Client_ID(), getTrxName());
int m_ad_table_id = IDFinder.get_IDWithColumn("ad_table", "Name", "AD_Package_Exp_ID", getAD_Client_ID(), getTrxName());
//Create 2Pack Export Package
MPackageExp m_MPackageExp = new MPackageExp(getCtx(), 0, getTrxName());
m_MPackageExp.setName("testSqlStatement2Pack");
m_MPackageExp.setIsActive(true);
m_MPackageExp.setDescription("Test Output Package");
m_MPackageExp.setEMail("wgheath@gmail.com");
m_MPackageExp.setUserName("wgheath@gmail.com");
m_MPackageExp.setFile_Directory("packages/");
m_MPackageExp.setInstructions("use 2pack to import this package");
m_MPackageExp.setReleaseNo( X_AD_Package_Exp_Detail.RELEASENO_NoSpecificRelease);
m_MPackageExp.setVersion("1.0");
m_MPackageExp.setPK_Version("1.0");
boolean saveResult = m_MPackageExp.save();
assertTrue("MPackageExp.save()", saveResult);
X_AD_Package_Exp_Detail m_PackDetail =new X_AD_Package_Exp_Detail(getCtx(), 0, getTrxName());
m_PackDetail.setAD_Org_ID(m_MPackageExp.getAD_Org_ID());
m_PackDetail.setAD_Package_Exp_ID(m_MPackageExp.get_ID());
m_MPackageExp.setIsActive(true);
m_PackDetail.setType(X_AD_Package_Exp_Detail.TYPE_SQLStatement);
m_PackDetail.setDBType("ALL");
m_PackDetail.setSQLStatement("select * from ad_table");
m_PackDetail.setDescription("2pack test sql statement");
/*m_PackDetail.setFileName(rs.getString("FILENAME"));
m_PackDetail.setAD_Client_ID(m_MPackageExp.getAD_Client_ID());
m_PackDetail.setDescription(rs.getString("DESCRIPTION"));
m_PackDetail.setTarget_Directory(rs.getString("TARGET_DIRECTORY"));
m_PackDetail.setFile_Directory(rs.getString("FILE_DIRECTORY"));
m_PackDetail.setDestination_Directory(rs.getString("DESTINATION_DIRECTORY"));
m_PackDetail.setAD_Workflow_ID(rs.getInt("AD_WORKFLOW_ID"));
m_PackDetail.setAD_Window_ID(rs.getInt("AD_WINDOW_ID"));
m_PackDetail.setAD_Role_ID(rs.getInt("AD_ROLE_ID"));
m_PackDetail.setAD_Process_ID(rs.getInt("AD_PROCESS_ID"));
m_PackDetail.setAD_Menu_ID(rs.getInt("AD_MENU_ID"));
m_PackDetail.setAD_ImpFormat_ID(rs.getInt("AD_IMPFORMAT_ID"));
m_PackDetail.setAD_Workbench_ID(rs.getInt("AD_WORKBENCH_ID"));
m_PackDetail.setAD_Table_ID(rs.getInt("AD_TABLE_ID"));
m_PackDetail.setAD_Form_ID(rs.getInt("AD_FORM_ID"));
m_PackDetail.setAD_ReportView_ID(rs.getInt("AD_REPORTVIEW_ID"));
*/
m_PackDetail.setLine(10);
saveResult = m_PackDetail.save();
assertTrue("X_AD_Package_Exp_Detail.save()", saveResult);
@SuppressWarnings("unused")
int m_ad_record_id = IDFinder.get_IDWithColumn("ad_package_exp", "Name", "test2packJunit", getAD_Client_ID(), getTrxName());
ProcessInfo m_ProcessInfo = new ProcessInfo("PackOut", m_ad_process_id, m_ad_table_id, m_MPackageExp.get_ID());
m_PackOut.startProcess(getCtx(), m_ProcessInfo, m_trx);
assertFalse("PackOut", m_ProcessInfo.isError());
try {
commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
}