Search in sources :

Example 1 with WindowTabData

use of org.idempiere.adInterface.x10.WindowTabData in project idempiere by idempiere.

the class ModelADServiceImpl method queryData.

public WindowTabDataDocument queryData(ModelCRUDRequestDocument req) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        CompiereService m_cs = getCompiereService();
        WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
        WindowTabData resp = ret.addNewWindowTabData();
        ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
        String serviceType = modelCRUD.getServiceType();
        ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
        String err = login(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.getCtx();
        String tableName = modelCRUD.getTableName();
        Map<String, Object> reqCtx = getRequestCtx();
        MWebServiceType m_webservicetype = getWebServiceType();
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("queryData"));
        int roleid = reqlogin.getRoleID();
        MRole role = MRole.get(ctx, roleid);
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelQueryData");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_queryData");
        StringBuilder sqlBuilder = new StringBuilder(role.addAccessSQL("SELECT * FROM " + tableName, tableName, true, MRole.SQL_RO));
        ArrayList<Object> sqlParaList = new ArrayList<Object>();
        PO holderPo = table.getPO(0, trxName);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        if (modelCRUD.getDataRow() != null) {
            DataRow dr = modelCRUD.getDataRow();
            DataField[] fields = dr.getFieldArray();
            StandardResponseDocument stdRet = StandardResponseDocument.Factory.newInstance();
            StandardResponse stdResp = stdRet.addNewStandardResponse();
            StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, holderPo, fields, trx, reqCtx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            retResp = scanFields(fields, m_webservicetype, holderPo, poinfo, trx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            for (DataField field : modelCRUD.getDataRow().getFieldArray()) {
                if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
                    // Jan Thielemann Solution for query using the sentence like
                    X_WS_WebServiceFieldInput inputField = m_webservicetype.getFieldInput(field.getColumn());
                    I_AD_Column col = inputField.getAD_Column();
                    String sqlType = DisplayType.getSQLDataType(col.getAD_Reference_ID(), col.getColumnName(), col.getFieldLength());
                    if (sqlType.contains("CHAR"))
                        sqlBuilder.append(" AND ").append(field.getColumn()).append(" LIKE ?");
                    else
                        sqlBuilder.append(" AND ").append(field.getColumn()).append("=?");
                    sqlParaList.add(holderPo.get_Value(field.getColumn()));
                // End Jan Thielemann Solution for query using the sentence like
                } else if (m_webservicetype.getFieldInput(field.getColumn()) == null) {
                    // If not even ctx variable column
                    throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed", new QName("queryData"));
                }
            }
        }
        if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0) {
            String sql = parseSQL(" WHERE " + modelCRUD.getFilter(), sqlParaList, holderPo, poinfo, reqCtx);
            sqlBuilder.append(" AND ").append(sql.substring(6));
        }
        int cnt = 0;
        int rowCnt = 0;
        int offset = modelCRUD.getOffset();
        int limit = modelCRUD.getLimit();
        PreparedStatement pstmtquery = null;
        ResultSet rsquery = null;
        try {
            pstmtquery = DB.prepareStatement(sqlBuilder.toString(), trxName);
            DB.setParameters(pstmtquery, sqlParaList);
            rsquery = pstmtquery.executeQuery();
            // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop
            DataSet ds = resp.addNewDataSet();
            while (rsquery.next()) {
                cnt++;
                if ((offset >= cnt) || (limit > 0 && offset + limit < cnt))
                    continue;
                rowCnt++;
                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 (rsquery.getObject(columnName) instanceof byte[])
                            dfid.setVal(new String(Base64.encodeBase64(rsquery.getBytes(columnName))));
                        else
                            dfid.setVal(rsquery.getString(columnName));
                    }
                }
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            throw new IdempiereServiceFault(e);
        } finally {
            DB.close(rsquery, pstmtquery);
            rsquery = null;
            pstmtquery = null;
        }
        resp.setSuccess(true);
        resp.setRowCount(rowCnt);
        resp.setNumRows(rowCnt);
        resp.setTotalRows(cnt);
        resp.setStartRow(offset);
        return ret;
    } finally {
        if (manageTrx && trx != null)
            trx.close();
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) ResultSet(java.sql.ResultSet) Trx(org.compiere.util.Trx) X_WS_WebServiceFieldInput(org.idempiere.webservices.model.X_WS_WebServiceFieldInput) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) I_AD_Column(org.compiere.model.I_AD_Column) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) PO(org.compiere.model.PO)

