use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class OperationLogInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
BasicModule action = (BasicModule) invocation.getAction();
final Method method = action.getExecuteMethod();
final String result = invocation.invoke();
Func func = method.getAnnotation(Func.class);
if (func != null && !func.sideEffect()) {
return result;
}
AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
OperationLog log = new OperationLog();
log.setOpType(BasicModule.parseMehtodName());
if (StringUtils.startsWith(log.getOpType(), "doGet")) {
return result;
}
log.setCreateTime(new Date());
if (!(appDomain instanceof Nullable)) {
log.setAppName(appDomain.getAppName());
}
ActionProxy proxy = invocation.getProxy();
// log.setOpType(proxy.getMethod());
HttpServletRequest request = ServletActionContext.getRequest();
if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
// 当前是测试流程的话就不需要记录日志了
return result;
}
IUser user = UserUtils.getUser(request, daoContext);
if (user == null) {
throw new IllegalStateException("user can not be null");
}
StringBuffer jsonObject = new StringBuffer();
JSONObject params = null;
Map<String, String[]> paramsMap = null;
String url = request.getRequestURL().toString();
jsonObject.append("request:");
jsonObject.append(url).append("\n");
String requestBody = null;
if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
paramsMap = request.getParameterMap();
if (paramsMap.size() > 0) {
params = new JSONObject();
for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
if (entry.getValue().length == 1) {
params.put(entry.getKey(), entry.getValue()[0]);
} else {
params.put(entry.getKey(), entry.getValue());
}
}
jsonObject.append("params:").append("\n");
jsonObject.append(params.toString(1)).append("\n");
}
try (ServletInputStream input = request.getInputStream()) {
if (!input.isFinished()) {
requestBody = IOUtils.toString(input, TisUTF8.get());
jsonObject.append("body:").append("\n");
jsonObject.append(requestBody).append("\n");
}
}
}
Context context = new MockContext();
jsonObject.append("\n=================================");
jsonObject.append("response:").append("\n");
jsonObject.append(AjaxValve.buildResultStruct(context));
log.setTabName(proxy.getActionName());
log.setUsrId(user.getId());
log.setUsrName(user.getName());
log.setOpDesc(jsonObject.toString());
operationLogDAO.insertSelective(log);
return result;
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class SchemaAction method parseSchemaResultWithPluginCfg.
public static SchemaResult parseSchemaResultWithPluginCfg(String collection, IMessageHandler msgHandler, Context context, byte[] resContent) throws Exception {
final Map<String, Boolean> pluginTypeAddedMap = Maps.newHashMap();
ISchemaPluginContext schemaPlugin = createSchemaPlugin(collection);
SchemaResult schemaResult = SchemaResult.parseSchemaResult(msgHandler, context, resContent, false, schemaPlugin, (cols, sResult) -> {
boolean pluginTypeAdded;
String identityNameVal = null;
List<FieldTypeFactory> fieldTypeFactories = schemaPlugin.getFieldTypeFactories();
for (FieldTypeFactory plugin : fieldTypeFactories) {
identityNameVal = plugin.identityValue();
if (!(pluginTypeAdded = sResult.containType(identityNameVal))) {
sResult.addFieldType(identityNameVal, SolrFieldsParser.parseFieldType(identityNameVal, identityNameVal, plugin.forStringTokenizer()));
}
pluginTypeAddedMap.put(identityNameVal, pluginTypeAdded);
}
});
schemaResult.content = XModifier.modifySchemaContent(schemaResult.content, (document2, modifier) -> {
// FieldTypeFactory fieldTypeFactory = null;
for (Map.Entry<String, Boolean> entry : pluginTypeAddedMap.entrySet()) {
if (!entry.getValue()) {
// fieldTypeFactory = fieldTypePluginStore.find(entry.getKey());
// Objects.requireNonNull(fieldTypeFactory, "the name:" + entry.getKey() + " relevant fieldTypeFactory can not be null");
// fieldTypeFactory.
modifier.addModify(String.format("/types/fieldType[@name='%s']/@class", entry.getKey()), "plugin:" + entry.getKey());
// precisionStep="0" positionIncrementGap="0"
// modifier.addModify(String.format("/types/fieldType[@name='%s']/@precisionStep", entry.getKey()), "0");
modifier.addModify(String.format("/types/fieldType[@name='%s']/@positionIncrementGap", entry.getKey()), "0");
}
}
});
return schemaResult;
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class SchemaAction method doGetApp.
/**
* 当一个索引创建之后又被删除了,又需要重新创建就需要需执行该流程了,过程中需要将之前的记录找回来
*
* @param context
*/
public void doGetApp(Context context) throws Exception {
final String collectionName = this.getString("name");
if (StringUtils.isEmpty(collectionName)) {
throw new IllegalArgumentException("param name can not be null");
}
AddAppAction.ExtendApp app = new AddAppAction.ExtendApp();
Application a = this.getApplicationDAO().selectByName(collectionName);
BeanUtils.copyProperties(app, a);
WorkFlow df = this.getWorkflowDAOFacade().getWorkFlowDAO().selectByPrimaryKey(a.getWorkFlowId());
if (df == null) {
this.addErrorMessage(context, "当前索引'" + collectionName + "'还未绑定数据流实例");
return;
}
app.setWorkflow(df.getId() + ":" + df.getName());
DepartmentCriteria dc = new DepartmentCriteria();
dc.createCriteria();
List<Department> dpts = this.getDepartmentDAO().selectByExample(dc);
if (dpts.size() < 1) {
this.addErrorMessage(context, "系统还未创建部门实例");
return;
}
app.setSelectableDepartment(dpts.stream().map((r) -> new Option(r.getName(), String.valueOf(r.getDptId()))).collect(Collectors.toList()));
Map<String, Object> result = Maps.newHashMap();
result.put("app", app);
if (!getStructSchema(context, app, (schema) -> {
result.put("schema", schema);
})) {
return;
}
this.setBizResult(context, result);
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class SchemaAction method mergeWfColsWithTplCollection.
/**
* 通过解析workflow的最终导出的字段,来生成Schema配置
*
* @param module
* @param context
* @param appSource
* @return
* @throws Exception
*/
public static SchemaResult mergeWfColsWithTplCollection(BasicModule module, Context context, ISolrAppSource appSource, final ISchemaPluginContext schemaPlugin, SolrFieldsParser.ParseResultCallback... parseResultCallback) throws Exception {
// 通过version取默认模板
Application tplApp = getTemplateApp(module);
SchemaResult tplSchema = getTemplateSchema(module, context, tplApp);
if (!tplSchema.isSuccess()) {
return null;
}
ParseResult parseResult = (ParseResult) tplSchema.getParseResult();
SolrType strType = parseResult.getTisType(ReflectSchemaFieldType.STRING.literia);
List<ColumnMetaData> cols = appSource.reflectCols();
for (ColumnMetaData colName : cols) {
PSchemaField f = new PSchemaField();
f.setName(colName.getKey());
f.setType(strType);
f.setStored(true);
f.setIndexed(false);
f.setMltiValued(false);
f.setDocValue(false);
parseResult.dFields.add(f);
}
parseResult.setUniqueKey(null);
for (SolrFieldsParser.ParseResultCallback c : parseResultCallback) {
c.process(cols, parseResult);
}
parseResult.addReservedFields();
tplSchema.content = XModifier.modifySchemaContent(tplSchema.content, (document2, modifier) -> {
modifier.addModify("/fields/field(:delete)");
modifier.addModify("/sharedKey(:delete)");
modifier.deleteUniqueKey();
updateSchemaXML(parseResult.types, schemaPlugin, parseResult, document2, modifier);
});
parseResultCallback4test.process(cols, parseResult);
return tplSchema;
}
use of com.alibaba.citrus.turbine.Context in project tis by qlangtech.
the class PluginItems method save.
public List<Describable> save(Context context) {
Objects.requireNonNull(this.pluginContext, "pluginContext can not be null");
if (items == null) {
throw new IllegalStateException("prop items can not be null");
}
Descriptor.ParseDescribable describable = null;
AttrValMap attrValMap = null;
List<Descriptor.ParseDescribable<?>> dlist = Lists.newArrayList();
List<Describable> describableList = Lists.newArrayList();
if (this.pluginMeta.isAppend()) {
IPluginStore pluginStore = heteroEnum.getPluginStore(this.pluginContext, this.pluginMeta);
if (pluginStore != null) {
List<Describable> plugins = pluginStore.getPlugins();
boolean firstSkip = false;
for (Describable p : plugins) {
if (!firstSkip) {
firstSkip = true;
Descriptor.ParseDescribable describablesWithMeta = PluginStore.getDescribablesWithMeta(pluginStore, p);
dlist.add(describablesWithMeta);
} else {
dlist.add(new Descriptor.ParseDescribable(p));
}
}
}
}
for (int i = 0; i < this.items.size(); i++) {
attrValMap = this.items.get(i);
/**
*====================================================
* 将客户端post数据包装
* ======================================================
*/
describable = attrValMap.createDescribable(pluginContext);
dlist.add(describable);
describableList.add((Describable) describable.instance);
}
IPluginStoreSave<?> store = null;
if (heteroEnum == HeteroEnum.APP_SOURCE) {
for (Descriptor.ParseDescribable<?> d : dlist) {
if (d.instance instanceof IdentityName) {
store = IAppSource.getPluginStore(pluginContext, ((IdentityName) d.instance).identityValue());
break;
}
}
Objects.requireNonNull(store, "plugin type:" + heteroEnum.getIdentity() + " can not find relevant Store");
} else if (this.pluginContext.isDataSourceAware()) {
store = new IPluginStoreSave<DataSourceFactory>() {
@Override
public boolean setPlugins(IPluginContext pluginContext, Optional<Context> context, List<Descriptor.ParseDescribable<DataSourceFactory>> dlist, boolean update) {
for (Descriptor.ParseDescribable<DataSourceFactory> plugin : dlist) {
PostedDSProp dbExtraProps = PostedDSProp.parse(pluginMeta);
if (DbScope.DETAILED == dbExtraProps.getDbType()) {
dbExtraProps.setDbname(plugin.instance.identityValue());
}
boolean success = TIS.getDataBasePluginStore(dbExtraProps).setPlugins(pluginContext, context, Collections.singletonList(plugin), dbExtraProps.isUpdate());
if (!success) {
return false;
}
}
return true;
}
};
} else if (heteroEnum == HeteroEnum.DATAX_WRITER || heteroEnum == HeteroEnum.DATAX_READER) {
// final String dataxName = pluginMeta.getExtraParam(DataxUtils.DATAX_NAME);
// if (StringUtils.isEmpty(dataxName)) {
// String saveDbName = pluginMeta.getExtraParam(DataxUtils.DATAX_DB_NAME);
// if (StringUtils.isNotBlank(saveDbName)) {
// store = DataxReader.getPluginStore(this.pluginContext, true, saveDbName);
// } else {
// throw new IllegalArgumentException("plugin extra param " + DataxUtils.DATAX_NAME + " can not be null");
// }
// } else {
// KeyedPluginStore<?> keyStore = (heteroEnum == HeteroEnum.DATAX_READER)
// ? DataxReader.getPluginStore(this.pluginContext, dataxName) : DataxWriter.getPluginStore(this.pluginContext, dataxName);
// store = keyStore;
// }
// if ((heteroEnum == HeteroEnum.DATAX_READER)) {
// for (Descriptor.ParseDescribable<?> dataXReader : dlist) {
// DataSourceMeta sourceMeta = (DataSourceMeta) dataXReader.instance;
// pluginContext.setBizResult(context, sourceMeta.getTablesInDB());
// }
// }
store = HeteroEnum.getDataXReaderAndWriterStore(this.pluginContext, this.heteroEnum == HeteroEnum.DATAX_READER, this.pluginMeta);
Optional<IPropertyType.SubFormFilter> subFormFilter = pluginMeta.getSubFormFilter();
if (subFormFilter.isPresent()) {
IPropertyType.SubFormFilter filter = subFormFilter.get();
Optional<Descriptor> firstDesc = heteroEnum.descriptors().stream().filter((des) -> filter.match((Descriptor) des)).map((des) -> (Descriptor) des).findFirst();
if (!firstDesc.isPresent()) {
throw new IllegalStateException("can not find relevant descriptor:" + filter.uploadPluginMeta.toString());
}
// Describable p = keyStore.getPlugin();
// Descriptor des = p.getDescriptor();
PluginFormProperties pluginProps = firstDesc.get().getPluginFormPropertyTypes(subFormFilter);
store = pluginProps.accept(new PluginFormProperties.IVisitor() {
@Override
public IPluginStoreSave<?> visit(SuFormProperties props) {
// 为了在更新插件时候不把plugin上的@SubForm标记的属性覆盖掉,需要先将老的plugin上的值覆盖到新http post过来的反序列化之后的plugin上
// IPluginContext pluginContext, String appname, SuFormProperties subfieldForm, Class<TT> clazz
Class<Describable> clazz = (Class<Describable>) heteroEnum.getExtensionPoint();
// DataxReader.SubFieldFormAppKey<Describable> key
// = new DataxReader.SubFieldFormAppKey<>(pluginContext, dataxName, props, clazz);
//
DataxReader.SubFieldFormAppKey<Describable> key = HeteroEnum.createDataXReaderAndWriterRelevant(pluginContext, pluginMeta, new HeteroEnum.DataXReaderAndWriterRelevantCreator<DataxReader.SubFieldFormAppKey<Describable>>() {
@Override
public DataxReader.SubFieldFormAppKey<Describable> dbRelevant(IPluginContext pluginContext, String saveDbName) {
return new DataxReader.SubFieldFormAppKey<>(pluginContext, true, saveDbName, props, clazz);
}
@Override
public DataxReader.SubFieldFormAppKey<Describable> appRelevant(IPluginContext pluginContext, String dataxName) {
return new DataxReader.SubFieldFormAppKey<>(pluginContext, false, dataxName, props, clazz);
}
});
return KeyedPluginStore.getPluginStore(key);
}
});
}
} else if (heteroEnum == HeteroEnum.PARAMS_CONFIG) {
store = new ParamsConfigPluginStore(this.pluginMeta);
} else if (heteroEnum == HeteroEnum.DATAX_WORKER) {
if (!this.pluginContext.isCollectionAware()) {
throw new IllegalStateException("must be collection aware");
}
store = DataXJobWorker.getJobWorkerStore(new TargetResName(this.pluginContext.getCollectionName()));
// } else if (this.pluginContext.isCollectionAware()) {
// store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
} else {
if (heteroEnum.isAppNameAware()) {
if (!this.pluginContext.isCollectionAware()) {
throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be collection aware");
}
store = TIS.getPluginStore(this.pluginContext.getCollectionName(), heteroEnum.getExtensionPoint());
} else {
store = TIS.getPluginStore(heteroEnum.getExtensionPoint());
}
// if (heteroEnum.isAppNameAware()) {
// throw new IllegalStateException(heteroEnum.getExtensionPoint().getName() + " must be app name aware");
// }
}
// dlist
if (!store.setPlugins(pluginContext, Optional.of(context), convert(dlist))) {
return Collections.emptyList();
}
observable.notifyObservers(new PluginItemsSaveEvent(this.pluginContext, this.heteroEnum, describableList));
return describableList;
}
Aggregations