pipo is move from /plugins/pipo to /pipo due to ant4eclipse have problem building the bundle using the /plugins/pipo layout

This commit is contained in:
Heng Sin Low 2010-08-20 16:08:06 +08:00
parent adb09d2f33
commit 8524b29f66
70 changed files with 0 additions and 11823 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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<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>pipo</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,8 +0,0 @@
#Fri Mar 12 08:48:46 CET 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,4 +0,0 @@
#Fri Mar 12 15:16:08 CET 2010
eclipse.preferences.version=1
pluginProject.extensions=true
resolve.requirebundle=false

View File

@ -1,13 +0,0 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: PiPo
Bundle-SymbolicName: org.adempiere.pipo;singleton:=true
Bundle-Version: 0.0.0.1
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.adempiere.base,
org.adempiere.pipo,
org.compiere,
org.compiere.util
Export-Package: org.adempiere.pipo.srv
Require-Bundle: org.adempiere.base;bundle-version="0.0.0",
org.adempiere.tools;bundle-version="0.0.0"

View File

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

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="org.adempiere.pipo.Handlers" name="Element Handlers" schema="schema/org.adempiere.pipo.Handlers.exsd"/>
<extension
point="org.adempiere.base.IDictionaryService">
<client
class="org.adempiere.pipo.srv.PipoDictionaryService">
</client>
</extension>
</plugin>

View File

@ -1,109 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.adempiere.pipo" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.adempiere.pipo" id="org.adempiere.pipo.packOutHandlers" name="Packout Handlers"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice>
<element ref="handler" minOccurs="1" maxOccurs="unbounded"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="handler">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
element name like AD_Message, AD_Table, Code_Snippet, etc
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.adempiere.pipo2.ElementHandler"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View File

@ -1,59 +0,0 @@
package org.adempiere.pipo.srv;
import java.io.File;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.adempiere.base.IDictionaryService;
import org.adempiere.pipo2.PackIn;
import org.compiere.Adempiere;
import org.compiere.util.Env;
import org.compiere.util.Trx;
public class PipoDictionaryService implements IDictionaryService {
Logger logger = Logger.getLogger(PipoDictionaryService.class.getName());
@Override
public void merge(InputStream model) throws Exception {
if (model == null) {
logger.info("No PackIn Model found");
return;
}
String trxName = Trx.createTrxName();
try {
logger.info("starting " + trxName);
PackIn packIn = new PackIn();
packIn.setUpdateDictionary(true);
packIn.setPackageDirectory(getPackageDir());
packIn.importXML(model, Env.getCtx(), trxName);
Trx.get(trxName, false).commit();
logger.info("commit " + trxName);
} catch (Exception e) {
logger.log(Level.SEVERE, "importXML:", e);
throw e;
} finally {
Trx.get(trxName, false).close();
}
}
private String getPackageDir() {
// Create Target directory if required
String packageDirectory = Adempiere.getAdempiereHome();
String result = packageDirectory + File.separator
+ "packages";
File docDir = new File( result+File.separator+"doc");
if (!docDir.exists()) {
boolean success = docDir.mkdirs();
if (!success) {
logger.info("Target directory creation failed");
}
}
return result;
}
}

View File

@ -1,553 +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.pipo2;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
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.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Backup;
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.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import org.adempiere.pipo2.exception.DatabaseAccessException;
/**
*
* @author hengsin
*
*/
public abstract class AbstractElementHandler implements ElementHandler {
protected CLogger log = CLogger.getCLogger(getClass());
/**
* Get ID from Name for a table.
*
* @param tableName
* @param name
*
*/
public int findIdByName (Properties ctx, String tableName, String name) {
return IDFinder.findIdByName(tableName, name, getClientId(ctx), getTrxName(ctx));
}
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param name
*/
public int findIdByColumn (Properties ctx, String tableName, String columnName, Object value) {
int id = 0;
if ("AD_Table".equals(tableName) && "TableName".equals(columnName) && value != null) {
id = getPackInProcess(ctx).getTableId(value.toString());
if (id <= 0) {
id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
if (id > 0) {
getPackInProcess(ctx).addTable(value.toString(), id);
}
}
} else {
id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
}
return id;
}
/**
* @param ctx
* @param type
* @param tableName
* @param tableId
* @return X_AD_Package_Imp_Detail
*/
public X_AD_Package_Imp_Detail createImportDetail(Properties ctx, String type, String tableName, int tableId) {
X_AD_Package_Imp_Detail impDetail = new X_AD_Package_Imp_Detail(ctx, 0, getTrxName(ctx));
impDetail.setAD_Package_Imp_ID(getPackageImpId(ctx));
impDetail.setAD_Org_ID(Env.getAD_Org_ID(ctx) );
impDetail.setType(type);
impDetail.setName("");
impDetail.setAction("");
impDetail.setAD_Original_ID(1);
impDetail.setTableName(tableName);
impDetail.setAD_Table_ID(tableId);
impDetail.saveEx(getTrxName(ctx));
return impDetail;
}
/**
* Write results to log and records in history table
*
* @param ctx
* @param success
* @param detail
* @param objectName
* @param objectID
* @param action
* @throws SAXException
*
*/
public void logImportDetail (Properties ctx, X_AD_Package_Imp_Detail detail, int success, String objectName, int objectID,
String action) throws SAXException{
StringBuffer recordLayout = new StringBuffer();
TransformerHandler hd_document = getLogDocument(ctx);
AttributesImpl attsOut = new AttributesImpl();
String result = success == 1 ? "Success" : "Failure";
//hd_documemt.startElement("","","Successful",attsOut);
recordLayout.append("Type:")
.append(detail.getType())
.append(" - Name:")
.append(objectName)
.append(" - ID:")
.append(objectID)
.append(" - Action:")
.append(action)
.append(" - " + result);
hd_document.startElement("","",result,attsOut);
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
hd_document.endElement("","",result);
detail.setName(objectName);
detail.setAction(action);
detail.setSuccess(result);
detail.setAD_Original_ID(objectID);
detail.saveEx(getTrxName(ctx));
}
/**
* Get ID from Name for a table with a parent name reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int findIdByNameAndParentName (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
return IDFinder.findIdByNameAndParentName(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx));
}
/**
* Get ID from column value for a table with a parent id reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int findIdByColumnAndParentId (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) {
return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID,
getTrxName(ctx));
}
/**
* Get ID from Name for a table with a parent reference ID.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
*/
public int findIdByNameAndParentId (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) {
return IDFinder.findIdByNameAndParentId(tableName, name, tableNameMaster, masterID, getTrxName(ctx));
}
/**
* Make backup copy of record.
*
* @param tablename
*
*
*
*/
public void backupRecord(Properties ctx, int AD_Package_Imp_Detail_ID, String tableName,PO from){
// Create new record
int tableID = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx));
PreparedStatement pstmtReferenceId = DB.prepareStatement("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?", getTrxName(ctx));
ResultSet rs=null;
try{
for (int i = 0; i < poInfo.getColumnCount(); i++){
int columnID =findIdByColumnAndParentId (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID);
int referenceID=0;
pstmtReferenceId.setInt(1,columnID);
rs = pstmtReferenceId.executeQuery();
if (rs.next())
referenceID = rs.getInt(1);
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx));
backup.setAD_Org_ID(Env.getAD_Org_ID(ctx));
backup.setAD_Package_Imp_ID(getPackageImpId(ctx));
backup.setAD_Package_Imp_Detail_ID(AD_Package_Imp_Detail_ID);
backup.setAD_Table_ID(tableID);
backup.setAD_Column_ID(columnID);
backup.setAD_Reference_ID(referenceID);
Object value = from.get_ValueOld(i);
backup.setColValue(value != null ? value.toString() : null);
backup.saveEx(getTrxName(ctx));
}
}
catch(Exception e)
{
throw new DatabaseAccessException(e);
}
finally
{
DB.close(rs, pstmtReferenceId);
}
}
/**
* 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) {
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 element
* @param qName
* @return string value
*/
protected String getStringValue(Element element, String qName) {
return getStringValue(element, qName, null);
}
/**
* return null for empty string ("").
* @param element
* @param qName
* @return string value
*/
protected String getStringValue(Element element, String qName, List<String> excludes) {
String name = qName;
String s = element.properties.get(qName).contents.toString();
if (s != null && s.trim().length() > 0 && excludes != null) {
excludes.add(name);
}
return ((s == null || s.trim().length() == 0) ? null : s.trim());
}
/**
* @param element
* @param qName
* @param defaultValue
* @return boolean
*/
protected boolean getBooleanValue(Element element, String qName, boolean defaultValue) {
String value = element.properties.get(qName).contents.toString();
return value != null ? Boolean.valueOf(value).booleanValue() : defaultValue;
}
/**
* @param element
* @param qName
* @return BigDecimal
*/
protected BigDecimal getBigDecimal(Element element, String qName) {
String value = element.properties.get(qName).contents.toString();
return value != null ? new BigDecimal(value) : null;
}
/**
* @param element
* @param qName
* @return int
*/
protected int getIntValue(Element element, String qName) {
Element pe = element.properties.get(qName);
String value = pe != null ? pe.contents.toString() : null;
return value != null ? Integer.parseInt(value) : 0;
}
/**
* Returns option - Is export-import of AD translations is needed
* @param ctx
* @param entityType
* @return boolean
*/
protected boolean isHandleTranslations(Properties ctx) {
return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations"));
}
protected List<String> defaultExcludeList(String tableName) {
List<String> excludes = new ArrayList<String>();
excludes.add("ad_client_id");
excludes.add("ad_org_id");
excludes.add("created");
excludes.add("createdby");
excludes.add("updated");
excludes.add("updatedby");
excludes.add(tableName + "_ID");
return excludes;
}
protected PackIn getPackInProcess(Properties ctx) {
return (PackIn)ctx.get(PackInHandler.PACK_IN_PROCESS_CTX_KEY);
}
protected PackOut getPackOutProcess(Properties ctx) {
return (PackOut) ctx.get(PackOut.PACK_OUT_PROCESS_CTX_KEY);
}
protected int getParentId(Element element, String expectedName) {
if (element.parent != null && element.parent.getElementValue().equals(expectedName) &&
element.parent.recordId > 0)
return element.parent.recordId;
else
return 0;
}
protected boolean isParentDefer(Element element, String expectedName) {
if (element.parent != null
&& (expectedName == null || element.parent.getElementValue().equals(expectedName))
&& element.parent.defer)
return true;
else
return false;
}
protected boolean isParentSkip(Element element, String expectedName) {
if (element.parent != null
&& (expectedName == null || element.parent.getElementValue().equals(expectedName))
&& element.parent.skip)
return true;
else
return false;
}
protected boolean isOfficialId(Element element, String columnName) {
int value = getIntValue(element, columnName);
if (value > 0 && value <= PackOut.MAX_OFFICIAL_ID)
return true;
else
return false;
}
protected void addTextProperty(TransformerHandler handler, String qName, String text) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", qName, "reference", "property");
handler.startElement("", "", qName, atts);
append(handler, text);
handler.endElement("", "", qName);
}
protected void append(TransformerHandler document, String str) throws SAXException
{
char[] contents = str != null ? str.toCharArray() : new char[0];
document.characters(contents,0,contents.length);
}
/**
* Find po by uuid or id
* @param <T>
* @param ctx
* @param element
* @return T
*/
protected <T extends PO> T findPO(Properties ctx, Element element) {
T po = null;
String tableName = element.getElementValue();
String uuidColumn = tableName + "_UU";
String idColumn = tableName + "_ID";
if (element.properties.containsKey(uuidColumn)) {
String uuid = element.properties.get(uuidColumn).contents.toString();
if (uuid != null && uuid.trim().length() == 36) {
Query query = new Query(ctx, tableName, uuidColumn+"=?", getTrxName(ctx));
po = query.setParameters(uuid.trim()).firstOnly();
}
} else if (element.properties.containsKey(idColumn)) {
String id = element.properties.get(idColumn).contents.toString();
if (id != null && id.trim().length() > 0) {
Query query = new Query(ctx, tableName, idColumn+"=?", getTrxName(ctx));
po = query.setParameters(id.trim()).firstOnly();
}
}
return po;
}
protected void addTypeName(AttributesImpl atts, String typeName) {
atts.addAttribute("", "", "type", "CDATA", typeName);
}
}

View File

@ -1,83 +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.pipo2;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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;
public Map<String, Element> properties = new LinkedHashMap<String, Element>();
public List<Element> childrens = new ArrayList<Element>();
public StringBuffer contents = new StringBuffer();
/**
* @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,58 +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.pipo2;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.base.IService;
import org.xml.sax.SAXException;
/**
* Interface for handling import and export of table data using xml
* @author Low Heng Sin
*
*/
public interface ElementHandler extends IService {
/**
* 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;
/**
* @param packout
* @param packoutHandler
* @param docHandler
* @param recordId
* @throws Exception
*/
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception;
}

View File

@ -1,353 +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.pipo2;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* Utility class for the looking up of record id.
* @author Low Heng Sin
*
*/
public class IDFinder {
private static CLogger log = CLogger.getCLogger(IDFinder.class);
private static Map<String, Integer>idCache = new HashMap<String, Integer>();
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param value
* @param AD_Client_ID
* @param trxName
*/
public static int findIdByColumn (String tableName, String columnName, Object value, int AD_Client_ID, String trxName) {
int id = 0;
if (value == null)
return id;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".")
.append(columnName)
.append("=")
.append(value.toString())
.append(" AND AD_Client_ID=").append(AD_Client_ID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("SELECT ")
.append(tableName)
.append("_ID FROM ")
.append(tableName)
.append(" WHERE ")
.append(columnName)
.append(" = ?")
.append(" AND AD_Client_ID IN (0, ?)")
.append(" Order By AD_Client_ID Desc, ")
.append(tableName)
.append("_ID");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sqlB.toString(), trxName);
if (value instanceof String)
pstmt.setString(1, (String)value);
else if (value instanceof Integer)
pstmt.setInt(1, ((Integer)value).intValue());
else
pstmt.setObject(1, value);
pstmt.setInt(2, AD_Client_ID);
rs = pstmt.executeQuery();
if (rs.next())
id = rs.getInt(1);
}
catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
//update cache
if (id > 0)
idCache.put(key.toString(), id);
return id;
}
/**
* Get ID from Name for a table with a parent name reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
* @param trxName
*/
public static int findIdByNameAndParentName (String tableName, String name, String tableNameMaster, String nameMaster, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name)
.append(" and ")
.append(tableNameMaster)
.append(".Name=")
.append(nameMaster);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer parentSql = new StringBuffer("SELECT ")
.append(tableNameMaster)
.append("_ID FROM ")
.append(tableNameMaster)
.append(" WHERE Name = ? AND AD_Client_ID IN (0, ?) ")
.append("ORDER BY AD_Client_ID Desc");
int parentId = DB.getSQLValue(trxName, parentSql.toString(), Env.getAD_Client_ID(Env.getCtx()));
if (parentId > 0) {
StringBuffer sqlB = new StringBuffer ("SELECT ")
.append(tableName)
.append("_ID FROM ")
.append(tableName)
.append(" WHERE Name = ? AND ")
.append(tableNameMaster)
.append("_ID = ?");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sqlB.toString(), trxName);
pstmt.setString(1, name);
pstmt.setString(2, nameMaster);
pstmt.setInt(3, parentId);
rs = pstmt.executeQuery();
if (rs.next())
id = rs.getInt(1);
} catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
}
//update cache
if (id > 0)
idCache.put(key.toString(), id);
return id;
}
/**
* Get ID from column value for a table with a parent id reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
* @param trxName
*/
public static int findIdByColumnAndParentId (String tableName, String columnName, String name, String tableNameMaster, int masterID, String trxName) {
int id = 0;
//check cache
String key = tableName + "." + columnName + "=" + name + tableNameMaster + "=" + masterID;
if (idCache.containsKey(key))
return idCache.get(key);
StringBuffer sqlB = new StringBuffer ("SELECT ")
.append(tableName)
.append("_ID FROM ")
.append(tableName)
.append(" WHERE ")
.append(columnName)
.append(" = ? and ")
.append(tableNameMaster+"_ID = ? AND AD_Client_ID IN (0, ?) ")
.append("ORDER BY AD_Client_ID Desc ");
log.info(sqlB.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sqlB.toString(), trxName);
pstmt.setString(1, name);
pstmt.setInt(2, masterID);
pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx()));
rs = pstmt.executeQuery();
if (rs.next())
{
id = rs.getInt(1);
}
}
catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
//update cache
if (id > 0)
idCache.put(key, id);
return id;
}
/**
* Get ID from Name for a table with a parent reference ID.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
* @param trxName
*/
public static int findIdByNameAndParentId (String tableName, String name, String tableNameMaster, int masterID, String trxName) {
int id = 0;
//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);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("SELECT ")
.append(tableName)
.append("_ID FROM ")
.append(tableName)
.append(" WHERE Name=? AND ")
.append(tableNameMaster)
.append("_ID=? AND AD_Client_ID IN (0, ?) ")
.append("ORDER BY AD_Client_ID Desc");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sqlB.toString(), trxName);
pstmt.setString(1, name);
pstmt.setInt(2, masterID);
pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx()));
rs = pstmt.executeQuery();
if (rs.next())
id = rs.getInt(1);
}
catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
//update cache
if (id > 0)
idCache.put(key.toString(), id);
return id;
}
/**
* Get ID from Name for a table.
*
* @param tableName
* @param name
* @param AD_Client_ID
* @param trxName
*/
public static int findIdByName (String tableName, String name, int AD_Client_ID, String trxName) {
int id = 0;
//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());
StringBuffer sql = new StringBuffer("SELECT ")
.append(tableName)
.append("_ID ")
.append("FROM ")
.append(tableName)
.append(" ")
.append("WHERE Name=? ")
.append(" AND AD_Client_ID IN (0, ?) ")
.append(" ORDER BY AD_Client_ID Desc");
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql.toString(), trxName);
pstmt.setString(1, name);
pstmt.setInt(2, AD_Client_ID);
rs = pstmt.executeQuery();
if (rs.next())
id = rs.getInt(1);
}
catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
//update cache
if (id > 0)
idCache.put(key.toString(), id);
return id;
}
public static void clearIDCache() {
idCache.clear();
}
}

View File

@ -1,24 +0,0 @@
package org.adempiere.pipo2;
public interface IHandlerRegistry {
public static final String ELEMENT_TYPE_TRANSLATION = "translation";
public static final String ELEMENT_TYPE_TABLE = "table";
public static final String ELEMENT_TYPE_TASK = "task";
public static final String ELEMENT_TYPE_PROPERTIES = "properties";
public static final String TABLE_TRANSLATION_HANDLER = "table.translationHandler";
public static final String TABLE_GENERIC_HANDLER = "table.genericHandler";
/**
* @param element
* @return ElementHandler
*/
public ElementHandler getHandler(Element element);
/**
* @param name
* @return ElementHandler
*/
public ElementHandler getHandler(String name);
}

View File

