use of com.qlangtech.tis.plugin.IPluginStore in project tis by qlangtech.
the class HeteroEnum method getPlugins.
/**
* ref: PluginItems.save()
*
* @param pluginContext
* @param pluginMeta
* @param
* @return
*/
public List<T> getPlugins(IPluginContext pluginContext, UploadPluginMeta pluginMeta) {
IPluginStore store = getPluginStore(pluginContext, pluginMeta);
if (store == null) {
return Collections.emptyList();
}
// if (this == HeteroEnum.APP_SOURCE) {
// final String dataxName = (pluginMeta.getExtraParam(DataxUtils.DATAX_NAME));
// if (StringUtils.isEmpty(dataxName)) {
// throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME'" + DataxUtils.DATAX_NAME + " can not be null");
// }
// store = com.qlangtech.tis.manage.IAppSource.getPluginStore(pluginContext, dataxName);
// } else if (this == HeteroEnum.DATAX_WRITER || this == HeteroEnum.DATAX_READER) {
// final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
// if (StringUtils.isEmpty(dataxName)) {
// throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME': '" + DataxUtils.DATAX_NAME + "' can not be null");
// }
// store = (this == HeteroEnum.DATAX_READER) ? DataxReader.getPluginStore(pluginContext, dataxName) : DataxWriter.getPluginStore(pluginContext, dataxName);
// } else if (pluginContext.isCollectionAware()) {
// store = TIS.getPluginStore(pluginContext.getCollectionName(), this.extensionPoint);
// } else if (pluginContext.isDataSourceAware()) {
// PostedDSProp dsProp = PostedDSProp.parse(pluginMeta);
// if (StringUtils.isEmpty(dsProp.getDbname())) {
// return Collections.emptyList();
// }
// store = TIS.getDataBasePluginStore(dsProp);
// } else {
// store = TIS.getPluginStore(this.extensionPoint);
// }
// Objects.requireNonNull(store, "plugin store can not be null");
List<T> plugins = store.getPlugins();
if (pluginMeta != null && StringUtils.isNotEmpty(pluginMeta.getTargetPluginDesc())) {
return plugins.stream().filter((p) -> StringUtils.equals(p.getDescriptor().getDisplayName(), pluginMeta.getTargetPluginDesc())).collect(Collectors.toList());
}
return plugins;
}
use of com.qlangtech.tis.plugin.IPluginStore in project tis by qlangtech.
the class OfflineDatasourceAction method doGetDsRelevantReaderDesc.
@Func(value = PermissionConstant.PERMISSION_DATASOURCE_EDIT, sideEffect = false)
public void doGetDsRelevantReaderDesc(Context context) {
com.alibaba.fastjson.JSONObject form = this.parseJsonPost();
Integer dbId = form.getInteger("dbId");
if (dbId == null) {
throw new IllegalStateException("dbId can not be null");
}
com.qlangtech.tis.workflow.pojo.DatasourceDb db = this.offlineDAOFacade.getDatasourceDbDAO().selectByPrimaryKey(dbId);
// IPluginStore<DataSourceFactory> dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(db.getName(), DbScope.DETAILED));
// DataSourceFactory.BaseDataSourceFactoryDescriptor descriptor = (DataSourceFactory.BaseDataSourceFactoryDescriptor) dbPlugin.getPlugin().getDescriptor();
OfflineManager.DBDataXReaderDescName defaultDataXReaderDescName = offlineManager.getDBDataXReaderDescName(db.getName());
Map<String, Object> result = Maps.newHashMap();
if (!defaultDataXReaderDescName.readerDescName.isPresent()) {
// throw new IllegalStateException("datasource:" + db.getName() + " desc:" + descriptor.getDisplayName() + " has not relevant DataXReader defined");
// result.put(KEY_DATA_READER_SETTED + "NotSupport", descriptor.getId());
this.addErrorMessage(context, "插件:" + defaultDataXReaderDescName.dsDescriptor.getId() + " 不支持表导入");
return;
}
DataxReader dataxReader = OfflineManager.getDBDataxReader(this, db.getName());
if (dataxReader != null) {
result.put(KEY_DATA_READER_SETTED, true);
// this.setBizResult(context, result);
// return;
}
DescriptorExtensionList<DataxReader, Descriptor<DataxReader>> descriptorList = TIS.get().getDescriptorList(DataxReader.class);
Optional<DataxReader.BaseDataxReaderDescriptor> dataXReaderDesc = descriptorList.stream().filter((de) -> {
return defaultDataXReaderDescName.getReaderDescName().equals(de.getDisplayName());
}).map((d) -> (DataxReader.BaseDataxReaderDescriptor) d).findFirst();
if (!dataXReaderDesc.isPresent()) {
throw new IllegalStateException("DataXReaderDescName:" + defaultDataXReaderDescName.getReaderDescName() + " can not find relevant DataXReader Descriptor");
}
result.put("readerDesc", new DescriptorsJSON(dataXReaderDesc.get()).getDescriptorsJSON());
result.put("processMeta", DataxAction.getDataXBasicProcessMetaByReader(dataXReaderDesc.get()));
this.setBizResult(context, result);
}
use of com.qlangtech.tis.plugin.IPluginStore in project tis by qlangtech.
the class HeteroEnum method getPluginStore.
@Override
public IPluginStore getPluginStore(IPluginContext pluginContext, UploadPluginMeta pluginMeta) {
IPluginStore store = null;
if (this == HeteroEnum.APP_SOURCE) {
final String dataxName = (pluginMeta.getExtraParam(DataxUtils.DATAX_NAME));
if (StringUtils.isEmpty(dataxName)) {
throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME'" + DataxUtils.DATAX_NAME + " can not be null");
}
store = com.qlangtech.tis.manage.IAppSource.getPluginStore(pluginContext, dataxName);
} else if (this == HeteroEnum.DATAX_WRITER || this == HeteroEnum.DATAX_READER) {
// final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
// if (StringUtils.isEmpty(dataxName)) {
// throw new IllegalArgumentException("plugin extra param 'DataxUtils.DATAX_NAME': '" + DataxUtils.DATAX_NAME + "' can not be null");
// }
// (this == HeteroEnum.DATAX_READER) ? DataxReader.getPluginStore(pluginContext, dataxName) : DataxWriter.getPluginStore(pluginContext, dataxName);
store = getDataXReaderAndWriterStore(pluginContext, this == HeteroEnum.DATAX_READER, pluginMeta);
} else if (this == PARAMS_CONFIG) {
return new ParamsConfigPluginStore(pluginMeta);
} else if (pluginContext.isDataSourceAware()) {
PostedDSProp dsProp = PostedDSProp.parse(pluginMeta);
if (StringUtils.isEmpty(dsProp.getDbname())) {
// Collections.emptyList();
return null;
}
store = TIS.getDataBasePluginStore(dsProp);
} else {
if (this.isAppNameAware()) {
if (!pluginContext.isCollectionAware()) {
throw new IllegalStateException(this.getExtensionPoint().getName() + " must be collection aware");
}
store = TIS.getPluginStore(pluginContext.getCollectionName(), this.extensionPoint);
} else {
store = TIS.getPluginStore(this.extensionPoint);
}
}
Objects.requireNonNull(store, "plugin store can not be null");
return store;
}
use of com.qlangtech.tis.plugin.IPluginStore in project tis by qlangtech.
the class GenerateDAOAndIncrScript method generateIncrScript.
public void generateIncrScript(Context context, IndexIncrStatus incrStatus, boolean compilerAndPackage, Map<DBNode, List<String>> dbNameMap) {
try {
// final Map<DBNode, List<String>> dbNameMap = Collections.unmodifiableMap(indexStreamCodeGenerator.getDbTables());
File sourceRoot = StreamContextConstant.getStreamScriptRootDir(indexStreamCodeGenerator.collection, indexStreamCodeGenerator.incrScriptTimestamp);
if (// 检查Faild Token文件是否存在
!indexStreamCodeGenerator.isIncrScriptDirCreated() || incrStreamCodeCompileFaild(sourceRoot)) {
/**
* *********************************************************************************
* 自动生成scala代码
* ***********************************************************************************
*/
indexStreamCodeGenerator.generateStreamScriptCode();
// 生成依赖dao依赖元数据信息
DBNode.dump(dbNameMap.keySet().stream().collect(Collectors.toList()), StreamContextConstant.getDbDependencyConfigMetaFile(indexStreamCodeGenerator.collection, indexStreamCodeGenerator.incrScriptTimestamp));
/**
* *********************************************************************************
* 生成spring相关配置文件
* ***********************************************************************************
*/
indexStreamCodeGenerator.generateConfigFiles();
}
incrStatus.setIncrScriptMainFileContent(indexStreamCodeGenerator.readIncrScriptMainFileContent());
// TODO 真实生产环境中需要 和 代码build阶段分成两步
if (compilerAndPackage) {
IPluginStore pluginStore = HeteroEnum.INCR_STREAM_CONFIG.getPluginStore(IPluginContext.namedContext(this.indexStreamCodeGenerator.collection), null);
IncrStreamFactory streamFactory = (IncrStreamFactory) pluginStore.getPlugin();
Objects.requireNonNull(streamFactory, "relevant streamFactory can not be null,collection:" + this.indexStreamCodeGenerator.collection);
// CompileAndPackage packager = new CompileAndPackage();
streamFactory.getCompileAndPackageManager().process(context, this.msgHandler, indexStreamCodeGenerator.collection, dbNameMap.entrySet().stream().collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())), sourceRoot, indexStreamCodeGenerator.getSpringXmlConfigsObjectsContext());
}
} catch (Exception e) {
// 将原始文件删除干净
try {
FileUtils.forceDelete(indexStreamCodeGenerator.getStreamCodeGenerator().getIncrScriptDir());
} catch (Throwable ex) {
// ex.printStackTrace();
}
throw new RuntimeException(e);
}
}
Aggregations