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:
parent
8199b9f9b4
commit
490784dbbc
|
@ -16,3 +16,4 @@ bin.includes = META-INF/,\
|
|||
OSGI-INF/eventmanager.xml
|
||||
output.base.jar = build/
|
||||
source.base.jar = src/
|
||||
src.includes = schema/
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.adempiere.base;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.compiere.model.GridTab;
|
||||
|
||||
|
@ -27,9 +28,11 @@ public interface IGridTabExporter {
|
|||
/**
|
||||
* export gridTab data to file
|
||||
* @param gridTab
|
||||
* @param childs
|
||||
* @param isCurrentRowOnly
|
||||
* @param file
|
||||
*/
|
||||
public void export(GridTab gridTab, File file);
|
||||
public void export(GridTab gridTab, List<GridTab> childs, boolean isCurrentRowOnly, File file);
|
||||
|
||||
/**
|
||||
* @return file extension
|
||||
|
|
|
@ -55,27 +55,32 @@ public abstract class AbstractExcelExporter
|
|||
* @return true if function row
|
||||
*/
|
||||
public abstract boolean isFunctionRow();
|
||||
|
||||
|
||||
/**
|
||||
* Get Columns Count
|
||||
* @return number of columns
|
||||
*/
|
||||
public abstract int getColumnCount();
|
||||
|
||||
|
||||
/**
|
||||
* Get Rows Count
|
||||
* @return number of rows
|
||||
*/
|
||||
public abstract int getRowCount();
|
||||
|
||||
|
||||
/**
|
||||
* Set current row
|
||||
* @param row row index
|
||||
*/
|
||||
protected abstract void setCurrentRow(int row);
|
||||
|
||||
|
||||
/**
|
||||
* Check if column is printed (displayed)
|
||||
* @return current row index
|
||||
*/
|
||||
protected abstract int getCurrentRow();
|
||||
|
||||
/**
|
||||
* Check if column is printed (displayed)
|
||||
* @param col column index
|
||||
* @return true if is visible
|
||||
*/
|
||||
|
@ -87,7 +92,7 @@ public abstract class AbstractExcelExporter
|
|||
* @return header name
|
||||
*/
|
||||
public abstract String getHeaderName(int col);
|
||||
|
||||
|
||||
/**
|
||||
* Get cell display type (see {@link DisplayType})
|
||||
* @param row row index
|
||||
|
@ -95,7 +100,7 @@ public abstract class AbstractExcelExporter
|
|||
* @return display type
|
||||
*/
|
||||
public abstract int getDisplayType(int row, int col);
|
||||
|
||||
|
||||
/**
|
||||
* Get cell value
|
||||
* @param row row index
|
||||
|
@ -103,7 +108,7 @@ public abstract class AbstractExcelExporter
|
|||
* @return cell value
|
||||
*/
|
||||
public abstract Object getValueAt(int row, int col);
|
||||
|
||||
|
||||
/**
|
||||
* Check if there is a page break on given cell
|
||||
* @param row row index
|
||||
|
@ -124,6 +129,7 @@ public abstract class AbstractExcelExporter
|
|||
//
|
||||
private int m_colSplit = 1;
|
||||
private int m_rowSplit = 1;
|
||||
private boolean currentRowOnly = false;
|
||||
/** Styles cache */
|
||||
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
|
||||
|
||||
|
@ -349,6 +355,16 @@ public abstract class AbstractExcelExporter
|
|||
ps.setLandscape(false);
|
||||
}
|
||||
|
||||
protected boolean isCurrentRowOnly()
|
||||
{
|
||||
return currentRowOnly;
|
||||
}
|
||||
|
||||
protected void setCurrentRowOnly(boolean b)
|
||||
{
|
||||
currentRowOnly = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export to given stream
|
||||
* @param out
|
||||
|
@ -361,9 +377,12 @@ public abstract class AbstractExcelExporter
|
|||
String sheetName = null;
|
||||
//
|
||||
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;
|
||||
HSSFRow row = sheet.createRow(xls_rownum);
|
||||
|
@ -378,7 +397,7 @@ public abstract class AbstractExcelExporter
|
|||
{
|
||||
HSSFCell cell = row.createCell(colnum);
|
||||
cell.setEncoding(HSSFCell.ENCODING_UTF_16); // Bug-2017673 - Export Report as Excel - Bad Encoding
|
||||
|
||||
|
||||
// line row
|
||||
Object obj = getValueAt(rownum, col);
|
||||
int displayType = getDisplayType(rownum, col);
|
||||
|
|
|
@ -29,18 +29,18 @@ import org.compiere.util.Util;
|
|||
public class ArrayExcelExporter extends AbstractExcelExporter {
|
||||
private Properties m_ctx = null;
|
||||
private ArrayList<ArrayList<Object>> m_data = null;
|
||||
|
||||
|
||||
public ArrayExcelExporter(Properties ctx, ArrayList<ArrayList<Object>> data) {
|
||||
super();
|
||||
m_ctx = ctx;
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Properties getCtx() {
|
||||
return m_ctx;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return m_data.get(0).size();
|
||||
|
@ -113,4 +113,8 @@ public class ArrayExcelExporter extends AbstractExcelExporter {
|
|||
@Override
|
||||
protected void setCurrentRow(int row) {
|
||||
}
|
||||
|
||||
protected int getCurrentRow() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.adempiere.impexp;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.adempiere.base.IGridTabExporter;
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
|
@ -122,6 +123,11 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid
|
|||
; // nothing
|
||||
}
|
||||
|
||||
protected int getCurrentRow()
|
||||
{
|
||||
return m_tab.getCurrentRow();
|
||||
}
|
||||
|
||||
private HashMap<String, MLookup> m_buttonLookups = new HashMap<String, MLookup>();
|
||||
|
||||
private MLookup getButtonLookup(GridField mField)
|
||||
|
@ -147,8 +153,9 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid
|
|||
}
|
||||
|
||||
@Override
|
||||
public void export(GridTab gridTab, File file) {
|
||||
public void export(GridTab gridTab, List<GridTab> childs, boolean currentRowOnly, File file) {
|
||||
m_tab = gridTab;
|
||||
setCurrentRowOnly(currentRowOnly);
|
||||
try {
|
||||
export(file, null);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -44,7 +44,7 @@ extends AbstractExcelExporter
|
|||
this.m_printData = printData;
|
||||
this.m_printFormat = printFormat;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return m_printFormat.getItemCount();
|
||||
|
@ -73,7 +73,7 @@ extends AbstractExcelExporter
|
|||
return -1;
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row, int col) {
|
||||
PrintDataElement pde = getPDE(row, col);
|
||||
|
@ -133,6 +133,10 @@ extends AbstractExcelExporter
|
|||
m_printData.setRowIndex(row);
|
||||
}
|
||||
|
||||
protected int getCurrentRow() {
|
||||
return m_printData.getRowIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFunctionRow() {
|
||||
return m_printData.isFunctionRow();
|
||||
|
@ -187,6 +191,6 @@ extends AbstractExcelExporter
|
|||
sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72);
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -24,15 +24,15 @@ import org.compiere.util.DB;
|
|||
|
||||
/**
|
||||
* Menu Model
|
||||
*
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MMenu.java,v 1.5 2005/05/14 05:32:16 jjanke Exp $
|
||||
*/
|
||||
public class MPackageExpDetail extends X_AD_Package_Exp_Detail
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5110078103695767282L;
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class MPackageExpDetail extends X_AD_Package_Exp_Detail
|
|||
*/
|
||||
public MPackageExpDetail (Properties ctx, int AD_Package_Exp_ID, String trxName)
|
||||
{
|
||||
super(ctx, AD_Package_Exp_ID, trxName);
|
||||
|
||||
super(ctx, AD_Package_Exp_ID, trxName);
|
||||
|
||||
} // MPackageExp
|
||||
|
||||
/**
|
||||
|
@ -56,12 +56,12 @@ public class MPackageExpDetail extends X_AD_Package_Exp_Detail
|
|||
*/
|
||||
public MPackageExpDetail (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
|
||||
} // MPackageExp
|
||||
|
||||
super(ctx, rs, trxName);
|
||||
|
||||
} // MPackageExp
|
||||
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.compiere.model.PO#beforeSave(boolean)
|
||||
*/
|
||||
|
@ -79,9 +79,9 @@ public class MPackageExpDetail extends X_AD_Package_Exp_Detail
|
|||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return record id to export
|
||||
*/
|
||||
public int getExpRecordId() {
|
||||
|
|
|
@ -29,7 +29,7 @@ extends AbstractExcelExporter
|
|||
super();
|
||||
m_model = model;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return m_model.getColumnCount();
|
||||
|
@ -74,4 +74,8 @@ extends AbstractExcelExporter
|
|||
protected void setCurrentRow(int row) {
|
||||
m_currentRow = row;
|
||||
}
|
||||
|
||||
protected int getCurrentRow() {
|
||||
return m_currentRow;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ import javax.xml.transform.sax.TransformerHandler;
|
|||
|
||||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.model.X_AD_Package_Imp_Backup;
|
||||
import org.compiere.model.X_AD_Package_Imp_Detail;
|
||||
|
||||
|
@ -44,8 +42,10 @@ import org.xml.sax.SAXException;
|
|||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import org.adempiere.pipo2.AbstractElementHandler;
|
||||
import org.adempiere.pipo2.CodeSnippetElementParameters;
|
||||
import org.adempiere.pipo2.Element;
|
||||
import org.adempiere.pipo2.PackOut;
|
||||
import org.adempiere.pipo2.PackoutItem;
|
||||
|
||||
public class CodeSnippetElementHandler extends AbstractElementHandler {
|
||||
|
||||
|
@ -196,11 +196,11 @@ public class CodeSnippetElementHandler extends AbstractElementHandler {
|
|||
|
||||
public void create(Properties ctx, TransformerHandler document)
|
||||
throws SAXException {
|
||||
String FileDir = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
|
||||
String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
|
||||
String OldCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old);
|
||||
String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
|
||||
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
|
||||
String FileDir = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_DIRECTORY);
|
||||
String FileName = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_FILE_NAME);
|
||||
String OldCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_Old);
|
||||
String NewCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_New);
|
||||
String ReleaseNo = Env.getContext(ctx, CodeSnippetElementParameters.RELEASE_NO);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
addTypeName(atts, "custom");
|
||||
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
|
||||
{
|
||||
MPackageExpDetail detail = packout.getPackageExpDetail();
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Destination_Directory, detail.getDestination_Directory());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, detail.getDestination_FileName());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old, detail.getAD_Package_Code_Old());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New, detail.getAD_Package_Code_New());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo,detail.getReleaseNo());
|
||||
PackoutItem detail = packout.getCurrentPackoutItem();
|
||||
Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_DIRECTORY, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_DIRECTORY));
|
||||
Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_FILE_NAME, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_FILE_NAME));
|
||||
Env.setContext(packout.getCtx(), CodeSnippetElementParameters.AD_Package_Code_Old, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_Old));
|
||||
Env.setContext(packout.getCtx(), CodeSnippetElementParameters.AD_Package_Code_New, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_New));
|
||||
Env.setContext(packout.getCtx(), CodeSnippetElementParameters.RELEASE_NO, (String)detail.getProperty(CodeSnippetElementParameters.RELEASE_NO));
|
||||
this.create(packout.getCtx(), packoutHandler);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_File_Directory);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_Old);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
|
||||
packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_DIRECTORY);
|
||||
packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_FILE_NAME);
|
||||
packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_Old);
|
||||
packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_New);
|
||||
packout.getCtx().remove(CodeSnippetElementParameters.RELEASE_NO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ import javax.xml.transform.sax.TransformerHandler;
|
|||
import org.adempiere.pipo2.AbstractElementHandler;
|
||||
import org.adempiere.pipo2.Element;
|
||||
import org.adempiere.pipo2.PackOut;
|
||||
import org.adempiere.pipo2.PackoutItem;
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.model.MPackageExp;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.model.X_AD_Package_Imp_Backup;
|
||||
import org.compiere.model.X_AD_Package_Imp_Detail;
|
||||
|
@ -195,11 +195,11 @@ public class DistFileElementHandler extends AbstractElementHandler {
|
|||
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_ReleaseNo, detail.getReleaseNo());
|
||||
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_FileName, (String)detail.getProperty("FileName"));
|
||||
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, (String)detail.getProperty("TargetDirectory"));
|
||||
Env.setContext(packout.getCtx(), "Source_Directory", fileDest);
|
||||
this.create(packout.getCtx(), packOutDocument);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName);
|
||||
|
@ -213,6 +213,6 @@ public class DistFileElementHandler extends AbstractElementHandler {
|
|||
TransformerHandler docHandler,
|
||||
int recordId) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ import javax.xml.transform.sax.TransformerHandler;
|
|||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.adempiere.pipo2.Element;
|
||||
import org.adempiere.pipo2.ElementHandler;
|
||||
import org.adempiere.pipo2.FileElementParameters;
|
||||
import org.adempiere.pipo2.PackOut;
|
||||
import org.compiere.model.MPackageExp;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.adempiere.pipo2.PackoutDocument;
|
||||
import org.adempiere.pipo2.PackoutItem;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
@ -22,12 +23,12 @@ public class FileElementHandler implements ElementHandler {
|
|||
|
||||
public void packOut(PackOut packout, TransformerHandler packoutHandler,
|
||||
TransformerHandler docHandler, int recordId) throws Exception {
|
||||
MPackageExp header = packout.getPackageExp();
|
||||
MPackageExpDetail detail = packout.getPackageExpDetail();
|
||||
PackoutDocument header = packout.getPackoutDocument();
|
||||
PackoutItem detail = packout.getCurrentPackoutItem();
|
||||
log.log(Level.INFO,
|
||||
"In PackOut.java handling Code or Other 2pack module creation");
|
||||
String fileDirectory = header.getFile_Directory() + header.getName()
|
||||
+ detail.getTarget_Directory();
|
||||
String fileDirectory = packout.getPackoutDirectory() + header.getPackageName()
|
||||
+ detail.getProperty(FileElementParameters.TARGET_DIRECTORY);
|
||||
log.log(Level.INFO, "targetDirectory" + fileDirectory);
|
||||
String targetDirectory = null;
|
||||
char fileseperator1 = '/';
|
||||
|
@ -41,7 +42,7 @@ public class FileElementHandler implements ElementHandler {
|
|||
fileseperator2);
|
||||
|
||||
String sourceDirectory = null;
|
||||
fileDirectory = detail.getFile_Directory();
|
||||
fileDirectory = (String) detail.getProperty(FileElementParameters.SOURCE_DIRECTORY);
|
||||
// Correct package for proper file seperator
|
||||
if (File.separator.equals("/")) {
|
||||
sourceDirectory = fileDirectory.replace(fileseperator2,
|
||||
|
@ -50,14 +51,14 @@ public class FileElementHandler implements ElementHandler {
|
|||
sourceDirectory = fileDirectory.replace(fileseperator2,
|
||||
fileseperator1);
|
||||
|
||||
packout.copyFile(sourceDirectory + detail.getFileName(),
|
||||
targetDirectory + detail.getFileName());
|
||||
packout.copyFile(sourceDirectory + detail.getProperty(FileElementParameters.FILE_NAME),
|
||||
targetDirectory + detail.getProperty(FileElementParameters.FILE_NAME));
|
||||
|
||||
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;
|
||||
|
||||
// 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",
|
||||
"File: " + detail.getFileName(), atts);
|
||||
"File: " + detail.getProperty(FileElementParameters.FILE_NAME), atts);
|
||||
}
|
||||
PackOut.addTextElement(docHandler, "filedirectory", "Directory: "
|
||||
+ detail.getTarget_Directory(), atts);
|
||||
+ detail.getProperty(FileElementParameters.TARGET_DIRECTORY), atts);
|
||||
PackOut.addTextElement(docHandler, "filenotes",
|
||||
"Notes: " + detail.getDescription(), atts);
|
||||
"Notes: " + detail.getProperty(FileElementParameters.DESCRIPTION), atts);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,18 +28,18 @@ import javax.xml.transform.sax.TransformerHandler;
|
|||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.adempiere.model.GenericPO;
|
||||
import org.adempiere.pipo2.AbstractElementHandler;
|
||||
import org.adempiere.pipo2.DataElementParameters;
|
||||
import org.adempiere.pipo2.PackoutItem;
|
||||
import org.adempiere.pipo2.PoExporter;
|
||||
import org.adempiere.pipo2.Element;
|
||||
import org.adempiere.pipo2.PackOut;
|
||||
import org.adempiere.pipo2.PoFiller;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POInfo;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
|
@ -83,7 +83,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
|
|||
String searchColumn = info.getColumnLookup(i).getColumnName();
|
||||
parentTableName = searchColumn.substring(0, searchColumn.indexOf("."));
|
||||
}
|
||||
|
||||
|
||||
Element parent = element.parent;
|
||||
while (parent != null) {
|
||||
if (parent.getElementValue().equalsIgnoreCase(parentTableName)) {
|
||||
|
@ -135,7 +135,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
|
|||
throws SAXException {
|
||||
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;
|
||||
if (sql.indexOf(";") > 0) {
|
||||
components = sql.split("[;]");
|
||||
|
@ -143,7 +143,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
|
|||
} else {
|
||||
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);
|
||||
List<String> excludes = defaultExcludeList(tableName);
|
||||
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
|
||||
{
|
||||
MPackageExpDetail detail = packout.getPackageExpDetail();
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, detail.getAD_Table_ID());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement());
|
||||
PackoutItem detail = packout.getCurrentPackoutItem();
|
||||
Env.setContext(packout.getCtx(), DataElementParameters.AD_TABLE_ID, (Integer)detail.getProperty(DataElementParameters.AD_TABLE_ID));
|
||||
Env.setContext(packout.getCtx(), DataElementParameters.SQL_STATEMENT, (String)detail.getProperty(DataElementParameters.SQL_STATEMENT));
|
||||
this.create(packout.getCtx(), packoutHandler);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
|
||||
packout.getCtx().remove(DataElementParameters.AD_TABLE_ID);
|
||||
packout.getCtx().remove(DataElementParameters.SQL_STATEMENT);
|
||||
}
|
||||
}
|
|
@ -27,8 +27,8 @@ import javax.xml.transform.sax.TransformerHandler;
|
|||
import org.adempiere.pipo2.AbstractElementHandler;
|
||||
import org.adempiere.pipo2.Element;
|
||||
import org.adempiere.pipo2.PackOut;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.adempiere.pipo2.PackoutItem;
|
||||
import org.adempiere.pipo2.SQLElementParameters;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -90,8 +90,8 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
|
|||
|
||||
public void create(Properties ctx, TransformerHandler document)
|
||||
throws SAXException {
|
||||
String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
|
||||
String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
|
||||
String SQLStatement = Env.getContext(ctx, SQLElementParameters.SQL_STATEMENT);
|
||||
String DBType = Env.getContext(ctx, SQLElementParameters.DB_TYPE);
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
addTypeName(atts, "custom");
|
||||
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
|
||||
{
|
||||
MPackageExpDetail detail = packout.getPackageExpDetail();
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement, detail.getSQLStatement());
|
||||
Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_DBType, detail.getDBType());
|
||||
PackoutItem detail = packout.getCurrentPackoutItem();
|
||||
Env.setContext(packout.getCtx(), SQLElementParameters.SQL_STATEMENT, (String)detail.getProperty(SQLElementParameters.SQL_STATEMENT));
|
||||
Env.setContext(packout.getCtx(), SQLElementParameters.DB_TYPE, (String)detail.getProperty(SQLElementParameters.DB_TYPE));
|
||||
this.create(packout.getCtx(), packoutHandler);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
|
||||
packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
|
||||
packout.getCtx().remove(SQLElementParameters.SQL_STATEMENT);
|
||||
packout.getCtx().remove(SQLElementParameters.DB_TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,14 @@
|
|||
class="org.adempiere.pipo.srv.PipoDictionaryService">
|
||||
</client>
|
||||
</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>
|
||||
|
|
|
@ -5,13 +5,8 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.adempiere.base.IDictionaryService;
|
||||
import org.adempiere.pipo2.PackIn;
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.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.Trx;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
@ -20,9 +15,6 @@ public class PipoDictionaryService implements IDictionaryService {
|
|||
|
||||
Logger logger = Logger.getLogger(PipoDictionaryService.class.getName());
|
||||
|
||||
/** official packin process id **/
|
||||
private final static int PACKIN_PROCESS_ID = 50008;
|
||||
|
||||
@Override
|
||||
public void merge(BundleContext context, File packageFile) throws Exception {
|
||||
if (packageFile == null || !packageFile.exists()) {
|
||||
|
@ -31,25 +23,12 @@ public class PipoDictionaryService implements IDictionaryService {
|
|||
}
|
||||
String trxName = Trx.createTrxName();
|
||||
try {
|
||||
MProcess process = new MProcess(Env.getCtx(), PACKIN_PROCESS_ID, trxName);
|
||||
X_AD_Package_Imp_Proc packageImp = new X_AD_Package_Imp_Proc(Env.getCtx(), 0, trxName);
|
||||
packageImp.setAD_Override_Dict(false);
|
||||
packageImp.setAD_Package_Dir(getPackageDir());
|
||||
packageImp.setAD_Package_Source(packageFile.getAbsolutePath());
|
||||
packageImp.setAD_Package_Source_Type(X_AD_Package_Imp_Proc.AD_PACKAGE_SOURCE_TYPE_File);
|
||||
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));
|
||||
PackIn packIn = new PackIn();
|
||||
packIn.setPackageName(context.getBundle().getSymbolicName());
|
||||
packIn.setPackageVersion((String) context.getBundle().getHeaders().get("Bundle-Version"));
|
||||
packIn.setUpdateDictionary(false);
|
||||
packIn.setPackageDirectory(getPackageDir());
|
||||
packIn.importXML(packageFile.getAbsolutePath(), Env.getCtx(), trxName);
|
||||
Trx.get(trxName, false).commit();
|
||||
logger.info("commit " + trxName);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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";
|
||||
}
|
|
@ -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";
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -31,32 +31,20 @@ import java.util.logging.Level;
|
|||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.model.X_AD_Package_Imp_Proc;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.CLogMgt;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Ini;
|
||||
import org.compiere.util.Trx;
|
||||
|
||||
/**
|
||||
* IntPackIn Tool.
|
||||
*
|
||||
* @author: Robert KLEIN. robeklein@hotmail.com
|
||||
*/
|
||||
public class PackIn extends SvrProcess {
|
||||
public class PackIn {
|
||||
|
||||
/** Logger */
|
||||
private CLogger log = CLogger.getCLogger(getClass());
|
||||
//update system maintain dictionary, default to false
|
||||
private boolean m_UpdateDictionary = false;
|
||||
private String m_Database = "Oracle";
|
||||
private String m_Package_Dir = null;
|
||||
public int p_PackIn_ID = 0;
|
||||
private String m_packageDirectory = null;
|
||||
|
||||
private Map<String,Integer> tableCache = new HashMap<String,Integer>();
|
||||
private Map<String,Integer> columnCache = new HashMap<String,Integer>();
|
||||
|
@ -65,10 +53,6 @@ public class PackIn extends SvrProcess {
|
|||
|
||||
public PackIn() {
|
||||
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;
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @param fileName
|
||||
* xml file to read
|
||||
* @param fileName xml file to read
|
||||
* @return status message
|
||||
*/
|
||||
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) {
|
||||
try {
|
||||
log.info("starting");
|
||||
// clear cache of previous runs
|
||||
IDFinder.clearIDCache();
|
||||
|
||||
System.setProperty("javax.xml.parsers.SAXParserFactory",
|
||||
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
||||
PackInHandler handler = new PackInHandler();
|
||||
|
@ -167,7 +145,7 @@ public class PackIn extends SvrProcess {
|
|||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
SAXParser parser = factory.newSAXParser();
|
||||
String msg = "Start Parser";
|
||||
log.info(msg);
|
||||
log.info(msg);
|
||||
parser.parse(input, handler);
|
||||
msg = "End Parser";
|
||||
log.info(msg);
|
||||
|
@ -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() {
|
||||
return m_Package_Dir;
|
||||
return m_packageDirectory;
|
||||
}
|
||||
|
||||
public void setPackageDirectory(String packageDirectory) {
|
||||
m_Package_Dir = packageDirectory;
|
||||
}
|
||||
|
||||
public String getDatabaseType() {
|
||||
return m_Database;
|
||||
m_packageDirectory = packageDirectory;
|
||||
}
|
||||
|
||||
public boolean isUpdateDictionary() {
|
||||
|
@ -263,7 +174,7 @@ public class PackIn extends SvrProcess {
|
|||
|
||||
public byte[] readBlob(String fileName) throws IOException {
|
||||
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;
|
||||
|
||||
try {
|
||||
|
@ -286,14 +197,22 @@ public class PackIn extends SvrProcess {
|
|||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return package name
|
||||
*/
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param packageName
|
||||
*/
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return package Version
|
||||
*/
|
||||
|
@ -301,96 +220,11 @@ public class PackIn extends SvrProcess {
|
|||
return packageVersion;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
* XMLfile host port db username password
|
||||
* @param packageVersion
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out
|
||||
.println("Please give the file name to read as first parameter.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String file = args[0];
|
||||
org.compiere.Adempiere.startup(true);
|
||||
|
||||
// globalqss - added argument 8 to generate system sequences
|
||||
if (args.length > 8 && args[8].equals(Ini.P_ADEMPIERESYS)) {
|
||||
System.out.println("**** WARNING: Working with system sequences "
|
||||
+ Ini.P_ADEMPIERESYS + " ****");
|
||||
Ini.setProperty(Ini.P_ADEMPIERESYS, true);
|
||||
}
|
||||
|
||||
PackIn packIn = new PackIn();
|
||||
// org.compiere.Compiere.startupEnvironment(true);
|
||||
// Force connection if there are enough parameters. Else we work with
|
||||
// Compiere.properties
|
||||
if (args.length >= 6) {
|
||||
// CConnection cc = CConnection.get("PostgreSQL", args[1],
|
||||
// Integer.valueOf(args[2]).intValue(), args[5], args[3], args[4]);
|
||||
CConnection cc = CConnection.get();
|
||||
// System.out.println("DB Connect String1:"+cc.getDbName());
|
||||
packIn.m_Database = cc.getType();
|
||||
DB.setDBTarget(cc);
|
||||
}
|
||||
|
||||
// Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO,
|
||||
// Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL
|
||||
|
||||
Level logLevel = Level.FINER;
|
||||
|
||||
switch (Integer.parseInt(args[6])) {
|
||||
case 1:
|
||||
logLevel = Level.OFF;
|
||||
break;
|
||||
case 2:
|
||||
logLevel = Level.SEVERE;
|
||||
break;
|
||||
case 3:
|
||||
logLevel = Level.WARNING;
|
||||
break;
|
||||
case 4:
|
||||
logLevel = Level.INFO;
|
||||
break;
|
||||
case 5:
|
||||
logLevel = Level.CONFIG;
|
||||
break;
|
||||
case 6:
|
||||
logLevel = Level.FINE;
|
||||
break;
|
||||
case 7:
|
||||
logLevel = Level.FINER;
|
||||
break;
|
||||
case 8:
|
||||
logLevel = Level.FINEST;
|
||||
break;
|
||||
case 9:
|
||||
logLevel = Level.ALL;
|
||||
break;
|
||||
}
|
||||
CLogMgt.setLevel(logLevel);
|
||||
CLogMgt.setLoggerLevel(logLevel, null);
|
||||
|
||||
if (args.length >= 8)
|
||||
packIn.m_UpdateDictionary = Boolean.valueOf(args[7]);
|
||||
|
||||
String trxName = Trx.createTrxName("PackIn");
|
||||
try {
|
||||
packIn.importXML(file, Env.getCtx(), trxName);
|
||||
Trx trx = Trx.get(trxName, false);
|
||||
if (trx != null)
|
||||
trx.commit(true);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Import Failed: " + e.getLocalizedMessage());
|
||||
Trx trx = Trx.get(trxName, false);
|
||||
if (trx != null)
|
||||
trx.rollback();
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
} // main
|
||||
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
} // PackIn
|
||||
|
|
|
@ -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
|
|
@ -38,26 +38,10 @@ import javax.xml.transform.sax.SAXTransformerFactory;
|
|||
import javax.xml.transform.sax.TransformerHandler;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.compiere.model.I_AD_Form;
|
||||
import org.compiere.model.I_AD_ImpFormat;
|
||||
import org.compiere.model.I_AD_Menu;
|
||||
import org.compiere.model.I_AD_Message;
|
||||
import org.compiere.model.I_AD_PrintFormat;
|
||||
import org.compiere.model.I_AD_Process;
|
||||
import org.compiere.model.I_AD_Reference;
|
||||
import org.compiere.model.I_AD_ReportView;
|
||||
import org.compiere.model.I_AD_Role;
|
||||
import org.compiere.model.I_AD_Table;
|
||||
import org.compiere.model.I_AD_Val_Rule;
|
||||
import org.compiere.model.I_AD_Window;
|
||||
import org.compiere.model.I_AD_Workflow;
|
||||
import org.compiere.model.MClient;
|
||||
import org.compiere.model.MPackageExp;
|
||||
import org.compiere.model.MPackageExpDetail;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
|
@ -76,32 +60,28 @@ import org.adempiere.exceptions.AdempiereException;
|
|||
* <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";
|
||||
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 MPackageExp packageExp;
|
||||
private MPackageExpDetail packageExpDetail;
|
||||
private String packOutDir;
|
||||
private String packageDir;
|
||||
private String packageDirectory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
p_PackOut_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
||||
public static void addTextElement(TransformerHandler handler, String qName, String text, AttributesImpl atts) throws SAXException {
|
||||
handler.startElement("", "", qName, atts);
|
||||
|
@ -116,75 +96,60 @@ public class PackOut extends SvrProcess
|
|||
}
|
||||
|
||||
/**
|
||||
* Start the transformation to XML
|
||||
* @return info
|
||||
* @throws Exception
|
||||
* Start the transformation to XML
|
||||
* @param packoutDirectory
|
||||
* @param destinationPath
|
||||
* @param packoutDocument
|
||||
* @param packoutItems
|
||||
* @param trxName
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
|
||||
protected String doIt() throws java.lang.Exception
|
||||
public void export(String packoutDirectory, String destinationPath, PackoutDocument packoutDocument, List<PackoutItem> packoutItems, String trxName) throws java.lang.Exception
|
||||
{
|
||||
this.packoutDirectory = packoutDirectory;
|
||||
this.packoutDocument = packoutDocument;
|
||||
this.trxName = trxName;
|
||||
|
||||
initContext();
|
||||
|
||||
handlerRegistry = new OSGiHandlerRegistry();
|
||||
OutputStream docStream = null;
|
||||
OutputStream packoutStream = null;
|
||||
|
||||
OutputStream packageDocStream = null;
|
||||
OutputStream packOutDocStream = null;
|
||||
log.info("doIt - AD_PACKAGE_EXP_ID=" + p_PackOut_ID);
|
||||
|
||||
if (p_PackOut_ID == 0)
|
||||
throw new IllegalArgumentException("No Record");
|
||||
|
||||
int processedCount = 0;
|
||||
processedCount = 0;
|
||||
try {
|
||||
|
||||
packageExp = new MPackageExp(getCtx(), p_PackOut_ID, get_TrxName());
|
||||
|
||||
if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){
|
||||
//Create the package documentation
|
||||
packOutDir = packageExp.getFile_Directory().trim();
|
||||
if (!packOutDir.endsWith("/") && !packOutDir.endsWith("\\"))
|
||||
packOutDir+= File.separator;
|
||||
packageDir = packOutDir+ packageExp.getName();
|
||||
File packageDocDirFile = new File(packageDir+File.separator+"doc"+File.separator);
|
||||
if (!packageDocDirFile.exists()) {
|
||||
boolean success = packageDocDirFile.mkdirs();
|
||||
if (!success) {
|
||||
throw new AdempiereException("Failed to create directory for pack out. " + packageDir+File.separator+"doc"+File.separator);
|
||||
}
|
||||
packageDirectory = packoutDirectory+ packoutDocument.getPackageName();
|
||||
File docDirectoryFile = new File(packageDirectory+File.separator+"doc"+File.separator);
|
||||
if (!docDirectoryFile.exists()) {
|
||||
boolean success = docDirectoryFile.mkdirs();
|
||||
if (!success) {
|
||||
throw new AdempiereException("Failed to create directory for pack out. " + packageDirectory+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)
|
||||
{
|
||||
|
@ -194,53 +159,57 @@ public class PackOut extends SvrProcess
|
|||
finally
|
||||
{
|
||||
// Close streams - teo_sarca [ 1704762 ]
|
||||
if (packageDocStream != null)
|
||||
if (docStream != null)
|
||||
try {
|
||||
packageDocStream.close();
|
||||
docStream.close();
|
||||
} catch (Exception e) {}
|
||||
if (packOutDocStream != null)
|
||||
if (packoutStream != null)
|
||||
try {
|
||||
packOutDocStream.close();
|
||||
packoutStream.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
//create compressed packages
|
||||
//set the files
|
||||
File srcFolder = new File(packOutDir);
|
||||
File destZipFile = new File(packageDir+".zip");
|
||||
|
||||
File srcFolder = new File(packoutDirectory);
|
||||
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
|
||||
destZipFile.delete();
|
||||
|
||||
//create the compressed packages
|
||||
String includesdir = packageExp.getName() + File.separator +"**";
|
||||
String includesdir = packoutDocument.getPackageName() + File.separator +"**";
|
||||
Zipper.zipFolder(srcFolder, destZipFile, includesdir);
|
||||
|
||||
return "Exported="+processedCount + " File=" + destZipFile.getAbsolutePath();
|
||||
exportFile = destZipFile.getAbsolutePath();
|
||||
} // doIt
|
||||
|
||||
private TransformerHandler createPackOutDoc(MPackageExp packageExp,
|
||||
OutputStream packOutDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
|
||||
StreamResult packOutStreamResult = new StreamResult(new OutputStreamWriter(packOutDocStream,"utf-8"));
|
||||
SAXTransformerFactory packOutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
|
||||
packOutFactory.setAttribute("indent-number", new Integer(4));
|
||||
TransformerHandler packOutDocument = packOutFactory.newTransformerHandler();
|
||||
Transformer packOutTransformer = packOutDocument.getTransformer();
|
||||
packOutTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
|
||||
packOutTransformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
||||
packOutDocument.setResult(packOutStreamResult);
|
||||
packOutDocument.startDocument();
|
||||
private TransformerHandler createPackoutHandler(
|
||||
OutputStream packoutStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
|
||||
StreamResult packoutStreamResult = new StreamResult(new OutputStreamWriter(packoutStream,"utf-8"));
|
||||
SAXTransformerFactory packoutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
|
||||
packoutFactory.setAttribute("indent-number", new Integer(4));
|
||||
TransformerHandler packoutHandler = packoutFactory.newTransformerHandler();
|
||||
Transformer packoutTransformer = packoutHandler.getTransformer();
|
||||
packoutTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
|
||||
packoutTransformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
||||
packoutHandler.setResult(packoutStreamResult);
|
||||
packoutHandler.startDocument();
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute("","","Name","CDATA",packageExp.getName());
|
||||
atts.addAttribute("","","Version","CDATA",packageExp.getPK_Version());
|
||||
atts.addAttribute("","","AdempiereVersion","CDATA",packageExp.getReleaseNo());
|
||||
atts.addAttribute("","","DataBase","CDATA",packageExp.getVersion());
|
||||
atts.addAttribute("","","Description","CDATA",packageExp.getDescription());
|
||||
atts.addAttribute("","","Creator","CDATA",packageExp.getUserName());
|
||||
atts.addAttribute("","","CreatorContact","CDATA",packageExp.getEMail());
|
||||
atts.addAttribute("","","CreatedDate","CDATA",packageExp.getCreated().toString());
|
||||
atts.addAttribute("","","UpdatedDate","CDATA",packageExp.getUpdated().toString());
|
||||
atts.addAttribute("","","PackOutVersion","CDATA",PackOutVer);
|
||||
atts.addAttribute("","","Name","CDATA",packoutDocument.getPackageName());
|
||||
atts.addAttribute("","","Version","CDATA",packoutDocument.getPackageVersion());
|
||||
atts.addAttribute("","","AdempiereVersion","CDATA",packoutDocument.getAdempiereVersion());
|
||||
atts.addAttribute("","","DataBaseVersion","CDATA",packoutDocument.getDatabaseVersion());
|
||||
atts.addAttribute("","","Description","CDATA",emptyIfNull(packoutDocument.getDescription()));
|
||||
atts.addAttribute("","","Author","CDATA",packoutDocument.getAuthor());
|
||||
atts.addAttribute("","","AuthorEmail","CDATA",emptyIfNull(packoutDocument.getAuthorEmail()));
|
||||
atts.addAttribute("","","CreatedDate","CDATA",packoutDocument.getCreated().toString());
|
||||
atts.addAttribute("","","UpdatedDate","CDATA",packoutDocument.getUpdated().toString());
|
||||
atts.addAttribute("","","PackOutVersion","CDATA",PackOutVersion);
|
||||
|
||||
MClient client = MClient.get(localContext);
|
||||
StringBuffer sb = new StringBuffer ()
|
||||
|
@ -251,42 +220,46 @@ public class PackOut extends SvrProcess
|
|||
.append(client.getName());
|
||||
atts.addAttribute("", "", "Client", "CDATA", sb.toString());
|
||||
|
||||
packOutDocument.startElement("","","adempiereAD",atts);
|
||||
return packOutDocument;
|
||||
packoutHandler.startElement("","","adempiereAD",atts);
|
||||
return packoutHandler;
|
||||
}
|
||||
|
||||
private TransformerHandler createPackageDoc(MPackageExp packageExp, OutputStream packageDocStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException {
|
||||
StreamResult docStreamResult = new StreamResult(new OutputStreamWriter(packageDocStream,"utf-8"));
|
||||
private String emptyIfNull(String input) {
|
||||
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();
|
||||
transformerFactory.setAttribute("indent-number", new Integer(4));
|
||||
TransformerHandler packageDocument = transformerFactory.newTransformerHandler();
|
||||
Transformer transformer = packageDocument.getTransformer();
|
||||
TransformerHandler docHandler = transformerFactory.newTransformerHandler();
|
||||
Transformer transformer = docHandler.getTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
|
||||
transformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
||||
packageDocument.setResult(docStreamResult);
|
||||
packageDocument.startDocument();
|
||||
packageDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
|
||||
docHandler.setResult(docStreamResult);
|
||||
docHandler.startDocument();
|
||||
docHandler.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\"");
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
packageDocument.startElement("","","adempiereDocument",atts);
|
||||
addTextElement(packageDocument, "header", packageExp.getName()+" Package Description", atts);
|
||||
addTextElement(packageDocument, "H1", "Package Name:", atts);
|
||||
addTextElement(packageDocument, "packagename", packageExp.getName(), atts);
|
||||
addTextElement(packageDocument, "H1", "Author:", atts);
|
||||
addTextElement(packageDocument, "creator", packageExp.getUserName(), atts);
|
||||
addTextElement(packageDocument, "H1", "Email Address:", atts);
|
||||
addTextElement(packageDocument, "creatorcontact", packageExp.getEMail(), atts);
|
||||
addTextElement(packageDocument, "H1", "Created:", atts);
|
||||
addTextElement(packageDocument, "createddate", packageExp.getCreated().toString(), atts);
|
||||
addTextElement(packageDocument, "H1", "Updated:", atts);
|
||||
addTextElement(packageDocument, "updateddate", packageExp.getUpdated().toString(), atts);
|
||||
addTextElement(packageDocument, "H1", "Description:", atts);
|
||||
addTextElement(packageDocument, "description", packageExp.getDescription(), atts);
|
||||
addTextElement(packageDocument, "H1", "Instructions:", atts);
|
||||
addTextElement(packageDocument, "instructions", packageExp.getInstructions(), atts);
|
||||
addTextElement(packageDocument, "H1", "Files in Package:", atts);
|
||||
addTextElement(packageDocument, "file", "File: PackOut.xml", atts);
|
||||
addTextElement(packageDocument, "filedirectory", "Directory: \\dict\\", atts);
|
||||
addTextElement(packageDocument, "filenotes", "Notes: Contains all application/object settings for package", atts);
|
||||
docHandler.startElement("","","adempiereDocument",atts);
|
||||
addTextElement(docHandler, "header", packoutDocument.getPackageName()+" Package Description", atts);
|
||||
addTextElement(docHandler, "H1", "Package Name:", atts);
|
||||
addTextElement(docHandler, "packagename", packoutDocument.getPackageName(), atts);
|
||||
addTextElement(docHandler, "H1", "Author:", atts);
|
||||
addTextElement(docHandler, "Name:", packoutDocument.getAuthor(), atts);
|
||||
addTextElement(docHandler, "H1", "Email Address:", atts);
|
||||
addTextElement(docHandler, "Email", packoutDocument.getAuthorEmail(), atts);
|
||||
addTextElement(docHandler, "H1", "Created:", atts);
|
||||
addTextElement(docHandler, "Date", packoutDocument.getCreated().toString(), atts);
|
||||
addTextElement(docHandler, "H1", "Updated:", atts);
|
||||
addTextElement(docHandler, "Date", packoutDocument.getUpdated().toString(), atts);
|
||||
addTextElement(docHandler, "H1", "Description:", atts);
|
||||
addTextElement(docHandler, "description", packoutDocument.getDescription(), atts);
|
||||
addTextElement(docHandler, "H1", "Instructions:", atts);
|
||||
addTextElement(docHandler, "instructions", packoutDocument.getInstructions(), atts);
|
||||
addTextElement(docHandler, "H1", "Files in Package:", atts);
|
||||
addTextElement(docHandler, "file", "File: PackOut.xml", atts);
|
||||
addTextElement(docHandler, "filedirectory", "Directory: \\dict\\", atts);
|
||||
addTextElement(docHandler, "filenotes", "Notes: Contains all application/object settings for package", atts);
|
||||
|
||||
MClient client = MClient.get(localContext);
|
||||
StringBuffer sb = new StringBuffer ()
|
||||
|
@ -295,62 +268,24 @@ public class PackOut extends SvrProcess
|
|||
.append(client.getValue())
|
||||
.append("-")
|
||||
.append(client.getName());
|
||||
addTextElement(packageDocument, "H1", "Client:", atts);
|
||||
addTextElement(packageDocument, "Client", sb.toString(), atts);
|
||||
addTextElement(docHandler, "H1", "Client:", 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()) {
|
||||
boolean success = packageDictDirFile.mkdirs();
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
return docHandler;
|
||||
}
|
||||
|
||||
private void initContext() {
|
||||
Properties tmp = new Properties();
|
||||
if (getCtx() != null)
|
||||
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);
|
||||
localContext = tmp;
|
||||
}
|
||||
|
@ -417,9 +352,8 @@ public class PackOut extends SvrProcess
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
blobCount++;
|
||||
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();
|
||||
File file = new File(path, fileName);
|
||||
FileOutputStream os = null;
|
||||
|
@ -447,19 +381,24 @@ public class PackOut extends SvrProcess
|
|||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MPackageExp
|
||||
*/
|
||||
public MPackageExp getPackageExp() {
|
||||
return packageExp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MPackageExpDetail
|
||||
*/
|
||||
public MPackageExpDetail getPackageExpDetail() {
|
||||
return packageExpDetail;
|
||||
public PackoutItem getCurrentPackoutItem() {
|
||||
return packoutItem;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return PackoutDocument
|
||||
*/
|
||||
public PackoutDocument getPackoutDocument() {
|
||||
return packoutDocument;
|
||||
}
|
||||
|
||||
public String getPackoutDirectory() {
|
||||
return packoutDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -469,4 +408,18 @@ public class PackOut extends SvrProcess
|
|||
public ElementHandler getHandler(String 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
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
|
@ -13,18 +13,24 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.apps;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
import org.adempiere.base.IGridTabExporter;
|
||||
import org.adempiere.base.Service;
|
||||
import org.compiere.grid.GridController;
|
||||
import org.compiere.grid.VTabbedPane;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.util.CLogMgt;
|
||||
import org.compiere.util.CLogger;
|
||||
|
@ -41,6 +47,7 @@ public class AExport
|
|||
private int m_WindowNo = 0;
|
||||
private Map<String, IGridTabExporter> exporterMap = null;
|
||||
private Map<String, String> extensionMap = null;
|
||||
private APanel parent;
|
||||
|
||||
public AExport(APanel parent)
|
||||
{
|
||||
|
@ -91,6 +98,7 @@ public class AExport
|
|||
log.config( "File=" + outFile.getPath() + "; Type=" + ext);
|
||||
|
||||
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
this.parent = parent;
|
||||
try
|
||||
{
|
||||
if (extensionMap.containsKey(ext))
|
||||
|
@ -117,7 +125,41 @@ public class AExport
|
|||
private void export(File outFile, GridTab tab, String extension)
|
||||
throws Exception
|
||||
{
|
||||
boolean currentRowOnly = ADialog.ask(m_WindowNo, parent, "Export current row only ?");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -533,7 +533,7 @@ public final class APanel extends CPanel
|
|||
for (IMenuAction action:osgiActions) {
|
||||
action.addAction(menuBar);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
if (CLogMgt.isLevelAll())
|
||||
Util.printActionInputMap(this);
|
||||
|
@ -2871,7 +2871,17 @@ public final class APanel extends CPanel
|
|||
getActionMap().put(aSwitchLinesUpAction.getName(), aSwitchLinesUpAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isNested() {
|
||||
return isNested;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JTabbedPane
|
||||
*/
|
||||
public JTabbedPane getCurrentTabbedPane() {
|
||||
return m_curWinTab;
|
||||
}
|
||||
} // APanel
|
||||
|
|
|
@ -14,21 +14,28 @@
|
|||
package org.adempiere.webui.panel.action;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.adempiere.base.IGridTabExporter;
|
||||
import org.adempiere.base.Service;
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.Checkbox;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.IADTab;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.ListItem;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.panel.AbstractADWindowPanel;
|
||||
import org.adempiere.webui.panel.IADTabpanel;
|
||||
import org.adempiere.webui.window.FDialog;
|
||||
import org.compiere.model.GridTab;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.zkoss.util.media.AMedia;
|
||||
|
@ -54,6 +61,7 @@ public class ExportAction implements EventListener
|
|||
private Window winExportFile = null;
|
||||
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
|
||||
private Listbox cboType = new Listbox();
|
||||
private Checkbox chkCurrentRow = new Checkbox();
|
||||
|
||||
/**
|
||||
* @param panel
|
||||
|
@ -100,6 +108,10 @@ public class ExportAction implements EventListener
|
|||
|
||||
cboType.setSelectedIndex(0);
|
||||
|
||||
Vbox vb = new Vbox();
|
||||
vb.setWidth("390px");
|
||||
winExportFile.appendChild(vb);
|
||||
|
||||
Hbox hb = new Hbox();
|
||||
Div div = new Div();
|
||||
div.setAlign("right");
|
||||
|
@ -107,11 +119,14 @@ public class ExportAction implements EventListener
|
|||
hb.appendChild(div);
|
||||
hb.appendChild(cboType);
|
||||
cboType.setWidth("100%");
|
||||
|
||||
Vbox vb = new Vbox();
|
||||
vb.setWidth("390px");
|
||||
winExportFile.appendChild(vb);
|
||||
vb.appendChild(hb);
|
||||
|
||||
hb = new Hbox();
|
||||
chkCurrentRow.setLabel("Export Current Row Only");
|
||||
chkCurrentRow.setSelected(true);
|
||||
hb.appendChild(chkCurrentRow);
|
||||
vb.appendChild(hb);
|
||||
|
||||
vb.appendChild(confirmPanel);
|
||||
confirmPanel.addActionListener(this);
|
||||
}
|
||||
|
@ -144,8 +159,37 @@ public class ExportAction implements EventListener
|
|||
return;
|
||||
}
|
||||
|
||||
boolean currentRowOnly = chkCurrentRow.isSelected();
|
||||
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 = null;
|
||||
|
|
Loading…
Reference in New Issue