@ -1,59 +0,0 @@
/**
*
*/
package org.adempiere.pipo2;
import org.adempiere.base.Service;
import org.adempiere.base.ServiceQuery;
/**
* @author hengsin
*
*/
public class OSGiHandlerRegistry implements IHandlerRegistry {
private final static String SERVICE_ID = "org.adempiere.pipo.Handlers";
/**
*
*/
public OSGiHandlerRegistry() {
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.adempiere.pipo2.IHandlerRegistry#getHandler(org.adempiere.pipo2.Element)
*/
@Override
public ElementHandler getHandler(Element element) {
String id = null;
ElementHandler handler = null;
String type = element.attributes.getValue("type");
if (ELEMENT_TYPE_TRANSLATION.equals(type)) {
id = TABLE_TRANSLATION_HANDLER;
} else {
id = element.getElementValue();
}
ServiceQuery query = new ServiceQuery();
query.put("id", id);
handler = Service.locate(ElementHandler.class, SERVICE_ID, query);
if (handler == null) {
id = TABLE_GENERIC_HANDLER;
query.put("id", id);
handler = Service.locate(ElementHandler.class, SERVICE_ID, query);
}
return handler;
}
/* (non-Javadoc)
* @see org.adempiere.pipo2.IHandlerRegistry#getHandler(java.lang.String)
*/
@Override
public ElementHandler getHandler(String name) {
ElementHandler handler = null;
ServiceQuery query = new ServiceQuery();
query.put("id", name);
handler = Service.locate(ElementHandler.class, SERVICE_ID, query);
return handler;
}
}

View File

@ -1,367 +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.pipo2;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
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.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(getClass());
//update system maintain dictionary, default to false
private boolean m_UpdateDictionary = false;
private String m_Database = "Oracle";
private 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>();
public PackIn() {
super();
if (DB.isOracle())
m_Database = "Oracle";
else if (DB.isPostgreSQL())
m_Database = "PostgreSQL";
}
/**
* 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();
} // 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 {
log.info("importXML:" + fileName);
File in = new File(fileName);
if (!in.exists()) {
String msg = "File does not exist: " + fileName;
log.info("importXML:" + msg);
return msg;
}
try {
FileInputStream input = new FileInputStream(in);
return importXML(input, ctx, trxName);
} catch (Exception e) {
log.log(Level.SEVERE, "importXML:", e);
throw e;
}
}
public String importXML(InputStream input, Properties ctx, String trxName) {
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(input, handler);
msg = "End Parser";
log.info(msg);
return "Processed="+handler.getElementsProcessed()+" Un-Resolved="+handler.getUnresolvedCount();
} catch (Exception e) {
log.log(Level.SEVERE, "importXML:", e);
throw new RuntimeException(e.getLocalizedMessage(), 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();
}
String targetDirName = packageDirectory + File.separator + "packages";
File targetDir = new File(targetDirName);
if (!targetDir.exists()) {
boolean success = targetDir.mkdirs();
if (!success) {
log.warning("Failed to create target directory. " + targetDirName);
}
}
// Unzip package
File zipFilepath = new File(adPackageImp.getAD_Package_Source());
log.info("zipFilepath->" + zipFilepath);
String PackageName = Zipper.getParentDir(zipFilepath);
Zipper.unpackFile(zipFilepath, targetDir);
String dict_file = packageDirectory + File.separator
+ "packages" + File.separator + PackageName + File.separator
+ "dict" + File.separator + "PackOut.xml";
log.info("dict file->" + dict_file);
if (adPackageImp.isAD_Override_Dict() == true)
m_UpdateDictionary = true;
else
m_UpdateDictionary = false;
m_Package_Dir = packageDirectory + File.separator
+ "packages" + File.separator + PackageName + File.separator;
// call XML Handler
String msg = 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
public String getPackageDirectory() {
return m_Package_Dir;
}
public void setPackageDirectory(String packageDirectory) {
m_Package_Dir = packageDirectory;
}
public String getDatabaseType() {
return m_Database;
}
public boolean isUpdateDictionary() {
return m_UpdateDictionary;
}
public void setUpdateDictionary(boolean updateDictionary) {
m_UpdateDictionary = updateDictionary;
}
public byte[] readBlob(String fileName) throws IOException {
byte[] data = null;
File file = new File(m_Package_Dir+File.separator+"blobs"+File.separator, fileName);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
int b = bis.read();
if (b == -1)
break;
else
baos.write(b);
}
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {}
}
}
return data;
}
/***************************************************************************
*
* @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_UpdateDictionary = Boolean.valueOf(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,458 +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.pipo2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
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.pipo2.exception.DatabaseAccessException;
import org.compiere.model.X_AD_Package_Imp;
import org.compiere.model.X_AD_Package_Imp_Inst;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
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;
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@hotmailo
*
* Contributor: William G. Heath - Import of workflows and dynamic validations
*/
public class PackInHandler extends DefaultHandler {
public static final String PACK_IN_PROCESS_CTX_KEY = "PackInProcess";
/**
* PackInHandler Handler
*/
public PackInHandler () {
setupHandlers();
} // PackInHandler
/** Set this if you want to update Dictionary */
private boolean m_updateDictionary = false;
private String packageDirectory = null;
private int AD_Package_Imp_ID=0;
private int AD_Package_Imp_Inst_ID=0;
private CLogger log = CLogger.getCLogger(PackInHandler.class);
private OutputStream logOutputStream = null;
private TransformerHandler logDocument = null;
private StreamResult loStreamResult = null;
private SAXTransformerFactory transformerFactory = null;
private Transformer logTransformer = null;
private boolean isInit = false;
private String logDate = null;
private String packageStatus = "Installing";
// transaction name
private String m_trxName = null;
private Properties m_ctx = null;
private IHandlerRegistry handlerRegistry = null;
private List<DeferEntry> defer = new ArrayList<DeferEntry>();
private Stack<Element> stack = new Stack<Element>();
private PackIn packIn;
private int elementProcessed = 0;
private void init() throws SAXException {
packageDirectory = packIn.getPackageDirectory();
m_updateDictionary = packIn.isUpdateDictionary();
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 logFileName = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml";
log.info("packin log file="+logFileName);
try {
logOutputStream = new FileOutputStream (logFileName, false);
} catch (FileNotFoundException e1) {
log.warning ("Failed to create log file. error="+e1+" file="+logFileName);
}
loStreamResult = new StreamResult(logOutputStream);
transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try {
logDocument = transformerFactory.newTransformerHandler();
} catch (TransformerConfigurationException e2) {
log.info ("startElement:"+e2);
}
logTransformer = logDocument.getTransformer();
logTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
logTransformer.setOutputProperty(OutputKeys.INDENT,"yes");
logDocument.setResult(loStreamResult);
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");
isInit=true;
}
private void setupHandlers() {
handlerRegistry = new PropertyHandlerRegistry();
}
/**
* 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 {
// Initialize the handler
if (isInit == false){
init();
}
// adempiereAD.
if (qName.equals("adempiereAD"))
{
log.info("adempiereAD updateMode="+m_updateDictionary);
createLogHeader(atts);
// Update Summary Package History Table
int PK_preInstalled=0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement("SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =? AND PK_VERSION =?", null);
pstmt.setString(1,atts.getValue("Name"));
pstmt.setString(2,atts.getValue("Version"));
rs = pstmt.executeQuery();
if (rs.next())
{
PK_preInstalled = rs.getInt(1);
}
} catch (Exception e) {
throw new DatabaseAccessException(e);
} finally {
DB.close(rs, pstmt);
}
X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx, 0, null);
packageImp.setAD_Org_ID(Env.getAD_Org_ID(m_ctx));
packageImp.setReleaseNo(atts.getValue("CompVer"));
packageImp.setPK_Version(atts.getValue("Version"));
packageImp.setVersion(atts.getValue("DataBase"));
packageImp.setDescription(atts.getValue("Description").replaceAll("'","''"));
packageImp.setName(atts.getValue("Name"));
packageImp.setCreator(atts.getValue("Creator"));
packageImp.setCreatorContact(atts.getValue("CreatorContact"));
packageImp.setPK_Status(packageStatus);
packageImp.saveEx();
AD_Package_Imp_ID = packageImp.getAD_Package_Imp_ID();
if ( PK_preInstalled == -1){
//Insert Package into package install log
X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, 0, null);
packageInst.setAD_Org_ID(Env.getAD_Org_ID(m_ctx));
packageInst.setReleaseNo(atts.getValue("CompVer"));
packageInst.setPK_Version(atts.getValue("Version"));
packageInst.setVersion(atts.getValue("DataBase"));
packageInst.setDescription(atts.getValue("Description").replaceAll("'","''"));
packageInst.setName(atts.getValue("Name"));
packageInst.setCreator(atts.getValue("Creator"));
packageInst.setCreatorContact(atts.getValue("CreatorContact"));
packageInst.setPK_Status(packageStatus);
packageInst.saveEx();
AD_Package_Imp_Inst_ID = packageInst.get_ID();
} else {
//Update package list with package status
AD_Package_Imp_Inst_ID = PK_preInstalled;
X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, AD_Package_Imp_Inst_ID, null);
packageInst.setPK_Status(packageStatus);
packageInst.saveEx();
}
Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID);
Env.setContext(m_ctx, "UpdateMode", m_updateDictionary);
Env.setContext(m_ctx, "TrxName", m_trxName);
Env.setContext(m_ctx, "PackageDirectory", packageDirectory);
m_ctx.put("LogDocument", logDocument);
m_ctx.put(PACK_IN_PROCESS_CTX_KEY, packIn);
} else {
Element e = new Element(uri, localName, qName, new AttributesImpl(atts));
if (stack.size() > 0)
{
e.parent = stack.peek();
String reference = atts.getValue("type");
if (!IHandlerRegistry.ELEMENT_TYPE_PROPERTIES.equals(reference))
{
e.parent.childrens.add(e);
}
else
{
e.parent.properties.put(qName, e);
}
}
stack.push(e);
}
} // startElement
private void processElement(Element element) throws SAXException
{
ElementHandler handler = handlerRegistry.getHandler(element);
if (handler != null)
handler.startElement(m_ctx, element);
if (element.defer)
{
defer.add(new DeferEntry(element, true));
}
for (Element childElement : element.childrens)
{
processElement(childElement);
if (element.defer) {
defer.add(new DeferEntry(element, false));
} else {
if (handler != null)
handler.endElement(m_ctx, element);
if (element.defer || element.deferEnd)
defer.add(new DeferEntry(element, false));
else if (!element.skip) {
if (log.isLoggable(Level.INFO))
log.info("Processed: " + element.getElementValue() + " - " + element.attributes.getValue(0));
elementProcessed++;
}
}
}
}
private void createLogHeader(Attributes atts) throws SAXException {
AttributesImpl attsOut = new AttributesImpl();
logDocument.startElement("","","adempiereDocument",attsOut);
PackOut.addTextElement(logDocument, "header", atts.getValue("Name")+" Install Log", attsOut);
PackOut.addTextElement(logDocument, "H3", "Package Name:", attsOut);
PackOut.addTextElement(logDocument, "packagename4log", atts.getValue("Name"), attsOut);
PackOut.addTextElement(logDocument, "H3", "Version:", attsOut);
PackOut.addTextElement(logDocument, "Version", atts.getValue("Version"), attsOut);
PackOut.addTextElement(logDocument, "H3", "Package Install Date:", attsOut);
PackOut.addTextElement(logDocument, "installDate", logDate, attsOut);
PackOut.addTextElement(logDocument, "H3", "Min. Version:", attsOut);
PackOut.addTextElement(logDocument, "AdempiereVersion", atts.getValue("AdempiereVersion"), attsOut);
PackOut.addTextElement(logDocument, "H3", "Min. Database Date:", attsOut);
PackOut.addTextElement(logDocument, "Database", atts.getValue("Database"), attsOut);
}
/**
* @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
*/
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (stack.size() > 0 && length > 0)
{
Element e = stack.peek();
e.contents.append(ch, start, length);
}
}
/**
* 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();
if (!packageStatus.equals("Completed with errors"))
packageStatus = "Completed successfully";
//Update package history log with package status
X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx, AD_Package_Imp_ID, null);
packageImp.setPK_Status(packageStatus);
packageImp.saveEx();
//Update package list with package status
X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, AD_Package_Imp_Inst_ID, null);
packageInst.setPK_Status(packageStatus);
packageInst.saveEx();
logDocument.endElement("","","adempiereDocument");
logDocument.endDocument();
try {
logOutputStream.close();
}
catch (Exception e)
{}
//reset
setupHandlers();
} else {
Element e = stack.pop();
if (stack.isEmpty())
{
processElement(e);
}
}
} // endElement
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 Element: " + d.element.getElementValue() + " - "
+ d.element.attributes.getValue(0));
}
ElementHandler handler = handlerRegistry.getHandler(d.element);
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));
elementProcessed++;
}
}
}
int endSize = defer.size();
if (startSize == endSize) break;
} while (defer.size() > 0);
}
// 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;
}
/**
* @param packIn
*/
public void setProcess(PackIn packIn) {
this.packIn = packIn;
}
/**
* @return number of elements that processed successfully
*/
public int getElementsProcessed() {
return elementProcessed;
}
/**
* @return number of unresolved elements
*/
public int getUnresolvedCount() {
int count = 0;
if (defer != null && !defer.isEmpty()) {
for(DeferEntry entry : defer) {
if (!entry.startElement)
count++;
}
}
return count;
}
class DeferEntry {
Element element;
boolean startElement = false;
DeferEntry(Element e, boolean b) {
element = e;
startElement = b;
}
}
} // PackInHandler

View File

@ -1,472 +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.pipo2;
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.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Properties;
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.compiere.model.I_AD_Form;
import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.I_AD_Menu;
import org.compiere.model.I_AD_Message;
import org.compiere.model.I_AD_PrintFormat;
import org.compiere.model.I_AD_Process;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Table;
import org.compiere.model.I_AD_Val_Rule;
import org.compiere.model.I_AD_Window;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.MClient;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTable;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.process.SvrProcess;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.adempiere.exceptions.AdempiereException;
/**
* 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
*/
public class PackOut extends SvrProcess
{
private static final String TRX_NAME_CTX_KEY = "TrxName";
public static final String PACK_OUT_PROCESS_CTX_KEY = "PackOutProcess";
/** Record ID */
private int p_PackOut_ID = 0;
private String PackOutVer = "005";
public final static int MAX_OFFICIAL_ID = 999999;
private Properties localContext = null;
private MPackageExp packageExp;
private MPackageExpDetail packageExpDetail;
private String packOutDir;
private String packageDir;
private int blobCount = 0;
private IHandlerRegistry handlerRegistry = null;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
p_PackOut_ID = getRecord_ID();
} // prepare
public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException {
handler.startElement("", "", qName, atts);
append(handler, text);
handler.endElement("", "", qName);
}
private static void append(TransformerHandler handler, String str) throws SAXException
{
char[] contents = str != null ? str.toCharArray() : new char[0];
handler.characters(contents,0,contents.length);
}
/**
* Start the transformation to XML
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
initContext();
handlerRegistry = new PropertyHandlerRegistry();
OutputStream packageDocStream = null;
OutputStream packOutDocStream = null;
log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID);
if (p_PackOut_ID == 0)
throw new IllegalArgumentException("No Record");
int processedCount = 0;
try {
packageExp = new MPackageExp(getCtx(), p_PackOut_ID, get_TrxName());
if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){
//Create the package documentation
packOutDir = packageExp.getFile_Directory().trim();
if (!packOutDir.endsWith("/") && !packOutDir.endsWith("\\"))
packOutDir+= File.separator;
packageDir = packOutDir+ packageExp.getName();
File packageDocDirFile = new File(packageDir+File.separator+"doc"+File.separator);
if (!packageDocDirFile.exists()) {
boolean success = packageDocDirFile.mkdirs();
if (!success) {
throw new AdempiereException("Failed to create directory for pack out. " + packageDir+File.separator+"doc"+File.separator);
}
}
String docFileName = packageDir+File.separator+"doc"+File.separator+packageExp.getName()+"Doc.xml";
packageDocStream = new FileOutputStream (docFileName, false);
TransformerHandler packageDocument = createPackageDoc(packageExp, packageDocStream);
String packOutFileName = packageDir+File.separator+ "dict"+File.separator+"PackOut.xml";
packOutDocStream = new FileOutputStream (packOutFileName, false);
TransformerHandler packOutDocument = createPackOutDoc(packageExp, packOutDocStream);
Query query = new Query(getCtx(), MTable.get(getCtx(), X_AD_Package_Exp_Detail.Table_ID), "AD_Package_Exp_ID = ?", get_TrxName());
List<MPackageExpDetail> packageExpDetails = query.setOnlyActiveRecords(true)
.setOrderBy("Line")
.setParameters(new Object[]{p_PackOut_ID})
.list();
for(MPackageExpDetail dtl : packageExpDetails){
packageExpDetail = dtl;
String type = packageExpDetail.getType();
log.info(Integer.toString(packageExpDetail.getLine()));
ElementHandler handler = handlerRegistry.getHandler(getTypeName(type));
if (handler != null)
handler.packOut(this,packOutDocument,packageDocument,dtl.getExpRecordId());
else
throw new IllegalArgumentException("Packout handler not found for type " + type);
processedCount++;
}
packOutDocument.endElement("","","adempiereAD");
packOutDocument.endDocument();
packageDocument.endElement("","","adempiereDocument");
packageDocument.endDocument();
}
}
catch (Exception e)
{
log.log(Level.SEVERE,e.getLocalizedMessage(), e);
throw e;
}
finally
{
// 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(packOutDir);
File destZipFile = new File(packageDir+".zip");
//delete the old packages if necessary
destZipFile.delete();
//create the compressed packages
String includesdir = packageExp.getName() + File.separator +"**";
Zipper.zipFolder(srcFolder, destZipFile, includesdir);
return "Exported="+processedCount + " File=" + destZipFile.getAbsolutePath();
} // doIt
private TransformerHandler createPackOutDoc(MPackageExp packageExp,
OutputStream packOutDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
StreamResult packOutStreamResult = new StreamResult(new OutputStreamWriter(packOutDocStream,"utf-8"));
SAXTransformerFactory packOutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
packOutFactory.setAttribute("indent-number", new Integer(4));
TransformerHandler packOutDocument = packOutFactory.newTransformerHandler();
Transformer packOutTransformer = packOutDocument.getTransformer();
packOutTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
packOutTransformer.setOutputProperty(OutputKeys.INDENT,"yes");
packOutDocument.setResult(packOutStreamResult);
packOutDocument.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("","","Name","CDATA",packageExp.getName());
atts.addAttribute("","","Version","CDATA",packageExp.getPK_Version());
atts.addAttribute("","","AdempiereVersion","CDATA",packageExp.getReleaseNo());
atts.addAttribute("","","DataBase","CDATA",packageExp.getVersion());
atts.addAttribute("","","Description","CDATA",packageExp.getDescription());
atts.addAttribute("","","Creator","CDATA",packageExp.getUserName());
atts.addAttribute("","","CreatorContact","CDATA",packageExp.getEMail());
atts.addAttribute("","","CreatedDate","CDATA",packageExp.getCreated().toString());
atts.addAttribute("","","UpdatedDate","CDATA",packageExp.getUpdated().toString());
atts.addAttribute("","","PackOutVersion","CDATA",PackOutVer);
MClient client = MClient.get(localContext);
StringBuffer sb = new StringBuffer ()
.append(client.get_ID())
.append("-")
.append(client.getValue())
.append("-")
.append(client.getName());
atts.addAttribute("", "", "Client", "CDATA", sb.toString());
packOutDocument.startElement("","","adempiereAD",atts);
return packOutDocument;
}
private TransformerHandler createPackageDoc(MPackageExp packageExp, OutputStream packageDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
StreamResult docStreamResult = new StreamResult(new OutputStreamWriter(packageDocStream,"utf-8"));
SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", new Integer(4));
TransformerHandler packageDocument = transformerFactory.newTransformerHandler();
Transformer transformer = packageDocument.getTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
transformer.setOutputProperty(OutputKeys.INDENT,"yes");
packageDocument.setResult(docStreamResult);
packageDocument.startDocument();
packageDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
AttributesImpl atts = new AttributesImpl();
packageDocument.startElement("","","adempiereDocument",atts);
addTextElement(packageDocument, "header", packageExp.getName()+" Package Description", atts);
addTextElement(packageDocument, "H1", "Package Name:", atts);
addTextElement(packageDocument, "packagename", packageExp.getName(), atts);
addTextElement(packageDocument, "H1", "Author:", atts);
addTextElement(packageDocument, "creator", packageExp.getUserName(), atts);
addTextElement(packageDocument, "H1", "Email Address:", atts);
addTextElement(packageDocument, "creatorcontact", packageExp.getEMail(), atts);
addTextElement(packageDocument, "H1", "Created:", atts);
addTextElement(packageDocument, "createddate", packageExp.getCreated().toString(), atts);
addTextElement(packageDocument, "H1", "Updated:", atts);
addTextElement(packageDocument, "updateddate", packageExp.getUpdated().toString(), atts);
addTextElement(packageDocument, "H1", "Description:", atts);
addTextElement(packageDocument, "description", packageExp.getDescription(), atts);
addTextElement(packageDocument, "H1", "Instructions:", atts);
addTextElement(packageDocument, "instructions", packageExp.getInstructions(), atts);
addTextElement(packageDocument, "H1", "Files in Package:", atts);
addTextElement(packageDocument, "file", "File: PackOut.xml", atts);
addTextElement(packageDocument, "filedirectory", "Directory: \\dict\\", atts);
addTextElement(packageDocument, "filenotes", "Notes: Contains all application/object settings for package", atts);
MClient client = MClient.get(localContext);
StringBuffer sb = new StringBuffer ()
.append(client.get_ID())
.append("-")
.append(client.getValue())
.append("-")
.append(client.getName());
addTextElement(packageDocument, "H1", "Client:", atts);
addTextElement(packageDocument, "Client", sb.toString(), atts);
File packageDictDirFile = new File(packageDir+File.separator+ "dict"+File.separator);
if (!packageDictDirFile.exists()) {
boolean success = packageDictDirFile.mkdirs();
if (!success)
throw new AdempiereException("Failed to create directory. " + packageDir+File.separator+ "dict"+File.separator);
}
return packageDocument;
}
private String getTypeName(String type) {
if (X_AD_Package_Exp_Detail.TYPE_ApplicationOrModule.equals(type))
return I_AD_Menu.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_CodeSnipit.equals(type))
return "Code_Snipit";
else if (X_AD_Package_Exp_Detail.TYPE_Data.equals(type))
return IHandlerRegistry.TABLE_GENERIC_HANDLER;
else if (X_AD_Package_Exp_Detail.TYPE_DynamicValidationRule.equals(type))
return I_AD_Val_Rule.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_File_CodeOrOther.equals(type))
return "Dist_File";
else if (X_AD_Package_Exp_Detail.TYPE_Form.equals(type))
return I_AD_Form.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_ImportFormat.equals(type))
return I_AD_ImpFormat.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Message.equals(type))
return I_AD_Message.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_PrintFormat.equals(type))
return I_AD_PrintFormat.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_ProcessReport.equals(type))
return I_AD_Process.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Reference.equals(type))
return I_AD_Reference.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_ReportView.equals(type))
return I_AD_ReportView.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Role.equals(type))
return I_AD_Role.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_SQLStatement.equals(type))
return "SQL_Statement";
else if (X_AD_Package_Exp_Detail.TYPE_Table.equals(type))
return I_AD_Table.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Window.equals(type))
return I_AD_Window.Table_Name;
else if (X_AD_Package_Exp_Detail.TYPE_Workflow.equals(type))
return I_AD_Workflow.Table_Name;
return type;
}
private void initContext() {
Properties tmp = new Properties();
if (getCtx() != null)
tmp.putAll(getCtx());
tmp.put(TRX_NAME_CTX_KEY, get_TrxName());
tmp.put(PACK_OUT_PROCESS_CTX_KEY, this);
localContext = tmp;
}
/**
* @param sourceName
* @param destName
*/
public void copyFile (String sourceName, String destName ) {
InputStream source = null; // Stream for reading from the source file.
OutputStream copy= null; // 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;
}
try {
File file = new File(destName);
if (file.exists() && force == false) {
System.out.println("Output file exists. Use the -f option to replace it.");
return;
}
try {
copy = new FileOutputStream(destName, false);
} catch (IOException e) {
System.out.println("Can't open output file \""
+ destName + "\".");
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());
}
} finally {
if (source != null) {
try {
source.close();
} catch (IOException e) {}
}
if (copy != null) {
try {
copy.close();
} catch (IOException e) {}
}
}
}
@Override
public Properties getCtx() {
return localContext != null ? localContext : super.getCtx();
}
/**
* @param data
* @return
* @throws IOException
*/
public String writeBlob(byte[] data) throws IOException {
blobCount++;
String fileName = blobCount + ".dat";
File path = new File(packageDir+File.separator+"blobs"+File.separator);
path.mkdirs();
File file = new File(path, fileName);
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(data);
os.flush();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {}
}
}
return fileName;
}
/**
* @return MPackageExp
*/
public MPackageExp getPackageExp() {
return packageExp;
}
/**
* @return MPackageExpDetail
*/
public MPackageExpDetail getPackageExpDetail() {
return packageExpDetail;
}
/**
* @param name
* @return ElementHandler
*/
public ElementHandler getHandler(String name) {
return handlerRegistry.getHandler(name);
}
} // PackOut

View File

