es.webbeta.serializer.ConfigurationManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
dl 0
loc 62
c 1
b 0
f 0
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadataAccessor() 0 2 1
A ConfigurationManager(ConfigurationProvider,Environment,Cache) 0 18 2
A getAccessType() 0 2 1
A getFieldFormatter() 0 2 1
A newMetadataProvider() 0 2 1
A getIncludeNullValues() 0 2 1
A getDateFormatType() 0 2 1
A getMetadataPath() 0 2 1
1
package es.webbeta.serializer;
2
3
import es.webbeta.serializer.base.*;
4
import es.webbeta.serializer.type.DateFormatType;
5
import es.webbeta.serializer.type.FieldAccessType;
6
import es.webbeta.serializer.type.FieldFormatterType;
7
8
import java.nio.file.Path;
9
import java.nio.file.Paths;
10
11
public class ConfigurationManager {
12
13
    public static final String METADATA_DIR_KEY = "serializer.metadata.dir";
14
    public static final String INCLUDE_NULL_VALUES_KEY = "serializer.include_null_values";
15
    public static final String FIELD_FORMATTING_METHOD_KEY = "serializer.field_formatting_method";
16
    public static final String FIELD_ACCESS_TYPE_KEY = "serializer.access_type";
17
    public static final String DATE_FORMAT_KEY = "serializer.date_format";
18
19
    private Path metadataPath;
20
    private Boolean includeNullValues;
21
    private FieldFormatterType formatterType;
22
    private FieldAccessType accessType;
23
    private DateFormatType dateFormatType;
24
25
    private MetadataAccessor metadataAccessor;
26
27
    public ConfigurationManager(
28
            ConfigurationProvider conf,
29
            Environment environment,
30
            Cache cache
31
    ) {
32
33
        metadataPath = Paths.get(conf.getString(METADATA_DIR_KEY, "conf/serializer/"));
34
        includeNullValues = conf.getBoolean(INCLUDE_NULL_VALUES_KEY, false);
35
        formatterType = FieldFormatterType.fromString(conf.getString(FIELD_FORMATTING_METHOD_KEY, FieldFormatterType.LOWER_UNDERSCORE.toString()));
36
        accessType = FieldAccessType.fromString(conf.getString(FIELD_ACCESS_TYPE_KEY, FieldAccessType.PROPERTY.toString()));
37
        dateFormatType = DateFormatType.fromString(conf.getString(DATE_FORMAT_KEY, DateFormatType.ISO8601.toString()));
38
39
        if (environment.isProd()) {
40
            metadataAccessor = new CacheMetadataAccessor(cache);
41
        } else
42
            metadataAccessor = new FileMetadataAccessor();
43
44
        metadataAccessor.setMetadataPath(metadataPath);
45
    }
46
47
    public Path getMetadataPath() {
48
        return metadataPath;
49
    }
50
51
    public Boolean getIncludeNullValues() {
52
        return includeNullValues;
53
    }
54
55
    public MetadataAccessor getMetadataAccessor() {
56
        return metadataAccessor;
57
    }
58
59
    public SerializerMetadataProvider newMetadataProvider() {
60
        return new SerializerYamlMetadataProvider(metadataAccessor);
61
    }
62
63
    public es.webbeta.serializer.base.FieldFormatter getFieldFormatter() {
64
        return new FieldFormatter(formatterType);
65
    }
66
67
    public FieldAccessType getAccessType() {
68
        return accessType;
69
    }
70
71
    public DateFormatType getDateFormatType() {
72
        return dateFormatType;
73
    }
74
75
}
76