Example 2 with WindowTabData

use of org.idempiere.adInterface.x10.WindowTabData in project idempiere by idempiere.

the class QueryDataLookup method getData.

/* (non-Javadoc)
	 * @see org.compiere.model.Lookup#getData(boolean, boolean, boolean, boolean, boolean)
	 */
@Override
public ArrayList<Object> getData(boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary, boolean shortlist) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    SOAPConnectionFactory cf;
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        dataMap = new LinkedHashMap<Integer, KeyNamePair>();
        cf = SOAPConnectionFactory.newInstance();
        SOAPConnection conn = cf.createConnection();
        // Create a SOAPMessage instance
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();
        // Create a SOAP envelope and body
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope env = part.getEnvelope();
        SOAPBody body = env.getBody();
        ModelCRUDRequestDocument crudDocument = ModelCRUDRequestDocument.Factory.newInstance();
        ModelCRUDRequest crudRequest = crudDocument.addNewModelCRUDRequest();
        crudRequest.setADLoginRequest(login);
        ModelCRUD crud = crudRequest.addNewModelCRUD();
        crud.setRecordID(0);
        crud.setFilter(filter);
        crud.setAction(ModelCRUD.Action.READ);
        crud.setServiceType(serviceType);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element element = document.createElementNS("http://idempiere.org/ADInterface/1_0", "queryData");
        Node domNode = document.importNode(crudDocument.getDomNode().getFirstChild(), true);
        document.appendChild(element);
        element.appendChild(domNode);
        body.addDocument(document);
        // Invoke the service endpoint
        URL endpoint = new URL(endPoint);
        SOAPMessage responseMsg = null;
        try {
            responseMsg = conn.call(message, endpoint);
        } finally {
            conn.close();
        }
        if (responseMsg != null && responseMsg.getSOAPBody() != null) {
            if (responseMsg.getSOAPBody().hasFault()) {
                throw new RuntimeException(responseMsg.getSOAPBody().getFault().getFaultString());
            }
            WindowTabDataDocument responseDoc = WindowTabDataDocument.Factory.parse(responseMsg.getSOAPBody().getFirstChild().getFirstChild());
            WindowTabData windowTabData = responseDoc.getWindowTabData();
            if (windowTabData.isSetError()) {
                throw new RuntimeException(windowTabData.getError());
            }
            DataSet dataset = windowTabData.getDataSet();
            DataRow[] dataRows = dataset.getDataRowArray();
            for (DataRow dataRow : dataRows) {
                DataField[] dataFields = dataRow.getFieldArray();
                String key = null;
                String display = null;
                for (DataField dataField : dataFields) {
                    if (dataField.getColumn().equals(keyColumn)) {
                        key = dataField.getVal();
                    } else if (dataField.getColumn().equals(displayColumn)) {
                        display = dataField.getVal();
                    }
                }
                if (key != null && display != null) {
                    Integer id = Integer.valueOf(key);
                    dataMap.put(id, new KeyNamePair(id, display));
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e.getLocalizedMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    return new ArrayList<Object>(dataMap.values());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DataSet(org.idempiere.adInterface.x10.DataSet) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) Document(org.w3c.dom.Document) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) SOAPMessage(javax.xml.soap.SOAPMessage) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) DataRow(org.idempiere.adInterface.x10.DataRow) URL(java.net.URL) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) SOAPPart(javax.xml.soap.SOAPPart) SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) SOAPBody(javax.xml.soap.SOAPBody) ModelCRUDRequest(org.idempiere.adInterface.x10.ModelCRUDRequest) DataField(org.idempiere.adInterface.x10.DataField) DocumentBuilder(javax.xml.parsers.DocumentBuilder) KeyNamePair(org.compiere.util.KeyNamePair)

Example 3 with WindowTabData

use of org.idempiere.adInterface.x10.WindowTabData in project idempiere by idempiere.