@ -1,423 +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.pipo2;
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.List;
import java.util.logging.Level;
import org.compiere.model.MTable;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail;
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;
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
{
DB.executeUpdateEx("UPDATE AD_Package_Imp SET PK_Status = 'Uninstalling' WHERE AD_Package_Imp_ID = ?", new Object[]{m_AD_Package_Imp_ID}, get_TrxName());
log.info("Starting Package Reversal");
// select all records that are new or have been updated by package
// install
try {
Query query = new Query(getCtx(), X_AD_Package_Imp_Detail.Table_Name, "AD_Package_Imp_ID=?", get_TrxName());
List<X_AD_Package_Imp_Detail> packageImpDetails = query.setParameters(new Object[]{m_AD_Package_Imp_ID}).list();
for (X_AD_Package_Imp_Detail packageImpDetail : packageImpDetails) {
if (packageImpDetail.getType().equals("file")) {
Query query2 = new Query(getCtx(), X_AD_Package_Imp_Backup.Table_Name, "AD_Package_Imp_Detail_ID=? AND AD_Package_Imp_ID=?", get_TrxName());
List<X_AD_Package_Imp_Backup> backups = query2.setParameters(new Object[]{packageImpDetail.getAD_Package_Imp_Detail_ID(), packageImpDetail.getAD_Package_Imp_ID()}).list();
for (X_AD_Package_Imp_Backup backup : backups) {
if (backup.getAD_Package_Imp_Bck_Dir() != null
&& backup.getAD_Package_Imp_Org_Dir() != null) {
copyFile(backup.getAD_Package_Imp_Bck_Dir(),backup.getAD_Package_Imp_Org_Dir());
}
// Update uninstall field for column
backup.setUninstall(true);
backup.saveEx();
// Update uninstall field for record
packageImpDetail.setUninstall(true);
packageImpDetail.saveEx();
}
} else {
String tableName = packageImpDetail.getTableName();
int recordID = packageImpDetail.getAD_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 (packageImpDetail.getAction().equalsIgnoreCase("update")) {
// select all backed up columns for the record
try {
Query query2 = new Query(getCtx(), X_AD_Package_Imp_Backup.Table_Name, "AD_Package_Imp_Detail_ID=? AND AD_Package_Imp_ID=?", get_TrxName());
List<X_AD_Package_Imp_Backup> backups = query2.setParameters(new Object[]{packageImpDetail.getAD_Package_Imp_Detail_ID(), packageImpDetail.getAD_Package_Imp_ID()}).list();
String IsKey = null;
String columnName = null;
for (X_AD_Package_Imp_Backup backup : backups) {
PreparedStatement pstmt =null;
ResultSet rs=null;
try {
pstmt = DB.prepareStatement("SELECT IsKey,ColumnName FROM AD_Column WHERE AD_Column_ID = ?",get_TrxName());
pstmt.setInt(1,backup.getAD_Column_ID());
rs = pstmt.executeQuery();
if(rs.next())
{
IsKey = rs.getString(1);
columnName = rs.getString(2);
}
} finally {
DB.close(rs, pstmt);
}
// Get Table value
tableName = MTable.getTableName(getCtx(), backup.getAD_Table_ID());
// Get Column Name
// 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);
DB.executeUpdateEx(sqlC.toString(), get_TrxName());
// Update uninstall field
backup.setUninstall(true);
backup.saveEx();
}
// 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);
DB.executeUpdateEx(sqlC.toString(), get_TrxName());
backup.setUninstall(true);
backup.saveEx();
}
// Update all other fields with backup
// information
else {
Object[] parameters = null;
int v_AD_Reference_ID = backup.getAD_Reference_ID();
// Update columns that are Strings adjusting
// for single quotes
if (v_AD_Reference_ID == 10
|| v_AD_Reference_ID == 14
|| v_AD_Reference_ID == 34
|| v_AD_Reference_ID == 17
// Carlos Ruiz globalqss, special
// treatment for EntityType
// it's a Table reference but must
// be treated as String
|| (v_AD_Reference_ID == 18 && columnName
.equalsIgnoreCase("EntityType"))) {
if (backup.getColValue().toString().equals("null")) {
;// Ignore null values
} else {
sqlC = new StringBuffer("UPDATE "
+ tableName
+ " SET "
+ columnName
+ " = ?"
+ " WHERE " + columnIDName
+ " = " + recordID);
parameters = new Object[]{backup.getColValue()};
}
// Update true/false columns
} else if (v_AD_Reference_ID == 20
|| v_AD_Reference_ID == 28) {
sqlC = new StringBuffer("UPDATE "
+ tableName
+ " SET "
+ columnName
+ " = ? "
+ " WHERE "
+ columnIDName + " = "
+ recordID);
parameters = new Object[]{backup.getColValue().equals("true") ? "Y" : "N"};
}
// Update columns that are Strings adjusting
// for single quotes
else if (v_AD_Reference_ID == 13
|| v_AD_Reference_ID == 18
|| v_AD_Reference_ID == 19
|| v_AD_Reference_ID == 21
|| v_AD_Reference_ID == 25
|| v_AD_Reference_ID == 27
|| v_AD_Reference_ID == 30
|| v_AD_Reference_ID == 31
|| v_AD_Reference_ID == 35)
{
sqlC = new StringBuffer("UPDATE "
+ tableName
+ " SET "
+ columnName
+ " = ?"
+ " WHERE " + columnIDName
+ " = " + recordID);
parameters = new Object[]{backup.getColValue()};
}
// Update columns that are numbers
else if (v_AD_Reference_ID == 11
|| v_AD_Reference_ID == 12
|| v_AD_Reference_ID == 22
|| v_AD_Reference_ID == 29)
{
sqlC = new StringBuffer("UPDATE "
+ tableName
+ " SET "
+ columnName
+ " = ?"
+ " WHERE " + columnIDName
+ " = " + recordID);
parameters = new Object[]{backup.getColValue()};
}
// Update columns that are dates
else if (v_AD_Reference_ID == 15
|| v_AD_Reference_ID == 16)
// TODO Develop portable code to update
// date columns
;// ignore
else
// 23-Binary, 24-Radio, 26-RowID,
// 32-Image not supported
;// ignore
// execute update
if(sqlC!=null)
{
DB.executeUpdateEx(sqlC.toString(), parameters, get_TrxName());
}
// Update uninstall field for column
backup.setUninstall(true);
backup.saveEx();
// Update uninstall field for record
packageImpDetail.setUninstall(true);
packageImpDetail.saveEx();
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "doIt", e);
//System.exit(0);
}
} // ********* Update Loop
// Inactivate new records
else if (packageImpDetail.getAction().equalsIgnoreCase("new")) {
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 ")
.append(tableName)
.append(" SET IsActive = 'N' WHERE ")
.append(columnIDName)
.append(" = ? ");
DB.executeUpdateEx(sqlC.toString(), new Object[]{recordID}, get_TrxName());
// Update uninstall field for record
packageImpDetail.setUninstall(true);
packageImpDetail.saveEx();
}
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "doIt", e);
}
// Update uninstall field for package
DB.executeUpdateEx("UPDATE AD_Package_Imp SET Uninstall = 'Y', PK_Status = 'Uninstalled' WHERE AD_Package_Imp_ID = ?", new Object[]{m_AD_Package_Imp_ID}, 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,321 +0,0 @@
package org.adempiere.pipo2;
import java.math.BigDecimal;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_AD_Client;
import org.compiere.model.I_AD_Org;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PoExporter {
private PO po = null;
@SuppressWarnings("unused")
private CLogger log = CLogger.getCLogger(getClass());
private Properties ctx;
private TransformerHandler transformerHandler;
private void addTextElement(String qName, String text, AttributesImpl atts) {
try {
transformerHandler.startElement("", "", qName, atts);
append(text);
transformerHandler.endElement("", "", qName);
} catch (SAXException e) {
throw new RuntimeException(e);
}
}
private void append(String str) throws SAXException
{
char[] contents = str != null ? str.toCharArray() : new char[0];
transformerHandler.characters(contents,0,contents.length);
}
/**
* @param ctx
* @param po
*/
public PoExporter(Properties ctx, TransformerHandler handler, PO po){
this.ctx = ctx;
this.po = po;
transformerHandler = handler;
}
/**
*
* @param name
* @param value
*/
public void addUnchecked(String name, String value, AttributesImpl atts){
addTextElement(name, value, atts);
}
/**
*
* @param name
* @param stringValue
* @param atts
*/
public void addString(String name, String stringValue, AttributesImpl atts){
addString(name, stringValue, "", atts);
}
/**
*
* @param name
* @param defaultValue
* @param stringValue
*/
public void addString(String name, String stringValue, String defaultValue, AttributesImpl atts){
addTextElement(name, stringValue != null ? stringValue : defaultValue, atts);
}
/**
*
* @param name
* @param boolValue
*/
public void addBoolean(String name, boolean boolValue, AttributesImpl atts){
addTextElement(name, boolValue == true ? "true" : "false", atts);
}
/**
*
* @param name
* @param columnName
*/
public void add(String columnName, AttributesImpl atts) {
add(columnName, "", atts);
}
/**
*
* @param name
* @param columnName
* @param defaultValue
*/
public void add(String columnName, String defaultValue, AttributesImpl atts) {
Object value = po.get_Value(columnName);
if(value == null){
addTextElement(columnName, defaultValue, atts);
return;
}
if(value instanceof String){
addTextElement(columnName, (String)value, atts);
} else if(value instanceof Boolean) {
addTextElement(columnName, (Boolean)value == true ? "true" : "false", atts);
} else if(value instanceof Integer) {
addTextElement(columnName, value.toString(), atts);
} else if(value instanceof BigDecimal) {
addTextElement(columnName, value.toString(), atts);
} else{
addTextElement(columnName, value.toString(), atts);
}
}
/**
* @param columnName
* @param defaultValue
*/
public void add(String columnName, boolean defaultValue, AttributesImpl atts) {
Object oo = po.get_Value(columnName);
boolean value = defaultValue;
if (oo != null)
{
if (oo instanceof Boolean)
value = ((Boolean)oo).booleanValue();
else
value = "Y".equals(oo);
}
addBoolean(columnName, value, atts);
}
/**
*
*
*/
public void addIsActive(AttributesImpl atts){
addTextElement("IsActive", (Boolean)po.isActive() == true ? "true" : "false", atts);
}
public void addTableReference(String tableName, String searchColumn, AttributesImpl atts) {
String columnName = tableName + "_ID";
addTableReference(columnName, tableName, searchColumn, atts);
}
public void addTableReference(String columnName, String tableName, String searchColumn, AttributesImpl atts) {
int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0;
addTableReference(columnName, tableName, searchColumn, id, atts);
}
public void addTableReference(String columnName, String tableName, String searchColumn, int id, AttributesImpl atts) {
String value = ReferenceUtils.getTableReference(tableName, searchColumn, id, atts);
addString(columnName, value, atts);
}
public void export(List<String> excludes) {
export(excludes, false);
}
public void export(List<String> excludes, boolean preservedOrg) {
POInfo info = POInfo.getPOInfo(po.getCtx(), po.get_Table_ID());
int count = info.getColumnCount();
//special treatment for ad_org_id
int AD_Client_ID = po.getAD_Client_ID();
if (AD_Client_ID == 0)
{
addString("AD_Org_ID", "0", new AttributesImpl());
}
else
{
int AD_Org_ID = po.getAD_Org_ID();
if (AD_Org_ID == 0)
{
addString("AD_Org_ID", "0", new AttributesImpl());
}
else
{
if (!preservedOrg)
addString("AD_Org_ID", "@AD_Org_ID@", new AttributesImpl());
else {
addTableReference(I_AD_Client.Table_Name, I_AD_Client.COLUMNNAME_Value, new AttributesImpl());
addTableReference(I_AD_Org.Table_Name, I_AD_Org.COLUMNNAME_Value, new AttributesImpl());
}
}
}
for(int i = 0; i < count; i++) {
String columnName = info.getColumnName(i);
if (excludes != null) {
boolean exclude = false;
for(String ex : excludes)
{
if (ex.equalsIgnoreCase(columnName))
{
exclude = true;
break;
}
}
if (exclude)
continue;
}
int displayType = info.getColumnDisplayType(i);
if (DisplayType.YesNo == displayType) {
add(columnName, false, new AttributesImpl());
} else if (DisplayType.TableDir == displayType || DisplayType.ID == displayType) {
String tableName = null;
String searchColumn = null;
if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) {
int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null
? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0;
tableName = MTable.getTableName(ctx, AD_Table_ID);
searchColumn = tableName + "_ID";
} else {
//remove _ID
searchColumn = columnName;
tableName = columnName.substring(0, columnName.length() - 3);
if (tableName.equalsIgnoreCase("ad_table")) {
searchColumn = "TableName";
} else if (tableName.equalsIgnoreCase("ad_column")) {
searchColumn = "ColumnName";
}
}
if (searchColumn.endsWith("_ID")) {
int AD_Table_ID = MTable.getTable_ID(tableName);
POInfo pInfo = POInfo.getPOInfo(po.getCtx(), AD_Table_ID);
if (pInfo.getColumnIndex("Value") >= 0) {
searchColumn = "Value";
} else if (pInfo.getColumnIndex("Name") >= 0) {
searchColumn = "Name";
} else if (pInfo.getColumnIndex("DocumentNo") >= 0) {
searchColumn = "DocumentNo";
}
}
addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
} else if (DisplayType.List == displayType) {
add(columnName, "", new AttributesImpl());
} else if (DisplayType.isLookup(displayType)) {
String searchColumn = null;
String tableName = null;
if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) {
int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null
? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0;
tableName = MTable.getTableName(ctx, AD_Table_ID);
searchColumn = tableName + "_ID";
} else if (info.getColumnLookup(i) != null){
searchColumn = info.getColumnLookup(i).getColumnName();
tableName = searchColumn.substring(0, searchColumn.indexOf("."));
searchColumn = searchColumn.substring(searchColumn.indexOf(".")+1);
} else {
searchColumn = columnName;
}
if (searchColumn.endsWith("_ID")) {
if (tableName.equalsIgnoreCase("ad_table")) {
searchColumn = "TableName";
} else if (tableName.equalsIgnoreCase("ad_column")){
searchColumn = "ColumnName";
} else {
int AD_Table_ID = MTable.getTable_ID(tableName);
POInfo pInfo = POInfo.getPOInfo(po.getCtx(), AD_Table_ID);
if (pInfo.getColumnIndex("Value") >= 0) {
searchColumn = "Value";
} else if (pInfo.getColumnIndex("Name") >= 0) {
searchColumn = "Name";
} else if (pInfo.getColumnIndex("DocumentNo") >= 0) {
searchColumn = "DocumentNo";
}
}
}
addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
} else if (DisplayType.isLOB(displayType)) {
addBlob(columnName);
} else {
add(columnName, "", new AttributesImpl());
}
}
}
public void addBlob(String columnName) {
Object value = po.get_Value(columnName);
if (value == null) {
addString(columnName, "", new AttributesImpl());
return;
}
PackOut packOut = (PackOut) ctx.get(PackOut.PACK_OUT_PROCESS_CTX_KEY);
byte[] data = null;
String dataType = null;
String fileName = null;
try {
if (value instanceof String) {
data = ((String)value).getBytes("UTF-8");
dataType = "string";
} else {
data = (byte[]) value;
dataType = "byte[]";
}
fileName = packOut.writeBlob(data);
} catch (Exception e) {
throw new AdempiereException(e.getLocalizedMessage(), e);
}
addString(columnName, fileName + "|" + dataType, new AttributesImpl());
}
}

View File

@ -1,251 +0,0 @@
package org.adempiere.pipo2;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
public class PoFiller{
PO po = null;
private AbstractElementHandler handler;
private Properties ctx;
private Element element;
/**
*
* @param po
* @param atts
* @param handler
*/
public PoFiller(Properties ctx, PO po, Element element, AbstractElementHandler handler){
this.ctx = ctx;
this.po = po;
this.element = element;
this.handler = handler;
}
/**
*
* @param columnName
*/
public void setString(String columnName){
Element e = element.properties.get(columnName);
String value = e != null ? e.contents.toString() : null;
value = "".equals(value) ? null : value;
po.set_ValueOfColumn(columnName, value);
}
/**
*
* @param columnName
*/
public void setBoolean(String columnName){
Element e = element.properties.get(columnName);
String value = e != null ? e.contents.toString() : null;
boolean bool = "true".equals(value) ? true : false;
po.set_ValueOfColumn(columnName, bool);
}
/**
*
* @param qName
*/
public void setTimestamp(String qName) {
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
value = null;
Timestamp ts = value != null ? Timestamp.valueOf(value) : null;
po.set_ValueOfColumn(qName, ts);
}
/**
*
* @param qName
*/
public void setInteger(String qName) {
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
value = null;
Integer i = value != null ? new Integer(value) : null;
po.set_ValueOfColumn(qName, i);
}
/**
*
* @param qName
*/
public void setBigDecimal(String qName) {
Element e = element.properties.get(qName);
String value = e != null ? e.contents.toString() : null;
if (value.trim().length() == 0)
value = null;
BigDecimal bd = value != null ? new BigDecimal(value) : null;
po.set_ValueOfColumn(qName, bd);
}
public static int findTableReference(Properties ctx, AbstractElementHandler handler, Element element, String qName) {
Element propertyElement = element.properties.get(qName);
if (propertyElement == null)
return 0;
int id = 0;
String value = propertyElement.contents.toString();
if (value != null && value.trim().length() > 0)
{
String[] names = qName.split("[.]");
if (names.length < 2)
return 0;
String columnName = names[0];
if (names.length != 3)
columnName = columnName + "_ID";
String tableName = names.length == 3 ? names[1] : names[0];
String searchColumn = names.length == 3 ? names[2] : names[1];
id = handler.findIdByColumn(ctx, tableName, searchColumn, value.trim());
}
return id;
}
/**
*
* @param qName
*/
public int setTableReference(String qName) {
Element e = element.properties.get(qName);
if (e == null)
return 0;
String value = e.contents.toString();
String columnName = qName;
if (value != null && value.trim().length() > 0) {
int id = ReferenceUtils.resolveReference(ctx, e);
if (columnName.equals("AD_Client_ID") && id > 0) {
if (id != Env.getAD_Client_ID(ctx)) {
return -1;
}
}
if (po.get_ColumnIndex(columnName) >= 0) {
if (id > 0) {
po.set_ValueOfColumn(columnName, id);
return id;
}
return -1;
} else {
return 0;
}
} else {
return 0;
}
}
/**
* process all attributes
* @param excludes list of attribute to exclude
*/
public List<String> autoFill(List<String> excludes) {
POInfo info = POInfo.getPOInfo(po.getCtx(), po.get_Table_ID());
List<String>notFounds = new ArrayList<String>();
//special treatment for ad_org_id
Element orgElement = element.properties.get("AD_Org_ID");
String sAD_Org_ID = orgElement != null ? orgElement.contents.toString() : null;
if (sAD_Org_ID != null && sAD_Org_ID.equals("0"))
po.setAD_Org_ID(0);
else if (sAD_Org_ID != null && sAD_Org_ID.equals("@AD_Org_ID@"))
po.setAD_Org_ID(Env.getAD_Org_ID(ctx));
else {
if (setTableReference("AD_Client_ID") >= 0)
setTableReference("AD_Org_ID");
}
for(String qName : element.properties.keySet()) {
if (excludes != null ){
boolean exclude = false;
for(String ex : excludes)
{
if (ex.equalsIgnoreCase(qName))
{
exclude = true;
break;
}
}
if (exclude)
continue;
}
Element e = element.properties.get(qName);
if ("table".equalsIgnoreCase(e.attributes.getValue("reference"))) {
int id = setTableReference(qName);
if (id < 0) {
notFounds.add(qName);
}
} else {
int index = info.getColumnIndex(qName);
if (index < 0)
continue;
if (info.getColumnClass(index) == Boolean.class) {
setBoolean(qName);
} else if (info.getColumnClass(index) == BigDecimal.class){
setBigDecimal(qName);
} else if (info.getColumnClass(index) == Integer.class) {
setInteger(qName);
} else if (info.getColumnClass(index) == Timestamp.class) {
setTimestamp(qName);
} else if (DisplayType.isLOB(info.getColumnDisplayType(index))) {
setBlob(qName);
} else {
setString(qName);
}
}
}
return notFounds;
}
private void setBlob(String qName) {
Element pe = element.properties.get(qName);
String value = pe != null ? pe.contents.toString() : null;
Object data = null;
if (value != null && value.trim().length() > 0) {
String[] component = value.split("[|]");
if (component.length == 2) {
String fileName = component[0];
String dataType = component[1];
PackIn packIn = handler.getPackInProcess(ctx);
try {
byte[] bytes = packIn.readBlob(fileName);
if ("byte[]".equals(dataType)) {
data = bytes;
} else {
data = new String(bytes, "UTF-8");
}
} catch (IOException e) {
throw new AdempiereException(e.getLocalizedMessage(), e);
}
}
}
po.set_ValueOfColumn(qName, data);
}
}

View File

@ -1,100 +0,0 @@
/**
*
*/
package org.adempiere.pipo2;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.handler.CommonTranslationHandler;
import org.adempiere.pipo2.handler.GenericPOElementHandler;
/**
* @author hengsin
*
*/
public class PropertyHandlerRegistry implements IHandlerRegistry {
private static Properties handlerRegistry;
static {
handlerRegistry = new Properties();
try {
handlerRegistry.load((PackInHandler.class.getResourceAsStream("pipo-handler.properties")));
} catch (IOException e) {
e.printStackTrace();
}
}
private Map<String, ElementHandler>handlers = null;
/**
* default constructor
*/
public PropertyHandlerRegistry() {
handlers = new HashMap<String, ElementHandler>();
handlers.put(TABLE_GENERIC_HANDLER, new GenericPOElementHandler());
handlers.put(TABLE_TRANSLATION_HANDLER, new CommonTranslationHandler());
}
/**
* @see org.adempiere.pipo2.IHandlerRegistry#getHandler(org.adempiere.pipo2.Element)
*/
@Override
public ElementHandler getHandler(Element element) {
ElementHandler handler = null;
String type = element.attributes.getValue("type");
if (ELEMENT_TYPE_TRANSLATION.equals(type))
handler = handlers.get(TABLE_TRANSLATION_HANDLER);
else
handler = handlers.get(element.getElementValue());
if (handler == null)
{
String className = handlerRegistry.getProperty(element.getElementValue());
if (className != null)
{
try
{
Class<?> clazz = getClass().getClassLoader().loadClass(className);
handler = (ElementHandler) clazz.newInstance();
}
catch (Exception e)
{
throw new AdempiereException(e.getLocalizedMessage(), e);
}
handlers.put(element.getElementValue(), handler);
}
else
{
handler = handlers.get(TABLE_GENERIC_HANDLER);
}
}
return handler;
}
/**
* @see org.adempiere.pipo2.IHandlerRegistry#getHandler(java.lang.String)
*/
@Override
public ElementHandler getHandler(String name) {
String className = handlerRegistry.getProperty(name);
ElementHandler handler = className != null ? handlers.get(className) : null;
if (handler == null && className != null)
{
try
{
Class<?> clazz = getClass().getClassLoader().loadClass(className);
handler = (ElementHandler)clazz.newInstance();
handlers.put(className, handler);
} catch (Exception e)
{
throw new AdempiereException(e.getLocalizedMessage(), e);
}
}
return handler;
}
}

View File

