use of org.idempiere.adInterface.x10.ModelCRUDRequest 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());
}
use of org.idempiere.adInterface.x10.ModelCRUDRequest in project idempiere by idempiere.
the class CompositeServiceImpl method getWrappedCRUD.
/**
* create ModelCRUDRequestDocument for operation element
* @param operation
* @param reqlogin
* @return
*/
private ModelCRUDRequestDocument getWrappedCRUD(Operation operation, ADLoginRequest reqlogin) {
if (operation.getModelCRUD() == null)
return null;
ModelCRUDRequestDocument wrapperDoc = ModelCRUDRequestDocument.Factory.newInstance();
ModelCRUDRequest wrapperCRUD = wrapperDoc.addNewModelCRUDRequest();
wrapperCRUD.setModelCRUD(operation.getModelCRUD());
wrapperCRUD.setADLoginRequest(reqlogin);
return wrapperDoc;
}
Aggregations