|
1
|
|
|
package com.hltech.vaunt.generator; |
|
2
|
|
|
|
|
3
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException; |
|
4
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
5
|
|
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; |
|
6
|
|
|
import com.hltech.vaunt.core.domain.model.Service; |
|
7
|
|
|
import com.hltech.vaunt.generator.domain.representation.RepresentationExtractor; |
|
8
|
|
|
import com.hltech.vaunt.generator.domain.representation.RepresentationWriter; |
|
9
|
|
|
import lombok.RequiredArgsConstructor; |
|
10
|
|
|
|
|
11
|
|
|
import java.io.IOException; |
|
12
|
|
|
|
|
13
|
|
|
@RequiredArgsConstructor |
|
14
|
|
|
public class VauntGenerator { |
|
15
|
|
|
|
|
16
|
|
|
private final RepresentationExtractor extractor; |
|
17
|
|
|
private final RepresentationWriter writer; |
|
18
|
|
|
|
|
19
|
|
|
public VauntGenerator() { |
|
20
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
21
|
|
|
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper); |
|
22
|
|
|
|
|
23
|
|
|
extractor = new RepresentationExtractor(generator); |
|
24
|
|
|
writer = new RepresentationWriter(mapper); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public void writeVauntFile(String packageRoot, String serviceName, String targetDirectory) { |
|
28
|
|
|
try { |
|
29
|
|
|
writer.writeServiceRepresentation(serviceRepresentation(packageRoot, serviceName), targetDirectory); |
|
30
|
|
|
} catch (IOException ex) { |
|
31
|
|
|
throw new RuntimeException("Error when trying to write service representation to file", ex); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private Service serviceRepresentation(String packageRoot, String serviceName) { |
|
36
|
|
|
try { |
|
37
|
|
|
return extractor.extractServiceRepresentation(packageRoot, serviceName); |
|
38
|
|
|
} catch (JsonMappingException ex) { |
|
39
|
|
|
throw new RuntimeException( |
|
40
|
|
|
String.format( |
|
41
|
|
|
"Error when trying to extract service representation: package=%s, service name=%s", |
|
42
|
|
|
packageRoot, serviceName), ex); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|