Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 8d8e447

Browse files
Config editor: adding javadoc for config editor core (#821)
* adding javadoc for config editor core * adding more comments * fixes based on the review * fixing typos
1 parent 7be2029 commit 8d8e447

File tree

64 files changed

+1272
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1272
-72
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
package uk.co.gresearch.siembol.configeditor.common;
2-
2+
/**
3+
* An object for providing authorisation for Siembol services
4+
*
5+
* <p>This interface is for providing authorisation for a Siembol service.
6+
* It decides whether the user is allowed to access a service under its role.
7+
*
8+
* @author Marian Novotny
9+
*
10+
*/
311
public interface AuthorisationProvider {
412
enum AuthorisationResult {
513
UNDEFINED,
614
ALLOWED,
715
FORBIDDEN,
816
}
917

18+
/**
19+
* Gets authorisation decision for a user and a service
20+
* @param user a user info object
21+
* @param serviceName the name of teh service
22+
* @return the authorisation result
23+
*/
1024
AuthorisationResult getUserAuthorisation(UserInfo user, String serviceName);
1125
}

config-editor/config-editor-core/src/main/java/uk/co/gresearch/siembol/configeditor/common/ConfigEditorUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
import java.io.*;
1717
import java.lang.invoke.MethodHandles;
1818
import java.util.*;
19-
19+
/**
20+
* A class with static helper methods for config editor
21+
*
22+
* <p>This class exposes static helper methods for config editor.
23+
*
24+
* @author Marian Novotny
25+
*/
2026
public class ConfigEditorUtils {
2127
private static final Logger LOG = LoggerFactory
2228
.getLogger(MethodHandles.lookup().lookupClass());
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
package uk.co.gresearch.siembol.configeditor.common;
22

33
import uk.co.gresearch.siembol.configeditor.model.ConfigEditorResult;
4-
4+
/**
5+
* An object for importing configurations
6+
*
7+
* <p>This interface is for providing functionality for importing open standard configuration into Siembol.
8+
* Moreover, it validates attributes and provides importer attributes schema.
9+
*
10+
* @author Marian Novotny
11+
*
12+
*/
513
public interface ConfigImporter {
14+
/**
15+
* Gets a json schema for importer attributes
16+
* @return config editor result with json schema
17+
*/
618
ConfigEditorResult getImporterAttributesSchema();
19+
20+
/**
21+
* Validates importer attributes
22+
* @param attributes a json string with importer attributes
23+
* @return config editor result with OK status code if the attributes are valid, otherwise
24+
* the result with ERROR status.
25+
*/
726
ConfigEditorResult validateImporterAttributes(String attributes);
27+
28+
/**
29+
* Imports open standard configuration into Siembol syntax
30+
* @param user a user info object
31+
* @param importerAttributes a json string with importer attributes
32+
* @param configuration configuration for importing into Siembol
33+
* @return config editor result with OK status code and the imported config if the import was successful, otherwise
34+
* the result with ERROR status.
35+
*/
836
ConfigEditorResult importConfig(UserInfo user, String importerAttributes, String configuration);
937
}

config-editor/config-editor-core/src/main/java/uk/co/gresearch/siembol/configeditor/common/ConfigInfo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import java.util.Map;
44
import java.util.Optional;
5-
5+
/**
6+
* An object that represents information about a configuration change
7+
*
8+
* <p>This class represents information about configuration change such as the name of the configuration,
9+
* its version, content etc.
10+
*
11+
* @author Marian Novotny
12+
*/
613
public class ConfigInfo {
714
private String name;
815
private Map<String, Optional<String>> filesContent;

config-editor/config-editor-core/src/main/java/uk/co/gresearch/siembol/configeditor/common/ConfigInfoType.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package uk.co.gresearch.siembol.configeditor.common;
2-
2+
/**
3+
* An enum of configuration types
4+
*
5+
* @author Marian Novotny
6+
* @see #RULE
7+
* @see #CONFIG
8+
* @see #TEST_CASE
9+
* @see #ADMIN_CONFIG
10+
*/
311
public enum ConfigInfoType {
412
RULE("rule", "rules", "Rules"),
513
CONFIG("configuration", "configurations", "Configurations"),

config-editor/config-editor-core/src/main/java/uk/co/gresearch/siembol/configeditor/common/ConfigSchemaService.java

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,82 @@
44
import uk.co.gresearch.siembol.configeditor.model.*;
55

66
import java.util.ArrayList;
7-
import java.util.Collections;
87
import java.util.List;
98
import java.util.Map;
109
import java.util.stream.Collectors;
1110

1211
import static uk.co.gresearch.siembol.configeditor.model.ConfigEditorResult.StatusCode.OK;
13-
12+
/**
13+
* An object for configuration schema service
14+
*
15+
* <p>This interface is for providing functionality for configuration schema service.
16+
* It validates configurations, and provides a json schema.
17+
* it provides config importers and testers registered for the service.
18+
*
19+
* @author Marian Novotny
20+
* @see ConfigTester
21+
* @see ConfigImporter
22+
*
23+
*/
1424
public interface ConfigSchemaService extends HealthCheckable {
1525
String NOT_IMPLEMENTED_MSG = "Not implemented";
1626
String SCHEMA_INIT_ERROR = "Error during computing json schema";
1727

28+
/**
29+
* Gets a json schema for configurations
30+
* @return a config editor result with a json schema for configurations
31+
*/
1832
ConfigEditorResult getSchema();
1933

34+
/**
35+
* Validates a configuration
36+
* @param configuration a json string with configuration
37+
* @return a config editor result with OK status code if the configuration is valid, otherwise
38+
* the result with ERROR status.
39+
*/
2040
ConfigEditorResult validateConfiguration(String configuration);
2141

42+
/**
43+
* Validates configurations
44+
* @param configurations a json string with configurations
45+
* @return a config editor result with OK status code if the configurations are valid, otherwise
46+
* the result with ERROR status.
47+
*/
2248
ConfigEditorResult validateConfigurations(String configurations);
2349

50+
/**
51+
* Gets config importers
52+
* @return the map of an importer name string to a config importer object
53+
*/
2454
Map<String, ConfigImporter> getConfigImporters();
2555

56+
/**
57+
* Gets config testers
58+
* @return a config editor result with config testers registered for the service
59+
*/
2660
default ConfigEditorResult getConfigTesters() {
2761
ConfigEditorAttributes attributes = new ConfigEditorAttributes();
2862
attributes.setConfigTesters(new ArrayList<>());
2963
return new ConfigEditorResult(OK, attributes);
3064
}
3165

66+
/**
67+
* Gets a config tester by name
68+
* @return a config tester
69+
*/
3270
ConfigTester getConfigTester(String name);
3371

72+
/**
73+
* Checks a health of the service
74+
* @return health object with the status
75+
* @see Health
76+
*/
3477
default Health checkHealth() { return Health.up().build(); }
3578

79+
/**
80+
* Get config importers
81+
* @return config editor result with config importers
82+
*/
3683
default ConfigEditorResult getImporters() {
3784
List<ConfigImporterDto> importers = getConfigImporters().entrySet().stream().map(x -> {
3885
ConfigImporterDto importer = new ConfigImporterDto();
@@ -46,7 +93,19 @@ default ConfigEditorResult getImporters() {
4693
return new ConfigEditorResult(OK, attributes);
4794
}
4895

49-
default ConfigEditorResult importConfig(UserInfo user, String importerName, String importerAttributes, String configToImport) {
96+
/**
97+
* Imports a config into a service syntax
98+
* @param user a user info object
99+
* @param importerName the name of the importer
100+
* @param importerAttributes a json string with importer attributes
101+
* @param configToImport a string with configuration to be imported
102+
* @return config editor result with OK status code and the imported config if the import was successful, otherwise
103+
* the result with ERROR status.
104+
*/
105+
default ConfigEditorResult importConfig(UserInfo user,
106+
String importerName,
107+
String importerAttributes,
108+
String configToImport) {
50109
if (!getConfigImporters().containsKey(importerName)) {
51110
return ConfigEditorResult.fromMessage(ConfigEditorResult.StatusCode.BAD_REQUEST,
52111
ErrorMessages.UNKNOWN_CONFIG_IMPORTER.getMessage(importerName));
@@ -67,18 +126,38 @@ default ConfigEditorResult importConfig(UserInfo user, String importerName, Stri
67126
return importResult;
68127
}
69128

129+
/**
130+
* Gets a json schema for an admin configuration
131+
* @return a config editor result with a json schema for an admin configuration
132+
*/
70133
default ConfigEditorResult getAdminConfigurationSchema() {
71134
return ConfigEditorResult.fromMessage(ConfigEditorResult.StatusCode.ERROR, NOT_IMPLEMENTED_MSG);
72135
}
73136

137+
/**
138+
* Validates an admin configuration
139+
* @param configuration a json string with an admin configuration
140+
* @return a config editor result with OK status code if the admin configuration is valid, otherwise
141+
* the result with ERROR status.
142+
*/
74143
default ConfigEditorResult validateAdminConfiguration(String configuration) {
75144
return ConfigEditorResult.fromMessage(ConfigEditorResult.StatusCode.ERROR, NOT_IMPLEMENTED_MSG);
76145
}
77146

147+
/**
148+
* Gets a topology name from an admin configuration
149+
* @param configuration a json string with an admin configuration
150+
* @return a config editor result with the topology name on success, otherwise
151+
* the result with ERROR status.
152+
*/
78153
default ConfigEditorResult getAdminConfigTopologyName(String configuration) {
79154
return ConfigEditorResult.fromMessage(ConfigEditorResult.StatusCode.ERROR, NOT_IMPLEMENTED_MSG);
80155
}
81156

157+
/**
158+
* Get a config schema service with enhanced error messages
159+
* @return a config schema service with enhanced error messages
160+
*/
82161
default ConfigSchemaService withErrorMessage() {
83162
return new ConfigSchemaServiceWithErrorMessage(this);
84163
}

config-editor/config-editor-core/src/main/java/uk/co/gresearch/siembol/configeditor/common/ConfigSchemaServiceWithErrorMessage.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@
88

99
import java.util.Map;
1010
import java.util.function.Supplier;
11-
11+
/**
12+
* An object for configuration schema service with enhanced error messages
13+
*
14+
* <p>This class implements ConfigSchemaService interface, and it extends ServiceWithErrorMessage class.
15+
* It enriches error messages on error.
16+
*
17+
* @author Marian Novotny
18+
* @see ServiceWithErrorMessage
19+
* @see ConfigSchemaService
20+
*/
1221
public class ConfigSchemaServiceWithErrorMessage extends ServiceWithErrorMessage<ConfigSchemaService>
1322
implements ConfigSchemaService {
1423

1524
public ConfigSchemaServiceWithErrorMessage(ConfigSchemaService service) {
1625
super(service);
1726
}
1827

28+
/**
29+
* {@inheritDoc}
30+
*/
1931
@Override
2032
public ConfigEditorResult getSchema() {
2133
return service.getSchema();
2234
}
2335

36+
/**
37+
* {@inheritDoc}
38+
*/
2439
@Override
2540
public ConfigEditorResult validateConfiguration(String configuration) {
2641
Supplier<ConfigEditorResult> fun = () -> service.validateConfiguration(configuration);
@@ -29,6 +44,9 @@ public ConfigEditorResult validateConfiguration(String configuration) {
2944
ErrorResolutions.VALIDATION.getResolution());
3045
}
3146

47+
/**
48+
* {@inheritDoc}
49+
*/
3250
@Override
3351
public ConfigEditorResult validateConfigurations(String configurations) {
3452
Supplier<ConfigEditorResult> fun = () -> service.validateConfigurations(configurations);
@@ -37,31 +55,49 @@ public ConfigEditorResult validateConfigurations(String configurations) {
3755
ErrorResolutions.VALIDATION.getResolution());
3856
}
3957

58+
/**
59+
* {@inheritDoc}
60+
*/
4061
@Override
4162
public Map<String, ConfigImporter> getConfigImporters() {
4263
return service.getConfigImporters();
4364
}
4465

66+
/**
67+
* {@inheritDoc}
68+
*/
4569
@Override
4670
public ConfigEditorResult getConfigTesters() {
4771
return service.getConfigTesters();
4872
}
4973

74+
/**
75+
* {@inheritDoc}
76+
*/
5077
@Override
5178
public ConfigTester getConfigTester(String name) {
5279
return service.getConfigTester(name);
5380
}
5481

82+
/**
83+
* {@inheritDoc}
84+
*/
5585
@Override
5686
public Health checkHealth() {
5787
return service.checkHealth();
5888
}
5989

90+
/**
91+
* {@inheritDoc}
92+
*/
6093
@Override
6194
public ConfigEditorResult getImporters() {
6295
return service.getImporters();
6396
}
6497

98+
/**
99+
* {@inheritDoc}
100+
*/
65101
@Override
66102
public ConfigEditorResult importConfig(UserInfo user,
67103
String importerName,
@@ -74,11 +110,17 @@ public ConfigEditorResult importConfig(UserInfo user,
74110
ErrorResolutions.GENERIC_BAD_REQUEST.getResolution());
75111
}
76112

113+
/**
114+
* {@inheritDoc}
115+
*/
77116
@Override
78117
public ConfigEditorResult getAdminConfigurationSchema() {
79118
return service.getAdminConfigurationSchema();
80119
}
81120

121+
/**
122+
* {@inheritDoc}
123+
*/
82124
@Override
83125
public ConfigEditorResult validateAdminConfiguration(String configuration) {
84126
Supplier<ConfigEditorResult> fun = () -> service.validateAdminConfiguration(configuration);
@@ -87,6 +129,9 @@ public ConfigEditorResult validateAdminConfiguration(String configuration) {
87129
ErrorResolutions.VALIDATION.getResolution());
88130
}
89131

132+
/**
133+
* {@inheritDoc}
134+
*/
90135
@Override
91136
public ConfigEditorResult getAdminConfigTopologyName(String configuration) {
92137
return service.getAdminConfigTopologyName(configuration);

0 commit comments

Comments
 (0)