11package root .core .service .implement ;
22
3- import java .io .File ;
43import java .util .ArrayList ;
54import java .util .List ;
65import java .util .Map ;
1110import java .util .stream .Collectors ;
1211import java .util .stream .StreamSupport ;
1312
14- import org .apache .commons .configuration2 .PropertiesConfiguration ;
15- import org .apache .commons .configuration2 .builder .FileBasedConfigurationBuilder ;
16- import org .apache .commons .configuration2 .builder .fluent .Parameters ;
17- import org .apache .commons .configuration2 .builder .fluent .PropertiesBuilderParameters ;
18- import org .apache .commons .configuration2 .convert .DefaultListDelimiterHandler ;
19- import org .apache .commons .configuration2 .convert .ListDelimiterHandler ;
20- import org .apache .commons .configuration2 .ex .ConfigurationException ;
21-
22- import root .core .domain .exceptions .PropertyNotLoadedException ;
13+ import root .core .repository .constracts .PropertyRepository ;
2314import root .core .service .contracts .PropertyService ;
2415
2516public class FilePropertyService implements PropertyService {
2617
2718 private static final String MONITORING_PRESET_KEY = "monitoring.setting.preset.(.*).filepath" ;
2819 private static final Pattern MONITORING_PRESET_KEY_PATTERN = Pattern .compile (MONITORING_PRESET_KEY );
2920
30- private PropertiesConfiguration connInfoConfig = null ; // DB, Server 접속정보 Configuration
31-
32- public FilePropertyService (String filePath ) throws ConfigurationException {
33- loadAppConfiguration (filePath );
34- }
35-
36- /**
37- * 매개변수로 주어진 경로에 저장된 설정파일을 읽어 [propConfig] PropertiesConfiguration 객체를 초기화한다.
38- *
39- * @param filePath
40- * @throws ConfigurationException
41- */
42- @ Override
43- public void loadAppConfiguration (String filePath ) throws ConfigurationException {
44- File file = new File (filePath );
45- ListDelimiterHandler delimiter = new DefaultListDelimiterHandler (',' );
46-
47- PropertiesBuilderParameters propertyParameters = new Parameters ().properties ();
48- propertyParameters .setFile (file );
49- propertyParameters .setThrowExceptionOnMissing (true );
50- propertyParameters .setListDelimiterHandler (delimiter );
51-
52- FileBasedConfigurationBuilder <PropertiesConfiguration > builder = new FileBasedConfigurationBuilder <>(
53- PropertiesConfiguration .class );
54- builder .configure (propertyParameters );
55-
56- connInfoConfig = builder .getConfiguration ();
21+ private PropertyRepository propRepo ;
22+
23+ public FilePropertyService (PropertyRepository propRepo ) {
24+ this .propRepo = propRepo ;
5725 }
5826
5927 @ Override
60- public boolean isLoaded (String configName ) {
61- boolean result = false ;
62-
63- switch (configName ) {
64- case "connInfoConfig" :
65- if (connInfoConfig != null ) {
66- result = true ;
67- }
68- break ;
69- }
70-
71- return result ;
72- }
73-
74- @ Override
75- public Map <String , String > getMonitoringPresetMap () throws PropertyNotLoadedException {
76- if (!isLoaded ("connInfoConfig" )) {
77- throw new PropertyNotLoadedException ("connInfoConfig" );
78- }
79-
28+ public Map <String , String > getMonitoringPresetMap () {
8029 return StreamSupport
81- .stream (Spliterators .spliteratorUnknownSize (connInfoConfig .getKeys (), Spliterator .ORDERED ), false )
30+ .stream (Spliterators .spliteratorUnknownSize (propRepo .getConfiguration ("connInfoConfig" ).getKeys (),
31+ Spliterator .ORDERED ), false )
8232 .filter (key -> key .matches (MONITORING_PRESET_KEY ))
8333 .collect (Collectors .toUnmodifiableMap (key -> {
8434 Matcher m = MONITORING_PRESET_KEY_PATTERN .matcher (key );
@@ -87,27 +37,17 @@ public Map<String, String> getMonitoringPresetMap() throws PropertyNotLoadedExce
8737 }
8838
8939 @ Override
90- public List <String > getMonitoringPresetFilePathList () throws PropertyNotLoadedException {
91- if (!isLoaded ("connInfoConfig" )) {
92- throw new PropertyNotLoadedException ("connInfoConfig" );
93- }
94-
40+ public List <String > getMonitoringPresetFilePathList () {
9541 return new ArrayList <>(getMonitoringPresetMap ().values ());
9642 }
9743
9844 @ Override
99- public List <String > getMonitoringPresetNameList () throws PropertyNotLoadedException {
100- if (!isLoaded ("connInfoConfig" )) {
101- throw new PropertyNotLoadedException ("connInfoConfig" );
102- }
45+ public List <String > getMonitoringPresetNameList () {
10346 return new ArrayList <>(getMonitoringPresetMap ().keySet ());
10447 }
10548
10649 @ Override
107- public String getMonitoringPresetFilePath (String presetName ) throws PropertyNotLoadedException {
108- if (!isLoaded ("connInfoConfig" )) {
109- throw new PropertyNotLoadedException ("connInfoConfig" );
110- }
50+ public String getMonitoringPresetFilePath (String presetName ) {
11151 return getMonitoringPresetMap ().get (presetName );
11252 }
11353}
0 commit comments