use of org.compiere.model.MRefTable in project adempiere by adempiere.
the class MRelationType method retrieveRefTable.
public static MRefTable retrieveRefTable(final Properties ctx, final int referenceId, final String trxName) {
final Object[] params = { referenceId };
final MRefTable refTable = new Query(ctx, I_AD_Ref_Table.Table_Name, COLUMNNAME_AD_Reference_ID + "=?", trxName).setParameters(params).firstOnly();
return refTable;
}
use of org.compiere.model.MRefTable in project adempiere by adempiere.
the class ReferenceTableElementHandler method createReferenceTableBinding.
private AttributesImpl createReferenceTableBinding(Properties ctx, AttributesImpl atts, int reference_ID) {
atts.clear();
if (reference_ID <= PackOut.MAX_OFFICIAL_ID)
atts.addAttribute("", "", "AD_Reference_ID", "CDATA", Integer.toString(reference_ID));
I_AD_Reference reference = new X_AD_Reference(ctx, reference_ID, getTrxName(ctx));
MRefTable refTable;
if (X_AD_Reference.VALIDATIONTYPE_TableValidation.equals(reference.getValidationType())) {
refTable = new MRefTable(ctx, reference_ID, getTrxName(ctx));
if (refTable != null) {
atts.addAttribute("", "", "ADRefenceNameID", "CDATA", reference.getName());
if (refTable.getAD_Table_ID() > 0)
atts.addAttribute("", "", "ADTableNameID", "CDATA", refTable.getAD_Table().getTableName());
else
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
if (refTable.getAD_Display() > 0)
atts.addAttribute("", "", "ADDisplay", "CDATA", MColumn.get(ctx, refTable.getAD_Display()).getColumnName());
else
atts.addAttribute("", "", "ADDisplay", "CDATA", "");
if (refTable.getAD_Key() > 0)
atts.addAttribute("", "", "Key", "CDATA", MColumn.get(ctx, refTable.getAD_Key()).getColumnName());
else
atts.addAttribute("", "", "Key", "CDATA", "");
if (refTable.getAD_Window_ID() > 0)
atts.addAttribute("", "", "ADWindowNameID", "CDATA", refTable.getAD_Window().getName());
else
atts.addAttribute("", "", "ADWindowNameID", "CDATA", "");
atts.addAttribute("", "", "EntityType", "CDATA", (refTable.getEntityType() != null ? refTable.getEntityType() : ""));
atts.addAttribute("", "", "IsValueDisplayed", "CDATA", refTable.isValueDisplayed() ? "Y" : "N");
atts.addAttribute("", "", "IsDisplayIdentifier", "CDATA", refTable.isDisplayIdentifier() ? "Y" : "N");
atts.addAttribute("", "", "IsAlert", "CDATA", refTable.isAlert() ? "Y" : "N");
atts.addAttribute("", "", "DisplaySQL", "CDATA", (refTable.getDisplaySQL() != null ? refTable.getDisplaySQL() : ""));
atts.addAttribute("", "", "OrderByClause", "CDATA", (refTable.getOrderByClause() != null ? refTable.getOrderByClause() : ""));
atts.addAttribute("", "", "isActive", "CDATA", (refTable.isActive() ? "Y" : "N"));
atts.addAttribute("", "", "WhereClause", "CDATA", (refTable.getWhereClause() != null ? refTable.getWhereClause() : ""));
}
}
return atts;
}
use of org.compiere.model.MRefTable in project adempiere by adempiere.
the class ReferenceTableElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADRefenceNameID");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
int AD_Reference_ID = 0;
if (element.parent != null && element.parent.getElementValue().equals("reference") && element.parent.recordId > 0) {
AD_Reference_ID = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer("SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?");
AD_Reference_ID = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (AD_Reference_ID <= 0 && atts.getValue("AD_Reference_ID") != null && Integer.parseInt(atts.getValue("AD_Reference_ID")) <= PackOut.MAX_OFFICIAL_ID)
AD_Reference_ID = Integer.parseInt(atts.getValue("AD_Reference_ID"));
int tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
if (tableId == 0) {
MTable m_Table = new MTable(ctx, 0, getTrxName(ctx));
m_Table.setAccessLevel("3");
m_Table.setName(atts.getValue("ADTableNameID"));
m_Table.setTableName(atts.getValue("ADTableNameID"));
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table", m_Table.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
} else {
record_log(ctx, 0, m_Table.getName(), "Table", m_Table.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
}
tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
}
name = atts.getValue("Key");
int keyId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, "AD_Table", tableId);
if (keyId == 0)
throw new AdempiereException("@AD_Column_ID@:" + name + "@NotFound@");
int displayId = 0;
name = atts.getValue("ADDisplay");
displayId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, "AD_Table", tableId);
String isDisplayIdentifier = atts.getValue("IsDisplayIdentifier");
String isAlert = atts.getValue("IsAlert");
String entityType = atts.getValue("EntityType");
String isValueDisplayed = atts.getValue("IsValueDisplayed");
String OrderByClause = "";
String WhereClause = "";
String displaySQL = "";
if (DB.isOracle()) {
OrderByClause = atts.getValue("OrderByClause");
WhereClause = atts.getValue("WhereClause");
displaySQL = atts.getValue("DisplaySQL");
} else if (DB.isPostgreSQL()) {
OrderByClause = atts.getValue("OrderByClause").replaceAll("''", "'");
WhereClause = atts.getValue("WhereClause").replaceAll("''", "'");
displaySQL = atts.getValue("DisplaySQL").replaceAll("''", "'");
;
}
MRefTable refTable = new Query(ctx, I_AD_Ref_Table.Table_Name, COLUMNNAME_AD_Reference_ID + "=?", getTrxName(ctx)).setParameters(AD_Reference_ID).firstOnly();
if (refTable != null) {
refTable.setAD_Table_ID(tableId);
refTable.setAD_Display(displayId);
refTable.setAD_Key(keyId);
refTable.setIsValueDisplayed(isValueDisplayed.equals("Y"));
refTable.setIsDisplayIdentifier(isDisplayIdentifier.equals("Y"));
refTable.setIsAlert(isAlert.equals("Y"));
refTable.setDisplaySQL(displaySQL);
refTable.setOrderByClause(OrderByClause);
refTable.setEntityType(entityType);
refTable.setWhereClause(WhereClause);
refTable.saveEx();
if (refTable != null) {
record_log(ctx, 1, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
} else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
} else {
refTable = new MRefTable(ctx, 0, getTrxName(ctx));
refTable.setAD_Reference_ID(AD_Reference_ID);
refTable.setAD_Table_ID(tableId);
refTable.setAD_Display(displayId);
refTable.setAD_Key(keyId);
refTable.setIsValueDisplayed(isValueDisplayed.equals("Y"));
refTable.setIsDisplayIdentifier(isDisplayIdentifier.equals("Y"));
refTable.setIsAlert(isAlert.equals("Y"));
refTable.setDisplaySQL(displaySQL);
refTable.setOrderByClause(OrderByClause);
refTable.setEntityType(entityType);
refTable.setWhereClause(WhereClause);
if (refTable.save())
record_log(ctx, 1, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
}
} else {
element.skip = true;
}
}
use of org.compiere.model.MRefTable in project adempiere by adempiere.
the class MRelationType method retrieveZoomInfos.
/**
*
* @param po
* @return
*/
public List<ZoomInfoFactory.ZoomInfo> retrieveZoomInfos(final PO po) {
checkDestinationRefId();
final MRefTable refTable = retrieveRefTable(getCtx(), destinationRefId, get_TrxName());
final MQuery query = new MQuery();
query.addRestriction(parseWhereClause(po, refTable.getWhereClause()));
query.setZoomTableName(retrieveDestinationTableName());
query.setZoomColumnName(retrieveDestinationKeyColName());
evaluateQuery(query);
final int windowId = retrieveWindowID(po, refTable);
String display = getDestinationRoleDisplay();
if (Util.isEmpty(display)) {
display = retrieveWindowName(windowId);
}
assert !Util.isEmpty(display);
return Collections.singletonList(new ZoomInfoFactory.ZoomInfo(windowId, query, display));
}
use of org.compiere.model.MRefTable in project adempiere by adempiere.
the class ModelADServiceImpl method getList.
public WindowTabDataDocument getList(ModelGetListRequestDocument req) throws XFireFault {
WindowTabDataDocument resdoc = WindowTabDataDocument.Factory.newInstance();
WindowTabData res = resdoc.addNewWindowTabData();
DataSet ds = res.addNewDataSet();
ModelGetList modelGetList = req.getModelGetListRequest().getModelGetList();
String serviceType = modelGetList.getServiceType();
int cnt = 0;
ADLoginRequest reqlogin = req.getModelGetListRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "getList", serviceType);
if (err != null && err.length() > 0) {
res.setError(err);
res.setErrorInfo(err);
res.setSuccess(false);
return resdoc;
}
int roleid = reqlogin.getRoleID();
// Validate parameters
modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", modelGetList.getADReferenceID()));
modelGetList.setFilter(validateParameter("Filter", modelGetList.getFilter()));
int ref_id = modelGetList.getADReferenceID();
String filter = modelGetList.getFilter();
if (filter == null || filter.length() == 0)
filter = "";
else
filter = " AND " + filter;
Properties ctx = m_cs.getM_ctx();
X_AD_Reference ref = new X_AD_Reference(ctx, ref_id, null);
String sql = null;
ArrayList<String> listColumnNames = new ArrayList<String>();
PreparedStatement pstmt = null;
ResultSet rs = null;
if (X_AD_Reference.VALIDATIONTYPE_ListValidation.equals(ref.getValidationType())) {
// Fill List Reference
String ad_language = Env.getAD_Language(ctx);
boolean isBaseLanguage = Env.isBaseLanguage(ad_language, "AD_Ref_List");
sql = isBaseLanguage ? "SELECT AD_Ref_List.AD_Ref_List_ID, AD_Ref_List.Value, AD_Ref_List.Name, AD_Ref_List.Description " + "FROM AD_Ref_List " + "WHERE AD_Ref_List.AD_Reference_ID=? AND AD_Ref_List.IsActive='Y' " + filter + " ORDER BY AD_Ref_List.Name" : "SELECT AD_Ref_List.AD_Ref_List_ID, AD_Ref_List.Value, AD_Ref_List_Trl.Name, AD_Ref_List_Trl.Description " + "FROM AD_Ref_List, AD_Ref_List_Trl " + "WHERE AD_Ref_List.AD_Reference_ID=? AND AD_Ref_List.IsActive='Y' AND AD_Ref_List_Trl.AD_Language=? AND AD_Ref_List.AD_Ref_List_ID=AD_Ref_List_Trl.AD_Ref_List_ID " + filter + " ORDER BY AD_Ref_List_Trl.Name";
listColumnNames.add("AD_Ref_List_ID");
listColumnNames.add("Value");
listColumnNames.add("Name");
listColumnNames.add("Description");
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, ref_id);
if (!isBaseLanguage)
pstmt.setString(2, ad_language);
rs = pstmt.executeQuery();
} catch (SQLException e) {
res.setError(e.getMessage());
res.setErrorInfo(sql);
res.setSuccess(false);
DB.close(rs, pstmt);
rs = null;
pstmt = null;
throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
}
} else if (X_AD_Reference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) {
// Fill values from a reference table
MRole role = new MRole(ctx, roleid, null);
String sqlrt = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID=?";
MRefTable rt = null;
PreparedStatement pstmtrt = null;
ResultSet rsrt = null;
try {
pstmtrt = DB.prepareStatement(sqlrt, null);
pstmtrt.setInt(1, ref_id);
rsrt = pstmtrt.executeQuery();
if (rsrt.next())
rt = new MRefTable(ctx, rsrt, null);
} catch (Exception e) {
// ignore this exception
} finally {
DB.close(rsrt, pstmtrt);
rsrt = null;
pstmtrt = null;
}
if (rt == null)
throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": reference table " + ref_id + " not found", new QName("getList"));
MTable table = new MTable(ctx, rt.getAD_Table_ID(), null);
MColumn column = new MColumn(ctx, rt.getAD_Key(), null);
// TODO: if any value or identifier column is translated, then get them from trl table (and client has multilanguage documents enabled)
sql = "SELECT " + column.getColumnName();
listColumnNames.add(column.getColumnName());
if (rt.isValueDisplayed()) {
sql += ",Value";
listColumnNames.add("Value");
}
String sqlident = "SELECT ColumnName FROM AD_Column WHERE AD_Table_ID=? AND IsActive='Y' AND IsIdentifier='Y' ORDER BY SeqNo";
PreparedStatement pstmtident = null;
ResultSet rsident = null;
try {
pstmtident = DB.prepareStatement(sqlident, null);
pstmtident.setInt(1, rt.getAD_Table_ID());
rsident = pstmtident.executeQuery();
while (rsident.next()) {
String colnameident = rsident.getString("ColumnName");
if (rt.isValueDisplayed() && colnameident.equalsIgnoreCase("Value")) {
// Value already added
} else {
sql += "," + colnameident;
listColumnNames.add(colnameident);
}
}
} catch (Exception e) {
// ignore this exception
} finally {
DB.close(rsident, pstmtident);
rsident = null;
pstmtident = null;
}
sql += " FROM " + table.getTableName() + " WHERE IsActive='Y'";
/** 2014-11-05 Carlos Parada Change for ReadOnly SQL Access */
//sql = role.addAccessSQL(sql, table.getTableName(), true, true);
sql = role.addAccessSQL(sql, table.getTableName(), true, false);
/** End Carlos Parada */
sql += filter;
if (rt.getWhereClause() != null && rt.getWhereClause().length() > 0)
sql += " AND " + rt.getWhereClause();
if (rt.getOrderByClause() != null && rt.getOrderByClause().length() > 0)
sql += " ORDER BY " + rt.getOrderByClause();
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
} catch (SQLException e) {
res.setError(e.getMessage());
res.setErrorInfo(sql);
res.setSuccess(false);
DB.close(rs, pstmt);
rs = null;
pstmt = null;
throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
}
} else {
// Don't fill - wrong type
}
if (rs != null) {
try {
while (rs.next()) {
cnt++;
// Add values to the dataset
DataRow dr = ds.addNewDataRow();
for (String listColumnName : listColumnNames) {
if (m_webservicetype.isOutputColumnNameAllowed(listColumnName)) {
DataField dfid = dr.addNewField();
dfid.setColumn(listColumnName);
dfid.setVal(rs.getString(listColumnName));
}
}
}
res.setSuccess(true);
} catch (SQLException e) {
res.setError(e.getMessage());
res.setErrorInfo(sql);
res.setSuccess(false);
throw new XFireFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
res.setRowCount(cnt);
res.setNumRows(cnt);
res.setTotalRows(cnt);
res.setStartRow(1);
return resdoc;
}
Aggregations