Search in sources :

Example 1 with ODataLexer

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");
    }
}
Also used : ODataParser(nikita.webapp.odata.ODataParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ODataLexer(nikita.webapp.odata.ODataLexer) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) NikitaODataToSQLWalker(nikita.webapp.odata.NikitaODataToSQLWalker) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 2 with ODataLexer

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());
}
Also used : ODataParser(nikita.webapp.odata.ODataParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Query(org.hibernate.query.Query) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) CharStream(org.antlr.v4.runtime.CharStream) ODataLexer(nikita.webapp.odata.ODataLexer) NikitaODataToHQLWalker(nikita.webapp.odata.NikitaODataToHQLWalker) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Session(org.hibernate.Session) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ODataLexer (nikita.webapp.odata.ODataLexer)2 ODataParser (nikita.webapp.odata.ODataParser)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)2 NoarkEntity (nikita.common.model.noark5.v4.NoarkEntity)1 NikitaODataToHQLWalker (nikita.webapp.odata.NikitaODataToHQLWalker)1 NikitaODataToSQLWalker (nikita.webapp.odata.NikitaODataToSQLWalker)1 CharStream (org.antlr.v4.runtime.CharStream)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 Session (org.hibernate.Session)1 Query (org.hibernate.query.Query)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1