4
4
import org .slf4j .LoggerFactory ;
5
5
6
6
import java .io .IOException ;
7
- import java .nio .file .Path ;
8
- import java .util .*;
7
+ import java .util .ArrayList ;
8
+ import java .util .Collections ;
9
+ import java .util .List ;
10
+ import java .util .Objects ;
9
11
10
12
public class AngularJSToReact {
11
13
private static final Logger LOGGER = LoggerFactory .getLogger (AngularJSToReact .class );
@@ -18,16 +20,35 @@ public AngularJSToReact() throws IOException {
18
20
public String help () throws IOException {
19
21
return this .cli .call (Collections .singletonList ("--help" ), String .class );
20
22
}
23
+
24
+ /**
25
+ * Checks the connection to the API
26
+ */
27
+ public boolean checkConnection (Ng2rCheckOptions options ) throws IOException {
28
+ final String [] cmd = {
29
+ Ng2rCommand .CHECK_CONNECTION .value (),
30
+ Ng2rOption .API_KEY .value (),
31
+ Objects .requireNonNull (options .getApiKey ()),
32
+ Ng2rOption .MODEL .value (),
33
+ Objects .requireNonNull (options .getModel ().value ())
34
+ };
35
+ try {
36
+ LOGGER .info ("OpenAI Connection test: {}" , this .cli .call (cmd , String .class ));
37
+ } catch (IOException e ) {
38
+ LOGGER .error ("OpenAI Connection test failed: {}" , e .getMessage ());
39
+ return false ;
40
+ }
41
+ return true ;
42
+ }
43
+
21
44
/**
22
45
* Searches a file for convertable AngularJS Components
23
46
*/
24
- public Ng2rSearchResult search (Ng2rCommonOptions options ) throws IOException {
47
+ public Ng2rSearchResult search (Ng2rSearchOptions options ) throws IOException {
25
48
LOGGER .debug ("Finding components in " + options .getFile () + "..." );
26
49
final String [] cmd = {
27
50
Ng2rCommand .SEARCH .value (),
28
- Objects .requireNonNull (options .getFile ()),
29
- Ng2rOption .CWD .value (),
30
- Objects .requireNonNull (options .getCwd ()),
51
+ Objects .requireNonNull (options .getFile ())
31
52
};
32
53
return cli .call (cmd , Ng2rSearchResult .class );
33
54
}
@@ -65,10 +86,8 @@ public Ng2rGenerationResponse generateReactTest(Ng2rTestGenerationOptions option
65
86
return cli .call (cmd , Ng2rGenerationResponse .class );
66
87
}
67
88
68
- private List <String > getTestOptions (Ng2rTestGenerationOptions options ) {
89
+ private List <String > getTestOptions (Ng2rGptOptions options ) {
69
90
final List <String > cmd = new ArrayList <>(List .of (
70
- Ng2rOption .CWD .value (),
71
- Objects .requireNonNull (options .getCwd ()),
72
91
Ng2rOption .API_KEY .value (),
73
92
Objects .requireNonNull (options .getApiKey ())
74
93
));
0 commit comments