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());
}
Aggregations