@ -1,113 +0,0 @@
package org.adempiere.pipo2;
import java.util.Properties;
import org.compiere.model.MTable;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.helpers.AttributesImpl;
public class ReferenceUtils {
public static int resolveReference(Properties ctx, Element e)
{
String value = e.contents.toString();
String referenceKey = e.attributes.getValue("reference-key");
if (value != null && value.trim().length() > 0)
{
if (isTableLookup(e))
{
String[] names = referenceKey.split("[.]");
if (names.length < 2)
return 0;
String tableName = names[0];
String searchColumn = names[1];
return IDFinder.findIdByColumn(tableName, searchColumn, value.trim(), Env.getAD_Client_ID(ctx), null);
}
else if (isIDLookup(e))
{
int id = Integer.parseInt(value);
return id;
}
else if (isUUIDLookup(e))
{
return IDFinder.findIdByColumn(referenceKey, referenceKey + "_UU", value.trim(), Env.getAD_Client_ID(ctx), null);
}
else
{
throw new IllegalArgumentException("Unknown table reference type="+e.attributes.getValue("reference"));
}
}
else
{
return 0;
}
}
public static boolean isLookup(Element element)
{
if (isIDLookup(element) || isUUIDLookup(element) || isTableLookup(element))
return true;
else
return false;
}
public static boolean isIDLookup(Element element)
{
return "id".equals(element.properties.get("reference"));
}
public static boolean isUUIDLookup(Element element)
{
return "uuid".equals(element.properties.get("reference"));
}
public static boolean isTableLookup(Element element)
{
return "table".equals(element.properties.get("reference"));
}
public static String getTableReference(String tableName, String searchColumn, int id, AttributesImpl atts)
{
String keyColumn = tableName + "_ID";
String sql = "SELECT " + searchColumn + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID)
{
atts.addAttribute("", "", "reference", "CDATA", "id");
String value = Integer.toString(id);
return value;
}
else if (id == 0)
{
atts.addAttribute("", "", "reference", "CDATA", "id");
return "";
}
else
{
MTable table = MTable.get(Env.getCtx(), tableName);
if (table.get_ColumnIndex(tableName + "_UU") >= 0 )
{
sql = "SELECT " + tableName + "_UU" + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
String value = DB.getSQLValueString(null, sql, id);
if (value != null && value.trim().length() > 0)
{
atts.addAttribute("", "", "reference", "CDATA", "uuid");
atts.addAttribute("", "", "reference-key", "CDATA", tableName);
return value.trim();
}
}
String value = DB.getSQLValueString(null, sql, id);
StringBuffer buffer = new StringBuffer();
buffer.append(tableName).append(".").append(searchColumn);
atts.addAttribute("", "", "reference", "CDATA", "table");
atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString());
return value;
}
}
}

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.pipo2;
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 Zipper {
/**
* 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.replace(" ", "*"));
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,26 +0,0 @@
package org.adempiere.pipo2.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,25 +0,0 @@
package org.adempiere.pipo2.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,159 +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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.M_Element;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
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 action = null;
String entitytype = getStringValue(element, "EntityType");
String ColumnName = getStringValue(element, "ColumnName");
if (isProcessElement(ctx, entitytype)) {
M_Element mElement = findPO(ctx, element);
if (mElement == null) {
int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
mElement = new M_Element(ctx, id, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name);
if (mElement.getAD_Element_ID() == 0 && isOfficialId(element, "AD_Element_ID"))
mElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID"));
if (processedElements.contains(mElement.getAD_Element_ID())) {
element.skip = true;
return;
}
PoFiller pf = new PoFiller(ctx, mElement, element, this);
List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mElement.is_new() || mElement.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Element.Table_Name, X_AD_Element.Table_ID);
if (!mElement.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_ELEMENT, mElement);
action = "Update";
} else {
action = "New";
}
if (mElement.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mElement.getName(),
mElement.get_ID(), action);
element.recordId = mElement.getAD_Element_ID();
processedElements.add(mElement.getAD_Element_ID());
} else {
logImportDetail(ctx, impDetail, 0, mElement.getName(),
mElement.get_ID(), action);
throw new POSaveFailedException("Reference");
}
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
protected 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();
addTypeName(atts, "table");
document.startElement("", "", "AD_Element", atts);
createAdElementBinding(ctx, document, m_AdElement);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
try{
new CommonTranslationHandler().packOut(packOut,document,null,m_AdElement.get_ID());
}
catch(Exception e)
{
log.info(e.toString());
}
document.endElement("", "", "AD_Element");
}
private void createAdElementBinding(Properties ctx, TransformerHandler document,
X_AD_Element m_AdElement) {
PoExporter filler = new PoExporter(ctx, document, m_AdElement);
if (m_AdElement.getAD_Element_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add(X_AD_Element.COLUMNNAME_AD_Element_ID, new AttributesImpl());
List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name);
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Element.COLUMNNAME_AD_Element_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Element.COLUMNNAME_AD_Element_ID);
}
}

View File

@ -1,247 +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.pipo2.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 javax.xml.transform.sax.TransformerHandler;
import org.compiere.Adempiere;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
public class CodeSnippetElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
String action = null;
action = "Update";
String releaseNumber = getStringValue(element, "ReleaseNo");
//Check Release Number
if(Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){
String sourceName = getStringValue(element, "filename");
String targetDirectory = getStringValue(element, "filedir");
String oldCode = getStringValue(element, "oldcode");
String newCode = getStringValue(element, "newcode");
InputStream source; // Stream for reading from the source file.
OutputStream copy; // Stream for writing the copy.
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 seperator
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);
log.info(targetDirectoryModified+sourceName);
//TODO: derived force from user parameter
boolean force = true;
// check to see if overwrites are allowed
if (file.exists()) {
if (!force) {
System.out.println("Output file exists. Use the -f option to replace it.");
return;
}
//backup file to package directory
else {
action = "Update";
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);
log.info("Source Backup:"+packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName);
copyFile (source,copy);
log.info("Backup Complete");
}
}
int success = readReplace(targetDirectoryModified+sourceName, oldCode, newCode);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, "codesnipit", sourceName, 0);
// Record in log
if (success != -1){
try {
logImportDetail (ctx, impDetail, 1, sourceName, 0, action);
} catch (SAXException e) {
log.info ("setfile:"+e);
}
}
else{
try {
logImportDetail (ctx, impDetail, 0, sourceName, 0, action);
} catch (SAXException e) {
log.info ("setfile:"+e);
}
}
//Record in transaction file
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx));
backup.setAD_Org_ID(Env.getAD_Org_ID(ctx));
backup.setAD_Package_Imp_ID(getPackageImpId(ctx));
backup.setAD_Package_Imp_Org_Dir(targetDirectoryModified+sourceName );
backup.setAD_Package_Imp_Bck_Dir(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName);
backup.saveEx();
}
}
/**
* 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();
addTypeName(atts, "custom");
createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo);
document.startElement("","","Code_Snipit",atts);
document.endElement("","","Code_Snipit");
}
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;
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
MPackageExpDetail detail = packout.getPackageExpDetail();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory, detail.getDestination_Directory());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, detail.getDestination_FileName());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old, detail.getAD_Package_Code_Old());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New, detail.getAD_Package_Code_New());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo,detail.getReleaseNo());
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
}
}

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.pipo2.handler;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Column;
import org.compiere.model.I_AD_Table;
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.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Trx;
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 {
int success = 0;
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, I_AD_Table.Table_Name)) {
element.defer = true;
return;
}
List<String> excludes = defaultExcludeList(X_AD_Column.Table_Name);
String columnName = getStringValue(element, "ColumnName", excludes);
MColumn mColumn = findPO(ctx, element);
if (mColumn == null) {
int tableid = 0;
if (getParentId(element, I_AD_Table.Table_Name) > 0) {
tableid = getParentId(element, "table");
} else {
mColumn = new MColumn(ctx, 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mColumn, element, this);
filler.setTableReference("AD_Table_ID");
tableid = mColumn.getAD_Table_ID();
}
int AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
mColumn = new MColumn(ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx));
if (mColumn.getAD_Column_ID() == 0 && isOfficialId(element, "AD_Column_ID")) {
mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID"));
}
}
mColumn.setColumnName(columnName);
mColumn.setIsSyncDatabase(getStringValue(element, "IsSyncDatabase", excludes));
PoFiller filler = new PoFiller(ctx, mColumn, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (!mColumn.is_new() && !mColumn.is_Changed())
return;
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Column.Table_Name, X_AD_Column.Table_ID);
String action = null;
if (!mColumn.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_Column", mColumn);
action = "Update";
} else {
action = "New";
}
// Setup Element.
if (mColumn.getAD_Element_ID() == 0) {
X_AD_Element adElement = new X_AD_Element(ctx, 0, getTrxName(ctx));
adElement.setColumnName(mColumn.getColumnName());
adElement.setEntityType(mColumn.getEntityType());
adElement.setPrintName(mColumn.getColumnName());
adElement.setName(mColumn.getColumnName());
adElement.saveEx();
X_AD_Package_Imp_Detail eleDetail = createImportDetail(ctx, "Element", X_AD_Element.Table_Name,
X_AD_Element.Table_ID);
logImportDetail(ctx, eleDetail, 1, mColumn.getColumnName(), adElement
.getAD_Element_ID(), "New");
mColumn.setAD_Element_ID(adElement.getAD_Element_ID());
}
boolean recreateColumn = (mColumn.is_new()
|| mColumn.is_ValueChanged("AD_Reference_ID")
|| mColumn.is_ValueChanged("FieldLength")
|| mColumn.is_ValueChanged("ColumnName") || mColumn
.is_ValueChanged("IsMandatory"));
//ignore fieldlength change for clob and lob
if (!mColumn.is_ValueChanged("AD_Reference_ID") && mColumn.is_ValueChanged("FieldLength")) {
if (DisplayType.isLOB(mColumn.getAD_Reference_ID())) {
recreateColumn = false;
}
}
// changed default ??
// m_Column.is_ValueChanged("DefaultValue") doesn't work well with
// nulls
if (!recreateColumn) {
String oldDefault = (String) mColumn
.get_ValueOld("DefaultValue");
String newDefault = mColumn.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(getStringValue(element, "IsSyncDatabase"));
if (recreateColumn) {
if (mColumn.isVirtualColumn() || !syncDatabase)
recreateColumn = false;
}
if (mColumn.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mColumn.getName(), mColumn
.get_ID(), action);
element.recordId = mColumn.getAD_Column_ID();
} else {
logImportDetail(ctx, impDetail, 0, mColumn.getName(), mColumn
.get_ID(), action);
throw new POSaveFailedException("Failed to import column.");
}
if (recreateColumn || syncDatabase) {
MTable table = new MTable(ctx, mColumn.getAD_Table_ID(), getTrxName(ctx));
if (!table.isView() && !mColumn.isVirtualColumn()) {
success = createColumn(ctx, table, mColumn, recreateColumn);
X_AD_Package_Imp_Detail dbDetail = createImportDetail(ctx, "dbColumn", X_AD_Column.Table_Name, X_AD_Column.Table_ID);
if (success == 1) {
logImportDetail(ctx, dbDetail, 1, mColumn.getColumnName(),
mColumn.get_ID(), action);
} else {
logImportDetail(ctx, dbDetail, 0, mColumn.getColumnName(),
mColumn.get_ID(), action);
throw new DatabaseAccessException("Failed to create column or related constraint for " + mColumn.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 (DB.isOracle()) {
tableName = tableName.toUpperCase();
columnName = columnName.toUpperCase();
} else if (DB.isPostgreSQL()) {
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));
addTypeName(atts, "table");
document.startElement("", "", I_AD_Column.Table_Name, atts);
createColumnBinding(ctx, document, m_Column);
document.endElement("", "", I_AD_Column.Table_Name);
}
private void createColumnBinding(Properties ctx, TransformerHandler document,
X_AD_Column m_Column) {
PoExporter filler = new PoExporter(ctx, document, m_Column);
List<String>excludes = defaultExcludeList(X_AD_Column.Table_Name);
if (m_Column.getAD_Column_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Column_ID", new AttributesImpl());
filler.addString("IsSyncDatabase", "Y", new AttributesImpl());
filler.addTableReference("AD_Table", "TableName", new AttributesImpl());
filler.addTableReference("AD_Reference_Value_ID", "AD_Reference", "Name", new AttributesImpl());
excludes.add("IsSyncDatabase");
excludes.add("AD_Table_ID");
excludes.add("AD_Reference_Value_ID");
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Column.COLUMNNAME_AD_Column_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Column.COLUMNNAME_AD_Column_ID);
}
}

View File

@ -1,301 +0,0 @@
package org.adempiere.pipo2.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 javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PackOut;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.compiere.model.X_AD_Element;
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";
private HashMap<String, ArrayList<String>> cacheColumns = new HashMap<String, ArrayList<String>>();//Key: table name. Value: set of PIPO columns
public void startElement(Properties ctx, Element element) throws SAXException {
if(! isHandleTranslations(ctx)){
return;//translation import option is disabled
}
if(isParentSkip(element, null)){
return;
}
if(isParentDefer(element, null)){
element.defer = true;
return;
}
String elementValue = element.getElementValue();
int parentID = element.parent.recordId;
if(parentID ==0)
throw new SAXException();
String language = getStringValue(element, "AD_Language");
log.info(elementValue+" "+getStringValue(element, "Name"));
if(isRecordExists(elementValue, parentID, language, ctx)){
updateTranslation(elementValue, parentID, ctx, element);
}else{
insertTranslation(elementValue, parentID, ctx, element);
}
}
private boolean isRecordExists(String tableName, int parentID,
String language, Properties ctx) {
String sql =
"SELECT AD_Client_ID FROM " + tableName +" WHERE " +
tableName.substring(0, tableName.length()-4) + "_ID = ? AND AD_Language = ?";
if(DB.getSQLValue(getTrxName(ctx), sql, parentID, language) == -1){
return false;
}else{
return true;
}
}
private void insertTranslation(String tableName, int parentID,
Properties ctx, Element element) throws SAXException{
String parentTable = tableName.substring(0, tableName.length()-4);
ArrayList<String> columns = getTranslatedColumns(parentTable);
StringBuffer sql = new StringBuffer();
sql.append("INSERT INTO ")
.append(tableName)
.append(" (")
.append(parentTable)
.append("_ID, ")
.append(" AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ")
.append(cast(columns))
.append(") values ( ?, ?, ?, ?, ? ");
for (int i = 0; i<columns.size(); i++) {
sql.append(",?");
}
sql.append(")");
PreparedStatement pstm = null;
try {
pstm = DB.prepareStatement(sql.toString(), getTrxName(ctx));
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 : columns) {
i++;
String value = getStringValue(element, 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();
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(pstm);
}
}
private void updateTranslation(String tableName, int parentID,
Properties ctx, Element element) throws SAXException{
String parentTable = tableName.substring(0, tableName.length()-4);
ArrayList<String> columns = getTranslatedColumns(parentTable);
StringBuffer buffer = new StringBuffer("UPDATE "+tableName+" SET ");
for (String columnName : columns) {
buffer.append(columnName).append("=?,");
}
String sql = buffer.substring(0, buffer.length()-1);
sql += " WHERE AD_Language = '"+getStringValue(element, "AD_Language")+
"' AND "+parentTable+"_ID="+parentID;
PreparedStatement pstm = null;
try {
pstm = DB.prepareStatement(sql,getTrxName(ctx));
int i=0;
for (String columnName : columns) {
String value = getStringValue(element, 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();
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(pstm);
}
}
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(ctx, parenTableName, parentRecordID, document);
}
private void createTranslationTags(Properties ctx, String parentTable,
int parentRecordID, TransformerHandler document) throws SAXException {
ArrayList<String> translatedColumns = getTranslatedColumns(parentTable);
String sql =
"select "+cast(translatedColumns)+" from "+parentTable+"_trl where "+
parentTable+"_ID="+parentRecordID;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = DB.prepareStatement(sql, null);
rs = pstm.executeQuery();
String elementName = parentTable + "_Trl";
while(rs.next()){
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "translation");
document.startElement("", "", elementName, atts);
exportRow(ctx, document, translatedColumns, rs);
document.endElement("", "", elementName);
}
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
} finally {
DB.close(rs, pstm);
}
}
private void exportRow(Properties ctx, TransformerHandler document, ArrayList<String> columns,
ResultSet rs) throws Exception {
PoExporter af = new PoExporter(ctx, document, null);
for (String columnName : columns) {
if(columnName.equalsIgnoreCase("IsActive")||
columnName.equalsIgnoreCase("IsTranslated")) {
af.addBoolean(columnName, rs.getString(columnName).equalsIgnoreCase("Y"), new AttributesImpl());
} else{
af.addString(columnName, rs.getString(columnName), new AttributesImpl());
}
}
}
/**
*
* @param parentTable
* @return
* @throws SAXException
*/
private ArrayList<String> getTranslatedColumns(String parentTable) throws SAXException {
ArrayList<String> pipolColumns = cacheColumns.get(parentTable);
if(pipolColumns != null){
return pipolColumns;
}
ArrayList<String> 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'";
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = DB.prepareStatement(sql, null);
pstm.setString(1, parentTable);
rs = pstm.executeQuery();
while(rs.next()){
columns.add(rs.getString("columnName"));
}
} catch (SQLException e) {
e.printStackTrace();
throw new SAXException();
} finally {
DB.close(rs, pstm);
}
columns.add("AD_Language");
columns.add("IsActive");
columns.add("IsTranslated");
//Putting in cache
cacheColumns.put(parentTable, columns);
return columns;
}
private String cast(ArrayList<String> arg){
String str = arg.toString();
return str.substring(1, str.length()-1);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
if("true".equals(packout.getCtx().getProperty("isHandleTranslations"))){
Env.setContext(packout.getCtx(), CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE,X_AD_Element.Table_Name);
Env.setContext(packout.getCtx(), CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID,recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE);
packout.getCtx().remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID);
}
}
}

View File

@ -1,218 +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.pipo2.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 javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.compiere.Adempiere;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class DistFileElementHandler extends AbstractElementHandler {
String fileDest;
public DistFileElementHandler()
{
}
public DistFileElementHandler(String fileDest)
{
this.fileDest=fileDest;
}
public void startElement(Properties ctx, Element element) throws SAXException {
String action = null;
String releaseNumber = getStringValue(element,"ReleaseNo");
//Check Release Number
if(releaseNumber==null||Adempiere.MAIN_VERSION.equals(releaseNumber)||releaseNumber.equals("all")){
String fileName = getStringValue(element, "filename");
String sourceDirectory = getStringValue(element, "sourceDirectory");
String targetDirectory = getStringValue(element, "targetDirectory");
action = "New";
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 seperator
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())
{
if (!force) {
System.out.println(
"Output file exists. Use the -f option to replace it.");
return;
}
//backup file to package directory
else {
action = "Update";
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);
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 seperator
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
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, "file", fileName, 0);
if (success != -1){
try {
logImportDetail (ctx, impDetail, 1, fileName, 0, action);
} catch (SAXException e) {
log.info ("setfile:"+e);
}
}
else{
try {
logImportDetail (ctx, impDetail, 0, fileName, 0, action);
} catch (SAXException e) {
log.info ("setfile:"+e);
}
}
//Record in transaction file
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx));
backup.setAD_Org_ID(Env.getAD_Org_ID(ctx));
backup.setAD_Package_Imp_Org_Dir(fullTargetPath+fileName);
backup.setAD_Package_Imp_Bck_Dir(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName);
backup.setAD_Package_Imp_ID(getPackageImpId(ctx));
backup.saveEx();
}
}
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();
addTypeName(atts, "custom");
document.startElement("","","Dist_File",atts);
addTextProperty(document,"filename",FileName);
addTextProperty(document,"sourceDirectory",Source_Directory);
addTextProperty(document,"targetDirectory",Target_Directory);
addTextProperty(document,"ReleaseNo",ReleaseNo);
atts.addAttribute("","","ReleaseNo","CDATA",ReleaseNo);
document.endElement("","","Dist_File");
}
public void doPackout(PackOut packout, MPackageExp header, MPackageExpDetail detail,TransformerHandler packOutDocument,TransformerHandler packageDocument,AttributesImpl atts,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, detail.getFileName());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, detail.getReleaseNo());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, detail.getTarget_Directory());
Env.setContext(packout.getCtx(), "Source_Directory", fileDest);
this.create(packout.getCtx(), packOutDocument);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
packout.getCtx().remove("Source_Directory");
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
// TODO Auto-generated method stub
}
}

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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Val_Rule;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Val_Rule;
import org.compiere.util.Env;
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 entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = getStringValue(element, "Name");
X_AD_Val_Rule mValRule = findPO(ctx, element);
if (mValRule == null)
{
int id = findIdByColumn(ctx, "AD_Val_Rule", "Name", name);
mValRule = new X_AD_Val_Rule(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
if (mValRule.getAD_Val_Rule_ID() == 0 && isOfficialId(element, "AD_Val_Rule_ID"))
mValRule.setAD_Val_Rule_ID(getIntValue(element, "AD_Val_Rule_ID"));
List<String> excludes = defaultExcludeList(X_AD_Val_Rule.Table_Name);
PoFiller filler = new PoFiller(ctx, mValRule, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mValRule.is_new() || mValRule.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Val_Rule.Table_Name,
X_AD_Val_Rule.Table_ID);
String action = null;
if (!mValRule.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Val_Rule.Table_Name, mValRule);
action = "Update";
}
else{
action = "New";
}
if (mValRule.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mValRule.getName(), mValRule.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action);
throw new POSaveFailedException("Failed to save dynamic validation rule.");
}
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
protected 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);
X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("","",I_AD_Val_Rule.Table_Name, atts);
createDynamicValidationRuleBinding(ctx,document,m_ValRule);
document.endElement("","",I_AD_Val_Rule.Table_Name);
}
private void createDynamicValidationRuleBinding(Properties ctx, TransformerHandler document, X_AD_Val_Rule m_ValRule)
{
PoExporter filler = new PoExporter(ctx, document, m_ValRule);
List<String>excludes = defaultExcludeList(X_AD_Val_Rule.Table_Name);
if (m_ValRule.getAD_Val_Rule_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Val_Rule_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID);
}
}

View File

