Passed
Push — master ( 698c53...e943e4 )
by Filip
02:26
created

serviceRepresentation(String,String,Properties)   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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