use of com.google.cloud.automl.v1beta1.Dataset in project java-automl by googleapis.
the class AutoMlClientTest method listColumnSpecsTest.
@Test
public void listColumnSpecsTest() throws Exception {
ColumnSpec responsesElement = ColumnSpec.newBuilder().build();
ListColumnSpecsResponse expectedResponse = ListColumnSpecsResponse.newBuilder().setNextPageToken("").addAllColumnSpecs(Arrays.asList(responsesElement)).build();
mockAutoMl.addResponse(expectedResponse);
TableSpecName parent = TableSpecName.of("[PROJECT]", "[LOCATION]", "[DATASET]", "[TABLE_SPEC]");
ListColumnSpecsPagedResponse pagedListResponse = client.listColumnSpecs(parent);
List<ColumnSpec> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getColumnSpecsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListColumnSpecsRequest actualRequest = ((ListColumnSpecsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.automl.v1beta1.Dataset in project java-automl by googleapis.
the class AutoMlClientTest method listDatasetsTest2.
@Test
public void listDatasetsTest2() throws Exception {
Dataset responsesElement = Dataset.newBuilder().build();
ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
mockAutoMl.addResponse(expectedResponse);
String parent = "parent-995424086";
ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent);
List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.automl.v1beta1.Dataset in project java-automl by googleapis.
the class AutoMlClientTest method listDatasetsTest.
@Test
public void listDatasetsTest() throws Exception {
Dataset responsesElement = Dataset.newBuilder().build();
ListDatasetsResponse expectedResponse = ListDatasetsResponse.newBuilder().setNextPageToken("").addAllDatasets(Arrays.asList(responsesElement)).build();
mockAutoMl.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListDatasetsPagedResponse pagedListResponse = client.listDatasets(parent);
List<Dataset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatasetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatasetsRequest actualRequest = ((ListDatasetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.automl.v1beta1.Dataset in project java-automl by googleapis.
the class AutoMlClientTest method listTableSpecsTest.
@Test
public void listTableSpecsTest() throws Exception {
TableSpec responsesElement = TableSpec.newBuilder().build();
ListTableSpecsResponse expectedResponse = ListTableSpecsResponse.newBuilder().setNextPageToken("").addAllTableSpecs(Arrays.asList(responsesElement)).build();
mockAutoMl.addResponse(expectedResponse);
DatasetName parent = DatasetName.of("[PROJECT]", "[LOCATION]", "[DATASET]");
ListTableSpecsPagedResponse pagedListResponse = client.listTableSpecs(parent);
List<TableSpec> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTableSpecsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTableSpecsRequest actualRequest = ((ListTableSpecsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.automl.v1beta1.Dataset 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();
}
}
Aggregations