use of nikita.webapp.odata.ODataLexer in project nikita-noark5-core by HiOA-ABI.
the class TestODataApp method main.
public static void main(String[] args) throws Exception {
System.out.println("Starting OData parser test");
System.out.println("Picks first line from odata_samples.txt in " + "resources folder.");
try {
AfterApplicationStartup afterApplicationStartup = new AfterApplicationStartup(null);
afterApplicationStartup.populateTranslatedNames();
TestODataApp app = new TestODataApp();
ODataLexer lexer = new ODataLexer(CharStreams.fromStream(app.getInputStreamForParseFile("odata" + File.separator + "odata_samples.txt")));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ODataParser parser = new ODataParser(tokens);
ParseTree tree = parser.odataURL();
ParseTreeWalker walker = new ParseTreeWalker();
// Make the SQL Statement
NikitaODataToSQLWalker sqlWalker = new NikitaODataToSQLWalker();
walker.walk(sqlWalker, tree);
System.out.println(sqlWalker.getSqlStatement());
} catch (RecognitionException e) {
throw new IllegalStateException("Recognition exception");
}
}
use of nikita.webapp.odata.ODataLexer in project nikita-noark5-core by HiOA-ABI.
the class OdataTest method testOdata.
@RequestMapping(method = RequestMethod.GET, value = "arkivstruktur/{\\w*}")
public ResponseEntity<String> testOdata(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) throws Exception {
String uqueryString = request.getQueryString();
String decoded = URLDecoder.decode(uqueryString, UTF_8);
StringBuffer originalRequest = request.getRequestURL();
originalRequest.append("?" + decoded);
CharStream stream = CharStreams.fromString(originalRequest.toString());
ODataLexer lexer = new ODataLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ODataParser parser = new ODataParser(tokens);
ParseTree tree = parser.odataURL();
ParseTreeWalker walker = new ParseTreeWalker();
// Make the HQL Statement
NikitaODataToHQLWalker hqlWalker = new NikitaODataToHQLWalker();
walker.walk(hqlWalker, tree);
Session session = entityManager.unwrap(org.hibernate.Session.class);
Query query = hqlWalker.getHqlStatment(session);
String queryString = query.getQueryString();
System.out.println(queryString);
List<NoarkEntity> list = query.getResultList();
return ResponseEntity.status(HttpStatus.CREATED).body(list.toString());
}
Aggregations