the class ModelADServiceImpl method readData.

// updateData
public WindowTabDataDocument readData(ModelCRUDRequestDocument req) {
    try {
        getCompiereService().connect();
        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 = login(reqlogin, webServiceName, "readData", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            return ret;
        }
        // Validate parameters vs service type
        try {
            validateCRUD(modelCRUD);
        } catch (IdempiereServiceFault e) {
            resp.setError(e.getMessage());
            return ret;
        }
        CompiereService m_cs = getCompiereService();
        MWebServiceType m_webservicetype = getWebServiceType();
        // start a trx
        String trxName = localTrxName;
        Properties ctx = m_cs.getCtx();
        String tableName = modelCRUD.getTableName();
        String recordIDVar = modelCRUD.getRecordIDVariable();
        int recordID = modelCRUD.getRecordID();
        if (recordIDVar != null && recordIDVar.startsWith("@")) {
            Integer retVal = (Integer) parseVariable(recordIDVar, null, null, getRequestCtx());
            if (retVal == null) {
                resp.setError("Cannot resolve variable: " + recordIDVar);
                return ret;
            }
            recordID = retVal;
        }
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("readData"));
        PO po = table.getPO(recordID, trxName);
        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) {
                    if (po.get_Value(i) instanceof byte[]) {
                        dfid.setVal(new String(Base64.encodeBase64((byte[]) po.get_Value(i))));
                    } else if (po.get_Value(i) instanceof Boolean) {
                        dfid.setVal((Boolean) po.get_Value(i) ? "Y" : "N");
                    } else {
                        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;
    } finally {
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) POInfo(org.compiere.model.POInfo) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) PO(org.compiere.model.PO)

Example 4 with WindowTabData

use of org.idempiere.adInterface.x10.WindowTabData in project idempiere by idempiere.

the class ModelADServiceImpl method getList.

