11package com .lohika .jclub .dsl .service ;
22
3- import groovy .lang .GroovyShell ;
4- import groovy .util .DelegatingScript ;
5-
63import com .lohika .jclub .dsl .MyDsl ;
7- import com .lohika .jclub .rating .client .RatingServiceClient ;
8- import com .lohika .jclub .storage .client .StorageServiceClient ;
94
10- import org .codehaus .groovy .control .CompilerConfiguration ;
115import org .springframework .beans .factory .annotation .Autowired ;
126import org .springframework .beans .factory .annotation .Value ;
137import org .springframework .web .bind .annotation .GetMapping ;
148import org .springframework .web .bind .annotation .PathVariable ;
159import org .springframework .web .bind .annotation .RequestMapping ;
1610import org .springframework .web .bind .annotation .RestController ;
1711
18- import java .io .File ;
1912import java .io .IOException ;
20- import java .nio .file .Files ;
21- import java .nio .file .Paths ;
2213
2314@ RestController
2415@ RequestMapping (path = "/dsl" )
@@ -28,27 +19,10 @@ public class DslController {
2819 private String basepath ;
2920
3021 @ Autowired
31- private StorageServiceClient storageServiceClient ;
32-
33- @ Autowired
34- private RatingServiceClient ratingServiceClient ;
22+ private DslService dslService ;
3523
3624 @ GetMapping (path = "/{scriptName}" )
37- public Object runScript (@ PathVariable (name = "scriptName" ) String scriptName ) throws IOException {
38- File file = new File (basepath + scriptName + ".mydsl" );
39- String script = new String (Files .readAllBytes (Paths .get (file .getPath ())));
40-
41- MyDsl dsl = new MyDsl (ratingServiceClient , storageServiceClient );
42-
43- CompilerConfiguration configuration = new CompilerConfiguration ();
44- configuration .setScriptBaseClass (DelegatingScript .class .getName ());
45-
46- GroovyShell groovy = new GroovyShell (configuration );
47-
48- DelegatingScript delegatingScript = (DelegatingScript ) groovy .parse (script );
49- delegatingScript .setDelegate (dsl );
50- delegatingScript .run ();
51-
52- return dsl ;
25+ public MyDsl runScript (@ PathVariable (name = "scriptName" ) String scriptName ) throws IOException {
26+ return dslService .runScript (scriptName );
5327 }
5428}
0 commit comments