IDEMPIERE-4905 : Export data from AD_ReportView_Column while exportin… (#818)

* IDEMPIERE-4905 : Export data from AD_ReportView_Column while exporting a ReportView with 2Pack

* IDEMPIERE-4905 : Export data from AD_ReportView_Column while exporting a ReportView with 2Pack - fix licence header + add author javadoc + remove a system.out.println

* IDEMPIERE-4905 : Export data from AD_ReportView_Column while exporting a ReportView with 2Pack

Remove unnecessary if condition

* IDEMPIERE-4905 : Export data from AD_ReportView_Column while exporting a ReportView with 2Pack

Instead of Env.get/setContext, you can use ctx.ctx.get/set
This commit is contained in:
Nicolas Micoud 2021-09-03 16:02:18 +02:00 committed by GitHub
parent 3cf82cbd78
commit 02d4b54714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 186 additions and 1 deletions

View File

@ -136,6 +136,10 @@
class="org.adempiere.pipo2.handler.ReportViewColElementHandler" class="org.adempiere.pipo2.handler.ReportViewColElementHandler"
id="AD_ReportView_Col"> id="AD_ReportView_Col">
</handler> </handler>
<handler
class="org.adempiere.pipo2.handler.ReportViewColumnElementHandler"
id="AD_ReportView_Column">
</handler>
<handler <handler
class="org.adempiere.pipo2.handler.PrintFormatElementHandler" class="org.adempiere.pipo2.handler.PrintFormatElementHandler"
id="AD_PrintFormat"> id="AD_PrintFormat">

View File

@ -0,0 +1,150 @@
/***********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Nicolas Micoud (TGI) *
**********************************************************************/
package org.adempiere.pipo2.handler;
import java.util.List;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_ReportView_Column;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/**
* Report View Column (AD_ReportView_Column) element handler
* @author Nicolas Micoud (TGI)
*/
public class ReportViewColumnElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element)
throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_ReportView_Column.Table_Name);
String entitytype = getStringValue(element,"EntityType");
if (isProcessElement(ctx.ctx, entitytype)) {
excludes.add("AD_Table_ID");
X_AD_ReportView_Column mReportviewColumn = findPO(ctx, element);
if (mReportviewColumn == null) {
mReportviewColumn = new X_AD_ReportView_Column(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mReportviewColumn, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
element.unresolved = notfounds.toString();
return;
}
if (mReportviewColumn.is_new() || mReportviewColumn.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView_Column.Table_Name,
X_AD_ReportView_Column.Table_ID);
String action = null;
if (!mReportviewColumn.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView_Column.Table_Name,
mReportviewColumn);
action = "Update";
} else {
action = "New";
}
if (mReportviewColumn.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, "" + mReportviewColumn.getAD_ReportView_ID(),
mReportviewColumn.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, "" + mReportviewColumn.getAD_ReportView_ID(),
mReportviewColumn.get_ID(),action);
throw new POSaveFailedException("Failed to save ReportViewColumn");
}
}
} else {
element.skip = true;
}
}
public void endElement(PIPOContext ctx, Element element) throws SAXException {
}
public void create(PIPOContext ctx, TransformerHandler document)
throws SAXException {
X_AD_ReportView_Column po = (X_AD_ReportView_Column) ctx.ctx.get("po");
if (po != null) {
if (!isPackOutElement(ctx, po))
return;
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_ReportView_Column.Table_Name, atts);
createReportViewColumnBinding(ctx, document, po);
document.endElement("", "", X_AD_ReportView_Column.Table_Name);
}
}
private void createReportViewColumnBinding(PIPOContext ctx, TransformerHandler document,
X_AD_ReportView_Column m_Reportview_Column) {
PoExporter filler = new PoExporter(ctx, document, m_Reportview_Column);
List<String> excludes = defaultExcludeList(X_AD_ReportView_Column.Table_Name);
filler.add("AD_ReportView_Column_UU", new AttributesImpl());
filler.export(excludes);
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId)
throws Exception {
throw new AdempiereException("X_AD_ReportView_Column doesn't have ID, use method with UUID");
}
@Override
public void packOut(PackOut packout, TransformerHandler packoutHandler,
TransformerHandler docHandler,
int recordId, String uuid) throws Exception {
X_AD_ReportView_Column po = new Query(packout.getCtx().ctx, X_AD_ReportView_Column.Table_Name, "X_AD_ReportView_Column_UU=?", getTrxName(packout.getCtx()))
.setParameters(uuid)
.first();
if (po != null) {
packout.getCtx().ctx.put("po", po);
this.create(packout.getCtx(), packoutHandler);
packout.getCtx().ctx.remove("po", po);
} else {
throw new AdempiereException("AD_Process_Access_UU not found = " + uuid);
}
}
}

View File

@ -34,10 +34,12 @@ import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormat; import org.compiere.model.I_AD_PrintFormat;
import org.compiere.model.I_AD_ReportView; import org.compiere.model.I_AD_ReportView;
import org.compiere.model.I_AD_Table; import org.compiere.model.I_AD_Table;
import org.compiere.model.MReportView;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.MReportView;
import org.compiere.model.X_AD_ReportView_Col; import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.model.X_AD_ReportView_Column;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -46,6 +48,7 @@ import org.xml.sax.helpers.AttributesImpl;
public class ReportViewElementHandler extends AbstractElementHandler { public class ReportViewElementHandler extends AbstractElementHandler {
private ReportViewColElementHandler columnHandler = new ReportViewColElementHandler(); private ReportViewColElementHandler columnHandler = new ReportViewColElementHandler();
private ReportViewColumnElementHandler columnSelHandler = new ReportViewColumnElementHandler();
public void startElement(PIPOContext ctx, Element element) public void startElement(PIPOContext ctx, Element element)
throws SAXException { throws SAXException {
@ -132,6 +135,22 @@ public class ReportViewElementHandler extends AbstractElementHandler {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
sql = "SELECT AD_Column_ID FROM AD_ReportView_Column WHERE AD_Reportview_ID= "
+ AD_ReportView_ID;
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createReportViewColumn(ctx, document, AD_ReportView_ID, rs.getInt("AD_Column_ID"));
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
if (createElement) { if (createElement) {
document.endElement("", "", MReportView.Table_Name); document.endElement("", "", MReportView.Table_Name);
} }
@ -164,6 +183,18 @@ public class ReportViewElementHandler extends AbstractElementHandler {
ctx.ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); ctx.ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID);
} }
private void createReportViewColumn(PIPOContext ctx,
TransformerHandler document, int AD_ReportView_ID, int AD_Column_ID)
throws SAXException {
Query query = new Query(ctx.ctx, "AD_ReportView_Column", "AD_ReportView_ID=? AND AD_Column_ID=?", getTrxName(ctx));
X_AD_ReportView_Column po = query.setParameters(new Object[]{AD_ReportView_ID, AD_Column_ID}).first();
ctx.ctx.put("po", po);
columnSelHandler.create(ctx, document);
ctx.ctx.remove("po");
}
private void createReportViewBinding(PIPOContext ctx, TransformerHandler document, private void createReportViewBinding(PIPOContext ctx, TransformerHandler document,
MReportView m_Reportview) { MReportView m_Reportview) {