Skip to content

Commit 90de633

Browse files
committed
Java API updated
1 parent 1d9ab6f commit 90de633

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

libraries/java/src/main/java/io/github/ng2react/AngularJSToReact.java

+28-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import org.slf4j.LoggerFactory;
55

66
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;
911

1012
public class AngularJSToReact {
1113
private static final Logger LOGGER = LoggerFactory.getLogger(AngularJSToReact.class);
@@ -18,16 +20,35 @@ public AngularJSToReact() throws IOException {
1820
public String help() throws IOException {
1921
return this.cli.call(Collections.singletonList("--help"), String.class);
2022
}
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+
2144
/**
2245
* Searches a file for convertable AngularJS Components
2346
*/
24-
public Ng2rSearchResult search(Ng2rCommonOptions options) throws IOException {
47+
public Ng2rSearchResult search(Ng2rSearchOptions options) throws IOException {
2548
LOGGER.debug("Finding components in " + options.getFile() + "...");
2649
final String[] cmd = {
2750
Ng2rCommand.SEARCH.value(),
28-
Objects.requireNonNull(options.getFile()),
29-
Ng2rOption.CWD.value(),
30-
Objects.requireNonNull(options.getCwd()),
51+
Objects.requireNonNull(options.getFile())
3152
};
3253
return cli.call(cmd, Ng2rSearchResult.class);
3354
}
@@ -65,10 +86,8 @@ public Ng2rGenerationResponse generateReactTest(Ng2rTestGenerationOptions option
6586
return cli.call(cmd, Ng2rGenerationResponse.class);
6687
}
6788

68-
private List<String> getTestOptions(Ng2rTestGenerationOptions options) {
89+
private List<String> getTestOptions(Ng2rGptOptions options) {
6990
final List<String> cmd = new ArrayList<>(List.of(
70-
Ng2rOption.CWD.value(),
71-
Objects.requireNonNull(options.getCwd()),
7291
Ng2rOption.API_KEY.value(),
7392
Objects.requireNonNull(options.getApiKey())
7493
));

libraries/java/src/test/java/io/github/ng2react/AngularJSToReactTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import java.util.Objects;
1111

1212
class AngularJSToReactTest {
13-
private static final String CWD = Objects.requireNonNull(AngularJSToReact.class.getResource("/")).getPath();
14-
private static final String TODO_COMPONENT = "/sourceRoot/todoComponent.js";
13+
private static final String TODO_COMPONENT = Objects.requireNonNull(
14+
AngularJSToReact.class.getResource("/sourceRoot/todoComponent.js")
15+
).getPath();
1516

1617
@Test
1718
void testHelp() throws IOException {
@@ -24,8 +25,7 @@ class WhenAFileIsSearched {
2425

2526
@BeforeEach
2627
void doSearch() throws IOException {
27-
Ng2rCommonOptions options = new Ng2rCommonOptions()
28-
.withCwd(CWD)
28+
Ng2rSearchOptions options = new Ng2rSearchOptions()
2929
.withFile(TODO_COMPONENT);
3030
result = new AngularJSToReact()
3131
.search(options);

schemas/CliArgs.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
],
7070
"properties": {
7171
"file": {
72-
"description": "File path relative to cwd",
72+
"description": "Absolute path of file to search",
7373
"type": "string"
7474
}
7575
}
@@ -80,9 +80,7 @@
8080
"additionalProperties": false,
8181
"required": [
8282
"file",
83-
"apiKey",
84-
"model",
85-
"temperature"
83+
"apiKey"
8684
],
8785
"properties": {
8886
"file": {

schemas/Options.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"title": "Ng2rOption",
55
"type": "string",
66
"enum": [
7-
"--cwd",
87
"--file",
98
"--sourceRoot",
109
"--apiKey",

0 commit comments

Comments
 (0)