@ -1,197 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Field;
import org.compiere.model.I_AD_Tab;
import org.compiere.model.MField;
import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, I_AD_Tab.Table_Name)) {
element.defer = true;
return;
}
List<String>excludes = defaultExcludeList(X_AD_Field.Table_Name);
int tabid = getParentId(element, I_AD_Tab.Table_Name) ;
if (tabid <= 0) {
element.defer = true;
return;
}
MField mField = findPO(ctx, element);
if (mField == null)
{
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, element.parent.properties.get("AD_Table_ID"));
Element columnElement = element.parent.properties.get("AD_Column_ID");
int AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement))
{
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
}
else
{
String colname = getStringValue(element, "AD_Column_ID", excludes);
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", colname, "AD_Table", AD_Table_ID);
}
StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(AD_Column_ID)
.append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
mField = new MField(ctx, id > 0 ? id : 0, getTrxName(ctx));
if (mField.is_new()) {
mField.setAD_Column_ID(AD_Column_ID);
mField.setAD_Tab_ID(tabid);
}
}
PoFiller filler = new PoFiller(ctx, mField, element, this);
if (mField.getAD_Field_ID() == 0 && isOfficialId(element, "AD_Field_ID"))
{
filler.setInteger("AD_Field_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mField.is_new() || mField.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Field.Table_Name,
X_AD_Field.Table_ID);
String action = null;
if (!mField.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), I_AD_Field.Table_Name, mField);
action = "Update";
}
else{
action = "New";
}
if (mField.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mField.getName(), mField
.get_ID(), action);
element.recordId = mField.getAD_Field_ID();
} else {
logImportDetail(ctx, impDetail, 0, mField.getName(), mField
.get_ID(), action);
throw new POSaveFailedException("Failed to save field 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_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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Field.Table_Name, atts);
createFieldBinding(ctx, document, m_Field);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
try
{
if(m_Field.getAD_FieldGroup_ID() > 0)
{
ElementHandler handler = packOut.getHandler("FG");
handler.packOut(packOut,document,null,m_Field.getAD_FieldGroup_ID());
}
if (m_Field.getAD_Reference_ID()>0)
{
ElementHandler handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,m_Field.getAD_Reference_ID());
}
if (m_Field.getAD_Reference_Value_ID()>0)
{
ElementHandler handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,m_Field.getAD_Reference_Value_ID());
}
if (m_Field.getAD_Val_Rule_ID()>0)
{
ElementHandler handler = packOut.getHandler("V");
handler.packOut(packOut,document,null,m_Field.getAD_Val_Rule_ID());
}
}
catch(Exception e)
{
log.info(e.toString());
}
document.endElement("", "", I_AD_Field.Table_Name);
}
private void createFieldBinding(Properties ctx, TransformerHandler document,
X_AD_Field m_Field) {
List<String> excludes = defaultExcludeList(X_AD_Field.Table_Name);
PoExporter filler = new PoExporter(ctx, document, m_Field);
if (m_Field.getAD_Field_ID() <= PackOut.MAX_OFFICIAL_ID) {
filler.add("AD_Field_ID", new AttributesImpl());
}
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Field.COLUMNNAME_AD_Field_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Field.COLUMNNAME_AD_Field_ID);
}
}

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): Igor G. - progerpro@gmail.com
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_FieldGroup;
import org.compiere.model.X_AD_FieldGroup;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
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();
String action = null;
log.info(elementValue + " " + getStringValue(element, "Name"));
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx, entitytype)) {
X_AD_FieldGroup fieldGroup = findPO(ctx, element);
if (fieldGroup == null)
{
int id = findIdByColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
fieldGroup = new X_AD_FieldGroup(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller pf = new PoFiller(ctx, fieldGroup, element, this);
List<String> excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name);
if (fieldGroup.getAD_FieldGroup_ID() == 0 && isOfficialId(element, "AD_FieldGroup_ID"))
{
pf.setInteger("AD_FieldGroup_ID");
}
if (processedFieldGroups.contains(fieldGroup.getAD_FieldGroup_ID())) {
element.skip = true;
return;
}
List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (fieldGroup.is_new() || fieldGroup.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_FieldGroup.Table_Name,
X_AD_FieldGroup.Table_ID);
if (!fieldGroup.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_FieldGroup.Table_Name, fieldGroup);
action = "Update";
} else {
action = "New";
}
if (fieldGroup.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, fieldGroup.getName(),
fieldGroup.get_ID(), action);
element.recordId = fieldGroup.getAD_FieldGroup_ID();
processedFieldGroups.add(fieldGroup.getAD_FieldGroup_ID());
} else {
logImportDetail(ctx, impDetail, 0, fieldGroup.getName(),
fieldGroup.get_ID(), action);
throw new POSaveFailedException("Reference");
}
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
protected 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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_FieldGroup.Table_Name, atts);
createAdElementBinding(ctx, document, fieldGroup);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
try{
new CommonTranslationHandler().packOut(packOut,document,null,fieldGroup.get_ID());
}
catch(Exception e)
{
log.info(e.toString());
}
document.endElement("", "", I_AD_FieldGroup.Table_Name);
}
private void createAdElementBinding(Properties ctx, TransformerHandler document,
X_AD_FieldGroup fieldGroup) {
PoExporter filler = new PoExporter(ctx, document, fieldGroup);
List<String> excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name);
if (fieldGroup.getAD_FieldGroup_ID() <= PackOut.MAX_OFFICIAL_ID) {
filler.add(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, new AttributesImpl());
}
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
}
}

View File

@ -1,97 +0,0 @@
package org.adempiere.pipo2.handler;
import java.io.File;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PackOut;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.util.CLogger;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FileElementHandler implements ElementHandler {
private CLogger log = CLogger.getCLogger(FileElementHandler.class);
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler, int recordId) throws Exception {
MPackageExp header = packout.getPackageExp();
MPackageExpDetail detail = packout.getPackageExpDetail();
log.log(Level.INFO,
"In PackOut.java handling Code or Other 2pack module creation");
String fileDirectory = header.getFile_Directory() + header.getName()
+ detail.getTarget_Directory();
log.log(Level.INFO, "targetDirectory" + fileDirectory);
String targetDirectory = null;
char fileseperator1 = '/';
char fileseperator2 = '\\';
// Correct package for proper file seperator
if (File.separator.equals("/")) {
targetDirectory = fileDirectory.replace(fileseperator2,
fileseperator1);
} else
targetDirectory = fileDirectory.replace(fileseperator1,
fileseperator2);
String sourceDirectory = null;
fileDirectory = detail.getFile_Directory();
// Correct package for proper file seperator
if (File.separator.equals("/")) {
sourceDirectory = fileDirectory.replace(fileseperator2,
fileseperator1);
} else
sourceDirectory = fileDirectory.replace(fileseperator2,
fileseperator1);
packout.copyFile(sourceDirectory + detail.getFileName(),
targetDirectory + detail.getFileName());
AttributesImpl atts = new AttributesImpl();
if (detail.getDestination_Directory() != null) {
fileDirectory = detail.getDestination_Directory();
String destinationDirectory = null;
// Correct package for proper file seperator
if (File.separator.equals("/")) {
destinationDirectory = fileDirectory.replace(fileseperator2,
fileseperator1);
} else
destinationDirectory = fileDirectory.replace(fileseperator2,
fileseperator1);
try {
new DistFileElementHandler(destinationDirectory).doPackout(
packout, null, detail, packoutHandler, null, null, 0);
} catch (Exception e) {
throw new AdempiereException(e.getLocalizedMessage(), e);
}
}
if (detail.getFileName() != null) {
PackOut.addTextElement(docHandler, "file",
"File: " + detail.getFileName(), atts);
}
PackOut.addTextElement(docHandler, "filedirectory", "Directory: "
+ detail.getTarget_Directory(), atts);
PackOut.addTextElement(docHandler, "filenotes",
"Notes: " + detail.getDescription(), atts);
}
@Override
public void startElement(Properties ctx, Element element)
throws SAXException {
}
@Override
public void endElement(Properties ctx, Element element) throws SAXException {
}
}

View File

@ -1,125 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Form_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.MFormAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Form_Access;
import org.compiere.model.X_AD_Role;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name);
MFormAccess po = findPO(ctx, element);
if (po == null) {
int AD_Role_ID = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
AD_Role_ID = getParentId(element, I_AD_Role.Table_Name);
} else {
AD_Role_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Role_ID"));
}
if (AD_Role_ID <= 0)
{
element.defer = true;
return;
}
int AD_Form_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Form_ID"));
if (AD_Form_ID <= 0)
{
element.defer = true;
return;
}
Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID})
.setClient_ID()
.<MFormAccess>first();
if (po == null)
{
po = new MFormAccess(ctx, 0, null);
po.setAD_Form_ID(AD_Form_ID);
po.setAD_Role_ID(AD_Role_ID);
}
excludes.add("AD_Form_ID");
excludes.add("AD_Role_ID");
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Form_Access.Table_Name, atts);
createFormAccessBinding(ctx, document, AD_Form_ID, AD_Role_ID);
document.endElement("", "", I_AD_Form_Access.Table_Name);
}
private void createFormAccessBinding(Properties ctx, TransformerHandler document,
int formId, int roleId) {
MFormAccess po = null;
Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{formId, roleId}).<MFormAccess>first();
if (po != null) {
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name);
filler.export(excludes);
}
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
// TODO Auto-generated method stub
}
}

View File

@ -1,128 +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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Form;
import org.compiere.model.MForm;
import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Form.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MForm mForm = findPO(ctx, element);
if (mForm == null) {
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Form", name);
mForm = new MForm(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mForm, element, this);
if (mForm.getAD_Form_ID() == 0 && isOfficialId(element, "AD_Form_ID"))
{
filler.setInteger("AD_Form_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mForm.is_new() || mForm.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Form.Table_Name,
X_AD_Form.Table_ID);
String action = null;
if (!mForm.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Form.Table_Name, mForm);
action = "Update";
}
else{
action = "New";
}
if (mForm.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mForm.getName(), mForm.get_ID(), action);
}
else{
logImportDetail (ctx, impDetail, 0, mForm.getName(), mForm.get_ID(), action);
throw new POSaveFailedException("Failed to save form definition");
}
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
protected 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();
addTypeName(atts, "table");
document.startElement("","",I_AD_Form.Table_Name,atts);
createFormBinding(ctx, document, m_Form);
document.endElement("","",I_AD_Form.Table_Name);
}
private void createFormBinding(Properties ctx, TransformerHandler document, X_AD_Form m_Form)
{
PoExporter filler = new PoExporter(ctx, document, m_Form);
List<String> excludes = defaultExcludeList(X_AD_Form.Table_Name);
if (m_Form.getAD_Form_ID() <= PackOut.MAX_OFFICIAL_ID) {
filler.add("AD_Form_ID", new AttributesImpl());
}
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID);
}
}

View File

@ -1,219 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.model.GenericPO;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.compiere.model.MColumn;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
*
* @author Robert Klein.
* @author Low Heng Sin
*
*/
public class GenericPOElementHandler extends AbstractElementHandler {
public GenericPOElementHandler() {
}
public void startElement(Properties ctx, Element element) throws SAXException {
String tableName = element.getElementValue();
PO po = findPO(ctx, element);
if (po == null) {
MTable table = MTable.get(ctx, tableName);
POInfo info = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
MColumn columns[] = table.getColumns(false);
StringBuffer whereClause = new StringBuffer();
List<Object> parameters = new ArrayList<Object>();
for(int i = 0; i < columns.length; i++) {
MColumn column = columns[i];
if (column.isIdentifier()) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ? ");
parameters.add(getStringValue(element, column.getColumnName()));
} else if (column.isParent()) {
int parentId = 0;
String parentTableName = null;
if (column.getAD_Reference_ID() == DisplayType.TableDir) {
parentTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3);
} else {
String searchColumn = info.getColumnLookup(i).getColumnName();
parentTableName = searchColumn.substring(0, searchColumn.indexOf("."));
}
Element parent = element.parent;
while (parent != null) {
if (parent.getElementValue().equalsIgnoreCase(parentTableName)) {
parentId = parent.recordId;
break;
}
parent = parent.parent;
}
if (parentId > 0) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ?");
parameters.add(parentId);
}
}
}
Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx));
po = query.setParameters(parameters).first();
if (po == null) {
po = new GenericPO(tableName, ctx, 0);
}
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> excludes = defaultExcludeList(tableName);
if (po.get_ID() == 0) {
Element idElement = element.properties.get(tableName + "_ID");
if (idElement != null && idElement.contents != null && idElement.contents.length() > 0) {
int id = 0;
try {
id = Integer.parseInt(idElement.contents.toString());
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID) {
po.set_ValueOfColumn(tableName + "_ID", id);
}
} catch (Exception e) {}
}
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
AttributesImpl atts = new AttributesImpl();
String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
String components[] = null;
if (sql.indexOf(";") > 0) {
components = sql.split("[;]");
sql = components[0];
} else {
components = new String[]{sql};
}
int tableId = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
String tableName = MTable.getTableName(ctx, tableId);
List<String> excludes = defaultExcludeList(tableName);
Statement stmt = null;
ResultSet rs = null;
try {
sql = MRole.getDefault().addAccessSQL(sql, tableName, true, true);
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
GenericPO po = new GenericPO(tableName, ctx, rs);
int AD_Client_ID = po.getAD_Client_ID();
if (AD_Client_ID != Env.getAD_Client_ID(ctx))
continue;
addTypeName(atts, "table");
document.startElement("","", tableName, atts);
PoExporter filler = new PoExporter(ctx, document, po);
filler.export(excludes);
for (int i = 1; i < components.length; i++) {
String tables[] = components[i].split("[>]");
exportDetail(ctx, document, po, 0, tables);
}
document.endElement("","",tableName);
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, stmt);
}
}
private void exportDetail(Properties ctx, TransformerHandler document, GenericPO parent, int index, String[] tables) {
AttributesImpl atts = new AttributesImpl();
String sql = "SELECT * FROM " + tables[index] + " WHERE " + parent.get_TableName() + "_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
sql = MRole.getDefault().addAccessSQL(sql, tables[index], true, true);
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, parent.get_ID());
rs = pstmt.executeQuery();
while (rs.next()) {
GenericPO po = new GenericPO(tables[index], ctx, rs);
int AD_Client_ID = po.getAD_Client_ID();
if (AD_Client_ID != Env.getAD_Client_ID(ctx))
continue;
List<String> excludes = defaultExcludeList(tables[index]);
document.startElement("", "", tables[index], atts);
PoExporter filler = new PoExporter(ctx, document, po);
filler.export(excludes);
if (index + 1 < tables.length) {
exportDetail(ctx, document, po, index+1, tables);
}
document.endElement("","",tables[index]);
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
MPackageExpDetail detail = packout.getPackageExpDetail();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, detail.getAD_Table_ID());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement());
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
}
}

View File

@ -1,163 +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.pipo2.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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ImpFormat;
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.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name);
String name = getStringValue(element, "Name");
X_AD_ImpFormat mImpFormat = findPO(ctx, element);
if (mImpFormat == null) {
int id = findIdByName(ctx, "AD_ImpFormat", name);
mImpFormat = new X_AD_ImpFormat(ctx, id > 0 ? id : 0,
getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mImpFormat, element, this);
if (mImpFormat.getAD_ImpFormat_ID() == 0 && isOfficialId(element, "AD_ImpFormat_ID"))
{
filler.setInteger("AD_ImpFormat_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mImpFormat.is_new() || mImpFormat.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat.Table_Name,
X_AD_ImpFormat.Table_ID);
String action = null;
if (!mImpFormat.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat.Table_Name, mImpFormat);
action = "Update";
} else {
action = "New";
}
if (mImpFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mImpFormat.getName(), mImpFormat
.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mImpFormat.getName(), mImpFormat
.get_ID(), action);
throw new POSaveFailedException("Failed to save Import Format.");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
protected 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);
addTypeName(atts, "table");
document.startElement("", "", I_AD_ImpFormat.Table_Name, atts);
createImpFormatBinding(ctx, document, m_ImpFormat);
String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= "
+ import_id;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createImpFormatRow(ctx, document, rs
.getInt("AD_ImpFormat_Row_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "ImpFormat", e);
throw new DatabaseAccessException("Failed to export Import Format.", e);
} finally {
DB.close(rs, pstmt);
}
document.endElement("", "", I_AD_ImpFormat.Table_Name);
}
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 void createImpFormatBinding(Properties ctx, TransformerHandler document,
X_AD_ImpFormat m_ImpFormat) {
PoExporter filler = new PoExporter(ctx, document, m_ImpFormat);
List<String> excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name);
if (m_ImpFormat.getAD_ImpFormat_ID() <= PackOut.MAX_OFFICIAL_ID)
{
filler.add("AD_ImpFormat_ID", new AttributesImpl());
}
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID);
}
}

View File

@ -1,181 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.I_AD_ImpFormat_Row;
import org.compiere.model.X_AD_ImpFormat_Row;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 action = null;
List<String> excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name);
if (isParentDefer(element, I_AD_ImpFormat.Table_Name)) {
element.defer = true;
return;
}
X_AD_ImpFormat_Row mImpFormatRow = findPO(ctx, element);
if (mImpFormatRow == null) {
int impFormatId = 0;
if (getParentId(element, I_AD_ImpFormat.Table_Name) > 0) {
impFormatId = getParentId(element, I_AD_ImpFormat.Table_Name);
} else {
Element e = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_ID);
if (ReferenceUtils.isIDLookup(e) || ReferenceUtils.isUUIDLookup(e))
impFormatId = ReferenceUtils.resolveReference(ctx, e);
else
impFormatId = findIdByName(ctx, "AD_ImpFormat", e.contents.toString());
}
if (impFormatId <= 0) {
element.defer = true;
return;
}
Element tableElement = element.properties.get(I_AD_ImpFormat.COLUMNNAME_AD_Table_ID);
int tableId = 0;
if (ReferenceUtils.isIDLookup(tableElement) || ReferenceUtils.isUUIDLookup(tableElement)) {
tableId = ReferenceUtils.resolveReference(ctx, tableElement);
} else {
String tableName = getStringValue(element, I_AD_ImpFormat.COLUMNNAME_AD_Table_ID, excludes);
if (tableName != null && tableName.trim().length() > 0) {
tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
}
if (tableId <= 0) {
element.defer = true;
return;
}
}
Element columnElement = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID);
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
String columnName = getStringValue(element, I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID, excludes);
if (columnName != null && columnName.trim().length() > 0) {
columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "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,impFormatId);
mImpFormatRow = new X_AD_ImpFormat_Row(ctx, id > 0 ? id : 0, getTrxName(ctx));
mImpFormatRow.setAD_Column_ID(columnId);
mImpFormatRow.setAD_ImpFormat_ID(impFormatId);
}
PoFiller filler = new PoFiller(ctx, mImpFormatRow, element, this);
if (mImpFormatRow.getAD_ImpFormat_Row_ID() == 0 && isOfficialId(element, "AD_ImpFormat_Row_ID"))
{
filler.setInteger("AD_ImpFormat_Row_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mImpFormatRow.is_new() || mImpFormatRow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat_Row.Table_Name,
X_AD_ImpFormat_Row.Table_ID);
if (!mImpFormatRow.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat_Row.Table_Name, mImpFormatRow);
action = "Update";
}
else{
action = "New";
}
if (mImpFormatRow.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
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();
addTypeName(atts, "table");
document.startElement("","",I_AD_ImpFormat_Row.Table_Name,atts);
createImpFormatRowBinding(ctx,document,m_ImpFormat_Row);
document.endElement("","",I_AD_ImpFormat_Row.Table_Name);
}
private void createImpFormatRowBinding(Properties ctx, TransformerHandler document, X_AD_ImpFormat_Row m_ImpFormat_Row)
{
PoExporter filler = new PoExporter(ctx, document, m_ImpFormat_Row);
List<String> excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name);
String sql = null;
int tableId = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID());
filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableId, new AttributesImpl());
if (m_ImpFormat_Row.getAD_ImpFormat_Row_ID() <= PackOut.MAX_OFFICIAL_ID)
{
filler.add("AD_ImpFormat_Row_ID", new AttributesImpl());
}
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID);
}
}

View File

@ -1,367 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Menu;
import org.compiere.model.X_AD_Menu;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Task;
import org.compiere.model.X_AD_TreeNodeMM;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
X_AD_Menu mMenu = findPO(ctx, element);
if (mMenu == null) {
String menuName = getStringValue(element, "Name");
int menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName);
mMenu = new X_AD_Menu(ctx, menuId > 0 ? menuId : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMenu, element, this);
if (mMenu.getAD_Menu_ID() == 0 && isOfficialId(element, "AD_Menu_ID"))
{
filler.setInteger("AD_Menu_ID");
}
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
if (!mMenu.is_new() && !mMenu.is_Changed())
return;
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Menu.Table_Name,
X_AD_Menu.Table_ID);
String action = null;
if (!mMenu.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Menu.Table_Name, mMenu);
action = "Update";
} else {
action = "New";
}
if (mMenu.save(getTrxName(ctx)) == true) {
try {
logImportDetail(ctx, impDetail, 1, mMenu.getName(), mMenu
.get_ID(), action);
} catch (SAXException e) {
log.info("setmenu:" + e);
}
} else {
try {
logImportDetail(ctx, impDetail, 0, mMenu.getName(), mMenu
.get_ID(), action);
} catch (SAXException e) {
log.info("setmenu:" + e);
}
}
Element parentElement = element.properties.get("Parent_ID");
int parentId = 0;
if (ReferenceUtils.isIDLookup(parentElement) || ReferenceUtils.isUUIDLookup(parentElement)) {
parentId = ReferenceUtils.resolveReference(ctx, parentElement);
} else {
String parent = getStringValue(element, "Parent_ID");
parentId = findIdByName(ctx, "AD_Menu", parent);
}
StringBuffer updateSQL = null;
String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10"
+ " AND Node_ID = " + mMenu.getAD_Menu_ID();
int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = 10 and "
+ " Node_ID =?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql,
getTrxName(ctx));
pstmt.setInt(1, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
String colValue = null;
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
int tableID = X_AD_TreeNodeMM.Table_ID;
for (int q = 1; q <= columns; q++) {
String colName = meta.getColumnName(q).toUpperCase();
sql = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?";
int columnID = DB.getSQLValue(getTrxName(ctx), sql, colName, tableID);
sql = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?";
int referenceID = DB.getSQLValue(getTrxName(ctx), sql, columnID);
if (referenceID == 20 || referenceID == 28)
if (rs.getObject(q).equals("Y"))
colValue = "true";
else
colValue = "false";
else
colValue = rs.getObject(q).toString();
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx));
backup.setAD_Package_Imp_Detail_ID(impDetail.getAD_Package_Imp_Detail_ID());
backup.setAD_Package_Imp_ID(getPackageImpId(ctx));
backup.setAD_Table_ID(tableID);
backup.setAD_Column_ID(columnID);
backup.setAD_Reference_ID(referenceID);
backup.setColValue(colValue);
backup.saveEx();
}
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
}
updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + parentId).append(
" , SeqNo = " + getStringValue(element, "SeqNo")).append(
" WHERE AD_Tree_ID = 10").append(
" AND Node_ID = " + mMenu.getAD_Menu_ID());
} else {
updateSQL = 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(
parentId + "," + getStringValue(element, "SeqNo") + ", 10, "
+ mMenu.getAD_Menu_ID() + ")");
}
DB.executeUpdateEx(updateSQL.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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
createModule(ctx, document, AD_Menu_ID);
document.endElement("", "", I_AD_Menu.Table_Name);
}
}
private void createMenuBinding(Properties ctx, TransformerHandler document,
X_AD_Menu m_Menu) {
PoExporter filler = new PoExporter(ctx, document, m_Menu);
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
String 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) {
filler.addTableReference("Parent_ID", "AD_Menu", "Name", id, new AttributesImpl());
}
sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
filler.addString("SeqNo", Integer.toString(seqNo), new AttributesImpl());
if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.addString("AD_Menu_ID", Integer.toString(m_Menu.getAD_Menu_ID()), new AttributesImpl());
filler.export(excludes);
}
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;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null);
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
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) {
// Call CreateWindow.
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID)>0)
{
ElementHandler handler = packOut.getHandler("W");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID)>0)
{
ElementHandler handler = packOut.getHandler("P");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID));
} else if (rs.getInt(X_AD_Task.COLUMNNAME_AD_Task_ID)>0)
{
ElementHandler handler = packOut.getHandler("ad.task");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Task.COLUMNNAME_AD_Task_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID) > 0)
{
ElementHandler handler = packOut.getHandler("X");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID) > 0)
{
ElementHandler handler = packOut.getHandler("F");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID));
}
// Call CreateModule because entry is a summary menu
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", I_AD_Menu.Table_Name);
}
} catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e);
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
}
}
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;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
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);
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
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) {
// Call CreateWindow.
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID)>0)
{
ElementHandler handler = packOut.getHandler("W");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID)>0)
{
ElementHandler handler = packOut.getHandler("P");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID));
}
else if (rs.getInt(X_AD_Task.COLUMNNAME_AD_Task_ID)>0)
{
ElementHandler handler = packOut.getHandler("K");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Task.COLUMNNAME_AD_Task_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID) > 0)
{
ElementHandler handler = packOut.getHandler("X");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID));
}
else if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID) > 0)
{
ElementHandler handler = packOut.getHandler("F");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID));
}
// Call CreateModule because entry is a summary menu
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", I_AD_Menu.Table_Name);
}
} catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e);
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
}
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID);
}
}

