Search in sources :

Example 6 with DataRow

use of pl.x3E.adInterface.DataRow in project adempiere by adempiere.

the class InfoProduct method getColumns.

public DataRow getColumns() {
    DataRow col = DataRow.Factory.newInstance();
    DataField f = null;
    //0
    f = col.addNewField();
    f.setType("int");
    f.setLval("20, 0");
    f.setColumn("key");
    //1
    f = col.addNewField();
    f.setType("string");
    f.setLval("1, 15");
    f.setColumn("Discontinued");
    //2
    f = col.addNewField();
    f.setType("string");
    f.setLval("40, 110");
    f.setColumn("Value");
    //3
    f = col.addNewField();
    f.setType("string");
    f.setLval("60, 140");
    f.setColumn("Name");
    //4
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("QtyAvailable");
    //5
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("PriceList");
    //6
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("PriceStd");
    //7
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("QtyOnHand");
    //8
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("QtyReserved");
    //9
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("QtyOrdered");
    //10
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("Margin");
    //10
    f = col.addNewField();
    f.setType("string");
    f.setLval("10, 50");
    f.setColumn("PriceLimit");
    //10
    f = col.addNewField();
    f.setType("string");
    f.setLval("1, 20");
    f.setColumn("IsInstanceAttribute");
    return col;
}
Also used : DataField(pl.x3E.adInterface.DataField) DataRow(pl.x3E.adInterface.DataRow)

Example 7 with DataRow

use of pl.x3E.adInterface.DataRow in project adempiere by adempiere.

the class ModelADServiceImpl method createData.

public StandardResponseDocument createData(ModelCRUDRequestDocument req) throws XFireFault {
    StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
    StandardResponse resp = ret.addNewStandardResponse();
    ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
    String serviceType = modelCRUD.getServiceType();
    ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
    String err = modelLogin(reqlogin, webServiceName, "createData", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        resp.setIsError(true);
        return ret;
    }
    // Validate parameters vs service type
    validateCRUD(modelCRUD);
    String tableName = modelCRUD.getTableName();
    Properties ctx = m_cs.getM_ctx();
    // start a trx
    String trxName = Trx.createTrxName("ws_modelCreateData");
    Trx trx = Trx.get(trxName, false);
    // get the PO for the tablename and record ID
    MTable table = MTable.get(ctx, tableName);
    if (table == null)
        return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
    PO po = table.getPO(0, trxName);
    if (po == null)
        return rollbackAndSetError(trx, resp, ret, true, "Cannot create PO for " + tableName);
    POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
    DataRow dr = modelCRUD.getDataRow();
    for (DataField field : dr.getFieldList()) {
        // TODO: Implement lookup
        if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
            int idxcol = po.get_ColumnIndex(field.getColumn());
            if (idxcol < 0) {
                // The column doesn't exist - it must exist as it's defined in security
                return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " does not exist");
            } else {
                try {
                    setValueAccordingToClass(po, poinfo, field, idxcol);
                } catch (XFireFault e) {
                    log.log(Level.WARNING, "Error setting value", e);
                    return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " value could not be set: " + e.getLocalizedMessage());
                }
            }
        } else {
            return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed");
        }
    }
    if (!po.save())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
    int recordID = po.get_ID();
    resp.setRecordID(recordID);
    // close the trx
    if (!trx.commit())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
    trx.close();
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) StandardResponse(pl.x3E.adInterface.StandardResponse) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) StandardResponseDocument(pl.x3E.adInterface.StandardResponseDocument) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 8 with DataRow

use of pl.x3E.adInterface.DataRow in project adempiere by adempiere.

the class InfoBPartner method getColumns.

//  prepareTable
public DataRow getColumns() {
    DataRow col = DataRow.Factory.newInstance();
    DataField f = null;
    //0
    f = col.addNewField();
    f.setType("int");
    f.setColumn("key");
    f.setLval("20,0");
    //1
    f = col.addNewField();
    f.setType("string");
    f.setColumn("value");
    f.setLval("20,100");
    //2
    f = col.addNewField();
    f.setType("string");
    f.setColumn("name");
    f.setLval("20, 140");
    //3
    f = col.addNewField();
    f.setType("string");
    f.setColumn("contact");
    f.setLval("20, 70");
    //4
    f = col.addNewField();
    f.setType("string");
    f.setColumn("SO_CreditAvailable");
    f.setLval("20, 50");
    //5
    f = col.addNewField();
    f.setType("string");
    f.setColumn("SO_CreditUsed");
    f.setLval("20, 40");
    //6
    f = col.addNewField();
    f.setType("string");
    f.setColumn("Phone");
    f.setLval("20,50");
    //7
    f = col.addNewField();
    f.setType("string");
    f.setColumn("Postal");
    f.setLval("20, 40");
    //8
    f = col.addNewField();
    f.setType("string");
    f.setColumn("City");
    f.setLval("20, 50");
    //9
    f = col.addNewField();
    f.setType("string");
    f.setColumn("TotalOpenBalance");
    f.setLval("10,50");
    //10
    f = col.addNewField();
    f.setType("string");
    f.setColumn("ActualLifetimeValue");
    f.setLval("10,50");
    return col;
}
Also used : DataField(pl.x3E.adInterface.DataField) DataRow(pl.x3E.adInterface.DataRow)

Example 9 with DataRow

use of pl.x3E.adInterface.DataRow 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;
}
Also used : MColumn(org.compiere.model.MColumn) ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) DataSet(pl.x3E.adInterface.DataSet) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) MRole(org.compiere.model.MRole) WindowTabData(pl.x3E.adInterface.WindowTabData) ArrayList(java.util.ArrayList) ModelGetList(pl.x3E.adInterface.ModelGetList) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) MRefTable(org.compiere.model.MRefTable) SQLException(java.sql.SQLException) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) X_AD_Reference(org.compiere.model.X_AD_Reference) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ResultSet(java.sql.ResultSet)

Example 10 with DataRow

use of pl.x3E.adInterface.DataRow 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;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) DataSet(pl.x3E.adInterface.DataSet) QName(javax.xml.namespace.QName) WindowTabData(pl.x3E.adInterface.WindowTabData) Properties(java.util.Properties) XFireFault(org.codehaus.xfire.fault.XFireFault) DataRow(pl.x3E.adInterface.DataRow) POInfo(org.compiere.model.POInfo) WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) MTable(org.compiere.model.MTable) DataField(pl.x3E.adInterface.DataField) ModelCRUD(pl.x3E.adInterface.ModelCRUD) PO(org.compiere.model.PO)

Aggregations

DataRow (pl.x3E.adInterface.DataRow)17 DataSet (pl.x3E.adInterface.DataSet)12 WindowTabData (pl.x3E.adInterface.WindowTabData)12 WindowTabDataDocument (pl.x3E.adInterface.WindowTabDataDocument)12 DataField (pl.x3E.adInterface.DataField)10 Properties (java.util.Properties)5 XFireFault (org.codehaus.xfire.fault.XFireFault)5 MTable (org.compiere.model.MTable)5 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)5 PO (org.compiere.model.PO)4 POInfo (org.compiere.model.POInfo)4 ModelCRUD (pl.x3E.adInterface.ModelCRUD)4 SQLException (java.sql.SQLException)3 QName (javax.xml.namespace.QName)3 GridField (org.compiere.model.GridField)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 MLookup (org.compiere.model.MLookup)2 MRole (org.compiere.model.MRole)2