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());
}
}
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);
}
}
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;
}
Aggregations