View File

@ -1,124 +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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Message;
import org.compiere.model.MMessage;
import org.compiere.model.X_AD_Message;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.Env;
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 entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MMessage mMessage = findPO(ctx, element);
if (mMessage == null) {
String value = getStringValue(element, "Value");
int id = findIdByColumn(ctx, "AD_Message", "value", value);
mMessage = new MMessage(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMessage, element, this);
List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mMessage.is_new() || mMessage.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Message.Table_Name,
X_AD_Message.Table_ID);
String action = null;
if (mMessage.getAD_Message_ID() == 0 && isOfficialId(element, "AD_Message_ID"))
filler.setInteger("AD_Message_ID");
if (!mMessage.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Message.Table_Name, mMessage);
action = "Update";
}
else{
action = "New";
}
if (mMessage.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action);
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 {
int AD_Message_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID);
if (messages.contains(AD_Message_ID))
return;
messages.add(AD_Message_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null);
addTypeName(atts, "table");
document.startElement("","",I_AD_Message.Table_Name,atts);
createMessageBinding(ctx,document,m_Message);
document.endElement("","",I_AD_Message.Table_Name);
}
private void createMessageBinding(Properties ctx, TransformerHandler document, X_AD_Message m_Message)
{
PoExporter filler = new PoExporter(ctx, document, m_Message);
if (m_Message.getAD_Message_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Message_ID", new AttributesImpl());
List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name);
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID);
}
}

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
* Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Role_OrgAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Role_OrgAccess;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
X_AD_Role_OrgAccess po = findPO(ctx, element);
if (po == null) {
int roleId = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleId = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleId = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element orgElement = element.properties.get("AD_Org_ID");
int orgId = ReferenceUtils.resolveReference(ctx, orgElement);
Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleId, orgId})
.setClient_ID()
.<X_AD_Role_OrgAccess>first();
if (po == null) {
po = new X_AD_Role_OrgAccess(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgId);
po.setAD_Role_ID(roleId);
}
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts);
createOrgAccessBinding(ctx, document, AD_Org_ID, AD_Role_ID);
document.endElement("", "", I_AD_Role_OrgAccess.Table_Name);
}
private void createOrgAccessBinding(Properties ctx, TransformerHandler document,
int orgId, int roleId) {
Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
X_AD_Role_OrgAccess po = query.setParameters(new Object[]{roleId, orgId}).<X_AD_Role_OrgAccess>first();
PoExporter filler = new PoExporter(ctx, document, po);
AttributesImpl orgRefAtts = new AttributesImpl();
String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", orgId, orgRefAtts);
filler.addString("AD_Org_ID", orgReference, orgRefAtts);
AttributesImpl roleRefAtts = new AttributesImpl();
String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", roleId, roleRefAtts);
filler.addString("AD_Role_ID", roleReference, roleRefAtts);
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Preference;
import org.compiere.model.MPreference;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Preference;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Preference.Table_Name);
MPreference mPreference = findPO(ctx, element);
if (mPreference == null) {
mPreference = new MPreference(ctx, 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mPreference, element, this);
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
Query query = new Query(ctx, "AD_Preference", "Attribute = ? AND coalesce(AD_User_ID,0) = ? AND coalesce(AD_Window_ID,0) = ?", getTrxName(ctx));
MPreference tmp = query
.setParameters(new Object[]{mPreference.getAttribute(), mPreference.getAD_User_ID(), mPreference.getAD_Window_ID()})
.first();
if (tmp != null) {
filler = new PoFiller(ctx, tmp, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
mPreference = tmp;
}
} else {
PoFiller filler = new PoFiller(ctx, mPreference, element, this);
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
}
if (mPreference.get_ID() == 0 && isOfficialId(element, "AD_Preference_ID"))
mPreference.setAD_Preference_ID(Integer.parseInt(getStringValue(element, "AD_Preference_ID")));
if (mPreference.is_new() || mPreference.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Preference.Table_Name,
X_AD_Preference.Table_ID);
String action = null;
if (!mPreference.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Preference.Table_Name, mPreference);
action = "Update";
} else {
action = "New";
}
if (mPreference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPreference.getAttribute(),
mPreference.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mPreference.getAttribute(),
mPreference.get_ID(), action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Preference.Table_Name, atts);
createPreferenceBinding(ctx, document, m_Preference);
document.endElement("", "", I_AD_Preference.Table_Name);
}
private void createPreferenceBinding(Properties ctx, TransformerHandler document,
X_AD_Preference m_Preference) {
PoExporter filler = new PoExporter(ctx, document, m_Preference);
List<String> excludes = defaultExcludeList(X_AD_Preference.Table_Name);
if (m_Preference.getAD_Preference_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.addString("AD_Preference_ID", Integer.toString(m_Preference.getAD_Preference_ID()), new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Preference.COLUMNNAME_AD_Preference_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Preference.COLUMNNAME_AD_Preference_ID);
}
}

View File

@ -1,164 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormat;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_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.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PrintFormatElementHandler extends AbstractElementHandler {
private List<Integer> formats = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
X_AD_PrintFormat mPrintFormat = findPO(ctx, element);
if (mPrintFormat == null) {
String name = getStringValue(element, "Name");
int id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name);
mPrintFormat = new X_AD_PrintFormat(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this);
List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name);
if (mPrintFormat.getAD_PrintFormat_ID() == 0 && isOfficialId(element, "AD_PrintFormat_ID"))
mPrintFormat.setAD_PrintFormat_ID(getIntValue(element, "AD_PrintFormat_ID"));
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mPrintFormat.is_new() || mPrintFormat.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormat.Table_Name,
X_AD_PrintFormat.Table_ID);
String action = null;
if (!mPrintFormat.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormat.Table_Name, mPrintFormat);
action = "Update";
} else {
action = "New";
}
if (mPrintFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
element.recordId = mPrintFormat.getAD_PrintFormat_ID();
} else {
logImportDetail(ctx, impDetail, 0, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
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);
if (formats.contains(AD_PrintFormat_ID))
return;
formats.add(AD_PrintFormat_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_PrintFormat m_Printformat = new X_AD_PrintFormat(ctx, AD_PrintFormat_ID, null);
if (m_Printformat.getAD_PrintPaper_ID() > 0) {
try {
getPackOutProcess(ctx).getHandler("PP").packOut(getPackOutProcess(ctx), document, getLogDocument(ctx), m_Printformat.getAD_PrintPaper_ID());
} catch (Exception e) {
throw new SAXException(e);
}
}
addTypeName(atts, "table");
document.startElement("", "", I_AD_PrintFormat.Table_Name, atts);
createPrintFormatBinding(ctx, document, m_Printformat);
String sql = "SELECT AD_PrintFormatItem_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= "
+ m_Printformat.getAD_PrintFormat_ID()
+ " ORDER BY "+X_AD_PrintFormatItem.COLUMNNAME_SeqNo;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createItem(ctx, document, rs.getInt("AD_PrintFormatItem_ID"));
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
}
document.endElement("", "", I_AD_PrintFormat.Table_Name);
}
private void createItem(Properties ctx, TransformerHandler document,
int AD_PrintFormatItem_ID) throws SAXException {
try {
getPackOutProcess(ctx).getHandler("ad.printformat.item").packOut(getPackOutProcess(ctx), document, getLogDocument(ctx), AD_PrintFormatItem_ID);
} catch (Exception e) {
throw new SAXException(e);
}
}
private void createPrintFormatBinding(Properties ctx, TransformerHandler document,
X_AD_PrintFormat m_Printformat) {
PoExporter filler = new PoExporter(ctx, document, m_Printformat);
List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name);
if (m_Printformat.getAD_PrintFormat_ID() <= PackOut.MAX_OFFICIAL_ID) {
filler.add("AD_PrintFormat_ID", new AttributesImpl());
}
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID);
}
}

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
* Teo Sarca, SC ARHIPAC SERVICE SRL
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormatItem;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name);
if (isParentDefer(element, I_AD_PrintFormatItem.Table_Name)) {
element.defer = true;
return;
}
X_AD_PrintFormatItem mPrintFormatItem = findPO(ctx, element);
if (mPrintFormatItem == null) {
int parentId = 0;
if (getParentId(element, I_AD_PrintFormatItem.Table_Name) > 0) {
parentId = getParentId(element, I_AD_PrintFormatItem.Table_Name);
} else {
Element pfElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
parentId = ReferenceUtils.resolveReference(ctx, pfElement);
}
if (parentId <= 0) {
element.defer = true;
return;
}
String name = getStringValue(element, "Name");
int id = findIdByNameAndParentId(ctx, "AD_PrintFormatItem", name, "AD_PrintFormat", parentId);
mPrintFormatItem = new X_AD_PrintFormatItem(ctx, id > 0 ? id : 0, getTrxName(ctx));
mPrintFormatItem.setAD_PrintFormat_ID(parentId);
excludes.add(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
}
PoFiller filler = new PoFiller(ctx, mPrintFormatItem, element, this);
if (mPrintFormatItem.getAD_PrintFormatItem_ID() == 0 && isOfficialId(element, "AD_PrintFormatItem_ID"))
filler.setInteger("AD_PrintFormatItem_ID");
excludes.add("AD_Table_ID");
excludes.add("AD_Column_ID");
int columnId = 0;
Element columnElement = element.properties.get("AD_Column_ID");
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
Element tableElement = element.properties.get("AD_Table_ID");
int tableId = ReferenceUtils.resolveReference(ctx, tableElement);
String columnName = getStringValue(element, "AD_Column_ID");
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName,
"AD_Table", tableId);
}
if (columnId > 0)
mPrintFormatItem.setAD_Column_ID(columnId);
excludes.add("AD_PrintFormatChild_ID");
Element pfchildElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatChild_ID);
int AD_PrintFormatChild_ID = ReferenceUtils.resolveReference(ctx, pfchildElement);
if (AD_PrintFormatChild_ID > 0) {
mPrintFormatItem.setAD_PrintFormatChild_ID(AD_PrintFormatChild_ID);
} else if (pfchildElement.contents != null && pfchildElement.contents.length() > 0) {
element.defer = true;
element.unresolved = "AD_PrintFormat: " + pfchildElement.contents;
return;
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mPrintFormatItem.is_new() || mPrintFormatItem.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormatItem.Table_Name,
X_AD_PrintFormatItem.Table_ID);
String action = null;
if (!mPrintFormatItem.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormatItem.Table_Name, mPrintFormatItem);
action = "Update";
} else {
action = "New";
}
if (mPrintFormatItem.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPrintFormatItem.getName(),
mPrintFormatItem.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mPrintFormatItem.getName(),
mPrintFormatItem.get_ID(), action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_PrintFormatItem.Table_Name, atts);
createPrintFormatItemBinding(ctx, document, m_PrintFormatItem);
document.endElement("", "", I_AD_PrintFormatItem.Table_Name);
}
private void createPrintFormatItemBinding(Properties ctx, TransformerHandler document,
X_AD_PrintFormatItem mPrintformatItem) {
PoExporter filler = new PoExporter(ctx, document, mPrintformatItem);
List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name);
if (mPrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_PrintFormatItem_ID", new AttributesImpl());
if (mPrintformatItem.getAD_Column_ID() > 0) {
String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableID = DB.getSQLValue(null, sql, mPrintformatItem.getAD_Column_ID());
AttributesImpl referenceAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Table", "TableName", tableID, referenceAtts);
filler.addString("AD_Table.TableName", value, referenceAtts);
}
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID);
}
}

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
* Contributor(s): Low Heng Sin hengsin@avantz.com
* Teo Sarca, SC ARHIPAC SERVICE SRL
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintPaper;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_PrintPaper;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class PrintPaperElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name);
X_AD_PrintPaper printPaper = findPO(ctx, element);
if (printPaper == null) {
String printPaperName = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_PrintPaper", printPaperName);
printPaper = new X_AD_PrintPaper(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, printPaper, element, this);
if (printPaper.getAD_PrintPaper_ID() == 0 && isOfficialId(element, "AD_PrintPaper_ID"))
filler.setInteger("AD_PrintPaper_ID");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (printPaper.is_new() || printPaper.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintPaper.Table_Name, X_AD_PrintPaper.Table_ID);
String action = null;
if (!printPaper.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_PrintPaper", printPaper);
action = "Update";
} else {
action = "New";
}
if (printPaper.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, printPaper.getName(),
printPaper.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, printPaper.getName(),
printPaper.get_ID(), action);
throw new POSaveFailedException("PrintPaper");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_PrintPaper_ID = Env.getContextAsInt(ctx,
X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID);
X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx,
AD_PrintPaper_ID, null);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_PrintPaper.Table_Name, atts);
createPrintPaperBinding(ctx, document, printPaper);
document.endElement("", "", I_AD_PrintPaper.Table_Name);
}
private void createPrintPaperBinding(Properties ctx, TransformerHandler document,
X_AD_PrintPaper printPaper) {
PoExporter filler = new PoExporter(ctx, document, printPaper);
List<String> excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name);
if (printPaper.getAD_PrintPaper_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_PrintPaper_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID);
}
}

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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Process_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Access;
import org.compiere.model.X_AD_Role;
import org.compiere.util.Env;
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 {
int roleid =0;
int processid =0;
List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name);
X_AD_Process_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element processElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
processid = ReferenceUtils.resolveReference(ctx, processElement);
Query query = new Query(ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, processid}).first();
if (po == null)
{
po = new X_AD_Process_Access(ctx, 0, getTrxName(ctx));
po.setAD_Process_ID(processid);
po.setAD_Role_ID(roleid);
}
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process_Access.Table_Name, atts);
createProcessAccessBinding(ctx, document, AD_Process_ID, AD_Role_ID);
document.endElement("", "", I_AD_Process_Access.Table_Name);
}
private void createProcessAccessBinding(Properties ctx, TransformerHandler document,
int process_id, int role_id) {
X_AD_Process_Access po = null;
Query query = new Query(ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{role_id, process_id}).first();
if (po != null)
{
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name);
filler.export(excludes);
}
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

View File

@ -1,190 +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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.Env;
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 entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
X_AD_Process mProcess = findPO(ctx, element);
if (mProcess == null) {
String value = getStringValue(element, "Value");
// Get New process.
int id = findIdByColumn(ctx, "AD_Process", "Value", value);
mProcess = new X_AD_Process(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
if (mProcess.getAD_Process_ID() == 0 && isOfficialId(element, "AD_Process_ID"))
mProcess.setAD_Process_ID(Integer.parseInt(getStringValue(element, "AD_Process_ID")));
PoFiller filler = new PoFiller(ctx, mProcess, element, this);
List<String> excludes = defaultExcludeList(X_AD_Process.Table_Name);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mProcess.is_new() || mProcess.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process.Table_Name,
X_AD_Process.Table_ID);
String action = null;
if (!mProcess.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process.Table_Name, mProcess);
action = "Update";
} else {
action = "New";
}
if (mProcess.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcess.getName(), mProcess
.get_ID(), action);
element.recordId = mProcess.getAD_Process_ID();
} else {
logImportDetail(ctx, impDetail, 0, mProcess.getName(), mProcess
.get_ID(), action);
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 = getPackOutProcess(ctx);
X_AD_Process m_Process = new X_AD_Process(ctx, AD_Process_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
try {
if (m_Process.isReport() && m_Process.getAD_ReportView_ID() > 0)
{
ElementHandler handler = packOut.getHandler("R");
handler.packOut(packOut,document,null,m_Process.getAD_ReportView_ID());
}
if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0)
{
ElementHandler handler = packOut.getHandler("PFT");
handler.packOut(packOut,document,null,m_Process.getAD_PrintFormat_ID());
}
if (m_Process.getAD_Workflow_ID() > 0) {
ElementHandler handler = packOut.getHandler("F");
handler.packOut(packOut,document,null,m_Process.getAD_Workflow_ID());
}
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process.Table_Name, atts);
createProcessBinding(ctx, document, m_Process);
Query query = new Query(ctx, "AD_Process_PARA", "AD_Process_ID = ?", getTrxName(ctx));
List<X_AD_Process_Para> paralist = query.setParameters(new Object[]{AD_Process_ID}).list();
for (X_AD_Process_Para para : paralist) {
if (para.getAD_Reference_ID()>0)
{
ElementHandler handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,para.getAD_Reference_ID());
}
if (para.getAD_Reference_Value_ID()>0)
{
ElementHandler handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,para.getAD_Reference_Value_ID());
}
if (para.getAD_Val_Rule_ID() > 0)
{
ElementHandler handler = packOut.getHandler("V");
handler.packOut(packOut,document,null,para.getAD_Val_Rule_ID());
}
createProcessPara(ctx, document, para.getAD_Process_Para_ID());
}
document.endElement("", "", I_AD_Process.Table_Name);
} catch (Exception e) {
throw new AdempiereException(e);
}
}
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 void createProcessBinding(Properties ctx, TransformerHandler document,
X_AD_Process m_Process) {
PoExporter filler = new PoExporter(ctx, document, m_Process);
List<String> excludes = defaultExcludeList(X_AD_Process.Table_Name);
if (m_Process.getAD_Process_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Process_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID);
}
}

View File

@ -1,159 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
import org.compiere.model.I_AD_Process_Para;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Process_Para.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, I_AD_Process.Table_Name)) {
element.defer = true;
return;
}
X_AD_Process_Para mProcessPara = findPO(ctx, element);
if (mProcessPara == null) {
String name = getStringValue(element, "Name");
int id = 0;
int masterId = 0;
if (getParentId(element, I_AD_Process.Table_Name) > 0) {
masterId = getParentId(element, "process");
} else {
Element processElement = element.properties.get(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
masterId = ReferenceUtils.resolveReference(ctx, processElement);
}
if (masterId <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + getStringValue(element, I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
return;
}
id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "Name", name, "AD_Process", masterId);
mProcessPara = new X_AD_Process_Para(ctx, id > 0 ? id : 0, getTrxName(ctx));
mProcessPara.setAD_Process_ID(masterId);
excludes.add(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
}
if (mProcessPara.getAD_Process_Para_ID() == 0 && isOfficialId(element, "AD_Process_Para_ID"))
mProcessPara.setAD_Process_Para_ID(Integer.parseInt(getStringValue(element, "AD_Process_Para_ID")));
PoFiller filler = new PoFiller(ctx, mProcessPara, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mProcessPara.is_new() || mProcessPara.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process_Para.Table_Name,
X_AD_Process_Para.Table_ID);
String action = null;
if (!mProcessPara.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process_Para.Table_Name,
mProcessPara);
action = "Update";
} else {
action = "New";
}
if (mProcessPara.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcessPara.getName(),
mProcessPara.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mProcessPara.getName(),
mProcessPara.get_ID(), action);
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));
if (m_Processpara.getAD_Element_ID() > 0) {
PackOut packOut = getPackOutProcess(ctx);
ElementHandler handler = packOut.getHandler("ELE");
try {
handler.packOut(packOut,document,null,m_Processpara.getAD_Element_ID());
} catch (Exception e) {
throw new AdempiereException(e);
}
}
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process_Para.Table_Name, atts);
createProcessParaBinding(ctx, document, m_Processpara);
document.endElement("", "", I_AD_Process_Para.Table_Name);
}
private void createProcessParaBinding(Properties ctx, TransformerHandler document,
X_AD_Process_Para m_Processpara) {
PoExporter filler = new PoExporter(ctx, document, m_Processpara);
List<String> excludes = defaultExcludeList(X_AD_Process_Para.Table_Name);
if (m_Processpara.getAD_Process_Para_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Process_Para_ID", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID);
}
}

View File

@ -1,195 +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.pipo2.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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
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.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 entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx, entitytype)) {
X_AD_Reference mReference = findPO(ctx, element);
if (mReference == null) {
int id = findIdByName(ctx, "AD_Reference", name);
mReference = new X_AD_Reference(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
if (mReference.getAD_Reference_ID() == 0 && isOfficialId(element, "AD_Reference_ID"))
mReference.setAD_Reference_ID(getIntValue(element, "AD_Reference_ID"));
PoFiller filler = new PoFiller(ctx, mReference, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mReference.is_new() || mReference.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Reference.Table_Name,
X_AD_Reference.Table_ID);
String action = null;
if (!mReference.is_new()) {
if (references.contains(mReference.getAD_Reference_ID())) {
element.skip = true;
return;
}
backupRecord(ctx, impDetail.getAD_Package_Imp_ID(), X_AD_Reference.Table_Name, mReference);
action = "Update";
} else {
action = "New";
}
if (mReference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mReference.getName(),
mReference.get_ID(), action);
references.add(mReference.getAD_Reference_ID());
element.recordId = mReference.getAD_Reference_ID();
} else {
logImportDetail(ctx, impDetail, 0, mReference.getName(),
mReference.get_ID(), action);
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();
X_AD_Reference m_Reference = new X_AD_Reference(ctx, Reference_id, getTrxName(ctx));
addTypeName(atts, "table");
document.startElement("", "", I_AD_Reference.Table_Name, atts);
createReferenceBinding(ctx, document, m_Reference);
if (m_Reference.getValidationType().compareTo("L") == 0) {
String sql1 = "SELECT AD_REF_LIST_ID FROM AD_Ref_List WHERE AD_Reference_ID= "
+ Reference_id;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql1, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createReferenceList(ctx, document, rs.getInt("AD_REF_LIST_ID"));
}
}
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 {
DB.close(rs, pstmt);
}
} else if (m_Reference.getValidationType().compareTo("T") == 0) {
createReferenceTable(ctx, document, Reference_id);
}
document.endElement("", "", I_AD_Reference.Table_Name);
}
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 void createReferenceBinding(Properties ctx, TransformerHandler document,
X_AD_Reference m_Reference) {
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
PoExporter filler = new PoExporter(ctx, document, m_Reference);
if (m_Reference.getAD_Reference_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Reference_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID);
}
}

View File

