use of pl.x3E.adInterface.DataField 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;
}
use of pl.x3E.adInterface.DataField in project adempiere by adempiere.
the class ModelADServiceImpl method readData.
// updateData
public WindowTabDataDocument readData(ModelCRUDRequestDocument req) throws XFireFault {
WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
WindowTabData resp = ret.addNewWindowTabData();
ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
String serviceType = modelCRUD.getServiceType();
int cnt = 0;
ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "readData", serviceType);
if (err != null && err.length() > 0) {
resp.setError(err);
return ret;
}
// Validate parameters vs service type
validateCRUD(modelCRUD);
Properties ctx = m_cs.getM_ctx();
String tableName = modelCRUD.getTableName();
int recordID = modelCRUD.getRecordID();
// get the PO for the tablename and record ID
MTable table = MTable.get(ctx, tableName);
if (table == null)
throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("readData"));
PO po = table.getPO(recordID, null);
if (po == null) {
resp.setSuccess(false);
resp.setRowCount(cnt);
resp.setNumRows(cnt);
resp.setTotalRows(cnt);
resp.setStartRow(0);
return ret;
}
cnt = 1;
POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
DataSet ds = resp.addNewDataSet();
DataRow dr = ds.addNewDataRow();
for (int i = 0; i < poinfo.getColumnCount(); i++) {
String columnName = poinfo.getColumnName(i);
if (m_webservicetype.isOutputColumnNameAllowed(columnName)) {
DataField dfid = dr.addNewField();
dfid.setColumn(columnName);
if (po.get_Value(i) != null)
dfid.setVal(po.get_Value(i).toString());
else
dfid.setVal(null);
}
}
resp.setSuccess(true);
resp.setRowCount(cnt);
resp.setNumRows(cnt);
resp.setTotalRows(cnt);
resp.setStartRow(1);
return ret;
}
use of pl.x3E.adInterface.DataField in project adempiere by adempiere.
the class ModelADServiceImpl method queryData.
public WindowTabDataDocument queryData(ModelCRUDRequestDocument req) throws XFireFault {
WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
WindowTabData resp = ret.addNewWindowTabData();
ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
String serviceType = modelCRUD.getServiceType();
/** 2014-12-04 Carlos Parada Add Support for Paginate Records */
/** Current Page*/
int currentPage = req.getModelCRUDRequest().getModelCRUD().getPageNo();
/** Records per Page*/
int m_RecByPage = MSysConfig.getIntValue("WS_RECORDS_BY_PAGE", 1);
/** Quantity Pages*/
int qtyPages = 0;
log.info("Current Page " + currentPage);
/** 2014-12-04 Carlos Parada */
ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "queryData", serviceType);
if (err != null && err.length() > 0) {
resp.setError(err);
return ret;
}
// Validate parameters vs service type
validateCRUD(modelCRUD);
Properties ctx = m_cs.getM_ctx();
String tableName = modelCRUD.getTableName();
// get the PO for the tablename and record ID
MTable table = MTable.get(ctx, tableName);
if (table == null)
throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("queryData"));
int roleid = reqlogin.getRoleID();
MRole role = new MRole(ctx, roleid, null);
// 2014-12-04 Carlos Parada Replace ResultSet For Query
List<PO> records = null;
String key = m_cs.getM_AD_User_ID() + "_" + serviceType;
if (currentPage != 0)
records = (List<PO>) s_cache.get(key);
//"SELECT * FROM " + tableName;
String sqlWhere = "";
//sqlquery = role.addAccessSQL(sqlquery, tableName, true, true);
for (DataField field : modelCRUD.getDataRow().getFieldList()) {
if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
sqlWhere += (sqlWhere.equals("") ? "" : " AND ") + field.getColumn() + "=?";
} else {
throw new XFireFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed", new QName("queryData"));
}
}
if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0)
sqlWhere += " AND " + modelCRUD.getFilter();
POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
int cnt = 0;
try {
if (records == null) {
Query query = new Query(ctx, poinfo.getTableName(), sqlWhere, null);
Object[] parameters = new Object[modelCRUD.getDataRow().getFieldList().size()];
int p = 1;
int i = 0;
for (DataField field : modelCRUD.getDataRow().getFieldList()) {
parameters[i] = field.getVal();
i++;
}
if (parameters.length > 0)
query.setParameters(parameters);
records = query.setApplyAccessFilter(true).list();
}
// Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop
DataSet ds = resp.addNewDataSet();
// Set Quantity of Pages
if (records.size() != 0)
qtyPages = new BigDecimal(records.size()).divide(new BigDecimal(m_RecByPage)).setScale(0, BigDecimal.ROUND_UP).intValue();
int begin = 0, end = 0;
begin = currentPage * m_RecByPage;
end = (((currentPage + 1) * m_RecByPage) > records.size() ? records.size() : ((currentPage + 1) * m_RecByPage));
for (int j = begin; j < end; j++) {
PO record = records.get(j);
cnt++;
DataRow dr = ds.addNewDataRow();
for (int i = 0; i < poinfo.getColumnCount(); i++) {
String columnName = poinfo.getColumnName(i);
if (m_webservicetype.isOutputColumnNameAllowed(columnName)) {
DataField dfid = dr.addNewField();
dfid.setColumn(columnName);
dfid.setLval(record.get_ValueAsString(columnName));
}
}
}
} catch (Exception e) {
e.printStackTrace();
// ignore this exception
}
resp.setSuccess(true);
resp.setRowCount(cnt);
resp.setNumRows(cnt);
resp.setTotalRows(cnt);
resp.setStartRow(1);
resp.setQtyPages(qtyPages);
return ret;
}
use of pl.x3E.adInterface.DataField in project adempiere by adempiere.
the class ADServiceImpl method fillDataRow.
private void fillDataRow(DataRow dr, WWindowStatus ws, boolean handleLookups, boolean onlyUpdated) throws XFireFault {
authenticate(webServiceName, "fillDataRow");
int noFields = ws.curTab.getFieldCount();
//m_cs.dateFormat = new SimpleDateFormat( m_cs.datePattern );
//m_cs.dateTimeFormat = new SimpleDateFormat( m_cs.datePattern );
String column = "";
boolean isEditable = false;
if (onlyUpdated) {
java.util.Date clientUpdated = new java.util.Date();
java.util.Date updated = (java.util.Date) ws.curTab.getValue("Updated");
if (!updated.after(clientUpdated)) {
DataField df = dr.addNewField();
df.setColumn(recordIDfield);
df.setDisp(false);
df.setVal(Integer.toString(ws.curTab.getRecord_ID()));
return;
}
}
for (int colNo = 0; colNo < noFields; colNo++) {
GridField field = ws.curTab.getField(colNo);
column = field.getColumnName();
if (!field.isDisplayed(true)) {
DataField df = dr.addNewField();
df.setColumn(column);
df.setDisp(false);
df.setVal("");
//System.out.println(" *** not displayed: "+field.getColumnName()+" | "+field.getDisplayLogic());
continue;
}
if (field.getDisplayType() == DisplayType.Button)
continue;
DataField df = dr.addNewField();
isEditable = field.isEditable(true);
df.setEdit(isEditable);
// Get Data - turn to string
Object data = ws.curTab.getValue(column);
String info = null;
//
if (data == null && !DisplayType.isLookup(field.getDisplayType()))
info = "";
else {
int dt = field.getDisplayType();
switch(dt) {
case DisplayType.Date:
info = m_cs.dateFormat.format(data);
//System.out.println( "Date: "+info );
break;
case DisplayType.DateTime:
// TODO
//m_cs.dateTimeFormat.format(data);
info = m_cs.dateFormat.format(data);
//System.out.println( "DateTime: "+info );
break;
case DisplayType.Amount:
info = m_cs.amountFormat.format(data);
break;
case DisplayType.Number:
case DisplayType.CostPrice:
info = m_cs.numberFormat.format(data);
break;
case DisplayType.Quantity:
info = m_cs.quantityFormat.format(data);
break;
case DisplayType.Integer:
info = m_cs.integerFormat.format(data);
break;
case DisplayType.YesNo:
info = data.toString();
if ("Y".equals(info))
info = "true";
if ("N".equals(info))
info = "false";
//info = Msg.getMsg(ws.ctx, data.toString());
break;
case DisplayType.Location:
info = data.toString();
if (handleLookups) {
String x = DB.getSQLValueString(null, "select l.address1||', '||l.postal||', '||l.city from c_location l where c_location_id=?", Integer.parseInt(info));
df.setLval(x);
System.out.println(" location = " + x);
}
break;
default:
if (DisplayType.isLookup(dt)) {
Lookup lookup = field.getLookup();
//ArrayList<String> deps = field.getDependentOn();
String lookupValue = null;
if (field.getValue() != null) {
lookupValue = lookup.getDisplay(field.getValue());
}
//lookup.refresh();
if (data != null) {
info = lookup.getDisplay(data);
if (info == null) {
lookup.refresh();
info = lookup.getDisplay(data);
}
}
df.setLval(lookupValue);
if (handleLookups && /*&& isEditable*/
lookup != null && //deps.size()>0)
(field.getVO().ValidationCode != null && field.getVO().ValidationCode.length() > 0)) {
if (data != null)
info = lookup.getDisplay(data);
LookupValues lvs = df.addNewLookup();
ADLookup.fillLookupValues(lvs, lookup, field);
}
if (data != null)
info = data.toString();
} else {
info = data.toString();
//System.out.println(">>>>>>>> UNKNOWN > "+field.getColumnName() +" = "+info);
}
}
}
//System.out.println(" "+column+" = "+info);
if ("M_Product_ID".equals(field.getColumnName()))
System.out.println("--- " + info);
df.setDisp(true);
df.setVal(info);
df.setColumn(field.getColumnName());
if (field.isError()) {
df.setError(true);
df.setErrorVal(field.getErrorValue());
}
}
DataField df = dr.addNewField();
df.setColumn(recordIDfield);
df.setVal(Integer.toString(ws.curTab.getRecord_ID()));
}
use of pl.x3E.adInterface.DataField in project adempiere by adempiere.
the class ADServiceImpl method createQuery.
/*
public WindowTabDataDocument getWindowTabData(int WindowNo, int AD_Window_ID, int AD_Menu_ID, int TabNo, int PrevTabNo, int PrevRecNo, boolean getData) {
return getWindowTabData(WindowNo, AD_Window_ID, AD_Menu_ID, TabNo, PrevTabNo, PrevRecNo, getData, 0, -1);
}
public WindowTabDataDocument getWindowTabData(int WindowNo, int AD_Window_ID, int AD_Menu_ID, int TabNo, int PrevTabNo, int PrevRecNo, boolean getData, int RowStart, int RowCount)
{
return null; //TODO
}*/
private MQuery createQuery(String table_name, DataRow dr) {
MQuery q = new MQuery(table_name);
DataField[] df = dr.getFieldArray();
for (int i = 0; i < df.length; i++) {
if (df[i].getVal() != null && df[i].getVal().length() > 0) {
q.addRestriction("UPPER(" + df[i].getColumn() + ")", MQuery.LIKE, df[i].getVal().toUpperCase(), df[i].getColumn(), df[i].getVal().toUpperCase());
}
}
return q;
}
Aggregations