Passed
Pull Request — master (#26)
by
unknown
02:25 queued 18s
created

com.hltech.vaunt.generator.VauntGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

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