use of com.shencangsheng.view.query.model.QueryInstance in project View-Elasticsearch by shencangsheng.
the class QueryTest method main.
public static void main(String[] args) throws Exception {
FileReader templateJson = new FileReader("template.json");
String queryJson = templateJson.readString();
ObjectMapper objectMapper = new ObjectMapper();
List<QueryInstance> queryInstances = objectMapper.readValue(queryJson, new TypeReference<>() {
});
BoolQueryBuilder boolQueryBuilder = BoolQueryBuilderFactory.boolQueryBuilderFactory(queryInstances, new TemplateModuleInstance());
System.out.println(boolQueryBuilder);
}
use of com.shencangsheng.view.query.model.QueryInstance in project View-Elasticsearch by shencangsheng.
the class QueryModuleDeserializer method deserialize.
@Override
public QueryInstance deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
QueryInstance queryInstance = new QueryInstance();
JsonNode node = p.getCodec().readTree(p);
String module = node.get("module").asText();
AbstractModuleInstance moduleInstance = ReflectUtil.newInstance(queryInstance.getClass().getAnnotation(ModuleInstanceAnnotation.class).moduleInstance());
AbstractPropertyInstance propertyInstance = moduleInstance.getModule(module);
Map<String, PropertyInstance> properties = propertyInstance.getProperties();
JsonNode query = node.get("query");
List<SuperQuery> superQueries = Lists.newArrayListWithCapacity(query.size());
for (JsonNode element : query) {
String key = element.get("key").asText();
PropertyInstance property = properties.get(key);
((ObjectNode) element).putPOJO("property", property);
superQueries.add(ctxt.readTreeAsValue(element, SuperQuery.class));
}
queryInstance.setModule(module);
queryInstance.setQuery(superQueries);
return queryInstance;
}
Aggregations