|
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Arrays; |
| 5 | +import java.util.HashMap; |
5 | 6 | import java.util.List; |
6 | 7 | import java.util.Map; |
7 | | -import java.util.Spliterator; |
8 | | -import java.util.Spliterators; |
9 | 8 | import java.util.regex.Matcher; |
10 | 9 | import java.util.regex.Pattern; |
11 | 10 | import java.util.stream.Collectors; |
12 | | -import java.util.stream.StreamSupport; |
| 11 | + |
| 12 | +import org.apache.commons.configuration2.PropertiesConfiguration; |
| 13 | +import org.apache.commons.lang3.StringUtils; |
13 | 14 |
|
14 | 15 | import root.core.domain.JdbcConnectionInfo; |
15 | 16 | import root.core.domain.JschConnectionInfo; |
| 17 | +import root.core.domain.MonitoringYN; |
| 18 | +import root.core.domain.MonitoringYN.MonitoringTypeAndYN; |
| 19 | +import root.core.domain.enums.MonitoringType; |
| 20 | +import root.core.domain.enums.RoundingDigits; |
| 21 | +import root.core.domain.enums.UsageUIType; |
16 | 22 | import root.core.repository.constracts.PropertyRepository; |
17 | 23 | import root.core.service.contracts.PropertyService; |
| 24 | +import root.utils.UnitUtils.FileSize; |
18 | 25 |
|
19 | 26 | public class FilePropertyService implements PropertyService { |
20 | 27 |
|
@@ -59,20 +66,80 @@ public void loadMonitoringInfoConfig(String filePath) { |
59 | 66 | propRepo.loadMonitoringInfoConfig(filePath); |
60 | 67 | } |
61 | 68 |
|
| 69 | + /** |
| 70 | + * 최근 사용된 모니터링 여부 Preset 설정파일명을 반환한다. |
| 71 | + */ |
62 | 72 | @Override |
63 | 73 | public String getLastUsePresetFileName(String filePath) { |
64 | 74 | return propRepo.getLastUseMonitoringPresetName(filePath); |
65 | 75 | } |
66 | 76 |
|
| 77 | + @Override |
| 78 | + public List<MonitoringYN> getDBMonitoringYnList(String presetConfigFileName) { |
| 79 | + String presetConfigFilePath = propRepo.getMonitoringPresetMap().get(presetConfigFileName); |
| 80 | + |
| 81 | + // Load |
| 82 | + loadMonitoringInfoConfig(presetConfigFilePath); |
| 83 | + |
| 84 | + List<String> dbAliasList = Arrays.asList(propRepo.getMonitoringDBNames()); |
| 85 | + List<MonitoringType> monitoringTypeList = Arrays.asList(MonitoringType.values()).stream() |
| 86 | + .filter(t -> t.getCategory().equals("DB")).collect(Collectors.toList()); |
| 87 | + |
| 88 | + return getMonitoringYNList(dbAliasList, monitoringTypeList); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public List<MonitoringYN> getServerMonitoringYnList(String presetConfigFileName) { |
| 93 | + String presetConfigFilePath = propRepo.getMonitoringPresetMap().get(presetConfigFileName); |
| 94 | + |
| 95 | + // Load |
| 96 | + loadMonitoringInfoConfig(presetConfigFilePath); |
| 97 | + |
| 98 | + List<String> serverAliasList = Arrays.asList(propRepo.getMonitoringServerNames()); |
| 99 | + List<MonitoringType> monitoringTypeList = Arrays.asList(MonitoringType.values()).stream() |
| 100 | + .filter(t -> t.getCategory().equals("SERVER")).collect(Collectors.toList()); |
| 101 | + |
| 102 | + return getMonitoringYNList(serverAliasList, monitoringTypeList); |
| 103 | + } |
| 104 | + |
| 105 | + private List<MonitoringYN> getMonitoringYNList(List<String> aliasList, List<MonitoringType> monitoringTypeList) { |
| 106 | + |
| 107 | + List<MonitoringYN> result = new ArrayList<>(); |
| 108 | + for (String serverAlias : aliasList) { |
| 109 | + MonitoringYN monitoringYn = new MonitoringYN(serverAlias); |
| 110 | + List<MonitoringTypeAndYN> list = new ArrayList<>(); |
| 111 | + for (MonitoringType monitoringType : monitoringTypeList) { |
| 112 | + String yn = propRepo |
| 113 | + .getMonitoringConfigResource(monitoringType.getName().replace(" ", "_") + "." + serverAlias); |
| 114 | + if (!StringUtils.isEmpty(yn)) { |
| 115 | + list.add(new MonitoringTypeAndYN(monitoringType, yn.equals("Y") ? true : false)); |
| 116 | + } else { |
| 117 | + list.add(new MonitoringTypeAndYN(monitoringType, false)); |
| 118 | + } |
| 119 | + } |
| 120 | + monitoringYn.setMonitoringTypeList(list); |
| 121 | + result.add(monitoringYn); |
| 122 | + } |
| 123 | + |
| 124 | + return result; |
| 125 | + } |
| 126 | + |
67 | 127 | @Override |
68 | 128 | public Map<String, String> getMonitoringPresetMap() { |
69 | | - return StreamSupport |
70 | | - .stream(Spliterators.spliteratorUnknownSize(propRepo.getConfiguration("connInfoConfig").getKeys(), |
71 | | - Spliterator.ORDERED), false) |
72 | | - .filter(key -> key.matches(MONITORING_PRESET_KEY)).collect(Collectors.toUnmodifiableMap(key -> { |
73 | | - Matcher m = MONITORING_PRESET_KEY_PATTERN.matcher(key); |
74 | | - return m.matches() ? m.group(1) : null; |
75 | | - }, key -> propRepo.getMonitoringConfigResource(key))); |
| 129 | + Map<String, String> result = new HashMap<>(); |
| 130 | + |
| 131 | + PropertiesConfiguration config = propRepo.getConfiguration("connInfoConfig"); |
| 132 | + |
| 133 | + config.getKeys().forEachRemaining(key -> { |
| 134 | + if (key.matches(MONITORING_PRESET_KEY)) { |
| 135 | + Matcher m = MONITORING_PRESET_KEY_PATTERN.matcher(key); |
| 136 | + if (m.matches()) { |
| 137 | + String presetName = m.group(1); |
| 138 | + result.put(presetName, config.getString(key)); |
| 139 | + } |
| 140 | + } |
| 141 | + }); |
| 142 | + return result; |
76 | 143 | } |
77 | 144 |
|
78 | 145 | @Override |
@@ -112,4 +179,27 @@ public List<JschConnectionInfo> getJschConnInfoList(List<String> serverNames) { |
112 | 179 | Collectors.mapping(serverName -> propRepo.getJschConnectionInfo(serverName), Collectors.toList())); |
113 | 180 | } |
114 | 181 |
|
| 182 | + /** |
| 183 | + * 기본값으로 설정된 FileSize 단위를 반환한다. |
| 184 | + */ |
| 185 | + @Override |
| 186 | + public FileSize getDefaultFileSizeUnit() { |
| 187 | + return FileSize.find(propRepo.getCommonResource("unit.filesize")); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * 기본값으로 설정된 반올림 자릿수를 반환한다. |
| 192 | + */ |
| 193 | + @Override |
| 194 | + public RoundingDigits getDefaultRoundingDigits() { |
| 195 | + return RoundingDigits.find(propRepo.getCommonResource("unit.rounding")); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * 기본값으로 설정된 사용량 컬럼 UI 타입을 반환한다. |
| 200 | + */ |
| 201 | + @Override |
| 202 | + public UsageUIType getDefaultUsageUIType() { |
| 203 | + return UsageUIType.find(propRepo.getCommonResource("usage-ui-type")); |
| 204 | + } |
115 | 205 | } |
0 commit comments