use of org.compiere.model.X_AD_Reference 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.X_AD_Reference in project adempiere by adempiere.
the class RecordInfoController method dynInit.
/**
* Dynamic Init
* @param dse data status event
* @param title title
* @param mField field
*/
private void dynInit(DataStatusEvent dse, String title, GridField mField) {
m_Field = mField;
// Yamel Senih FR[ 146 ] Add support to change log in a specific column
// 2015-12-03
// For Field
int m_Record_ID = 0;
int m_AD_Table_ID = 0;
int m_AD_Column_ID = 0;
if (m_Field != null) {
// Set Values
m_Record_ID = m_Field.getGridTab().getRecord_ID();
m_AD_Table_ID = m_Field.getGridTab().getAD_Table_ID();
m_AD_Column_ID = m_Field.getAD_Column_ID();
//
MColumn column = MColumn.get(Env.getCtx(), m_AD_Column_ID);
X_AD_Reference reference = new X_AD_Reference(Env.getCtx(), m_Field.getDisplayType(), null);
DecimalFormat format = DisplayType.getNumberFormat(reference.getAD_Reference_ID());
MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
// Info
m_info.append("(").append(table.getTableName()).append(" - ").append(m_Field.getColumnName()).append(" = ").append(m_Field.getValue()).append(")").append("\n").append(Msg.translate(Env.getCtx(), "Name")).append(": ").append(m_Field.getHeader()).append("\n").append(Msg.translate(Env.getCtx(), "Description")).append(": ").append(m_Field.getDescription()).append("\n").append(Msg.translate(Env.getCtx(), "AD_Reference_ID")).append(": ").append(reference.get_Translation("Name")).append("\n");
// For Reference Key
if (m_Field.getDisplayType() == DisplayType.List || m_Field.getDisplayType() == DisplayType.Table || m_Field.getDisplayType() == DisplayType.Search) {
// Valid Reference Value
if (m_Field.getAD_Reference_Value_ID() != 0) {
X_AD_Reference referenceKey = new X_AD_Reference(Env.getCtx(), m_Field.getAD_Reference_Value_ID(), null);
m_info.append(Msg.translate(Env.getCtx(), "AD_Reference_Value_ID")).append(": ").append(referenceKey.get_Translation("Name")).append(" (").append(m_Field.getAD_Reference_Value_ID()).append(")").append("\n");
}
}
// Valid Dynamic Validation
if (column.getAD_Val_Rule_ID() != 0) {
X_AD_Val_Rule validation = (X_AD_Val_Rule) column.getAD_Val_Rule();
m_info.append(Msg.translate(Env.getCtx(), "AD_Val_Rule_ID")).append(": ").append(validation.get_Translation("Name")).append(" (").append(column.getAD_Val_Rule_ID()).append(")").append("\n");
}
m_info.append(Msg.translate(Env.getCtx(), "Length")).append(": ").append(format.format(column.getFieldLength())).append("\n");
// Add Entity Type for info
MEntityType entity = MEntityType.get(Env.getCtx(), column.getEntityType());
m_info.append(Msg.translate(Env.getCtx(), "EntityType")).append(": ").append(entity.get_Translation("Name"));
// Title
m_Title = title + " - " + m_Field.getHeader();
} else {
if (dse.CreatedBy == null)
return;
// Info
MUser user = MUser.get(Env.getCtx(), dse.CreatedBy.intValue());
m_info.append(" ").append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Created)).append("\n");
if (!dse.Created.equals(dse.Updated) || !dse.CreatedBy.equals(dse.UpdatedBy)) {
if (!dse.CreatedBy.equals(dse.UpdatedBy))
user = MUser.get(Env.getCtx(), dse.UpdatedBy.intValue());
m_info.append(" ").append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Updated)).append("\n");
}
if (dse.Info != null && dse.Info.length() > 0)
m_info.append("\n (").append(dse.Info).append(")");
// Title
if (dse.AD_Table_ID != 0) {
m_AD_Table_ID = dse.AD_Table_ID;
MTable table1 = MTable.get(Env.getCtx(), dse.AD_Table_ID);
m_Title = title + " - " + table1.getName();
}
// Set Record ID
if (dse.Record_ID instanceof Integer)
m_Record_ID = ((Integer) dse.Record_ID).intValue();
else
log.info("dynInit - Invalid Record_ID=" + dse.Record_ID);
}
// Valid Record Identifier
if (m_Record_ID == 0)
return;
// Only Client Preference can view Change Log
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()))
return;
// Data
String sql = "SELECT AD_Column_ID, Updated, UpdatedBy, OldValue, NewValue " + "FROM AD_ChangeLog " + "WHERE AD_Table_ID=? AND Record_ID=? " + (m_AD_Column_ID != 0 ? "AND AD_Column_ID=? " : "") + "ORDER BY Updated DESC";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_AD_Table_ID);
pstmt.setInt(2, m_Record_ID);
// Add support to column
if (m_AD_Column_ID != 0)
pstmt.setInt(3, m_AD_Column_ID);
//
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
addLine(rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5));
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
// Set Loaded to Ok
m_IsLoaded = true;
}
use of org.compiere.model.X_AD_Reference in project adempiere by adempiere.
the class ReferenceElementHandler method create.
public void create(Properties ctx, TransformerHandler document) throws SAXException {
int Reference_id = Env.getContextAsInt(ctx, X_AD_Reference.COLUMNNAME_AD_Reference_ID);
if (references.contains(Reference_id))
return;
references.add(Reference_id);
AttributesImpl atts = new AttributesImpl();
String sql = "SELECT * FROM AD_Reference WHERE AD_Reference_ID= " + Reference_id;
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Reference m_Reference = new X_AD_Reference(ctx, rs.getInt("AD_Reference_ID"), null);
createReferenceBinding(atts, m_Reference);
document.startElement("", "", "reference", atts);
if (m_Reference.getValidationType().compareTo("L") == 0) {
String sql1 = "SELECT * FROM AD_Ref_List WHERE AD_Reference_ID= " + Reference_id + " ORDER BY Value, AD_Ref_List_ID";
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceList(ctx, document, rs1.getInt("AD_REF_LIST_ID"));
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export Reference.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export Reference.", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
} else if (m_Reference.getValidationType().compareTo("T") == 0) {
String sql1 = "SELECT AD_Reference_ID FROM AD_Ref_Table WHERE AD_Reference_ID = " + Reference_id;
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sql1, getTrxName(ctx));
try {
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()) {
createReferenceTable(ctx, document, Reference_id);
}
rs1.close();
pstmt1.close();
pstmt1 = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getRef_Table", e);
} finally {
try {
if (pstmt1 != null)
pstmt1.close();
} catch (Exception e) {
}
pstmt1 = null;
}
}
document.endElement("", "", "reference");
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "getRefence", e);
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
pstmt = null;
}
}
use of org.compiere.model.X_AD_Reference in project adempiere by adempiere.
the class ReferenceElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("name"));
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("name");
if (isProcessElement(ctx, entitytype)) {
int id = get_ID(ctx, "AD_Reference", name);
X_AD_Reference m_Reference = new X_AD_Reference(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Reference_ID") != null && Integer.parseInt(atts.getValue("AD_Reference_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Reference.setAD_Reference_ID(Integer.parseInt(atts.getValue("AD_Reference_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Reference", m_Reference);
Object_Status = "Update";
if (references.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Reference.setDescription(getStringValue(atts, "Description"));
m_Reference.setEntityType(atts.getValue("EntityType"));
m_Reference.setHelp(getStringValue(atts, "Help"));
m_Reference.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Reference.setName(atts.getValue("name"));
// m_Reference.setVFormat(atts.getValue("VFormat"));
m_Reference.setValidationType(atts.getValue("ValidationType"));
if (m_Reference.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Reference.getName(), "Reference", m_Reference.get_ID(), AD_Backup_ID, Object_Status, "AD_Reference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Reference"));
references.add(m_Reference.getAD_Reference_ID());
element.recordId = m_Reference.getAD_Reference_ID();
} else {
record_log(ctx, 0, m_Reference.getName(), "Reference", m_Reference.get_ID(), AD_Backup_ID, Object_Status, "AD_Reference", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Reference"));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
use of org.compiere.model.X_AD_Reference 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