Search in sources :

Example 1 with IIndexMetaData

use of com.qlangtech.tis.exec.IIndexMetaData in project tis by qlangtech.

the class TestSolrFieldParser method testSchemaFields.

public void testSchemaFields() throws Exception {
    // SolrFieldsParser solrFieldsParser = new SolrFieldsParser();
    try (InputStream reader = this.getClass().getResourceAsStream("schema-sample.txt")) {
        assertNotNull(reader);
        IIndexMetaData meta = SolrFieldsParser.parse(() -> IOUtils.toByteArray(reader), (typeName) -> {
            throw new UnsupportedOperationException();
        });
        ParseResult parseResult = meta.getSchemaParseResult();
        Assert.assertTrue("isValid shall be true", parseResult.isValid());
        Assert.assertEquals(20, parseResult.dFields.size());
        System.out.println("dFields.size:" + parseResult.dFields.size());
        Assert.assertEquals("parseResult.getFieldNameSet() can not be empty", 20, parseResult.getFieldNameSet().size());
        System.out.println(parseResult.getFieldNameSet().size());
    }
}
Also used : ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) IIndexMetaData(com.qlangtech.tis.exec.IIndexMetaData) InputStream(java.io.InputStream)

Example 2 with IIndexMetaData

use of com.qlangtech.tis.exec.IIndexMetaData in project tis by qlangtech.

the class SolrPojoBuilder method create.

public void create() throws Exception {
    PrintWriter writer = null;
    InputStream reader = null;
    try {
        writer = new PrintWriter((buildContext.getOutputStream()));
        IIndexMetaData metaData = SolrFieldsParser.parse(() -> buildContext.getResourceInputStream(), ISchemaPluginContext.NULL);
        ArrayList<PSchemaField> fields = metaData.getSchemaParseResult().dFields;
        writer.print("package ");
        writer.println(this.buildContext.getTargetNameSpace() + ";");
        writer.println();
        writer.println();
        if (SolrFieldsParser.hasMultiValuedField(fields)) {
            writer.println("import java.util.List;");
        }
        writer.println("import org.apache.solr.client.solrj.beans.Field;");
        writer.println();
        writer.println("public class " + this.buildContext.getPojoName() + "{");
        for (PSchemaField f : fields) {
            if (f.isStored()) {
                writer.println("\t@Field(\"" + f.getName() + "\")");
                writer.println("\tprivate " + f.getFileTypeLiteria() + " " + f.getPropertyName() + ";");
            }
            writer.println();
        // System.out.println("name:" + f.getName() + ", type:"
        // + f.getPropertyName() + ", get:"
        // + f.getGetterMethodName() + " set:"
        // + f.getSetMethodName());
        }
        // 生成get set方法
        for (PSchemaField f : fields) {
            // setter mehod
            if (!f.isStored()) {
                continue;
            }
            writer.println("\tpublic void " + f.getSetMethodName() + "(" + f.getFileTypeLiteria() + " " + f.getPropertyName() + "){");
            writer.println("\t   this." + f.getPropertyName() + " = " + f.getPropertyName() + ";");
            writer.println("\t}");
            writer.println();
            // getter mehod
            writer.println("\tpublic " + f.getFileTypeLiteria() + " " + f.getGetterMethodName() + "(){");
            writer.println("\t   return this." + f.getPropertyName() + ";");
            writer.println("\t}");
            writer.println();
        // writer.println("\t@Field(\"" + f.getName() + "\")");
        // writer.println("\tprivate " + f.getFileTypeLiteria() +
        // " "
        // + f.getPropertyName() + ";");
        // writer.println();
        // System.out.println("name:" + f.getName() + ", type:"
        // + f.getPropertyName() + ", get:"
        // + f.getGetterMethodName() + " set:"
        // + f.getSetMethodName());
        }
        writer.println("}");
        // File targetFile = getNewFileName();
        System.out.println(" successful create new pojo file  ");
    } finally {
        IOUtils.closeQuietly(reader);
        writer.flush();
        buildContext.closeWriter(writer);
    }
}
Also used : PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) IIndexMetaData(com.qlangtech.tis.exec.IIndexMetaData) InputStream(java.io.InputStream) PrintWriter(java.io.PrintWriter)

Example 3 with IIndexMetaData

use of com.qlangtech.tis.exec.IIndexMetaData in project tis by qlangtech.

the class SchemaResult method parseSchemaResult.

/**
 * 解析提交的schemaxml 内容
 *
 * @param context
 * @return
 * @throws Exception
 */
public static SchemaResult parseSchemaResult(IMessageHandler module, Context context, byte[] schemaContent, boolean shallValidate, ISchemaFieldTypeContext schemaPlugin, SolrFieldsParser.ParseResultCallback... parseResultCallback) {
    if (schemaContent == null) {
        throw new IllegalStateException("schemaContent can not be null");
    }
    if (schemaPlugin == null) {
        throw new IllegalArgumentException("param schemaPlugin can not be null");
    }
    ParseResult parseResult;
    try {
        IIndexMetaData meta = SolrFieldsParser.parse(() -> schemaContent, schemaPlugin, shallValidate);
        parseResult = meta.getSchemaParseResult();
        for (SolrFieldsParser.ParseResultCallback process : parseResultCallback) {
            process.process(Collections.emptyList(), parseResult);
        }
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        parseResult = new ParseResult(shallValidate);
        parseResult.errlist.add(e.getMessage());
    }
    if (!parseResult.isValid() || parseResult.errlist.size() > 0) {
        for (String err : parseResult.errlist) {
            module.addErrorMessage(context, err);
        }
        return create(null, schemaContent).faild();
    }
    return create(parseResult, schemaContent);
// // new String(, getEncode());
// result.content = schemaContent;
// result.success = true;
// result.parseResult = parseResult;
// return result;
}
Also used : ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) IIndexMetaData(com.qlangtech.tis.exec.IIndexMetaData)

Aggregations

IIndexMetaData (com.qlangtech.tis.exec.IIndexMetaData)3 ParseResult (com.qlangtech.tis.solrdao.impl.ParseResult)2 InputStream (java.io.InputStream)2 PSchemaField (com.qlangtech.tis.solrdao.pojo.PSchemaField)1 PrintWriter (java.io.PrintWriter)1