@ -1,135 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Ref_List;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_List;
import org.compiere.util.Env;
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 entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
X_AD_Ref_List mRefList = findPO(ctx, element);
if (mRefList == null) {
String value = getStringValue(element, "Value");
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
Element referenceElement = element.properties.get(I_AD_Ref_List.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
}
int AD_Ref_List_ID = findIdByColumnAndParentId(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
mRefList = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx));
}
if (mRefList.getAD_Ref_List_ID() == 0 && isOfficialId(element, "AD_Ref_List_ID"))
mRefList.setAD_Ref_List_ID(getIntValue(element, "AD_Ref_List_ID"));
PoFiller filler = new PoFiller(ctx, mRefList, element, this);
List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mRefList.is_new() || mRefList.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_List.Table_Name,
X_AD_Ref_List.Table_ID);
String action = null;
if (!mRefList.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Ref_List.Table_Name, mRefList);
action = "Update";
} else {
action = "New";
}
if (mRefList.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mRefList.getName(),
mRefList.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mRefList.getName(),
mRefList.get_ID(), action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Ref_List.Table_Name, atts);
createRefListBinding(ctx, document, m_Ref_List);
document.endElement("", "", I_AD_Ref_List.Table_Name);
}
private void createRefListBinding(Properties ctx, TransformerHandler document,
X_AD_Ref_List m_Ref_List) {
List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name);
PoExporter filler = new PoExporter(ctx, document, m_Ref_List);
if (m_Ref_List.getAD_Ref_List_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Ref_List_ID", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID);
}
}

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
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.compiere.model.I_AD_Ref_Table;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
X_AD_Ref_Table refTable = findPO(ctx, element);
if (refTable == null) {
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
Element referenceElement = element.properties.get(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
}
if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID"))
AD_Reference_ID = getIntValue(element, "AD_Reference_ID");
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx));
} else {
refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx));
}
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
}
}
String action = refTable.is_new() ? "New" : "Update";
PoFiller filler = new PoFiller(ctx, refTable, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
int tableId = refTable.getAD_Table_ID();
Element displayElement = element.properties.get("AD_Display");
int displayColumnId = 0;
if (ReferenceUtils.isIDLookup(displayElement) || ReferenceUtils.isUUIDLookup(displayElement)) {
displayColumnId = ReferenceUtils.resolveReference(ctx, displayElement);
} else {
displayColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", displayElement.contents.toString(), "AD_Table", tableId);
}
refTable.setAD_Display(displayColumnId);
Element keyElement = element.properties.get("AD_Key");
int keyColumnId = 0;
if (ReferenceUtils.isIDLookup(keyElement) || ReferenceUtils.isUUIDLookup(keyElement)) {
keyColumnId = ReferenceUtils.resolveReference(ctx, keyElement);
} else {
keyColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", keyElement.contents.toString(), "AD_Table", tableId);
}
refTable.setAD_Key(keyColumnId);
if (refTable.is_new() || refTable.is_Changed()) {
refTable.saveEx();
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_Table.Table_Name,
X_AD_Ref_Table.Table_ID);
logImportDetail(ctx, impDetail, 1, refTable.getAD_Reference().getName(), refTable.getAD_Reference_ID(), action);
}
} 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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Ref_Table.Table_Name, atts);
createReferenceTableBinding(ctx, document, Reference_id);
document.endElement("", "", I_AD_Ref_Table.Table_Name);
}
private void createReferenceTableBinding(Properties ctx,
TransformerHandler document, int reference_ID) {
if (reference_ID <= PackOut.MAX_OFFICIAL_ID)
{
PoExporter filler = new PoExporter(ctx,document,null);
filler.addString("AD_Reference_ID", Integer.toString(reference_ID), new AttributesImpl());
}
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= "
+ reference_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
if (rs.next()) {
X_AD_Ref_Table refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx));
PoExporter filler = new PoExporter(ctx,document,refTable);
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
excludes.add("ad_display");
excludes.add("ad_key");
filler.export(excludes);
filler.addTableReference("AD_Display", "AD_Column", "ColumnName", new AttributesImpl());
filler.addTableReference("AD_Key", "AD_Column", "ColumnName", new AttributesImpl());
}
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new DatabaseAccessException("Failed to export Reference Table", e);
} finally {
DB.close(rs, pstmt);
}
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
}
}

View File

@ -1,179 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.I_AD_ReportView_Col;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name);
String entitytype = getStringValue(element,"EntityType");
if (isProcessElement(ctx, entitytype)) {
excludes.add("AD_Table_ID");
X_AD_ReportView_Col mReportviewCol = findPO(ctx, element);
if (mReportviewCol == null) {
int AD_ReportView_ID = 0;
if (getParentId(element, I_AD_ReportView.Table_Name) > 0) {
AD_ReportView_ID = getParentId(element, I_AD_ReportView.Table_Name);
} else {
Element rvElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_ID);
AD_ReportView_ID = ReferenceUtils.resolveReference(ctx, rvElement);
}
if (AD_ReportView_ID <= 0) {
element.defer = true;
return;
}
int AD_Column_ID = 0;
Element columnElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_Column_ID);
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
if (columnElement.contents != null && columnElement.contents.length() > 0) {
Element tableElement = element.properties.get("AD_Table_ID");
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement);
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(),
"AD_Table", AD_Table_ID);
if (AD_Column_ID <= 0) {
element.defer = true;
return;
}
}
}
String functionColumn = getStringValue(element, "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 = ?");
sql.append(" AND AD_ReportView_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID);
mReportviewCol = new X_AD_ReportView_Col(ctx, id > 0 ? id : 0, getTrxName(ctx));
mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID);
if (AD_Column_ID > 0) {
mReportviewCol.setAD_Column_ID(id);
}
mReportviewCol.setFunctionColumn(functionColumn);
excludes.add("FunctionColumn");
excludes.add("AD_ReportView_ID");
excludes.add("AD_Column_ID");
}
if (mReportviewCol.getAD_ReportView_Col_ID() == 0 && isOfficialId(element, "AD_ReportView_Col_ID"))
mReportviewCol.setAD_ReportView_Col_ID(getIntValue(element, "AD_ReportView_Col_ID"));
PoFiller filler = new PoFiller(ctx, mReportviewCol, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mReportviewCol.is_new() || mReportviewCol.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView_Col.Table_Name,
X_AD_ReportView_Col.Table_ID);
String action = null;
if (!mReportviewCol.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView_Col.Table_Name,
mReportviewCol);
action = "Update";
} else {
action = "New";
}
if (mReportviewCol.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(),action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_ReportView_Col.Table_Name, atts);
createReportViewColBinding(ctx, document, m_Reportview_Col);
document.endElement("", "", I_AD_ReportView_Col.Table_Name);
}
private void createReportViewColBinding(Properties ctx, TransformerHandler document,
X_AD_ReportView_Col m_Reportview_Col) {
PoExporter filler = new PoExporter(ctx, document, m_Reportview_Col);
List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name);
if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_ReportView_Col_ID", new AttributesImpl());
if (m_Reportview_Col.getAD_Column_ID() > 0) {
int AD_Table_ID = m_Reportview_Col.getAD_Column().getAD_Table_ID();
AttributesImpl tableAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAtts);
filler.addString("AD_Table_ID", value, tableAtts);
}
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID);
}
}

View File

@ -1,182 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
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.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 {
List<String> excludes = defaultExcludeList(X_AD_ReportView.Table_Name);
X_AD_ReportView mReportview = findPO(ctx, element);
if (mReportview == null) {
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_ReportView", name);
mReportview = new X_AD_ReportView(ctx, id, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mReportview, element, this);
if (mReportview.getAD_ReportView_ID() == 0 && isOfficialId(element, "AD_ReportView_ID"))
mReportview.setAD_ReportView_ID(getIntValue(element, "AD_ReportView_ID"));
List<String> notfound = filler.autoFill(excludes);
if (notfound.size() > 0) {
element.defer = true;
return;
}
if (mReportview.is_new() || mReportview.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView.Table_Name,
X_AD_ReportView.Table_ID);
String action = null;
if (!mReportview.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView.Table_Name, mReportview);
action = "Update";
} else {
action = "New";
}
if (mReportview.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mReportview.getName(),
mReportview.get_ID(), action);
element.recordId = mReportview.getAD_ReportView_ID();
} else {
logImportDetail(ctx, impDetail, 0, mReportview.getName(),
mReportview.get_ID(), action);
throw new POSaveFailedException("ReportView");
}
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
PackOut packOut = getPackOutProcess(ctx);
int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID");
if (views.contains(AD_ReportView_ID))
return;
views.add(AD_ReportView_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, AD_ReportView_ID, getTrxName(ctx));
// Export Table if neccessary
ElementHandler tableHandler = packOut.getHandler("T");
try {
tableHandler.packOut(packOut, document, null, m_Reportview.getAD_Table_ID());
} catch (Exception e) {
throw new AdempiereException(e);
}
addTypeName(atts, "table");
document.startElement("", "", I_AD_ReportView.Table_Name, atts);
createReportViewBinding(ctx, document, m_Reportview);
document.endElement("", "", I_AD_ReportView.Table_Name);
String sql = "SELECT AD_PrintFormat_ID FROM AD_PrintFormat WHERE AD_ReportView_ID= "
+ AD_ReportView_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
ElementHandler pftHandler = packOut.getHandler("PFT");
pftHandler.packOut(packOut, document, null, rs.getInt(1));
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
sql = "SELECT AD_ReportView_Col_ID FROM AD_ReportView_Col WHERE AD_Reportview_ID= "
+ AD_ReportView_ID;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createReportViewCol(ctx, document, rs.getInt("AD_ReportView_Col_ID"));
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
}
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 void createReportViewBinding(Properties ctx, TransformerHandler document,
X_AD_ReportView m_Reportview) {
PoExporter filler = new PoExporter(ctx, document, m_Reportview);
List<String> excludes = defaultExcludeList(X_AD_ReportView.Table_Name);
if (m_Reportview.getAD_ReportView_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_ReportView_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID);
}
}

View File

@ -1,336 +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.pipo2.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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Role;
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_Package_Imp_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.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 {
List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name);
MRole mRole = findPO(ctx, element);
if (mRole == null) {
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Role", name);
mRole = new MRole(ctx, id > 0 ? id : 0, getTrxName(ctx));
mRole.setName(name);
}
if (mRole.getAD_Role_ID() == 0 && isOfficialId(element, "AD_Role_ID"))
mRole.setAD_Role_ID(getIntValue(element, "AD_Role_ID"));
PoFiller filler = new PoFiller(ctx, mRole, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mRole.is_new() || mRole.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Role.Table_Name,
X_AD_Role.Table_ID);
String action = null;
if (!mRole.is_new()) {
action = "Update";
} else {
action = "New";
}
if (mRole.save(getTrxName(ctx)) == true) {
element.recordId = mRole.getAD_Role_ID();
logImportDetail(ctx, impDetail, 1, mRole.getName(), mRole.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mRole.getName(), mRole.get_ID(),
action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Role.Table_Name, atts);
createRoleBinding(ctx, document, m_Role);
// Process org access
String sql = "SELECT AD_Org_ID, AD_Role_ID FROM AD_Role_OrgAccess WHERE AD_Role_ID= "
+ Role_id;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createOrgAccess(ctx, document, rs.getInt("AD_Org_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Role_OrgAccess", e);
throw new DatabaseAccessException("Failed to export organization role access.");
} finally {
DB.close(rs, pstmt);
}
// Process user assignment access
sql = "SELECT AD_User_ID, AD_Role_ID, AD_Org_ID FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createUserRole(ctx, document, rs.getInt("AD_User_ID"), rs.getInt("AD_Role_ID"), rs.getInt("AD_Org_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_User_Roles", e);
throw new DatabaseAccessException("Failed to export user role assignment.");
} finally {
DB.close(rs, pstmt);
}
// Process AD_Window_Access Values
sql = "SELECT AD_Window_ID, AD_Role_ID FROM AD_Window_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createWindowAccess(ctx, document, rs.getInt("AD_Window_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Window_Access", e);
throw new DatabaseAccessException("Failed to export window access.");
} finally {
DB.close(rs, pstmt);
}
// Process AD_Process_Access Values
sql = "SELECT AD_Process_ID, AD_Role_ID FROM AD_Process_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createProcessAccess(ctx, document, rs.getInt("AD_Process_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Process_Access", e);
throw new DatabaseAccessException("Failed to export process access.");
} finally {
DB.close(rs, pstmt);
}
// Process AD_Form_Access Values
sql = "SELECT AD_Form_ID, AD_Role_ID FROM AD_Form_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createFormAccess(ctx, document, rs.getInt("AD_Form_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Form_Access", e);
throw new DatabaseAccessException("Failed to export form access.");
} finally {
DB.close(rs, pstmt);
}
// Process AD_Workflow_Access Values
sql = "SELECT AD_Workflow_ID, AD_Role_ID FROM AD_Workflow_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createWorkflowAccess(ctx, document, rs.getInt("AD_Workflow_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Workflow_Access", e);
throw new DatabaseAccessException("Failed to export workflow access.");
} finally {
DB.close(rs, pstmt);
}
// Process AD_Task_Access Values
sql = "SELECT AD_Task_ID, AD_Role_ID FROM AD_Task_Access WHERE AD_Role_ID= " + Role_id;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createTaskAccess(ctx, document, rs.getInt("AD_Task_ID"), rs.getInt("AD_Role_ID"));
}
} catch (Exception e) {
log.log(Level.SEVERE, "AD_Task_Access", e);
throw new DatabaseAccessException("Failed to export task access.");
} finally {
DB.close(rs, pstmt);
}
document.endElement("", "", I_AD_Role.Table_Name);
}
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 void createRoleBinding(Properties ctx, TransformerHandler document,
X_AD_Role m_Role) {
PoExporter filler = new PoExporter(ctx, document, m_Role);
List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name);
if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Role_ID", new AttributesImpl());
if (m_Role.getC_Currency_ID() > 0) {
AttributesImpl currencyAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("C_Currency", "ISO_Code", m_Role.getC_Currency_ID(), currencyAtts);
filler.addString("C_Currency_ID", value, currencyAtts);
} else
filler.addString("C_Currency_ID", "", new AttributesImpl());
excludes.add(X_AD_Role.COLUMNNAME_C_Currency_ID);
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
}
}

View File

@ -1,125 +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.pipo2.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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
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();
log.info(elementValue);
String DBType = getStringValue(element, "DBType");
String sql = getStringValue(element, "statement");
if (sql.endsWith(";"))
sql = sql.substring(0, sql.length() - 1);
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
if(DBType.equals("ALL")) {
int n = pstmt.executeUpdate();
log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+n);
}
else if(DB.isOracle() == true && DBType.equals("Oracle")) {
pstmt.executeUpdate();
log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "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();
int n = stmt.executeUpdate (sql);
log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n);
// Postgres needs to commit DDL statements
if (m_con != null && !m_con.getAutoCommit())
m_con.commit();
stmt.close();
} finally {
m_con.close();
}
}
} catch (Exception e) {
log.log(Level.SEVERE,"SQLSatement", e);
} finally {
DB.close(pstmt);
}
}
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();
addTypeName(atts, "custom");
document.startElement("","","SQLStatement",atts);
createSQLStatmentBinding(document, SQLStatement, DBType);
document.endElement("","","SQLStatement");
}
private void createSQLStatmentBinding( TransformerHandler document, String sqlStatement, String DBType) throws SAXException
{
document.startElement("","","DBType", new AttributesImpl());
char[] contents = DBType.toCharArray();
document.characters(contents,0,contents.length);
document.endElement("","","DBType");
document.startElement("","","statement", new AttributesImpl());
contents = sqlStatement.toCharArray();
document.characters(contents,0,contents.length);
document.endElement("","","statement");
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int field) throws Exception
{
MPackageExpDetail detail = packout.getPackageExpDetail();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement());
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_DBType, detail.getDBType());
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
}
}

View File

@ -1,238 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Tab;
import org.compiere.model.I_AD_Window;
import org.compiere.model.MTab;
import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Tab;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Tab.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, I_AD_Window.Table_Name)) {
element.defer = true;
return;
}
MTab mTab = findPO(ctx, element);
if (mTab == null) {
String name = getStringValue(element, "Name", excludes);
int windowId = 0;
if (getParentId(element, I_AD_Window.Table_Name) > 0) {
windowId = getParentId(element, I_AD_Window.Table_Name);
} else {
Element windowElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Window_ID);
windowId = ReferenceUtils.resolveReference(ctx, windowElement);
}
if (windowId <= 0) {
element.defer = true;
return;
}
Element tableElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Table_ID);
int tableId = ReferenceUtils.resolveReference(ctx, tableElement);
if (tableId <= 0) {
element.defer = true;
return;
}
String sql = "SELECT AD_Tab_ID FROM AD_Tab where AD_Window_ID = ? "
+ " AND Name = ?"
+ " AND AD_Table_ID = ?";
int id = DB.getSQLValue(getTrxName(ctx), sql, windowId, name, tableId);
mTab = new MTab(ctx, id > 0 ? id : 0, getTrxName(ctx));
mTab.setAD_Table_ID(tableId);
mTab.setName(name);
mTab.setAD_Window_ID(windowId);
}
PoFiller filler = new PoFiller(ctx, mTab, element, this);
if (mTab.getAD_Tab_ID() == 0 && isOfficialId(element, "AD_Tab_ID"))
mTab.setAD_Tab_ID(getIntValue(element, "AD_Tab_ID"));
Element columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Column_ID);
int AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_Column_ID(AD_Column_ID);
columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_ColumnSortOrder_ID);
AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_ColumnSortOrder_ID(AD_Column_ID);
columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_ColumnSortYesNo_ID);
AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_ColumnSortYesNo_ID(AD_Column_ID);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mTab.is_new() || mTab.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Tab.Table_Name,
X_AD_Tab.Table_ID);
String action = null;
if (!mTab.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Tab.Table_Name,mTab);
action = "Update";
}
else{
action = "New";
}
if (mTab.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTab.getName(), mTab.get_ID(),action);
element.recordId = mTab.getAD_Tab_ID();
} else {
logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action);
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 = getPackOutProcess(ctx);
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();
addTypeName(atts, "table");
document.startElement("","",I_AD_Tab.Table_Name,atts);
createTabBinding(ctx,document,m_Tab);
//Fields tags.
String sql = "SELECT AD_Field_ID FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID
+ "ORDER BY SEQNO asc";
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);
}
document.endElement("","",I_AD_Tab.Table_Name);
if(m_Tab.getAD_Process_ID() > 0 )
{
try
{
ElementHandler handler = packOut.getHandler("P");
handler.packOut(packOut,document,null,m_Tab.getAD_Process_ID());
}
catch(Exception e)
{
throw new AdempiereException(e);
}
}
}
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 void createTabBinding(Properties ctx, TransformerHandler document, X_AD_Tab m_Tab)
{
PoExporter filler = new PoExporter(ctx, document, m_Tab);
List<String> excludes = defaultExcludeList(X_AD_Tab.Table_Name);
if (m_Tab.getAD_Tab_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Tab_ID", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_Tab.COLUMNNAME_AD_Tab_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_Tab.COLUMNNAME_AD_Tab_ID);
}
}

View File

@ -1,217 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Table;
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_Package_Imp_Detail;
import org.compiere.model.X_AD_Table;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
PackIn packIn = getPackInProcess(ctx);
List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MTable mTable = findPO(ctx, element);
if (mTable == null) {
String tableName = getStringValue(element, "TableName", excludes);
int id = packIn.getTableId(tableName);
if (id <= 0) {
id = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
}
if (id > 0 && isTableProcess(ctx, id)) {
return;
}
mTable = new MTable(ctx, id > 0 ? id : 0, getTrxName(ctx));
mTable.setTableName(tableName);
}
if (mTable.getAD_Table_ID() == 0 && isOfficialId(element, "AD_Table_ID"))
{
mTable.setAD_Table_ID(getIntValue(element, "AD_Table_ID"));
}
PoFiller filler = new PoFiller(ctx, mTable, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mTable.is_new() || mTable.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Table.Table_Name,
X_AD_Table.Table_ID);
String action = null;
if (!mTable.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(),X_AD_Table.Table_Name,mTable);
action = "Update";
}
else{
action = "New";
}
if (mTable.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTable.getName(),mTable.get_ID(),action);
tables.add(mTable.getAD_Table_ID());
packIn.addTable(mTable.getTableName(), mTable.getAD_Table_ID());
element.recordId = mTable.getAD_Table_ID();
}
else{
logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action);
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 = getPackOutProcess(ctx);
boolean exported = isTableProcess(ctx, AD_Table_ID);
AttributesImpl atts = new AttributesImpl();
//Export table if not already done so
if (!exported){
X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null);
addTypeName(atts, "table");
document.startElement("","",I_AD_Table.Table_Name,atts);
createTableBinding(ctx,document,m_Table);
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? "
+ " ORDER BY IsKey DESC, AD_Column_ID"; // Export key column as the first one
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
pstmt.setInt(1, AD_Table_ID);
rs = pstmt.executeQuery();
while (rs.next()){
ElementHandler handler = packOut.getHandler("ELE");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Column.COLUMNNAME_AD_Element_ID));
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID)>0)
{
handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID));
}
if (rs.getInt("AD_Reference_Value_ID")>0)
{
handler = packOut.getHandler("REF");
handler.packOut(packOut,document,null,rs.getInt("AD_Reference_Value_ID"));
}
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID)>0)
{
handler = packOut.getHandler("P");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID));
}
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID)>0)
{
handler = packOut.getHandler("V");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID));
}
createColumn(ctx, document, rs.getInt("AD_Column_ID"));
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
document.endElement("","",I_AD_Table.Table_Name);
}
}
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 void createTableBinding(Properties ctx, TransformerHandler document, X_AD_Table m_Table)
{
PoExporter filler = new PoExporter(ctx, document, m_Table);
if (m_Table.getAD_Table_ID() <= PackOut.MAX_OFFICIAL_ID)
{
filler.add("AD_Table_ID", new AttributesImpl());
}
List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name);
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
}
}

View File

@ -1,109 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Task_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Task;
import org.compiere.model.X_AD_Task_Access;
import org.compiere.util.Env;
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 {
int roleid =0;
int taskid =0;
List<String> excludes = defaultExcludeList(X_AD_Task_Access.Table_Name);
X_AD_Task_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element taskElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Task_ID);
taskid = ReferenceUtils.resolveReference(ctx, taskElement);
Query query = new Query(ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, taskid}).first();
if (po == null){
po = new X_AD_Task_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Task_ID(taskid);
}
excludes.add(I_AD_Task_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Task_Access.COLUMNNAME_AD_Task_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Task_Access.Table_Name, atts);
createTaskAccessBinding(ctx, document, AD_Task_ID, AD_Role_ID);
document.endElement("", "", I_AD_Task_Access.Table_Name);
}
private void createTaskAccessBinding(Properties ctx, TransformerHandler document,
int taskid, int roleid) {
Query query = new Query(ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx));
X_AD_Task_Access po = query.setParameters(new Object[]{roleid, taskid}).first();
if (po != null) {
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Task_Access.Table_Name);
filler.export(excludes);
}
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

View File

