Example - Data Service Java API

This example shows both a browse and a count of the F0101 table, including a query. The response from the browse is assembled into a class (not included) that was generated with the AIS Client Class Generator for F0101 data service. The count response is assembled into a simple HashMap and printed.

//add to the used capabilities
loginEnv.getUsedCapabilities().add(AISClientCapability.DATA_SERVICE);
loginEnv.getUsedCapabilities().add(AISClientCapability.DATA_SERVICE_ORDERBY);
 
//create a new DataReqeust
DataRequest f0101 = new DataRequest(loginEnv);
 
//Set table information, this is a browse of F0101
f0101.setDataServiceType(DataRequest.TYPE_BROWSE);
f0101.setTargetName("F0101");
f0101.setTargetType(DataRequest.TARGET_TABLE);
f0101.setFindOnEntry(FormRequest.TRUE);
 
//set return control ids, only these three columns will be in the response
f0101.setReturnControlIDs("F0101.AN8|F0101.ALPH|F0101.AT1");
 
//only return the first 10 records
f0101.setMaxPageSize("10");
 
//create a new query, for address numbers greater than 7000
Query greaterQ = new Query(loginEnv);
greaterQ.setAutoFind(true);
greaterQ.setMatchType(Query.MATCH_ALL);
greaterQ.addStringCondition("F0101.AN8", StringOperator.GREATER(), "7000");
f0101.setQuery(greaterQ);

//order byf0101.addOrderBy(loginEnv,"F0101", "AT1", OrderByDirection.ORDER_DIRECT_ASCENDING());f0101.addOrderBy(loginEnv,"F0101", "AN8", OrderByDirection.ORDER_DIRECT_DESCENDING()) 
 
//execute the data request
String response = JDERestServiceProvider.jdeRestServiceCall(loginEnv, f0101, JDERestServiceProvider.POST_METHOD, JDERestServiceProvider.DATA_SERVICE_URI);
 
//marshal the response to a formparent class generated by the class generator
DATABROWSE_F0101_FormParent f010Data =loginEnv.getObjectMapper().readValue(response,DATABROWSE_F0101_FormParent.class);
 
//modify the type to count, and get a count response for the same query
f0101.setDataServiceType(DataRequest.TYPE_COUNT);
String countresponse = JDERestServiceProvider.jdeRestServiceCall(loginEnv, f0101, JDERestServiceProvider.POST_METHOD, JDERestServiceProvider.DATA_SERVICE_URI);        
     
 
//loop through the records in the response printing out the values
ArrayList<DATABROWSE_F0101_GridRow> rowSet = f010Data.getFs_DATABROWSE_F0101().getData().getGridData().getRowset();
if (rowSet.size() > 0)
{
    for (DATABROWSE_F0101_GridRow row: rowSet)
    {
System.out.println("Name: " + row.getSAlphaName_54().getValue());
System.out.println("Number: " + row.getMnAddressNumber_51().getValue());
System.out.println("Search Type: " + row.getSSchTyp_59().getValue());
 
System.out.println(" ");
    }
}
else
{
    fail("No Records in Reponse");
}
 
//marshal and print out the count response
HashMap countRespMap = loginEnv.getObjectMapper().readValue(countresponse, HashMap.class);        
HashMap countMap = (HashMap)countRespMap.get("ds_F0101");
System.out.println(countMap.get("count"));