-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.java
77 lines (62 loc) · 1.95 KB
/
Input.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.jacobmountain.graphql.client;
import com.jacobmountain.graphql.client.annotations.GraphQLClient;
import com.jacobmountain.graphql.client.exceptions.SchemaNotFoundException;
import com.jacobmountain.graphql.client.utils.Schema;
import com.jacobmountain.graphql.client.utils.StringUtils;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import javax.lang.model.element.TypeElement;
import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
@Slf4j
@Value
public class Input {
TypeElement element;
@Getter(value = AccessLevel.PRIVATE)
String packageStr;
Path root;
public Input(TypeElement element, Path root, String packageStr) {
this.element = element;
this.packageStr = packageStr;
this.root = root;
}
public GraphQLClient getAnnotation() {
return element.getAnnotation(GraphQLClient.class);
}
public TypeMapper getTypeMapper() {
return new TypeMapper(getDtoPackage(), getAnnotation().mapping());
}
public String getDtoPackage() {
return String.join(".", Arrays.asList(
getPackage(),
getAnnotation().dtoPackage()
));
}
public String getPackage() {
return packageStr;
}
public Schema getSchema() {
String value = getAnnotation().schema();
File file = getSchemaFile();
try {
if (StringUtils.hasLength(value)) {
log.info("Reading schema {}", file);
return new Schema(getSchemaFile());
}
} catch (Exception e) {
e.printStackTrace();
}
throw new SchemaNotFoundException(file.getPath());
}
public File getSchemaFile() {
return root.resolve(getAnnotation().schema())
.toAbsolutePath()
.toFile();
}
public boolean isReactive() {
return getAnnotation().reactive();
}
}