Search in sources :

Example 1 with SchemaResult

use of com.qlangtech.tis.solrdao.SchemaResult in project tis by qlangtech.

the class AddAppAction method doAdvanceAddApp.

/**
 * 高级添加,会在数据库中添加对象记录
 *
 * @param context
 */
@Func(PermissionConstant.APP_ADD)
public void doAdvanceAddApp(Context context) throws Exception {
    CreateIndexConfirmModel confiemModel = parseJsonPost(CreateIndexConfirmModel.class);
    confiemModel.setTplAppId(getTemplateApp(this).getAppId());
    SchemaResult schemaResult = this.parseSchema(context, ISchemaPluginContext.NULL, confiemModel);
    if (!createNewApp(context, confiemModel.getAppform(), -1, /**
     * publishSnapshotId
     */
    null, /* schemaContent */
    true).isSuccess()) {
        // 只作表单校验 表单校验不通过
        return;
    }
    this.createCollection(context, confiemModel, schemaResult, (ctx, app, publishSnapshotId, schemaContent) -> {
        return this.createNewApp(ctx, app, publishSnapshotId, schemaContent);
    });
}
Also used : SchemaResult(com.qlangtech.tis.solrdao.SchemaResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 2 with SchemaResult

use of com.qlangtech.tis.solrdao.SchemaResult in project tis by qlangtech.

the class CollectionAction method createCollection.

/**
 * 创建索引实例
 *
 * @param context
 * @param df
 * @param indexName
 * @param targetColMetas
 * @throws Exception
 */
private Optional<Application> createCollection(Context context, WorkFlow df, String indexName, TargetColumnMeta targetColMetas) throws Exception {
    Objects.requireNonNull(df, "param df can not be null");
    CreateIndexConfirmModel confirmModel = new CreateIndexConfirmModel();
    SelectableServer.ServerNodeTopology coreNode = new SelectableServer.ServerNodeTopology();
    SelectableServer.CoreNode[] coreNodeInfo = SelectableServer.getCoreNodeInfo(this.getRequest(), this, false, true);
    // FIXME 这一步应该是去掉的最终提交的host内容应该是一个ip格式的,应该是取getNodeName的内容,UI中的内容应该要改一下
    for (SelectableServer.CoreNode n : coreNodeInfo) {
        n.setHostName(n.getNodeName());
    }
    coreNode.setReplicaCount(1);
    coreNode.setShardCount(SHARED_COUNT);
    coreNode.setHosts(coreNodeInfo);
    confirmModel.setCoreNode(coreNode);
    confirmModel.setTplAppId(getTemplateApp(this).getAppId());
    ExtendApp extendApp = new ExtendApp();
    extendApp.setDptId(SysInitializeAction.DEPARTMENT_DEFAULT_ID);
    extendApp.setName(indexName);
    extendApp.setRecept(this.getUser().getName());
    Objects.requireNonNull(df.getId(), "id of dataflow can not be null");
    extendApp.setWorkflow(df.getId() + ":" + df.getName());
    confirmModel.setAppform(extendApp);
    SchemaResult schemaResult = SchemaAction.mergeWfColsWithTplCollection(this, context, null, ISchemaPluginContext.NULL, (cols, schemaParseResult) -> {
        ColumnMetaData pkMeta = targetColMetas.getPKMeta();
        PSchemaField field = null;
        ColMetaTuple rft = null;
        TargetCol tcol = null;
        final Map<String, ColMetaTuple> targetCols = targetColMetas.getTargetCols();
        for (ISchemaField f : schemaParseResult.getSchemaFields()) {
            field = (PSchemaField) f;
            rft = targetCols.get(f.getName());
            if (rft == null) {
                throw new IllegalStateException("field:" + f.getName() + " relevant reflect 'SchemaFieldType' can not be null");
            }
            boolean isPk = false;
            if (StringUtils.equals(pkMeta.getKey(), field.getName())) {
                // 设置主键
                isPk = true;
                field.setIndexed(true);
                field.setType(schemaParseResult.getTisType(ReflectSchemaFieldType.STRING.literia));
            } else {
                field.setType(schemaParseResult.getTisType(rft.getSchemaFieldType()));
            }
            tcol = targetColMetas.targetColMap.get(field.getName());
            if (tcol != null) {
                if (tcol.isIndexable()) {
                    field.setIndexed(true);
                }
                if (rft.colMeta.getSchemaFieldType().tokenizer) {
                    if (StringUtils.isNotEmpty(tcol.getToken())) {
                        field.setTokenizerType(tcol.getToken());
                    } else {
                        // 主键不需要分词
                        if (!isPk && rft.isTypeOf(ReflectSchemaFieldType.STRING)) {
                            // String类型默认使用like分词
                            field.setTokenizerType(ReflectSchemaFieldType.LIKE.literia);
                        }
                    }
                }
            }
        }
        schemaParseResult.setUniqueKey(pkMeta.getKey());
        schemaParseResult.setSharedKey(pkMeta.getKey());
    });
    // 创建索引实例
    return this.createCollection(context, confirmModel, schemaResult, (ctx, app, publishSnapshotId, schemaContent) -> {
        return this.createNewApp(ctx, app, publishSnapshotId, schemaContent);
    });
}
Also used : ISchemaField(com.qlangtech.tis.solrdao.ISchemaField) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) SelectableServer(com.qlangtech.tis.coredefine.module.control.SelectableServer) SchemaResult(com.qlangtech.tis.solrdao.SchemaResult) CreateIndexConfirmModel(com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel)

Example 3 with SchemaResult

use of com.qlangtech.tis.solrdao.SchemaResult in project tis by qlangtech.

the class AddAppAction method doCreateCollection.

/**
 * 创建索引,不在数据库中添加记录<br>
 * 当一个索引创建之后又被删除了,又需要重新创建就需要需执行该流程了
 *
 * @param context
 * @throws Exception
 */
@Func(PermissionConstant.APP_ADD)
public void doCreateCollection(Context context) throws Exception {
    CreateIndexConfirmModel confiemModel = parseJsonPost(CreateIndexConfirmModel.class);
    confiemModel.setTplAppId(getTemplateApp(this).getAppId());
    SchemaResult schemaResult = this.parseSchema(context, ISchemaPluginContext.NULL, confiemModel);
    this.createCollection(context, confiemModel, schemaResult, (ctx, app, publishSnapshotId, schemaContent) -> {
        CreateSnapshotResult result = new CreateSnapshotResult();
        result.setSuccess(true);
        Application a = getApplicationDAO().selectByName(app.getProjectName());
        if (a == null) {
            throw new IllegalStateException("appname:" + app.getProjectName() + " relevant app can not be find in DB");
        }
        result.setNewSnapshotId(getPublishSnapshotId(this.getServerGroupDAO(), a));
        return result;
    });
}
Also used : SchemaResult(com.qlangtech.tis.solrdao.SchemaResult) Func(com.qlangtech.tis.manage.spring.aop.Func)

Aggregations

SchemaResult (com.qlangtech.tis.solrdao.SchemaResult)3 Func (com.qlangtech.tis.manage.spring.aop.Func)2 SelectableServer (com.qlangtech.tis.coredefine.module.control.SelectableServer)1 CreateIndexConfirmModel (com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel)1 ISchemaField (com.qlangtech.tis.solrdao.ISchemaField)1 PSchemaField (com.qlangtech.tis.solrdao.pojo.PSchemaField)1