use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestSchemaAction method testDoSaveByExpertModel.
/**
* 测试专家模式Schema保存, 将mall_id类型由string改成test类型,并且去掉了一个动态字段pt_*
*
* @throws Exception
*/
public void testDoSaveByExpertModel() throws Exception {
// event_submit_do_save_by_expert_model: y
request.setParameter("emethod", "saveByExpertModel");
request.setParameter("action", "schema_action");
// request.addHeader("appname", collection);
setCollection(collection);
try (InputStream post = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model.json")) {
request.setContent(IOUtils.toByteArray(post));
}
ActionProxy proxy = getActionProxy();
String result = proxy.execute();
assertEquals("SchemaAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
// this.verifyAll();
SchemaAction.CreateSnapshotResult bizResult = (SchemaAction.CreateSnapshotResult) aResult.getBizResult();
assertNotNull(bizResult);
Integer newSnapshotId = bizResult.getNewId();
assertTrue("newSnapshotId can not be null", newSnapshotId > 0);
SnapshotDomain snapshotView = runContext.getSnapshotViewDAO().getView(newSnapshotId);
assertNotNull("snapshotView can not be null", snapshotView);
UploadResource solrSchema = snapshotView.getSolrSchema();
String mallIdTypeModifiedXml = StringUtils.remove(new String(solrSchema.getContent(), TisUTF8.get()), '\r');
try (InputStream input = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml")) {
assertNotNull(input);
String mallIdTypeModifiedXmlExpect = StringUtils.trimToEmpty(IOUtils.toString(input, TisUTF8.get()));
assertEquals(mallIdTypeModifiedXmlExpect, StringUtils.trimToEmpty(mallIdTypeModifiedXml));
}
// JsonUtil.assertJSONEqual(TestSchemaAction.class, "schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml"
// , mallIdTypeModifiedXml, (msg, e, a) -> {
// assertEquals(msg, e, a);
// });
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestSchemaAction method testGetFieldsBySnapshotId.
public void testGetFieldsBySnapshotId() throws Exception {
request.setParameter("emethod", "getFieldsBySnapshotId");
request.setParameter("action", "schema_action");
request.setParameter("snapshot", "21123");
request.setParameter("editable", "false");
request.setParameter("restype", "schema.xml");
setCollection(collection);
ActionProxy proxy = getActionProxy();
String result = proxy.execute();
assertEquals("SchemaAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
JSONObject biz = (JSONObject) aResult.getBizResult();
assertNotNull(biz);
String assertFileName = "assert-testGetFieldsBySnapshotId.json";
try (InputStream assertInput = this.getClass().getResourceAsStream(assertFileName)) {
assertNotNull(assertInput);
// FileUtils.write(new File("testGetFieldsBySnapshotId.json"), JsonUtil.toString(biz), TisUTF8.get());
assertEquals(IOUtils.toString(assertInput, TisUTF8.get()), JsonUtil.toString(biz));
}
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestPluginAction method testGetPluginConfigInfoWithTargetDescriptorName.
/**
* 在DataX实例创建时,使用Mysql类型的Reader时 需要选择导入表的的步骤中需要使用到
*
* @throws Exception
*/
public void testGetPluginConfigInfoWithTargetDescriptorName() throws Exception {
// this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,);
// event_submit_do_get_plugin_config_info: y
// action: plugin_action
// plugin: dataxReader:require,targetDescriptorName_MySQL,subFormFieldName_selectedTabs,dataxName_baisuitest
// doGetPluginConfigInfo
String dataXName = "baisuitestTestcase";
request.addHeader(DataxReader.HEAD_KEY_REFERER, "/x/" + dataXName + "/config");
request.setParameter("event_submit_do_get_plugin_config_info", "y");
request.setParameter("action", "plugin_action");
request.setParameter("plugin", "dataxReader:require,targetDescriptorName_MySQL,subFormFieldName_selectedTabs,dataxName_" + dataXName);
// JSONObject content = new JSONObject();
// content.put(CollectionAction.KEY_INDEX_NAME, TEST_TABLE_EMPLOYEES_NAME);
// request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
ActionProxy proxy = getActionProxy();
this.replay();
String result = proxy.execute();
assertEquals("PluginAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
Object bizResult = aResult.getBizResult();
assertNotNull(bizResult);
JSONObject bizJSON = (JSONObject) bizResult;
JSONArray plugins = bizJSON.getJSONArray("plugins");
assertEquals(1, plugins.size());
JSONObject plugin = plugins.getJSONObject(0);
JSONObject descriptors = plugin.getJSONObject("descriptors");
JSONObject descriptor = null;
JSONObject subFormMeta = null;
int descriptorCount = 0;
for (String readerImpl : descriptors.keySet()) {
assertEquals("com.qlangtech.tis.plugin.datax.DataxMySQLReader", readerImpl);
descriptor = descriptors.getJSONObject(readerImpl);
assertNotNull(descriptor);
subFormMeta = descriptor.getJSONObject("subFormMeta");
assertNotNull(subFormMeta);
JsonUtil.assertJSONEqual(TestPluginAction.class, "pluginAction-subformmeta.json", subFormMeta, (m, e, a) -> {
assertEquals(m, e, a);
});
descriptorCount++;
}
assertEquals(1, descriptorCount);
this.verifyAll();
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class TestOfflineDatasourceAction method testDoGetDsTabsVals.
public void testDoGetDsTabsVals() throws Exception {
// request.addHeader(DataxReader.HEAD_KEY_REFERER, "/x/" + dataXName + "/config");
request.setParameter("emethod", "get_ds_tabs_vals");
request.setParameter("action", "offline_datasource_action");
//
String postContent = "{\n" + " \"tabs\":[\n" + " \"base\"\n" + " ],\n" + " \"name\":\"dataxReader\",\n" + " \"require\":true,\n" + " \"extraParam\":\"" + SubFormFilter.PLUGIN_META_TARGET_DESCRIPTOR_NAME + "_MySQL," + SubFormFilter.PLUGIN_META_SUB_FORM_FIELD + "_selectedTabs," + DataxUtils.DATAX_DB_NAME + "_order,maxReaderTableCount_9999\"\n" + "}";
request.setContent(postContent.getBytes(TisUTF8.get()));
ActionProxy proxy = getActionProxy();
String result = proxy.execute();
assertEquals("PluginAction_ajax", result);
AjaxValve.ActionExecResult aResult = showBizResult();
assertNotNull(aResult);
assertTrue(aResult.isSuccess());
Object bizResult = aResult.getBizResult();
}
use of com.opensymphony.xwork2.Result in project tis by qlangtech.
the class CollectionAction method doQuery.
/**
* 利用solr的disMax QP进行查询
*
* @param context
* @throws Exception
*/
public void doQuery(Context context) throws Exception {
// this.parseJsonPost();
JSONObject post = getIndexWithPost();
// if (StringUtils.isEmpty(post.getString(KEY_INDEX_NAME))) {
// throw new IllegalArgumentException("indexName can not be null");
// }
// this.indexName = TISCollectionUtils.NAME_PREFIX + post.getString(KEY_INDEX_NAME);
JSONArray searchFields = post.getJSONArray(KEY_QUERY_SEARCH_FIELDS);
Objects.requireNonNull(searchFields, "param " + KEY_QUERY_SEARCH_FIELDS + " can not be null ");
if (searchFields.size() < 1) {
throw new IllegalArgumentException(KEY_QUERY_SEARCH_FIELDS + " relevant field can not be empty");
}
final List<SubCriteria> andQueryCriteria = Lists.newArrayList();
searchFields.forEach((f) -> {
SubCriteria subCriteria = new SubCriteria();
JSONObject o = (JSONObject) f;
Option opt = null;
String word = null;
for (String key : o.keySet()) {
word = o.getString(key);
if (StringUtils.isEmpty(word)) {
throw new IllegalArgumentException("query field:" + key + ",relevant:" + word + ",val can not be null");
}
opt = new Option(key, word);
subCriteria.addOr(opt);
}
andQueryCriteria.add(subCriteria);
});
JSONArray storedFields = post.getJSONArray(KEY_QUERY_FIELDS);
if (storedFields == null) {
throw new IllegalArgumentException("param 'fields' can not be null");
}
storedFields.stream().map((r) -> (String) r).collect(Collectors.toList());
// final String fields = post.getString(KEY_QUERY_FIELDS);
// if (StringUtils.isEmpty(fields)) {
// throw new IllegalArgumentException("param 'fields' can not be null");
// }
final Integer limit = post.getInteger(KEY_QUERY_LIMIT);
if (limit == null) {
throw new IllegalArgumentException("param limit can not be null");
}
// final String queryFields = post.getString(KEY_QUERY_QUERY_FIELDS);
// if (StringUtils.isEmpty(queryFields)) {
// throw new IllegalArgumentException("'queryFields' can not be null");
// }
final String orderBy = post.getString(KEY_QUERY_ORDER_BY);
Integer rowsOffset = post.getInteger(KEY_QUERY_ROWS_OFFSET);
AppDomainInfo app = getAppDomain();
final QueryResutStrategy queryResutStrategy = QueryIndexServlet.createQueryResutStrategy(app, this.getRequest(), getResponse(), getDaoContext());
final List<ServerJoinGroup> serverlist = queryResutStrategy.queryProcess();
for (ServerJoinGroup server : serverlist) {
// 组装url
final String url = server.getIpAddress();
QueryCloudSolrClient solrClient = new QueryCloudSolrClient(url);
SolrQuery query = new SolrQuery();
query.set(CommonParams.FL, storedFields.stream().map((r) -> (String) r).collect(Collectors.joining(",")));
// query.setParam(QUERY_PARSIING_DEF_TYPE, "dismax");
// query.setParam(DisMaxParams.QF, queryFields);
query.setQuery(this.createQuery(andQueryCriteria));
query.setRows(limit);
if (rowsOffset != null) {
query.setStart(rowsOffset);
}
if (StringUtils.isNotEmpty(orderBy)) {
query.add(CommonParams.SORT, orderBy);
}
QueryResponse result = solrClient.query(indexName.getCollectionName(), query, SolrRequest.METHOD.POST);
solrClient.close();
Map<String, Object> biz = Maps.newHashMap();
long c = result.getResults().getNumFound();
biz.put(RESULT_KEY_ROWS_COUNT, c);
List<Map<String, Object>> resultList = Lists.newArrayList();
Map<String, Object> row = null;
for (SolrDocument doc : result.getResults()) {
row = Maps.newHashMap();
for (Map.Entry<String, Object> f : doc.entrySet()) {
row.put(f.getKey(), f.getValue());
}
resultList.add(row);
}
biz.put(RESULT_KEY_ROWS, resultList);
this.setBizResult(context, biz);
return;
}
}
Aggregations