@ -1,126 +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.pipo2.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Task;
import org.compiere.model.MTask;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Task;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_Task.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MTask mTask = findPO(ctx, element);
if (mTask == null) {
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Task", name);
mTask = new MTask(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
if (mTask.getAD_Task_ID() == 0 && isOfficialId(element, "AD_Task_ID"))
mTask.setAD_Task_ID(getIntValue(element, "AD_Task_ID"));
PoFiller filler = new PoFiller(ctx, mTask, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mTask.is_new() || mTask.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Task.Table_Name,
X_AD_Task.Table_ID);
String action = null;
if (!mTask.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Task.Table_Name, mTask);
action = "Update";
} else {
action = "New";
}
if (mTask.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mTask.getName(), mTask.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mTask.getName(), mTask.get_ID(),
action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Task.Table_Name, atts);
createTaskBinding(ctx, document, m_Task);
document.endElement("", "", I_AD_Task.Table_Name);
}
private void createTaskBinding(Properties ctx, TransformerHandler document,
X_AD_Task m_Task) {
PoExporter filler = new PoExporter(ctx, document, m_Task);
List<String> excludes = defaultExcludeList(X_AD_Task.Table_Name);
if (m_Task.getAD_Task_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Task_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Task.COLUMNNAME_AD_Task_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Task.COLUMNNAME_AD_Task_ID);
}
}

View File

@ -1,116 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_User_Roles;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_User;
import org.compiere.model.X_AD_User_Roles;
import org.compiere.util.Env;
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 {
int roleid =0;
int userid =0;
int orgid =0;
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
X_AD_User_Roles po = findPO(ctx, element);
if (po == null) {
Element userElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
userid = ReferenceUtils.resolveReference(ctx, userElement);
if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role");
} else {
Element roleElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element orgElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
orgid = ReferenceUtils.resolveReference(ctx, orgElement);
Query query = new Query(ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{userid, roleid, orgid}).first();
if (po == null) {
po = new X_AD_User_Roles(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgid);
po.setAD_Role_ID(roleid);
po.setAD_User_ID(userid);
}
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_User_Roles.Table_Name, atts);
createUserAssignBinding(ctx, document, AD_User_ID,AD_Role_ID, AD_Org_ID);
document.endElement("", "", I_AD_User_Roles.Table_Name);
}
private void createUserAssignBinding(Properties ctx, TransformerHandler document,
int user_id, int role_id, int org_id) {
Query query = new Query(ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx));
X_AD_User_Roles po = query.setParameters(new Object[]{user_id, role_id, org_id}).first();
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

View File

@ -1,115 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Window_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Window;
import org.compiere.model.X_AD_Window_Access;
import org.compiere.util.Env;
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 {
int roleid =0;
int windowid =0;
List<String> excludes = defaultExcludeList(X_AD_Window_Access.Table_Name);
X_AD_Window_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
if (roleid <= 0) {
element.defer = true;
return;
}
Element windowElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Window_ID);
windowid = ReferenceUtils.resolveReference(ctx, windowElement);
if (windowid <= 0) {
element.defer = true;
return;
}
Query query = new Query(ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, windowid}).first();
if (po == null) {
po = new X_AD_Window_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Window_ID(windowid);
}
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Window_Access.Table_Name, atts);
createWindowAccessBinding(ctx, document, AD_Window_ID, AD_Role_ID);
document.endElement("", "", I_AD_Window_Access.Table_Name);
}
private void createWindowAccessBinding(Properties ctx, TransformerHandler document,
int window_id, int role_id) {
Query query = new Query(ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx));
X_AD_Window_Access po = query.setParameters(new Object[]{role_id, window_id}).first();
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Window_Access.Table_Name);
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

View File

@ -1,219 +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.pipo2.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.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Window;
import org.compiere.model.MWindow;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
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.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 {
List<String> excludes = defaultExcludeList(X_AD_Window.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MWindow mWindow = findPO(ctx, element);
if (mWindow == null) {
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
return;
}
mWindow = new MWindow(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWindow.setName(name);
} else {
if (windows.contains(mWindow.getAD_Window_ID())) {
return;
}
}
if (mWindow.getAD_Window_ID() == 0 && isOfficialId(element, "AD_Window_ID"))
mWindow.setAD_Window_ID(getIntValue(element, "AD_Window_ID"));
PoFiller filler = new PoFiller(ctx, mWindow, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWindow.is_new() || mWindow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Window.Table_Name,
X_AD_Window.Table_ID);
String action = null;
if (!mWindow.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Window.Table_Name, mWindow);
action = "Update";
} else {
action = "New";
}
if (mWindow.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mWindow.getName(), mWindow
.get_ID(), action);
element.recordId = mWindow.getAD_Window_ID();
windows.add(mWindow.getAD_Window_ID());
} else {
logImportDetail(ctx, impDetail, 0, mWindow.getName(), mWindow
.get_ID(), action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Window.Table_Name, atts);
createWindowBinding(ctx, document, m_Window);
// Tab Tag
String sql = "SELECT AD_Tab_ID, AD_Table_ID FROM AD_TAB WHERE AD_WINDOW_ID = "
+ AD_Window_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
ElementHandler handler = packOut.getHandler("T");
handler.packOut(packOut,document,null,rs.getInt("AD_Table_ID"));
createTab(ctx, document, rs.getInt("AD_Tab_ID"));
}
} 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 {
DB.close(rs, pstmt);
}
//TODO: export of ad_image and ad_color use
// Loop tags.
document.endElement("", "", I_AD_Window.Table_Name);
// Preference Tag
sql = "SELECT AD_Preference_ID FROM AD_PREFERENCE WHERE AD_WINDOW_ID = ?";
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Window_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
createPreference(ctx, document, rs.getInt("AD_Preference_ID"));
}
} 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 {
DB.close(rs, pstmt);
}
}
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 void createWindowBinding(Properties ctx, TransformerHandler document,
X_AD_Window m_Window) {
PoExporter filler = new PoExporter(ctx, document, m_Window);
List<String> excludes = defaultExcludeList(X_AD_Window.Table_Name);
if (m_Window.getAD_Window_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Window_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID);
}
}

View File

@ -1,111 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Workflow_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Workflow;
import org.compiere.model.X_AD_Workflow_Access;
import org.compiere.util.Env;
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 {
int roleid =0;
int workflowid =0;
List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name);
X_AD_Workflow_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element wfElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
workflowid = ReferenceUtils.resolveReference(ctx, wfElement);
Query query = new Query(ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, workflowid}).first();
if (po == null) {
po = new X_AD_Workflow_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Workflow_ID(workflowid);
}
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
po.saveEx();
}
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts);
createWorkflowAccessBinding(ctx, document, AD_Workflow_ID, AD_Role_ID);
document.endElement("", "", I_AD_Workflow_Access.Table_Name);
}
private void createWorkflowAccessBinding(Properties ctx, TransformerHandler document,
int workflow_id, int role_id) {
X_AD_Workflow_Access po = null;
Query query = new Query(ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{role_id, workflow_id}).first();
PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name);
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
create(packout.getCtx(), packoutHandler);
}
}

View File

@ -1,251 +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.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_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.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 {
List<String> excludes = defaultExcludeList(X_AD_Workflow.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
MWorkflow mWorkflow = findPO(ctx, element);
if (mWorkflow == null) {
String workflowValue = getStringValue(element, "Value", excludes);
int id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
mWorkflow = new MWorkflow(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWorkflow.setValue(workflowValue);
}
PoFiller filler = new PoFiller(ctx, mWorkflow, element, this);
if (mWorkflow.getAD_Workflow_ID() == 0 && isOfficialId(element, "AD_Workflow_ID"))
filler.setInteger("AD_Workflow_ID");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWorkflow.is_new() || mWorkflow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Workflow.Table_Name,
X_AD_Workflow.Table_ID);
String action = null;
if (!mWorkflow.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Workflow.Table_Name, mWorkflow);
action = "Update";
} else {
action = "New";
}
if (mWorkflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success");
logImportDetail(ctx,impDetail, 1, mWorkflow.getName(), mWorkflow
.get_ID(), action);
workflows.add(mWorkflow.getAD_Workflow_ID());
element.recordId = mWorkflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
logImportDetail(ctx, impDetail, 0, mWorkflow.getName(), mWorkflow
.get_ID(), action);
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) {
//set start node
String value = getStringValue(element, "AD_WF_Node.Value");
if (value != null && value.trim().length() > 0) {
MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx));
int id = findIdByColumnAndParentId(ctx, "AD_WF_Node", "Value", value, "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=" + value);
return;
}
m_Workflow.setAD_WF_Node_ID(id);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Workflow.Table_Name,
X_AD_Workflow.Table_ID);
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow update success");
logImportDetail(ctx, impDetail, 1, m_Workflow.getName(), m_Workflow
.get_ID(), "Update");
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow update fail");
logImportDetail(ctx, impDetail, 0, m_Workflow.getName(), m_Workflow
.get_ID(), "Update");
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);
int ad_wf_nodenext_id = 0;
int ad_wf_nodenextcondition_id = 0;
AttributesImpl atts = new AttributesImpl();
X_AD_Workflow m_Workflow = new X_AD_Workflow(ctx,
AD_Workflow_ID, null);
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow");
document.startElement("", "", I_AD_Workflow.Table_Name, atts);
createWorkflowBinding(ctx, document, m_Workflow);
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = "
+ AD_Workflow_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
// Generated workflowNodeNext(s) and
// workflowNodeNextCondition(s)
rs = pstmt.executeQuery();
while (rs.next()) {
int nodeId = rs.getInt("AD_WF_Node_ID");
createNode(ctx, document, nodeId);
ad_wf_nodenext_id = 0;
sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id = ?";
ad_wf_nodenext_id = DB.getSQLValue(null, sql, nodeId);
if (ad_wf_nodenext_id > 0) {
createNodeNext(ctx, document, ad_wf_nodenext_id);
ad_wf_nodenextcondition_id = 0;
sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id = ?";
ad_wf_nodenextcondition_id = DB.getSQLValue(null, sql, nodeId);
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);
}
}
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
document.endElement("", "", I_AD_Workflow.Table_Name);
}
}
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 void createWorkflowBinding(Properties ctx, TransformerHandler document, X_AD_Workflow m_Workflow) {
PoExporter filler = new PoExporter(ctx, document, m_Workflow);
List<String> excludes = defaultExcludeList(X_AD_Workflow.Table_Name);
if (m_Workflow.getAD_Workflow_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Workflow_ID", new AttributesImpl());
filler.export(excludes);
}
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID, recordId);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID);
}
}

View File

@ -1,157 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_Node;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB;
import org.compiere.util.Env;
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 {
List<String> excludes = defaultExcludeList(X_AD_WF_Node.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
if (isParentDefer(element, I_AD_Workflow.Table_Name)) {
element.unresolved = "Parent element mark as defer: " + getStringValue(element, "AD_Workflow.Value");
element.defer = true;
return;
}
X_AD_WF_Node mWFNode = findPO(ctx, element);
if (mWFNode == null) {
int workflowId = 0;
Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
String workflowNodeValue = getStringValue(element, "Value", excludes);
StringBuffer sqlB = new StringBuffer(
"SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? and Value =?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeValue);
mWFNode = new X_AD_WF_Node(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNode.setValue(workflowNodeValue);
mWFNode.setAD_Workflow_ID(workflowId);
excludes.add(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
excludes.add("Value");
}
PoFiller filler = new PoFiller(ctx, mWFNode, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWFNode.is_new() || mWFNode.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_Node.Table_Name,
X_AD_WF_Node.Table_ID);
String action = null;
if (mWFNode.getAD_WF_Node_ID() == 0 && isOfficialId(element, "AD_WF_Node_ID"))
mWFNode.setAD_WF_Node_ID(getIntValue(element, "AD_WF_Node_ID"));
if (!mWFNode.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_Node.Table_Name, mWFNode);
action = "Update";
} else {
action = "New";
}
if (mWFNode.save(getTrxName(ctx)) == true) {
log.info("m_WFNode save success");
logImportDetail(ctx, impDetail, 1, mWFNode.getName(), mWFNode
.get_ID(), action);
} else {
log.info("m_WFNode save failure");
logImportDetail(ctx, impDetail, 0, mWFNode.getName(), mWFNode
.get_ID(), action);
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));
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_Node.Table_Name, atts);
createWorkflowNodeBinding(ctx, document, m_WF_Node);
document.endElement("", "", I_AD_WF_Node.Table_Name);
}
private void createWorkflowNodeBinding(Properties ctx, TransformerHandler document,
X_AD_WF_Node m_WF_Node) {
PoExporter filler = new PoExporter(ctx, document, m_WF_Node);
List<String> excludes = defaultExcludeList(X_AD_WF_Node.Table_Name);
if (m_WF_Node.getAD_WF_Node_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_Node_ID", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID);
}
}

View File

@ -1,217 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_NextCondition;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
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.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowNodeNextConditionElementHandler extends
AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
MWFNextCondition mWFNodeNextCondition = findPO(ctx, element);
if (mWFNodeNextCondition == null) {
int workflowId = 0;
Element wfElement = element.properties.get("AD_Workflow_ID");
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
int AD_WF_NodeNext_ID = 0;
Element nodeNextElement = element.properties.get(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NodeNext_ID);
if (ReferenceUtils.isIDLookup(nodeNextElement) || ReferenceUtils.isUUIDLookup(nodeNextElement)) {
AD_WF_NodeNext_ID = ReferenceUtils.resolveReference(ctx, nodeNextElement);
} else {
Element wfnElement = element.properties.get("AD_WF_Node_ID");
int wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement);
if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + wfnElement.contents;
element.defer = true;
return;
}
Element nextElement = element.properties.get("AD_WF_Next_ID");
int wfNodeNextId = ReferenceUtils.resolveReference(ctx, nextElement);
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + nextElement.contents;
element.defer = true;
return;
}
String sql = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID =? and AD_WF_Next_ID =?";
AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), sql, wfNodeId, wfNodeNextId);
}
String sql = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID =?";
int id = DB.getSQLValue(getTrxName(ctx), sql, AD_WF_NodeNext_ID);
mWFNodeNextCondition = new MWFNextCondition(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID);
}
PoFiller filler = new PoFiller(ctx, mWFNodeNextCondition, element, this);
if (mWFNodeNextCondition.get_ID() == 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
filler.setInteger("AD_WF_NextCondition_ID");
Element tableElement = element.properties.get("AD_Table_ID");
Element columnElement = element.properties.get("AD_Column_ID");
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement);
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(), "AD_Table", AD_Table_ID);
}
mWFNodeNextCondition.setAD_Column_ID(columnId);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWFNodeNextCondition.is_new() || mWFNodeNextCondition.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NextCondition.Table_Name,
X_AD_WF_NextCondition.Table_ID);
String action = null;
if (!mWFNodeNextCondition.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NextCondition.Table_Name,
mWFNodeNextCondition);
action = "Update";
} else {
action = "New";
}
if (mWFNodeNextCondition.save(getTrxName(ctx)) == true) {
log.info("m_WFNodeNextCondition save success");
logImportDetail(
ctx,
impDetail,
1,
String.valueOf(mWFNodeNextCondition.get_ID()),
mWFNodeNextCondition.get_ID(),
action);
} else {
log.info("m_WFNodeNextCondition save failure");
logImportDetail(
ctx,
impDetail,
0,
String.valueOf(mWFNodeNextCondition.get_ID()),
mWFNodeNextCondition.get_ID(),
action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_NextCondition.Table_Name, atts);
createWorkflowNodeNextConditionBinding(ctx, document, m_WF_NodeNextCondition);
document.endElement("", "", I_AD_WF_NextCondition.Table_Name);
}
private void createWorkflowNodeNextConditionBinding(Properties ctx, TransformerHandler document, X_AD_WF_NextCondition mWFNodeNextCondition) {
PoExporter filler = new PoExporter(ctx, document, mWFNodeNextCondition);
List<String> excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name);
if (mWFNodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_NextCondition_ID", new AttributesImpl());
int AD_workflow_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node().getAD_Workflow_ID();
AttributesImpl wfAttributes = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Workflow", "Value", AD_workflow_ID, wfAttributes);
filler.addString("AD_Workflow_ID", value, wfAttributes);
int AD_WF_Node_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node_ID();
AttributesImpl wfnAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Node_ID, wfnAttributes);
filler.addString("AD_WF_Node_ID", value, wfnAttributes);
int AD_WF_Next_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Next_ID();
AttributesImpl nextAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Next_ID, nextAttributes);
filler.addString("AD_WF_Next_ID", value, nextAttributes);
if (mWFNodeNextCondition.getAD_Column_ID() > 0) {
int AD_Table_ID = mWFNodeNextCondition.getAD_Column().getAD_Table_ID();
AttributesImpl tableAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAttributes);
filler.addString("AD_Table_ID", value, tableAttributes);
}
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID);
}
}

View File

@ -1,175 +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.pipo2.handler;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_Node;
import org.compiere.model.I_AD_WF_NodeNext;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
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.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_WF_NodeNext.Table_Name);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
MWFNodeNext mWFNodeNext = findPO(ctx, element);
if (mWFNodeNext == null) {
int workflowId = 0;
Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
int wfNodeId = 0;
Element wfnElement = element.properties.get(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_Node_ID);
if (ReferenceUtils.isIDLookup(wfnElement) || ReferenceUtils.isUUIDLookup(wfnElement)) {
wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement);
} else {
wfNodeId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?",
workflowId, wfnElement.contents.toString(), Env.getAD_Client_ID(ctx));
}
if (wfNodeId <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + wfnElement.contents;
return;
}
int AD_WF_Next_ID = 0;
Element nextElement = element.properties.get(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_Next_ID);
if (ReferenceUtils.isIDLookup(nextElement) || ReferenceUtils.isUUIDLookup(nextElement)) {
AD_WF_Next_ID = ReferenceUtils.resolveReference(ctx, nextElement);
} else {
AD_WF_Next_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?",
workflowId, nextElement.contents.toString(), Env.getAD_Client_ID(ctx));
}
if (AD_WF_Next_ID <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + nextElement.contents;
return;
}
int AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID=? and AD_WF_NEXT_ID =?", wfNodeId, AD_WF_Next_ID);
mWFNodeNext = new MWFNodeNext(ctx, AD_WF_NodeNext_ID, getTrxName(ctx));
mWFNodeNext.setAD_WF_Node_ID(wfNodeId);
mWFNodeNext.setAD_WF_Next_ID(AD_WF_Next_ID);
}
PoFiller filler = new PoFiller(ctx, mWFNodeNext, element, this);
if (mWFNodeNext.getAD_WF_NodeNext_ID() == 0 && isOfficialId(element, "AD_WF_NodeNext_ID"))
mWFNodeNext.setAD_WF_NodeNext_ID(getIntValue(element, "AD_WF_NodeNext_ID"));
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWFNodeNext.is_new() || mWFNodeNext.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NodeNext.Table_Name,
X_AD_WF_NodeNext.Table_ID);
String action = null;
if (!mWFNodeNext.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NodeNext.Table_Name,mWFNodeNext);
action = "Update";
} else{
action = "New";
}
if (mWFNodeNext.save(getTrxName(ctx)) == true){
log.info("m_WFNodeNext save success");
logImportDetail (ctx, impDetail, 1, String.valueOf(mWFNodeNext.get_ID()),mWFNodeNext.get_ID(), action);
} else{
log.info("m_WFNodeNext save failure");
logImportDetail (ctx, impDetail, 0, String.valueOf(mWFNodeNext.get_ID()), mWFNodeNext.get_ID(), action);
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();
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_NodeNext.Table_Name, atts);
createWorkflowNodeNextBinding(ctx, document, m_WF_NodeNext);
document.endElement("", "", I_AD_WF_NodeNext.Table_Name);
}
private void createWorkflowNodeNextBinding(Properties ctx, TransformerHandler document,
X_AD_WF_NodeNext m_WF_NodeNext)
{
PoExporter filler = new PoExporter(ctx, document, m_WF_NodeNext);
List<String> excludes = defaultExcludeList(X_AD_WF_NodeNext.Table_Name);
if (m_WF_NodeNext.getAD_WF_NodeNext_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_NodeNext_ID", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId) throws Exception {
Env.setContext(packout.getCtx(), I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, recordId);
create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID);
}
}

View File

@ -1,40 +0,0 @@
AD_Menu=org.adempiere.pipo2.handler.MenuElementHandler
AD_Window=org.adempiere.pipo2.handler.WindowElementHandler
AD_Window_Access=org.adempiere.pipo2.handler.WindowAccessElementHandler
AD_Preference=org.adempiere.pipo2.handler.PreferenceElementHandler
AD_Tab=org.adempiere.pipo2.handler.TabElementHandler
AD_Field=org.adempiere.pipo2.handler.FieldElementHandler
AD_Process=org.adempiere.pipo2.handler.ProcessElementHandler
AD_Process_Para=org.adempiere.pipo2.handler.ProcessParaElementHandler
AD_Process_Access=org.adempiere.pipo2.handler.ProcessAccessElementHandler
AD_Messsage=org.adempiere.pipo2.handler.MessageElementHandler
AD_Val_Rule=org.adempiere.pipo2.handler.DynValRuleElementHandler
AD_Workflow=org.adempiere.pipo2.handler.WorkflowElementHandler
AD_WF_Node=org.adempiere.pipo2.handler.WorkflowNodeElementHandler
AD_WF_NodeNext=org.adempiere.pipo2.handler.WorkflowNodeNextElementHandler
AD_WF_NextCondition=org.adempiere.pipo2.handler.WorkflowNodeNextConditionElementHandler
AD_Workflow_Access=org.adempiere.pipo2.handler.WorkflowAccessElementHandler
AD_Table=org.adempiere.pipo2.handler.TableElementHandler
AD_Column=org.adempiere.pipo2.handler.ColumnElementHandler
AD_Role=org.adempiere.pipo2.handler.RoleElementHandler
AD_User_Roles=org.adempiere.pipo2.handler.UserRoleElementHandler
AD_Role_OrgAccess=org.adempiere.pipo2.handler.OrgRoleElementHandler
AD_Form=org.adempiere.pipo2.handler.FormElementHandler
AD_Form_Access=org.adempiere.pipo2.handler.FormAccessElementHandler
AD_Task=org.adempiere.pipo2.handler.TaskElementHandler
AD_Task_Access=org.adempiere.pipo2.handler.TaskAccessElementHandler
AD_ImpFormat=org.adempiere.pipo2.handler.ImpFormatElementHandler
AD_ImpFormat_Row=org.adempiere.pipo2.handler.ImpFormatRowElementHandler
Code_Snippet=org.adempiere.pipo2.handler.CodeSnipitElementHandler
Dist_File=org.adempiere.pipo2.handler.DistFileElementHandler
AD_ReportView=org.adempiere.pipo2.handler.ReportViewElementHandler
AD_ReportView_Col=org.adempiere.pipo2.handler.ReportViewColElementHandler
AD_PrintFormat=org.adempiere.pipo2.handler.PrintFormatElementHandler
AD_PrintFormatItem=org.adempiere.pipo2.handler.PrintFormatItemElementHandler
AD_PrintPaper=org.adempiere.pipo2.handler.PrintPaperElementHandler
SQLStatement=org.adempiere.pipo2.handler.SQLStatementElementHandler
AD_Reference=org.adempiere.pipo2.handler.ReferenceElementHandler
AD_Ref_List=org.adempiere.pipo2.handler.ReferenceListElementHandler
AD_Ref_Table=org.adempiere.pipo2.handler.ReferenceTableElementHandler
AD_FieldGroup=org.adempiere.pipo2.handler.FieldGroupElementHandler
AD_Element=org.adempiere.pipo2.handler.AdElementHandler