public WindowTabDataDocument getList(ModelGetListRequestDocument req) {
    try {
        getCompiereService().connect();
        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 = login(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
        try {
            modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", modelGetList.getADReferenceID()));
        } catch (XmlValueOutOfRangeException e) {
            // Catch the exception when the Reference ID is not an Integer
            String refUU = getUUIDValue(modelGetList.xgetADReferenceID());
            if (refUU == null) {
                throw e;
            }
            modelGetList.setADReferenceID(validateParameter("AD_Reference_ID", 0, refUU));
        }
        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;
        CompiereService m_cs = getCompiereService();
        Properties ctx = m_cs.getCtx();
        MReference ref = MReference.get(ctx, ref_id);
        String sql = null;
        ArrayList<String> listColumnNames = new ArrayList<String>();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        MWebServiceType m_webservicetype = getWebServiceType();
        if (MReference.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 IdempiereServiceFault(e.getClass().toString() + " " + e.getMessage() + " sql=" + sql, e.getCause(), new QName("getList"));
            }
        } else if (MReference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) {
            // Fill values from a reference table
            MRole role = MRole.get(ctx, roleid);
            MRefTable rt = MRefTable.get(ctx, ref_id);
            if (rt == null || rt.get_ID() == 0)
                throw new IdempiereServiceFault("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'";
            sql = role.addAccessSQL(sql, table.getTableName(), true, true);
            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 IdempiereServiceFault(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 IdempiereServiceFault(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;
    } finally {
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) SQLException(java.sql.SQLException) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) ModelGetList(org.idempiere.adInterface.x10.ModelGetList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) MRefTable(org.compiere.model.MRefTable) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ResultSet(java.sql.ResultSet) MReference(org.compiere.model.MReference) MColumn(org.compiere.model.MColumn) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) PreparedStatement(java.sql.PreparedStatement) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField)

Example 5 with WindowTabData

use of org.idempiere.adInterface.x10.WindowTabData in project idempiere by idempiere.

the class GetListLookup method getData.

/* (non-Javadoc)
	 * @see org.compiere.model.Lookup#getData(boolean, boolean, boolean, boolean, boolean)
	 */
@Override
public ArrayList<Object> getData(boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary, boolean shortlist) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    SOAPConnectionFactory cf;
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        dataMap = new LinkedHashMap<Object, NamePair>();
        cf = SOAPConnectionFactory.newInstance();
        SOAPConnection conn = cf.createConnection();
        // Create a SOAPMessage instance
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();
        // Create a SOAP envelope and body
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope env = part.getEnvelope();
        SOAPBody body = env.getBody();
        ModelGetListRequestDocument getListDocument = ModelGetListRequestDocument.Factory.newInstance();
        ModelGetListRequest getListRequest = getListDocument.addNewModelGetListRequest();
        getListRequest.setADLoginRequest(login);
        ModelGetList getList = getListRequest.addNewModelGetList();
        getList.setFilter(filter);
        getList.setServiceType(serviceType);
        body.addDocument((Document) getListDocument.getDomNode());
        // Invoke the service endpoint
        URL endpoint = new URL(endPoint);
        SOAPMessage responseMsg = null;
        try {
            responseMsg = conn.call(message, endpoint);
        } finally {
            conn.close();
        }
        if (responseMsg != null && responseMsg.getSOAPBody() != null) {
            if (responseMsg.getSOAPBody().hasFault()) {
                throw new RuntimeException(responseMsg.getSOAPBody().getFault().getFaultString());
            }
            WindowTabDataDocument responseDoc = WindowTabDataDocument.Factory.parse(responseMsg.getSOAPBody().getFirstChild().getFirstChild());
            WindowTabData windowTabData = responseDoc.getWindowTabData();
            if (windowTabData.isSetError()) {
                throw new RuntimeException(windowTabData.getError());
            }
            DataSet dataset = windowTabData.getDataSet();
            DataRow[] dataRows = dataset.getDataRowArray();
            for (DataRow dataRow : dataRows) {
                DataField[] dataFields = dataRow.getFieldArray();
                String key = null;
                String display = null;
                for (DataField dataField : dataFields) {
                    if (dataField.getColumn().equals(keyColumn)) {
                        key = dataField.getVal();
                    } else if (dataField.getColumn().equals(displayColumn)) {
                        display = dataField.getVal();
                    }
                }
                if (key != null && display != null) {
                    dataMap.put(key, new ValueNamePair(key, display));
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e.getLocalizedMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    return new ArrayList<Object>(dataMap.values());
}
Also used : DataSet(org.idempiere.adInterface.x10.DataSet) ArrayList(java.util.ArrayList) SOAPConnection(javax.xml.soap.SOAPConnection) ModelGetList(org.idempiere.adInterface.x10.ModelGetList) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) DataRow(org.idempiere.adInterface.x10.DataRow) URL(java.net.URL) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) SOAPPart(javax.xml.soap.SOAPPart) ValueNamePair(org.compiere.util.ValueNamePair) SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) ModelGetListRequestDocument(org.idempiere.adInterface.x10.ModelGetListRequestDocument) MessageFactory(javax.xml.soap.MessageFactory) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) SOAPBody(javax.xml.soap.SOAPBody) DataField(org.idempiere.adInterface.x10.DataField) ModelGetListRequest(org.idempiere.adInterface.x10.ModelGetListRequest)

Aggregations

DataField (org.idempiere.adInterface.x10.DataField)5 DataRow (org.idempiere.adInterface.x10.DataRow)5 DataSet (org.idempiere.adInterface.x10.DataSet)5 WindowTabData (org.idempiere.adInterface.x10.WindowTabData)5 WindowTabDataDocument (org.idempiere.adInterface.x10.WindowTabDataDocument)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)3 QName (javax.xml.namespace.QName)3 MTable (org.compiere.model.MTable)3 ADLoginRequest (org.idempiere.adInterface.x10.ADLoginRequest)3 ModelCRUD (org.idempiere.adInterface.x10.ModelCRUD)3 IdempiereServiceFault (org.idempiere.webservices.fault.IdempiereServiceFault)3 MWebServiceType (org.idempiere.webservices.model.MWebServiceType)3 URL (java.net.URL)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 MessageFactory (javax.xml.soap.MessageFactory)2 SOAPBody (javax.xml.soap.SOAPBody)2 SOAPConnection (javax.xml.soap.SOAPConnection)2