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

com.hltech.vaunt.generator.VauntGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
eloc 23
c 4
b 0
f 0
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A VauntGenerator() 0 4 1
A writeVauntFile(String,String,String) 0 2 1
A writeVauntFile(String,String,String,Properties) 0 6 2
A serviceRepresentation(String,String,Properties) 0 8 2
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