use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.
the class Descriptor method buildPluginInstance.
private <TARGET> TARGET buildPluginInstance(IPluginContext pluginContext, Map<String, JSONObject> keyValMap, ParseDescribable<TARGET> result, PluginFormProperties propertyTypes) {
TARGET describable = result.instance;
String attr;
PropertyType attrDesc;
JSONObject valJ;
String impl;
Descriptor descriptor;
String attrVal;
for (Map.Entry<String, PropertyType> entry : propertyTypes.getKVTuples()) {
attr = entry.getKey();
attrDesc = entry.getValue();
valJ = keyValMap.get(attr);
if (valJ == null && attrDesc.isInputRequired()) {
throw new IllegalStateException("prop:" + attr + " can not be empty");
}
if (valJ == null) {
valJ = new JSONObject();
}
if (attrDesc.isDescribable()) {
JSONObject descVal = valJ.getJSONObject("descVal");
impl = descVal.getString("impl");
descriptor = TIS.get().getDescriptor(impl);
if (descriptor == null) {
throw new IllegalStateException("impl:" + impl + " relevant descripotor can not be null");
}
ParseDescribable vals = descriptor.newInstance(pluginContext, parseAttrValMap(descVal.get("vals")), Optional.empty());
attrDesc.setVal(describable, vals.instance);
} else {
if (attrDesc.typeIdentity() == FormFieldType.MULTI_SELECTABLE.getIdentity()) {
List<FormFieldType.SelectedItem> selectedItems = getSelectedMultiItems(valJ);
List<String> multi = selectedItems.stream().filter((item) -> item.isChecked()).map((item) -> (String) item.getValue()).collect(Collectors.toList());
attrDesc.setVal(describable, multi);
} else {
boolean containVal = valJ.containsKey(KEY_primaryVal) && StringUtils.isNotBlank(valJ.getString(KEY_primaryVal));
// describable
if (!containVal && attrDesc.isInputRequired()) {
throw new IllegalStateException("prop:" + attr + " can not be empty");
}
if (containVal) {
attrVal = valJ.getString(KEY_primaryVal);
attrDesc.setVal(describable, attrVal);
if (valJ.containsKey(KEY_OPTIONS)) {
JSONArray options = valJ.getJSONArray(KEY_OPTIONS);
JSONObject opt = null;
for (int i = 0; i < options.size(); i++) {
opt = options.getJSONObject(i);
try {
// 将options中的选中的插件来源记录下来,后续在集群中各组件中传输插件可以用
if (StringUtils.equals(attrVal, opt.getString("name"))) {
Class<?> implClass = TIS.get().pluginManager.uberClassLoader.loadClass(opt.getString("impl"));
PluginWrapper pluginWrapper = TIS.get().pluginManager.whichPlugin(implClass);
XStream2.PluginMeta pluginMeta = pluginWrapper.getDesc();
result.extraPluginMetas.add(pluginMeta);
break;
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
}
}
}
}
return describable;
}
use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.
the class TestDataxReader method testGetDataxReader.
// public void testUpdateDataxReader() {
// KeyedPluginStore<DataxReader> readerStore = DataxReader.getPluginStore(null, dataXName);
//
// DataxReader dataxReader = readerStore.getPlugin();
// assertNotNull(dataxReader);
//
//
// SuFormProperties props = EasyMock.createMock("subformProp", SuFormProperties.class);
//
// EasyMock.expect(props.getSubFormFieldName()).andReturn("selectedTabs");
//
// DataxReader.SubFieldFormAppKey<DataxReader> subFieldKey
// = new DataxReader.SubFieldFormAppKey<>(null, false, dataXName, props, DataxReader.class);
// KeyedPluginStore<DataxReader> subFieldStore = KeyedPluginStore.getPluginStore(subFieldKey);
//
// List<Descriptor.ParseDescribable<DataxReader>> dlist = Lists.newArrayList();
// DataxReader subformReader =
// dlist.add(new Descriptor.ParseDescribable());
// subFieldStore.setPlugins(null, Optional.empty(), dlist);
//
// }
public void testGetDataxReader() {
KeyedPluginStore<DataxReader> readerStore = DataxReader.getPluginStore(null, dataXName);
DataxReader dataxReader = readerStore.getPlugin();
assertNotNull("dataxReader can not be null", dataxReader);
List<ISelectedTab> selectedTabs = dataxReader.getSelectedTabs();
assertNotNull(selectedTabs);
assertTrue(selectedTabs.size() > 0);
IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
//
String execId = "7b069200-9845-d60b-cef0-408c6940ffda";
EasyMock.expect(pluginContext.getExecId()).andReturn(execId).times(2);
EasyMock.expect(pluginContext.getRequestHeader(DataxReader.HEAD_KEY_REFERER)).andReturn("/x/" + dataXName + "/update").times(2);
EasyMock.expect(pluginContext.isCollectionAware()).andReturn(true).times(2);
EasyMock.replay(pluginContext);
readerStore = DataxReader.getPluginStore(pluginContext, dataXName);
assertNotNull("readerStore can not be null", readerStore);
dataxReader = readerStore.getPlugin();
assertNotNull("dataxReader can not be null", dataxReader);
selectedTabs = dataxReader.getSelectedTabs();
assertNotNull(selectedTabs);
assertTrue(selectedTabs.size() > 0);
for (ISelectedTab tab : selectedTabs) {
assertTrue(tab.getCols().size() > 0);
for (ISelectedTab.ColMeta col : tab.getCols()) {
assertNotNull("tab:" + tab.getName() + ",col:" + col.getName() + " can not be null", col.getType());
}
}
EasyMock.verify(pluginContext);
}
use of com.qlangtech.tis.util.IPluginContext in project tis by qlangtech.
the class TestDataxProcessor method testLoad.
/**
* 加载一个空的默认DataxProcessor
*/
public void testLoad() {
IPluginContext pluginContext = EasyMock.createMock("pluginContext", IPluginContext.class);
String randomDataXName = RandomStringUtils.randomAlphabetic(4);
EasyMock.replay(pluginContext);
DataxProcessor dataxProcessor = DataxProcessor.load(pluginContext, randomDataXName);
assertNotNull(dataxProcessor);
EasyMock.verify(pluginContext);
}
Aggregations