2pack refactoring - decouple from SvrProcess and DB Model. Enhance the grid tab export framework to support export of 2pack archive.

This commit is contained in:
Heng Sin Low 2010-12-14 07:59:58 +08:00
parent 8199b9f9b4
commit 490784dbbc
30 changed files with 1212 additions and 539 deletions

View File

@ -16,3 +16,4 @@ bin.includes = META-INF/,\
OSGI-INF/eventmanager.xml OSGI-INF/eventmanager.xml
output.base.jar = build/ output.base.jar = build/
source.base.jar = src/ source.base.jar = src/
src.includes = schema/

View File

@ -14,6 +14,7 @@
package org.adempiere.base; package org.adempiere.base;
import java.io.File; import java.io.File;
import java.util.List;
import org.compiere.model.GridTab; import org.compiere.model.GridTab;
@ -27,9 +28,11 @@ public interface IGridTabExporter {
/** /**
* export gridTab data to file * export gridTab data to file
* @param gridTab * @param gridTab
* @param childs
* @param isCurrentRowOnly
* @param file * @param file
*/ */
public void export(GridTab gridTab, File file); public void export(GridTab gridTab, List<GridTab> childs, boolean isCurrentRowOnly, File file);
/** /**
* @return file extension * @return file extension

View File

@ -74,6 +74,11 @@ public abstract class AbstractExcelExporter
*/ */
protected abstract void setCurrentRow(int row); protected abstract void setCurrentRow(int row);
/**
* @return current row index
*/
protected abstract int getCurrentRow();
/** /**
* Check if column is printed (displayed) * Check if column is printed (displayed)
* @param col column index * @param col column index
@ -124,6 +129,7 @@ public abstract class AbstractExcelExporter
// //
private int m_colSplit = 1; private int m_colSplit = 1;
private int m_rowSplit = 1; private int m_rowSplit = 1;
private boolean currentRowOnly = false;
/** Styles cache */ /** Styles cache */
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>(); private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
@ -349,6 +355,16 @@ public abstract class AbstractExcelExporter
ps.setLandscape(false); ps.setLandscape(false);
} }
protected boolean isCurrentRowOnly()
{
return currentRowOnly;
}
protected void setCurrentRowOnly(boolean b)
{
currentRowOnly = b;
}
/** /**
* Export to given stream * Export to given stream
* @param out * @param out
@ -361,9 +377,12 @@ public abstract class AbstractExcelExporter
String sheetName = null; String sheetName = null;
// //
short colnumMax = 0; short colnumMax = 0;
for (int rownum = 0, xls_rownum = 1; rownum < getRowCount(); rownum++, xls_rownum++) int rownum = isCurrentRowOnly() ? getCurrentRow() : 0;
int lastRowNum = isCurrentRowOnly() ? getRowCount() : getCurrentRow()+1;
for (int xls_rownum = 1; rownum < lastRowNum; rownum++, xls_rownum++)
{ {
setCurrentRow(rownum); if (!isCurrentRowOnly())
setCurrentRow(rownum);
boolean isPageBreak = false; boolean isPageBreak = false;
HSSFRow row = sheet.createRow(xls_rownum); HSSFRow row = sheet.createRow(xls_rownum);

View File

@ -113,4 +113,8 @@ public class ArrayExcelExporter extends AbstractExcelExporter {
@Override @Override
protected void setCurrentRow(int row) { protected void setCurrentRow(int row) {
} }
protected int getCurrentRow() {
return 0;
}
} }

View File

@ -15,6 +15,7 @@ package org.adempiere.impexp;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import org.adempiere.base.IGridTabExporter; import org.adempiere.base.IGridTabExporter;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
@ -122,6 +123,11 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid
; // nothing ; // nothing
} }
protected int getCurrentRow()
{
return m_tab.getCurrentRow();
}
private HashMap<String, MLookup> m_buttonLookups = new HashMap<String, MLookup>(); private HashMap<String, MLookup> m_buttonLookups = new HashMap<String, MLookup>();
private MLookup getButtonLookup(GridField mField) private MLookup getButtonLookup(GridField mField)
@ -147,8 +153,9 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid
} }
@Override @Override
public void export(GridTab gridTab, File file) { public void export(GridTab gridTab, List<GridTab> childs, boolean currentRowOnly, File file) {
m_tab = gridTab; m_tab = gridTab;
setCurrentRowOnly(currentRowOnly);
try { try {
export(file, null); export(file, null);
} catch (Exception e) { } catch (Exception e) {

View File

@ -133,6 +133,10 @@ extends AbstractExcelExporter
m_printData.setRowIndex(row); m_printData.setRowIndex(row);
} }
protected int getCurrentRow() {
return m_printData.getRowIndex();
}
@Override @Override
public boolean isFunctionRow() { public boolean isFunctionRow() {
return m_printData.isFunctionRow(); return m_printData.isFunctionRow();

View File

@ -74,4 +74,8 @@ extends AbstractExcelExporter
protected void setCurrentRow(int row) { protected void setCurrentRow(int row) {
m_currentRow = row; m_currentRow = row;
} }
protected int getCurrentRow() {
return m_currentRow;
}
} }

View File

@ -34,8 +34,6 @@ import javax.xml.transform.sax.TransformerHandler;
import org.compiere.Adempiere; 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_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -44,8 +42,10 @@ import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.CodeSnippetElementParameters;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PackoutItem;
public class CodeSnippetElementHandler extends AbstractElementHandler { public class CodeSnippetElementHandler extends AbstractElementHandler {
@ -196,11 +196,11 @@ public class CodeSnippetElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document) public void create(Properties ctx, TransformerHandler document)
throws SAXException { throws SAXException {
String FileDir = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory); String FileDir = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_DIRECTORY);
String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName); String FileName = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_FILE_NAME);
String OldCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old); String OldCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_Old);
String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New); String NewCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_New);
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); String ReleaseNo = Env.getContext(ctx, CodeSnippetElementParameters.RELEASE_NO);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "custom"); addTypeName(atts, "custom");
createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo); createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo);
@ -231,17 +231,17 @@ public class CodeSnippetElementHandler extends AbstractElementHandler {
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{ {
MPackageExpDetail detail = packout.getPackageExpDetail(); PackoutItem detail = packout.getCurrentPackoutItem();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory, detail.getDestination_Directory()); Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_DIRECTORY, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_DIRECTORY));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, detail.getDestination_FileName()); Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_FILE_NAME, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_FILE_NAME));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old, detail.getAD_Package_Code_Old()); Env.setContext(packout.getCtx(), CodeSnippetElementParameters.AD_Package_Code_Old, (String)detail.getProperty(CodeSnippetElementParameters.AD_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(), CodeSnippetElementParameters.AD_Package_Code_New, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_New));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo,detail.getReleaseNo()); Env.setContext(packout.getCtx(), CodeSnippetElementParameters.RELEASE_NO, (String)detail.getProperty(CodeSnippetElementParameters.RELEASE_NO));
this.create(packout.getCtx(), packoutHandler); this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory); packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_DIRECTORY);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_FILE_NAME);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old); packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_Old);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New); packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_New);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); packout.getCtx().remove(CodeSnippetElementParameters.RELEASE_NO);
} }
} }

View File

@ -29,9 +29,9 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PackoutItem;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.model.MPackageExp; 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_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Backup; import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -195,11 +195,11 @@ public class DistFileElementHandler extends AbstractElementHandler {
document.endElement("","","Dist_File"); document.endElement("","","Dist_File");
} }
public void doPackout(PackOut packout, MPackageExp header, MPackageExpDetail detail,TransformerHandler packOutDocument,TransformerHandler packageDocument,AttributesImpl atts,int recordId) throws Exception public void doPackout(PackOut packout, MPackageExp header, PackoutItem 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_FileName, (String)detail.getProperty("FileName"));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, detail.getReleaseNo()); Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, (String)detail.getProperty("ReleaseNo"));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, detail.getTarget_Directory()); Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, (String)detail.getProperty("TargetDirectory"));
Env.setContext(packout.getCtx(), "Source_Directory", fileDest); Env.setContext(packout.getCtx(), "Source_Directory", fileDest);
this.create(packout.getCtx(), packOutDocument); this.create(packout.getCtx(), packOutDocument);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);

View File

@ -9,9 +9,10 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.ElementHandler; import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.FileElementParameters;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.compiere.model.MPackageExp; import org.adempiere.pipo2.PackoutDocument;
import org.compiere.model.MPackageExpDetail; import org.adempiere.pipo2.PackoutItem;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -22,12 +23,12 @@ public class FileElementHandler implements ElementHandler {
public void packOut(PackOut packout, TransformerHandler packoutHandler, public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler, int recordId) throws Exception { TransformerHandler docHandler, int recordId) throws Exception {
MPackageExp header = packout.getPackageExp(); PackoutDocument header = packout.getPackoutDocument();
MPackageExpDetail detail = packout.getPackageExpDetail(); PackoutItem detail = packout.getCurrentPackoutItem();
log.log(Level.INFO, log.log(Level.INFO,
"In PackOut.java handling Code or Other 2pack module creation"); "In PackOut.java handling Code or Other 2pack module creation");
String fileDirectory = header.getFile_Directory() + header.getName() String fileDirectory = packout.getPackoutDirectory() + header.getPackageName()
+ detail.getTarget_Directory(); + detail.getProperty(FileElementParameters.TARGET_DIRECTORY);
log.log(Level.INFO, "targetDirectory" + fileDirectory); log.log(Level.INFO, "targetDirectory" + fileDirectory);
String targetDirectory = null; String targetDirectory = null;
char fileseperator1 = '/'; char fileseperator1 = '/';
@ -41,7 +42,7 @@ public class FileElementHandler implements ElementHandler {
fileseperator2); fileseperator2);
String sourceDirectory = null; String sourceDirectory = null;
fileDirectory = detail.getFile_Directory(); fileDirectory = (String) detail.getProperty(FileElementParameters.SOURCE_DIRECTORY);
// Correct package for proper file seperator // Correct package for proper file seperator
if (File.separator.equals("/")) { if (File.separator.equals("/")) {
sourceDirectory = fileDirectory.replace(fileseperator2, sourceDirectory = fileDirectory.replace(fileseperator2,
@ -50,14 +51,14 @@ public class FileElementHandler implements ElementHandler {
sourceDirectory = fileDirectory.replace(fileseperator2, sourceDirectory = fileDirectory.replace(fileseperator2,
fileseperator1); fileseperator1);
packout.copyFile(sourceDirectory + detail.getFileName(), packout.copyFile(sourceDirectory + detail.getProperty(FileElementParameters.FILE_NAME),
targetDirectory + detail.getFileName()); targetDirectory + detail.getProperty(FileElementParameters.FILE_NAME));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
if (detail.getDestination_Directory() != null) { if (detail.getProperty(FileElementParameters.DESTINATION_DIRECTORY) != null) {
fileDirectory = detail.getDestination_Directory(); fileDirectory = (String) detail.getProperty(FileElementParameters.DESTINATION_DIRECTORY);
String destinationDirectory = null; String destinationDirectory = null;
// Correct package for proper file seperator // Correct package for proper file seperator
@ -76,14 +77,14 @@ public class FileElementHandler implements ElementHandler {
} }
} }
if (detail.getFileName() != null) { if (detail.getProperty(FileElementParameters.FILE_NAME) != null) {
PackOut.addTextElement(docHandler, "file", PackOut.addTextElement(docHandler, "file",
"File: " + detail.getFileName(), atts); "File: " + detail.getProperty(FileElementParameters.FILE_NAME), atts);
} }
PackOut.addTextElement(docHandler, "filedirectory", "Directory: " PackOut.addTextElement(docHandler, "filedirectory", "Directory: "
+ detail.getTarget_Directory(), atts); + detail.getProperty(FileElementParameters.TARGET_DIRECTORY), atts);
PackOut.addTextElement(docHandler, "filenotes", PackOut.addTextElement(docHandler, "filenotes",
"Notes: " + detail.getDescription(), atts); "Notes: " + detail.getProperty(FileElementParameters.DESCRIPTION), atts);
} }
@Override @Override

View File

@ -28,18 +28,18 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.model.GenericPO; import org.adempiere.model.GenericPO;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.DataElementParameters;
import org.adempiere.pipo2.PackoutItem;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -135,7 +135,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
throws SAXException { throws SAXException {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); String sql = Env.getContext(ctx, DataElementParameters.SQL_STATEMENT);
String components[] = null; String components[] = null;
if (sql.indexOf(";") > 0) { if (sql.indexOf(";") > 0) {
components = sql.split("[;]"); components = sql.split("[;]");
@ -143,7 +143,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
} else { } else {
components = new String[]{sql}; components = new String[]{sql};
} }
int tableId = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); int tableId = Env.getContextAsInt(ctx, DataElementParameters.AD_TABLE_ID);
String tableName = MTable.getTableName(ctx, tableId); String tableName = MTable.getTableName(ctx, tableId);
List<String> excludes = defaultExcludeList(tableName); List<String> excludes = defaultExcludeList(tableName);
Statement stmt = null; Statement stmt = null;
@ -209,11 +209,11 @@ public class GenericPOElementHandler extends AbstractElementHandler {
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception
{ {
MPackageExpDetail detail = packout.getPackageExpDetail(); PackoutItem detail = packout.getCurrentPackoutItem();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, detail.getAD_Table_ID()); Env.setContext(packout.getCtx(), DataElementParameters.AD_TABLE_ID, (Integer)detail.getProperty(DataElementParameters.AD_TABLE_ID));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement()); Env.setContext(packout.getCtx(), DataElementParameters.SQL_STATEMENT, (String)detail.getProperty(DataElementParameters.SQL_STATEMENT));
this.create(packout.getCtx(), packoutHandler); this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); packout.getCtx().remove(DataElementParameters.AD_TABLE_ID);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); packout.getCtx().remove(DataElementParameters.SQL_STATEMENT);
} }
} }

View File

@ -27,8 +27,8 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.compiere.model.MPackageExpDetail; import org.adempiere.pipo2.PackoutItem;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.adempiere.pipo2.SQLElementParameters;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -90,8 +90,8 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document) public void create(Properties ctx, TransformerHandler document)
throws SAXException { throws SAXException {
String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); String SQLStatement = Env.getContext(ctx, SQLElementParameters.SQL_STATEMENT);
String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType); String DBType = Env.getContext(ctx, SQLElementParameters.DB_TYPE);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "custom"); addTypeName(atts, "custom");
document.startElement("","","SQLStatement",atts); document.startElement("","","SQLStatement",atts);
@ -115,11 +115,11 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int field) throws Exception public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int field) throws Exception
{ {
MPackageExpDetail detail = packout.getPackageExpDetail(); PackoutItem detail = packout.getCurrentPackoutItem();
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement()); Env.setContext(packout.getCtx(), SQLElementParameters.SQL_STATEMENT, (String)detail.getProperty(SQLElementParameters.SQL_STATEMENT));
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_DBType, detail.getDBType()); Env.setContext(packout.getCtx(), SQLElementParameters.DB_TYPE, (String)detail.getProperty(SQLElementParameters.DB_TYPE));
this.create(packout.getCtx(), packoutHandler); this.create(packout.getCtx(), packoutHandler);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); packout.getCtx().remove(SQLElementParameters.SQL_STATEMENT);
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_DBType); packout.getCtx().remove(SQLElementParameters.DB_TYPE);
} }
} }

View File

@ -8,5 +8,14 @@
class="org.adempiere.pipo.srv.PipoDictionaryService"> class="org.adempiere.pipo.srv.PipoDictionaryService">
</client> </client>
</extension> </extension>
<extension
id="org.adempiere.pipo2.GridTab2PackExporter"
name="2Pack Exporter"
point="org.adempiere.base.IGridTabExporter">
<exporter
class="org.adempiere.pipo2.GridTab2PackExporter"
priority="0">
</exporter>
</extension>
</plugin> </plugin>

View File

@ -5,13 +5,8 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.adempiere.base.IDictionaryService; import org.adempiere.base.IDictionaryService;
import org.adempiere.pipo2.PackIn;
import org.compiere.Adempiere; import org.compiere.Adempiere;
import org.compiere.model.I_AD_Package_Imp_Proc;
import org.compiere.model.MPInstance;
import org.compiere.model.MPInstancePara;
import org.compiere.model.MProcess;
import org.compiere.model.X_AD_Package_Imp_Proc;
import org.compiere.process.ProcessInfo;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
@ -20,9 +15,6 @@ public class PipoDictionaryService implements IDictionaryService {
Logger logger = Logger.getLogger(PipoDictionaryService.class.getName()); Logger logger = Logger.getLogger(PipoDictionaryService.class.getName());
/** official packin process id **/
private final static int PACKIN_PROCESS_ID = 50008;
@Override @Override
public void merge(BundleContext context, File packageFile) throws Exception { public void merge(BundleContext context, File packageFile) throws Exception {
if (packageFile == null || !packageFile.exists()) { if (packageFile == null || !packageFile.exists()) {
@ -31,25 +23,12 @@ public class PipoDictionaryService implements IDictionaryService {
} }
String trxName = Trx.createTrxName(); String trxName = Trx.createTrxName();
try { try {
MProcess process = new MProcess(Env.getCtx(), PACKIN_PROCESS_ID, trxName); PackIn packIn = new PackIn();
X_AD_Package_Imp_Proc packageImp = new X_AD_Package_Imp_Proc(Env.getCtx(), 0, trxName); packIn.setPackageName(context.getBundle().getSymbolicName());
packageImp.setAD_Override_Dict(false); packIn.setPackageVersion((String) context.getBundle().getHeaders().get("Bundle-Version"));
packageImp.setAD_Package_Dir(getPackageDir()); packIn.setUpdateDictionary(false);
packageImp.setAD_Package_Source(packageFile.getAbsolutePath()); packIn.setPackageDirectory(getPackageDir());
packageImp.setAD_Package_Source_Type(X_AD_Package_Imp_Proc.AD_PACKAGE_SOURCE_TYPE_File); packIn.importXML(packageFile.getAbsolutePath(), Env.getCtx(), trxName);
packageImp.saveEx();
int Record_ID = packageImp.getAD_Package_Imp_Proc_ID();
MPInstance pInstance = new MPInstance(process, Record_ID);
pInstance.saveEx();
MPInstancePara para = new MPInstancePara(pInstance, 10);
para.setParameter("Name", context.getBundle().getSymbolicName());
para.saveEx();
para = new MPInstancePara(pInstance, 20);
para.setParameter("Version", (String) context.getBundle().getHeaders().get("Bundle-Version"));
para.saveEx();
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), I_AD_Package_Imp_Proc.Table_ID, Record_ID);
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
process.processIt(pi, Trx.get(trxName, false));
Trx.get(trxName, false).commit(); Trx.get(trxName, false).commit();
logger.info("commit " + trxName); logger.info("commit " + trxName);
} catch (Exception e) { } catch (Exception e) {

View File

@ -0,0 +1,27 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
/**
*
* @author hengsin
*
*/
public interface CodeSnippetElementParameters {
public final static String DESTINATION_DIRECTORY = "DestinationDirectory";
public final static String DESTINATION_FILE_NAME = "DestinationFileName";
public final static String AD_Package_Code_Old = "AD_Package_Code_Old";
public final static String AD_Package_Code_New = "AD_Package_Code_New";
public final static String RELEASE_NO = "ReleaseNo";
}

View File

@ -0,0 +1,24 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
/**
*
* @author hengsin
*
*/
public interface DataElementParameters {
public final static String AD_TABLE_ID = "AD_Table_ID";
public final static String SQL_STATEMENT = "SQLStatement";
}

View File

@ -0,0 +1,28 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
/**
*
* @author hengsin
*
*/
public interface FileElementParameters {
public final static String TARGET_DIRECTORY = "TargetDirectory";
public final static String SOURCE_DIRECTORY = "SourceDirectory";
public final static String FILE_NAME = "FileName";
public final static String DESTINATION_DIRECTORY = "DestinationDirectory";
public final static String DESCRIPTION = "Description";
public final static String RELEASE_NO = "ReleaseNo";
}

View File

@ -0,0 +1,148 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.adempiere.base.IGridTabExporter;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.Adempiere;
import org.compiere.model.GridTab;
import org.compiere.model.MUser;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
* @author hengsin
*
*/
public class GridTab2PackExporter implements IGridTabExporter {
private final static CLogger logger = CLogger.getCLogger(GridTab2PackExporter.class);
/* (non-Javadoc)
* @see org.adempiere.base.IGridTabExporter#export(org.compiere.model.GridTab, java.io.File)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void export(GridTab gridTab, List<GridTab> childs, boolean currentRowOnly, File file) {
String tableName = gridTab.getTableName();
PackOut packOut = new PackOut();
Map properties = new HashMap();
properties.putAll(Env.getCtx());
List<PackoutItem> packoutItems = new ArrayList<PackoutItem>();
if (packOut.getHandler(tableName) == null) {
properties.put(DataElementParameters.AD_TABLE_ID, gridTab.getAD_Table_ID());
StringBuffer sql = new StringBuffer("SELECT * FROM ");
sql.append(tableName);
if (currentRowOnly) {
sql.append(" WHERE ").append(tableName).append("_ID=").append(gridTab.getRecord_ID());
} else {
for(int i = 0; i < gridTab.getRowCount(); i++) {
if (i == 0)
sql.append(" WHERE ");
else
sql.append(" OR ");
sql.append(tableName).append("_ID=").append(gridTab.getKeyID(i));
}
}
for(GridTab child : childs) {
if (child.getTabLevel() > gridTab.getTabLevel()+1) {
sql = sql.append(">").append(child.getTableName());
} else {
sql = sql.append(";").append(child.getTableName());
}
}
properties.put(DataElementParameters.SQL_STATEMENT, sql.toString());
PackoutItem packoutItem = new PackoutItem(IHandlerRegistry.TABLE_GENERIC_HANDLER, gridTab.getRecord_ID(),
properties);
packoutItems.add(packoutItem);
} else {
if (currentRowOnly) {
PackoutItem packoutItem = new PackoutItem(tableName, gridTab.getRecord_ID(),
properties);
packoutItems.add(packoutItem);
} else {
for(int i = 0; i < gridTab.getRowCount(); i++) {
PackoutItem packoutItem = new PackoutItem(tableName, gridTab.getKeyID(i),
properties);
packoutItems.add(packoutItem);
}
}
}
MUser user = MUser.get(Env.getCtx());
PackoutDocument packoutDocument = new PackoutDocument(tableName, "1.0.0", Adempiere.getVersion(),
Adempiere.DB_VERSION, "", "", user.getName(), user.getEMail(), new Date(), new Date());
if (file == null) {
try {
file = File.createTempFile(tableName + "_", ".zip");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
packOut.export(getPackoutDirectory(), file.getAbsolutePath(), packoutDocument, packoutItems, null);
} catch (Exception e) {
throw new AdempiereException(e);
}
}
private String getPackoutDirectory() {
// 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+File.separator;
}
/* (non-Javadoc)
* @see org.adempiere.base.IGridTabExporter#getFileExtension()
*/
@Override
public String getFileExtension() {
return "zip";
}
/* (non-Javadoc)
* @see org.adempiere.base.IGridTabExporter#getFileExtensionLabel()
*/
@Override
public String getFileExtensionLabel() {
return Msg.getMsg(Env.getCtx(), "File2PackZip");
}
/* (non-Javadoc)
* @see org.adempiere.base.IGridTabExporter#getContentType()
*/
@Override
public String getContentType() {
return "application/zip";
}
}

View File

@ -31,32 +31,20 @@ import java.util.logging.Level;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import org.compiere.Adempiere;
import org.compiere.db.CConnection;
import org.compiere.model.X_AD_Package_Imp_Proc;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Trx;
/** /**
* IntPackIn Tool. * IntPackIn Tool.
* *
* @author: Robert KLEIN. robeklein@hotmail.com * @author: Robert KLEIN. robeklein@hotmail.com
*/ */
public class PackIn extends SvrProcess { public class PackIn {
/** Logger */ /** Logger */
private CLogger log = CLogger.getCLogger(getClass()); private CLogger log = CLogger.getCLogger(getClass());
//update system maintain dictionary, default to false //update system maintain dictionary, default to false
private boolean m_UpdateDictionary = false; private boolean m_UpdateDictionary = false;
private String m_Database = "Oracle"; private String m_packageDirectory = null;
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> tableCache = new HashMap<String,Integer>();
private Map<String,Integer> columnCache = new HashMap<String,Integer>(); private Map<String,Integer> columnCache = new HashMap<String,Integer>();
@ -65,10 +53,6 @@ public class PackIn extends SvrProcess {
public PackIn() { public PackIn() {
super(); super();
if (DB.isOracle())
m_Database = "Oracle";
else if (DB.isPostgreSQL())
m_Database = "PostgreSQL";
} }
/** /**
@ -116,26 +100,10 @@ public class PackIn extends SvrProcess {
return 0; return 0;
} }
protected void prepare() {
p_PackIn_ID = getRecord_ID();
ProcessInfoParameter[] params = getParameter();
if (params != null && params.length > 0) {
for(ProcessInfoParameter param : params) {
if ("Name".equals(param.getParameterName())) {
packageName = param.getParameter().toString();
} else if ("Version".equals(param.getParameterName())) {
packageVersion = param.getParameter().toString();
}
}
}
} // prepare
/** /**
* Uses PackInHandler to update AD. * Uses PackInHandler to update AD.
* *
* @param fileName * @param fileName xml file to read
* xml file to read
* @return status message * @return status message
*/ */
public String importXML(String fileName, Properties ctx, String trxName) throws Exception { public String importXML(String fileName, Properties ctx, String trxName) throws Exception {
@ -155,9 +123,19 @@ public class PackIn extends SvrProcess {
} }
} }
/**
*
* @param input
* @param ctx
* @param trxName
* @return status message
*/
public String importXML(InputStream input, Properties ctx, String trxName) { public String importXML(InputStream input, Properties ctx, String trxName) {
try { try {
log.info("starting"); log.info("starting");
// clear cache of previous runs
IDFinder.clearIDCache();
System.setProperty("javax.xml.parsers.SAXParserFactory", System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl"); "org.apache.xerces.jaxp.SAXParserFactoryImpl");
PackInHandler handler = new PackInHandler(); PackInHandler handler = new PackInHandler();
@ -178,79 +156,12 @@ public class PackIn extends SvrProcess {
} }
} }
/**
* 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() { public String getPackageDirectory() {
return m_Package_Dir; return m_packageDirectory;
} }
public void setPackageDirectory(String packageDirectory) { public void setPackageDirectory(String packageDirectory) {
m_Package_Dir = packageDirectory; m_packageDirectory = packageDirectory;
}
public String getDatabaseType() {
return m_Database;
} }
public boolean isUpdateDictionary() { public boolean isUpdateDictionary() {
@ -263,7 +174,7 @@ public class PackIn extends SvrProcess {
public byte[] readBlob(String fileName) throws IOException { public byte[] readBlob(String fileName) throws IOException {
byte[] data = null; byte[] data = null;
File file = new File(m_Package_Dir+File.separator+"blobs"+File.separator, fileName); File file = new File(m_packageDirectory+File.separator+"blobs"+File.separator, fileName);
FileInputStream fis = null; FileInputStream fis = null;
try { try {
@ -294,6 +205,14 @@ public class PackIn extends SvrProcess {
return packageName; return packageName;
} }
/**
*
* @param packageName
*/
public void setPackageName(String packageName) {
this.packageName = packageName;
}
/** /**
* @return package Version * @return package Version
*/ */
@ -301,96 +220,11 @@ public class PackIn extends SvrProcess {
return packageVersion; return packageVersion;
} }
/*************************************************************************** /**
* *
* @param args * @param packageVersion
* XMLfile host port db username password
*/ */
public static void main(String[] args) { public void setPackageVersion(String packageVersion) {
if (args.length < 1) { this.packageVersion = packageVersion;
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 } // PackIn

View File

@ -0,0 +1,121 @@
/******************************************************************************
* 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 org.compiere.Adempiere;
import org.compiere.model.X_AD_Package_Imp_Proc;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.CLogger;
/**
* IntPackIn Tool.
*
* @author: Robert KLEIN. robeklein@hotmail.com
*/
public class PackInProcess extends SvrProcess {
/** Logger */
private CLogger log = CLogger.getCLogger(getClass());
//update system maintain dictionary, default to false
private boolean m_UpdateDictionary = false;
private String m_packageDirectory = null;
public int p_PackIn_ID = 0;
private String packageName = null;
private String packageVersion = null;
public PackInProcess() {
super();
}
protected void prepare() {
p_PackIn_ID = getRecord_ID();
ProcessInfoParameter[] params = getParameter();
if (params != null && params.length > 0) {
for(ProcessInfoParameter param : params) {
if ("Name".equals(param.getParameterName())) {
packageName = param.getParameter().toString();
} else if ("Version".equals(param.getParameterName())) {
packageVersion = param.getParameter().toString();
}
}
}
} // prepare
/**
* Doit
*
* @return ""
*
*/
protected String doIt() throws Exception {
X_AD_Package_Imp_Proc adPackageImp = new X_AD_Package_Imp_Proc(getCtx(),
p_PackIn_ID, null);
// 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 parentDir = Zipper.getParentDir(zipFilepath);
Zipper.unpackFile(zipFilepath, targetDir);
String dict_file = packageDirectory + File.separator
+ "packages" + File.separator + parentDir + 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_packageDirectory = packageDirectory + File.separator
+ "packages" + File.separator + parentDir + File.separator;
PackIn packIn = new PackIn();
packIn.setPackageDirectory(m_packageDirectory);
packIn.setPackageName(packageName);
packIn.setPackageVersion(packageVersion);
packIn.setUpdateDictionary(m_UpdateDictionary);
// call XML Handler
String msg = packIn.importXML(dict_file, getCtx(), get_TrxName());
return msg;
} // doIt
} // PackInProcess

View File

@ -38,26 +38,10 @@ import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult; 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.MClient;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.Query; import org.compiere.util.CLogger;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.util.Env;
import org.compiere.process.SvrProcess;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -76,33 +60,29 @@ import org.adempiere.exceptions.AdempiereException;
* <li>BF [ 1819319 ] PackOut: use just active AD_Package_Exp_Detail lines * <li>BF [ 1819319 ] PackOut: use just active AD_Package_Exp_Detail lines
*/ */
public class PackOut extends SvrProcess public class PackOut
{ {
/*** 1.0.0 **/
public final static String PackOutVersion = "100";
private final static CLogger log = CLogger.getCLogger(PackOut.class);
private static final String TRX_NAME_CTX_KEY = "TrxName"; private static final String TRX_NAME_CTX_KEY = "TrxName";
public static final String PACK_OUT_PROCESS_CTX_KEY = "PackOutProcess"; public static final String PACK_OUT_PROCESS_CTX_KEY = "PackOutProcess";
/** Record ID */
private int p_PackOut_ID = 0;
private String PackOutVer = "005";
private Properties localContext = null; private Properties localContext = null;
private MPackageExp packageExp; private String packageDirectory;
private MPackageExpDetail packageExpDetail;
private String packOutDir;
private String packageDir;
private int blobCount = 0; private int blobCount = 0;
private IHandlerRegistry handlerRegistry = null; private IHandlerRegistry handlerRegistry = new OSGiHandlerRegistry();
private PackoutItem packoutItem;
private String trxName;
private PackoutDocument packoutDocument;
private int processedCount;
private String exportFile;
private String packoutDirectory;
public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID; public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID;
/**
* 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 { public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException {
handler.startElement("", "", qName, atts); handler.startElement("", "", qName, atts);
append(handler, text); append(handler, text);
@ -116,75 +96,60 @@ public class PackOut extends SvrProcess
} }
/** /**
* Start the transformation to XML * Start the transformation to XML
* @return info * @param packoutDirectory
* @throws Exception * @param destinationPath
* @param packoutDocument
* @param packoutItems
* @param trxName
* @throws java.lang.Exception
*/ */
public void export(String packoutDirectory, String destinationPath, PackoutDocument packoutDocument, List<PackoutItem> packoutItems, String trxName) throws java.lang.Exception
protected String doIt() throws java.lang.Exception
{ {
this.packoutDirectory = packoutDirectory;
this.packoutDocument = packoutDocument;
this.trxName = trxName;
initContext(); initContext();
handlerRegistry = new OSGiHandlerRegistry(); OutputStream docStream = null;
OutputStream packoutStream = null;
OutputStream packageDocStream = null; processedCount = 0;
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 { try {
packageDirectory = packoutDirectory+ packoutDocument.getPackageName();
packageExp = new MPackageExp(getCtx(), p_PackOut_ID, get_TrxName()); File docDirectoryFile = new File(packageDirectory+File.separator+"doc"+File.separator);
if (!docDirectoryFile.exists()) {
if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){ boolean success = docDirectoryFile.mkdirs();
//Create the package documentation if (!success) {
packOutDir = packageExp.getFile_Directory().trim(); throw new AdempiereException("Failed to create directory for pack out. " + packageDirectory+File.separator+"doc"+File.separator);
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();
} }
String docFileName = packageDirectory+File.separator+"doc"+File.separator+packoutDocument.getPackageName()+"Doc.xml";
docStream = new FileOutputStream (docFileName, false);
TransformerHandler docHandler = createDocHandler(docStream);
String packoutFileName = packageDirectory+File.separator+ "dict"+File.separator+"PackOut.xml";
packoutStream = new FileOutputStream (packoutFileName, false);
TransformerHandler packoutHandler = createPackoutHandler(packoutStream);
for(PackoutItem packoutItem : packoutItems){
this.packoutItem = packoutItem;
String type = packoutItem.getType();
ElementHandler handler = handlerRegistry.getHandler(type);
if (handler != null)
handler.packOut(this,packoutHandler,docHandler,packoutItem.getRecordId());
else
throw new IllegalArgumentException("Packout handler not found for type " + type);
processedCount++;
}
packoutHandler.endElement("","","adempiereAD");
packoutHandler.endDocument();
docHandler.endElement("","","adempiereDocument");
docHandler.endDocument();
} }
catch (Exception e) catch (Exception e)
{ {
@ -194,53 +159,57 @@ public class PackOut extends SvrProcess
finally finally
{ {
// Close streams - teo_sarca [ 1704762 ] // Close streams - teo_sarca [ 1704762 ]
if (packageDocStream != null) if (docStream != null)
try { try {
packageDocStream.close(); docStream.close();
} catch (Exception e) {} } catch (Exception e) {}
if (packOutDocStream != null) if (packoutStream != null)
try { try {
packOutDocStream.close(); packoutStream.close();
} catch (Exception e) {} } catch (Exception e) {}
} }
//create compressed packages //create compressed packages
//set the files //set the files
File srcFolder = new File(packOutDir); File srcFolder = new File(packoutDirectory);
File destZipFile = new File(packageDir+".zip"); File destZipFile = null;
if (destinationPath != null && destinationPath.trim().length() > 0)
{
destZipFile = new File(destinationPath);
} else {
destZipFile = new File(packageDirectory+".zip");
}
//delete the old packages if necessary //delete the old packages if necessary
destZipFile.delete(); destZipFile.delete();
//create the compressed packages //create the compressed packages
String includesdir = packageExp.getName() + File.separator +"**"; String includesdir = packoutDocument.getPackageName() + File.separator +"**";
Zipper.zipFolder(srcFolder, destZipFile, includesdir); Zipper.zipFolder(srcFolder, destZipFile, includesdir);
exportFile = destZipFile.getAbsolutePath();
return "Exported="+processedCount + " File=" + destZipFile.getAbsolutePath();
} // doIt } // doIt
private TransformerHandler createPackOutDoc(MPackageExp packageExp, private TransformerHandler createPackoutHandler(
OutputStream packOutDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException { OutputStream packoutStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
StreamResult packOutStreamResult = new StreamResult(new OutputStreamWriter(packOutDocStream,"utf-8")); StreamResult packoutStreamResult = new StreamResult(new OutputStreamWriter(packoutStream,"utf-8"));
SAXTransformerFactory packOutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); SAXTransformerFactory packoutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
packOutFactory.setAttribute("indent-number", new Integer(4)); packoutFactory.setAttribute("indent-number", new Integer(4));
TransformerHandler packOutDocument = packOutFactory.newTransformerHandler(); TransformerHandler packoutHandler = packoutFactory.newTransformerHandler();
Transformer packOutTransformer = packOutDocument.getTransformer(); Transformer packoutTransformer = packoutHandler.getTransformer();
packOutTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); packoutTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
packOutTransformer.setOutputProperty(OutputKeys.INDENT,"yes"); packoutTransformer.setOutputProperty(OutputKeys.INDENT,"yes");
packOutDocument.setResult(packOutStreamResult); packoutHandler.setResult(packoutStreamResult);
packOutDocument.startDocument(); packoutHandler.startDocument();
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("","","Name","CDATA",packageExp.getName()); atts.addAttribute("","","Name","CDATA",packoutDocument.getPackageName());
atts.addAttribute("","","Version","CDATA",packageExp.getPK_Version()); atts.addAttribute("","","Version","CDATA",packoutDocument.getPackageVersion());
atts.addAttribute("","","AdempiereVersion","CDATA",packageExp.getReleaseNo()); atts.addAttribute("","","AdempiereVersion","CDATA",packoutDocument.getAdempiereVersion());
atts.addAttribute("","","DataBase","CDATA",packageExp.getVersion()); atts.addAttribute("","","DataBaseVersion","CDATA",packoutDocument.getDatabaseVersion());
atts.addAttribute("","","Description","CDATA",packageExp.getDescription()); atts.addAttribute("","","Description","CDATA",emptyIfNull(packoutDocument.getDescription()));
atts.addAttribute("","","Creator","CDATA",packageExp.getUserName()); atts.addAttribute("","","Author","CDATA",packoutDocument.getAuthor());
atts.addAttribute("","","CreatorContact","CDATA",packageExp.getEMail()); atts.addAttribute("","","AuthorEmail","CDATA",emptyIfNull(packoutDocument.getAuthorEmail()));
atts.addAttribute("","","CreatedDate","CDATA",packageExp.getCreated().toString()); atts.addAttribute("","","CreatedDate","CDATA",packoutDocument.getCreated().toString());
atts.addAttribute("","","UpdatedDate","CDATA",packageExp.getUpdated().toString()); atts.addAttribute("","","UpdatedDate","CDATA",packoutDocument.getUpdated().toString());
atts.addAttribute("","","PackOutVersion","CDATA",PackOutVer); atts.addAttribute("","","PackOutVersion","CDATA",PackOutVersion);
MClient client = MClient.get(localContext); MClient client = MClient.get(localContext);
StringBuffer sb = new StringBuffer () StringBuffer sb = new StringBuffer ()
@ -251,42 +220,46 @@ public class PackOut extends SvrProcess
.append(client.getName()); .append(client.getName());
atts.addAttribute("", "", "Client", "CDATA", sb.toString()); atts.addAttribute("", "", "Client", "CDATA", sb.toString());
packOutDocument.startElement("","","adempiereAD",atts); packoutHandler.startElement("","","adempiereAD",atts);
return packOutDocument; return packoutHandler;
} }
private TransformerHandler createPackageDoc(MPackageExp packageExp, OutputStream packageDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException { private String emptyIfNull(String input) {
StreamResult docStreamResult = new StreamResult(new OutputStreamWriter(packageDocStream,"utf-8")); return input != null ? input : "";
}
private TransformerHandler createDocHandler(OutputStream docStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
StreamResult docStreamResult = new StreamResult(new OutputStreamWriter(docStream,"utf-8"));
SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", new Integer(4)); transformerFactory.setAttribute("indent-number", new Integer(4));
TransformerHandler packageDocument = transformerFactory.newTransformerHandler(); TransformerHandler docHandler = transformerFactory.newTransformerHandler();
Transformer transformer = packageDocument.getTransformer(); Transformer transformer = docHandler.getTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.setOutputProperty(OutputKeys.INDENT,"yes");
packageDocument.setResult(docStreamResult); docHandler.setResult(docStreamResult);
packageDocument.startDocument(); docHandler.startDocument();
packageDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); docHandler.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
packageDocument.startElement("","","adempiereDocument",atts); docHandler.startElement("","","adempiereDocument",atts);
addTextElement(packageDocument, "header", packageExp.getName()+" Package Description", atts); addTextElement(docHandler, "header", packoutDocument.getPackageName()+" Package Description", atts);
addTextElement(packageDocument, "H1", "Package Name:", atts); addTextElement(docHandler, "H1", "Package Name:", atts);
addTextElement(packageDocument, "packagename", packageExp.getName(), atts); addTextElement(docHandler, "packagename", packoutDocument.getPackageName(), atts);
addTextElement(packageDocument, "H1", "Author:", atts); addTextElement(docHandler, "H1", "Author:", atts);
addTextElement(packageDocument, "creator", packageExp.getUserName(), atts); addTextElement(docHandler, "Name:", packoutDocument.getAuthor(), atts);
addTextElement(packageDocument, "H1", "Email Address:", atts); addTextElement(docHandler, "H1", "Email Address:", atts);
addTextElement(packageDocument, "creatorcontact", packageExp.getEMail(), atts); addTextElement(docHandler, "Email", packoutDocument.getAuthorEmail(), atts);
addTextElement(packageDocument, "H1", "Created:", atts); addTextElement(docHandler, "H1", "Created:", atts);
addTextElement(packageDocument, "createddate", packageExp.getCreated().toString(), atts); addTextElement(docHandler, "Date", packoutDocument.getCreated().toString(), atts);
addTextElement(packageDocument, "H1", "Updated:", atts); addTextElement(docHandler, "H1", "Updated:", atts);
addTextElement(packageDocument, "updateddate", packageExp.getUpdated().toString(), atts); addTextElement(docHandler, "Date", packoutDocument.getUpdated().toString(), atts);
addTextElement(packageDocument, "H1", "Description:", atts); addTextElement(docHandler, "H1", "Description:", atts);
addTextElement(packageDocument, "description", packageExp.getDescription(), atts); addTextElement(docHandler, "description", packoutDocument.getDescription(), atts);
addTextElement(packageDocument, "H1", "Instructions:", atts); addTextElement(docHandler, "H1", "Instructions:", atts);
addTextElement(packageDocument, "instructions", packageExp.getInstructions(), atts); addTextElement(docHandler, "instructions", packoutDocument.getInstructions(), atts);
addTextElement(packageDocument, "H1", "Files in Package:", atts); addTextElement(docHandler, "H1", "Files in Package:", atts);
addTextElement(packageDocument, "file", "File: PackOut.xml", atts); addTextElement(docHandler, "file", "File: PackOut.xml", atts);
addTextElement(packageDocument, "filedirectory", "Directory: \\dict\\", atts); addTextElement(docHandler, "filedirectory", "Directory: \\dict\\", atts);
addTextElement(packageDocument, "filenotes", "Notes: Contains all application/object settings for package", atts); addTextElement(docHandler, "filenotes", "Notes: Contains all application/object settings for package", atts);
MClient client = MClient.get(localContext); MClient client = MClient.get(localContext);
StringBuffer sb = new StringBuffer () StringBuffer sb = new StringBuffer ()
@ -295,62 +268,24 @@ public class PackOut extends SvrProcess
.append(client.getValue()) .append(client.getValue())
.append("-") .append("-")
.append(client.getName()); .append(client.getName());
addTextElement(packageDocument, "H1", "Client:", atts); addTextElement(docHandler, "H1", "Client:", atts);
addTextElement(packageDocument, "Client", sb.toString(), atts); addTextElement(docHandler, "Client", sb.toString(), atts);
File packageDictDirFile = new File(packageDir+File.separator+ "dict"+File.separator); File packageDictDirFile = new File(packageDirectory+File.separator+ "dict"+File.separator);
if (!packageDictDirFile.exists()) { if (!packageDictDirFile.exists()) {
boolean success = packageDictDirFile.mkdirs(); boolean success = packageDictDirFile.mkdirs();
if (!success) if (!success)
throw new AdempiereException("Failed to create directory. " + packageDir+File.separator+ "dict"+File.separator); throw new AdempiereException("Failed to create directory. " + packageDirectory+File.separator+ "dict"+File.separator);
} }
return packageDocument; return docHandler;
}
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() { private void initContext() {
Properties tmp = new Properties(); Properties tmp = new Properties();
if (getCtx() != null) if (getCtx() != null)
tmp.putAll(getCtx()); tmp.putAll(getCtx());
tmp.put(TRX_NAME_CTX_KEY, get_TrxName()); if (trxName != null)
tmp.put(TRX_NAME_CTX_KEY, trxName);
tmp.put(PACK_OUT_PROCESS_CTX_KEY, this); tmp.put(PACK_OUT_PROCESS_CTX_KEY, this);
localContext = tmp; localContext = tmp;
} }
@ -417,9 +352,8 @@ public class PackOut extends SvrProcess
} }
} }
@Override
public Properties getCtx() { public Properties getCtx() {
return localContext != null ? localContext : super.getCtx(); return localContext != null ? localContext : Env.getCtx();
} }
/** /**
@ -430,7 +364,7 @@ public class PackOut extends SvrProcess
public String writeBlob(byte[] data) throws IOException { public String writeBlob(byte[] data) throws IOException {
blobCount++; blobCount++;
String fileName = blobCount + ".dat"; String fileName = blobCount + ".dat";
File path = new File(packageDir+File.separator+"blobs"+File.separator); File path = new File(packageDirectory+File.separator+"blobs"+File.separator);
path.mkdirs(); path.mkdirs();
File file = new File(path, fileName); File file = new File(path, fileName);
FileOutputStream os = null; FileOutputStream os = null;
@ -449,17 +383,22 @@ public class PackOut extends SvrProcess
} }
/** /**
* @return MPackageExp * @return MPackageExpDetail
*/ */
public MPackageExp getPackageExp() { public PackoutItem getCurrentPackoutItem() {
return packageExp; return packoutItem;
} }
/** /**
* @return MPackageExpDetail *
* @return PackoutDocument
*/ */
public MPackageExpDetail getPackageExpDetail() { public PackoutDocument getPackoutDocument() {
return packageExpDetail; return packoutDocument;
}
public String getPackoutDirectory() {
return packoutDirectory;
} }
/** /**
@ -469,4 +408,18 @@ public class PackOut extends SvrProcess
public ElementHandler getHandler(String name) { public ElementHandler getHandler(String name) {
return handlerRegistry.getHandler(name); return handlerRegistry.getHandler(name);
} }
/**
* @return number of records exported
*/
public int getExportCount() {
return processedCount;
}
/**
* @return absolute path for export file
*/
public String getExportFile() {
return exportFile;
}
} // PackOut } // PackOut

View File

@ -0,0 +1,196 @@
/******************************************************************************
* 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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
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.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;
/**
* 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 PackOutProcess extends SvrProcess
{
/** Record ID */
private int p_PackOut_ID = 0;
private MPackageExp packageExp;
private String packoutDirectory;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
p_PackOut_ID = getRecord_ID();
} // prepare
/**
* Start the transformation to XML
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID);
if (p_PackOut_ID == 0)
throw new IllegalArgumentException("No Record");
int processedCount = 0;
String exportFile = "";
try {
packageExp = new MPackageExp(getCtx(), p_PackOut_ID, get_TrxName());
if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){
//Create the package documentation
packoutDirectory = packageExp.getFile_Directory().trim();
if (!packoutDirectory.endsWith("/") && !packoutDirectory.endsWith("\\"))
packoutDirectory+= File.separator;
PackoutDocument packoutDocument = new PackoutDocument(packageExp.getName(), packageExp.getPK_Version(), packageExp.getReleaseNo(), packageExp.getVersion(),
packageExp.getDescription(), packageExp.getInstructions(), packageExp.getUserName(),
packageExp.getEMail(), packageExp.getCreated(), packageExp.getUpdated());
List<PackoutItem> packoutItems = new ArrayList<PackoutItem>();
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){
String type = getTypeName(dtl.getType());
log.info(Integer.toString(dtl.getLine()));
PackoutItem item = new PackoutItem(type, dtl.getExpRecordId(), getExpProperties(dtl));
packoutItems.add(item);
}
PackOut packOut = new PackOut();
packOut.export(packoutDirectory, null, packoutDocument, packoutItems, get_TrxName());
processedCount = packOut.getExportCount();
exportFile = packOut.getExportFile();
}
}
catch (Exception e)
{
log.log(Level.SEVERE,e.getLocalizedMessage(), e);
throw e;
}
return "Exported="+processedCount + " File=" + exportFile;
} // doIt
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 Map<String, Object> getExpProperties(MPackageExpDetail dtl) {
Map<String, Object> properties = new HashMap<String, Object>();
String type = dtl.getType();
if (MPackageExpDetail.TYPE_Data.equals(type)) {
properties.put(DataElementParameters.AD_TABLE_ID, dtl.getAD_Table_ID());
properties.put(DataElementParameters.SQL_STATEMENT, dtl.getSQLStatement());
} else if (MPackageExpDetail.TYPE_SQLStatement.equals(type)) {
properties.put(SQLElementParameters.SQL_STATEMENT, dtl.getSQLStatement());
properties.put(SQLElementParameters.DB_TYPE, dtl.getDBType());
} else if (MPackageExpDetail.TYPE_File_CodeOrOther.equals(type)) {
properties.put(FileElementParameters.TARGET_DIRECTORY, dtl.getTarget_Directory());
properties.put(FileElementParameters.SOURCE_DIRECTORY, dtl.getFile_Directory());
properties.put(FileElementParameters.FILE_NAME, dtl.getFileName());
properties.put(FileElementParameters.DESTINATION_DIRECTORY, dtl.getDestination_Directory());
properties.put(FileElementParameters.DESCRIPTION, dtl.getDescription());
properties.put(FileElementParameters.RELEASE_NO, dtl.getReleaseNo());
} else if (MPackageExpDetail.TYPE_CodeSnipit.equals(type)) {
properties.put(CodeSnippetElementParameters.DESTINATION_DIRECTORY, dtl.getDestination_Directory());
properties.put(CodeSnippetElementParameters.DESTINATION_FILE_NAME, dtl.getDestination_FileName());
properties.put(CodeSnippetElementParameters.RELEASE_NO, dtl.getReleaseNo());
properties.put(CodeSnippetElementParameters.AD_Package_Code_Old, dtl.getAD_Package_Code_Old());
properties.put(CodeSnippetElementParameters.AD_Package_Code_New, dtl.getAD_Package_Code_New());
}
return properties;
}
} // PackOut

View File

@ -0,0 +1,129 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
import java.util.Date;
/**
*
* @author hengsin
*
*/
public class PackoutDocument {
private String packageName;
private String packageVersion;
private String adempiereVersion;
private String databaseVersion;
private String description;
private String instructions;
private String author;
private String authorEmail;
private Date created;
private Date updated;
/**
* @param packageName
* @param packageVersion
* @param adempiereVersion
* @param databaseVersion
* @param description
* @param author
* @param authorEmail
* @param created
* @param updated
*/
public PackoutDocument(String packageName, String packageVersion,
String adempiereVersion, String databaseVersion,
String description, String instructions, String author, String authorEmail,
Date created, Date updated) {
super();
this.packageName = packageName;
this.packageVersion = packageVersion;
this.adempiereVersion = adempiereVersion;
this.databaseVersion = databaseVersion;
this.description = description;
this.instructions = instructions;
this.author = author;
this.authorEmail = authorEmail;
this.created = created;
this.updated = updated;
}
/**
* @return the packageName
*/
public String getPackageName() {
return packageName;
}
/**
* @return the packageVersion
*/
public String getPackageVersion() {
return packageVersion;
}
/**
* @return the adempiereVersion
*/
public String getAdempiereVersion() {
return adempiereVersion;
}
/**
* @return the databaseVersion
*/
public String getDatabaseVersion() {
return databaseVersion;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
public String getInstructions() {
return instructions;
}
/**
* @return the author
*/
public String getAuthor() {
return author;
}
/**
* @return the authorEmail
*/
public String getAuthorEmail() {
return authorEmail;
}
/**
* @return the created
*/
public Date getCreated() {
return created;
}
/**
* @return the updated
*/
public Date getUpdated() {
return updated;
}
}

View File

@ -0,0 +1,62 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
import java.util.Map;
/**
*
* @author hengsin
*
*/
public class PackoutItem {
private String type;
private int recordId;
private Map<String, Object> properties;
/**
* @param type
* @param recordId
*/
public PackoutItem(String type, int recordId, Map<String, Object> properties) {
super();
this.type = type;
this.recordId = recordId;
this.properties = properties;
}
/**
* @return the type
*/
public String getType() {
return type;
}
/**
* @return the recordId
*/
public int getRecordId() {
return recordId;
}
/**
*
* @param key
* @return property value
*/
public Object getProperty(String key) {
return properties != null ? properties.get(key) : null;
}
}

View File

@ -0,0 +1,24 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2010 Heng Sin Low *
* 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. *
*****************************************************************************/
package org.adempiere.pipo2;
/**
*
* @author hengsin
*
*/
public interface SQLElementParameters {
public final static String SQL_STATEMENT = "SQLStatement";
public final static String DB_TYPE = "DBType";
}

View File

@ -13,18 +13,24 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.apps; package org.compiere.apps;
import java.awt.Component;
import java.awt.Cursor; import java.awt.Cursor;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import org.adempiere.base.IGridTabExporter; import org.adempiere.base.IGridTabExporter;
import org.adempiere.base.Service; import org.adempiere.base.Service;
import org.compiere.grid.GridController;
import org.compiere.grid.VTabbedPane;
import org.compiere.model.GridTab; import org.compiere.model.GridTab;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -41,6 +47,7 @@ public class AExport
private int m_WindowNo = 0; private int m_WindowNo = 0;
private Map<String, IGridTabExporter> exporterMap = null; private Map<String, IGridTabExporter> exporterMap = null;
private Map<String, String> extensionMap = null; private Map<String, String> extensionMap = null;
private APanel parent;
public AExport(APanel parent) public AExport(APanel parent)
{ {
@ -91,6 +98,7 @@ public class AExport
log.config( "File=" + outFile.getPath() + "; Type=" + ext); log.config( "File=" + outFile.getPath() + "; Type=" + ext);
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
this.parent = parent;
try try
{ {
if (extensionMap.containsKey(ext)) if (extensionMap.containsKey(ext))
@ -117,7 +125,41 @@ public class AExport
private void export(File outFile, GridTab tab, String extension) private void export(File outFile, GridTab tab, String extension)
throws Exception throws Exception
{ {
boolean currentRowOnly = ADialog.ask(m_WindowNo, parent, "Export current row only ?");
IGridTabExporter exporter = exporterMap.get(extension); IGridTabExporter exporter = exporterMap.get(extension);
exporter.export(tab, outFile); Set<String> tables = new HashSet<String>();
List<GridTab> childs = new ArrayList<GridTab>();
List<GridTab> includedList = tab.getIncludedTabs();
for(GridTab included : includedList)
{
String tableName = included.getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(included);
}
int selected = parent.getSelectedTabIndex();
VTabbedPane tabbedPane = (VTabbedPane) parent.getCurrentTabbedPane();
for(int i = selected+1; i < tabbedPane.getTabCount(); i++)
{
Component c = tabbedPane.getComponentAt(i);
if (!(c instanceof GridController))
continue;
GridController gc = (GridController) c;
if (gc.getMTab() == null)
continue;
if (gc.getMTab().getTabLevel() <= tab.getTabLevel())
break;
String tableName = gc.getMTab().getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(gc.getMTab());
}
exporter.export(tab, childs, currentRowOnly, outFile);
} }
} }

View File

@ -2871,7 +2871,17 @@ public final class APanel extends CPanel
getActionMap().put(aSwitchLinesUpAction.getName(), aSwitchLinesUpAction); getActionMap().put(aSwitchLinesUpAction.getName(), aSwitchLinesUpAction);
} }
/**
* @return boolean
*/
public boolean isNested() { public boolean isNested() {
return isNested; return isNested;
} }
/**
* @return JTabbedPane
*/
public JTabbedPane getCurrentTabbedPane() {
return m_curWinTab;
}
} // APanel } // APanel

View File

@ -14,21 +14,28 @@
package org.adempiere.webui.panel.action; package org.adempiere.webui.panel.action;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.adempiere.base.IGridTabExporter; import org.adempiere.base.IGridTabExporter;
import org.adempiere.base.Service; import org.adempiere.base.Service;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.IADTab;
import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.ListItem; import org.adempiere.webui.component.ListItem;
import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.panel.AbstractADWindowPanel; import org.adempiere.webui.panel.AbstractADWindowPanel;
import org.adempiere.webui.panel.IADTabpanel;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.zkoss.util.media.AMedia; import org.zkoss.util.media.AMedia;
@ -54,6 +61,7 @@ public class ExportAction implements EventListener
private Window winExportFile = null; private Window winExportFile = null;
private ConfirmPanel confirmPanel = new ConfirmPanel(true); private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private Listbox cboType = new Listbox(); private Listbox cboType = new Listbox();
private Checkbox chkCurrentRow = new Checkbox();
/** /**
* @param panel * @param panel
@ -100,6 +108,10 @@ public class ExportAction implements EventListener
cboType.setSelectedIndex(0); cboType.setSelectedIndex(0);
Vbox vb = new Vbox();
vb.setWidth("390px");
winExportFile.appendChild(vb);
Hbox hb = new Hbox(); Hbox hb = new Hbox();
Div div = new Div(); Div div = new Div();
div.setAlign("right"); div.setAlign("right");
@ -107,11 +119,14 @@ public class ExportAction implements EventListener
hb.appendChild(div); hb.appendChild(div);
hb.appendChild(cboType); hb.appendChild(cboType);
cboType.setWidth("100%"); cboType.setWidth("100%");
Vbox vb = new Vbox();
vb.setWidth("390px");
winExportFile.appendChild(vb);
vb.appendChild(hb); vb.appendChild(hb);
hb = new Hbox();
chkCurrentRow.setLabel("Export Current Row Only");
chkCurrentRow.setSelected(true);
hb.appendChild(chkCurrentRow);
vb.appendChild(hb);
vb.appendChild(confirmPanel); vb.appendChild(confirmPanel);
confirmPanel.addActionListener(this); confirmPanel.addActionListener(this);
} }
@ -144,8 +159,37 @@ public class ExportAction implements EventListener
return; return;
} }
boolean currentRowOnly = chkCurrentRow.isSelected();
File file = File.createTempFile("Export", "."+ext); File file = File.createTempFile("Export", "."+ext);
exporter.export(panel.getActiveGridTab(), file); IADTab adTab = panel.getADTab();
int selected = adTab.getSelectedIndex();
int tabLevel = panel.getActiveGridTab().getTabLevel();
Set<String> tables = new HashSet<String>();
List<GridTab> childs = new ArrayList<GridTab>();
List<GridTab> includedList = panel.getActiveGridTab().getIncludedTabs();
for(GridTab included : includedList)
{
String tableName = included.getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(included);
}
for(int i = selected+1; i < adTab.getTabCount(); i++)
{
IADTabpanel adTabPanel = adTab.getADTabpanel(i);
if (adTabPanel.getGridTab().isSortTab())
continue;
if (adTabPanel.getGridTab().getTabLevel() <= tabLevel)
break;
String tableName = adTabPanel.getGridTab().getTableName();
if (tables.contains(tableName))
continue;
tables.add(tableName);
childs.add(adTabPanel.getGridTab());
}
exporter.export(panel.getActiveGridTab(), childs, currentRowOnly, file);
winExportFile.onClose(); winExportFile.onClose();
winExportFile = null; winExportFile = null;