Search in sources :

Example 1 with ModelGetListRequest

use of org.idempiere.adInterface.x10.ModelGetListRequest 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

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPBody (javax.xml.soap.SOAPBody)1 SOAPConnection (javax.xml.soap.SOAPConnection)1 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)1 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 SOAPPart (javax.xml.soap.SOAPPart)1 NamePair (org.compiere.util.NamePair)1 ValueNamePair (org.compiere.util.ValueNamePair)1 DataField (org.idempiere.adInterface.x10.DataField)1 DataRow (org.idempiere.adInterface.x10.DataRow)1 DataSet (org.idempiere.adInterface.x10.DataSet)1 ModelGetList (org.idempiere.adInterface.x10.ModelGetList)1 ModelGetListRequest (org.idempiere.adInterface.x10.ModelGetListRequest)1 ModelGetListRequestDocument (org.idempiere.adInterface.x10.ModelGetListRequestDocument)1 WindowTabData (org.idempiere.adInterface.x10.WindowTabData)1 WindowTabDataDocument (org.idempiere.adInterface.x10.WindowTabDataDocument)1