-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSchemaManagerConfig.java
More file actions
110 lines (93 loc) · 4.08 KB
/
SchemaManagerConfig.java
File metadata and controls
110 lines (93 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
*
* Copyright [ 2020 - 2024 ] Matthew Buckton
* Copyright [ 2024 - 2026 ] MapsMessaging B.V.
*
* Licensed under the Apache License, Version 2.0 with the Commons Clause
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://commonsclause.com/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mapsmessaging.config;
import io.mapsmessaging.configuration.ConfigurationProperties;
import io.mapsmessaging.dto.rest.config.BaseConfigDTO;
import io.mapsmessaging.dto.rest.schema.*;
import io.mapsmessaging.license.FeatureManager;
import io.mapsmessaging.utilities.configuration.ConfigurationManager;
import java.io.IOException;
import java.util.List;
public class SchemaManagerConfig extends SchemaManagerConfigDTO implements Config, ConfigManager {
public SchemaManagerConfig() {}
public SchemaManagerConfig(ConfigurationProperties configurationProperties) {
String type = configurationProperties.getProperty("type", "simple");
switch (type) {
case "simple" -> super.setRepositoryConfig(new SimpleRepositoryConfigDTO());
case "file" -> super.setRepositoryConfig(configureFile( (ConfigurationProperties) configurationProperties.get("config")));
case "maps" -> super.setRepositoryConfig(configureMaps( (ConfigurationProperties) configurationProperties.get("config")));
default -> super.setRepositoryConfig(new SimpleRepositoryConfigDTO());
}
Object locations = configurationProperties.get("importLocations");
if(locations instanceof List list){
for(Object location : list){
if(location instanceof ConfigurationProperties props){
loadLocations(props);
}
}
}
else if(locations instanceof ConfigurationProperties props){
loadLocations(props);
}
setProtocPath(configurationProperties.getProperty("protocPath", null));
}
private void loadLocations(ConfigurationProperties props){
if(props.containsKey("path") && props.containsKey("format") && props.containsKey("name")){
SchemaImportLocationDTO locationDTO = new SchemaImportLocationDTO();
locationDTO.setPath(props.getProperty("path"));
locationDTO.setFormat(props.getProperty("format"));
locationDTO.setName(props.getProperty("name"));
super.getImportLocations().add(locationDTO);
}
}
@Override
public ConfigurationProperties toConfigurationProperties() {
return null;
}
@Override
public boolean update(BaseConfigDTO config) {
return false;
}
@Override
public ConfigManager load(FeatureManager featureManager) {
return new SchemaManagerConfig(ConfigurationManager.getInstance().getProperties(getName()));
}
@Override
public void save() throws IOException {
}
@Override
public String getName() {
return "SchemaManager";
}
private RepositoryConfigDTO configureFile(ConfigurationProperties properties){
FileRepositoryConfigDTO config = new FileRepositoryConfigDTO();
config.setDirectoryPath(properties.getProperty("directoryPath"));
return config;
}
private RepositoryConfigDTO configureMaps(ConfigurationProperties properties){
MapsRepositoryConfigDTO mapsRepositoryConfigDTO = new MapsRepositoryConfigDTO();
mapsRepositoryConfigDTO.setDirectoryPath(properties.getProperty("directoryPath"));
mapsRepositoryConfigDTO.setPullSchemas(properties.getBooleanProperty("pullSchemas", true));
mapsRepositoryConfigDTO.setPushSchemas(properties.getBooleanProperty("pushSchemas", true));
mapsRepositoryConfigDTO.setUrlPath(properties.getProperty("urlPath"));
mapsRepositoryConfigDTO.setUsername(properties.getProperty("username"));
mapsRepositoryConfigDTO.setPassword(properties.getProperty("password"));
return mapsRepositoryConfigDTO;
}
}