Removed regexp parameter due to sonar warning.
Skipping reading of config file unless it has been changed.
Issue-ID: CCSDK-3495
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I27bece78c99e0354cd476bb2e060788d40f2cbaf
"description": "Select types with the given type name (type identity has the format <typename_version>)",
"required": false
},
- {
- "schema": {"type": "string"},
- "in": "query",
- "name": "regexp",
- "description": "Select types with type identity that matches a regular expression.",
- "required": false
- },
{
"schema": {"type": "string"},
"in": "query",
this.appConfig = appConfig;
}
+ public long getLastModified() {
+ File file = new File(appConfig.getLocalConfigurationFilePath());
+ if (file.exists()) {
+ return file.lastModified();
+ }
+ return 0;
+ }
+
public synchronized Optional<JsonObject> readFile() {
String filepath = appConfig.getLocalConfigurationFilePath();
- if (!fileExists(filepath)) {
+ File file = new File(filepath);
+ if (!file.exists()) {
return Optional.empty();
}
return new FileWriter(filepath);
}
- private boolean fileExists(String filepath) {
- return (new File(filepath).exists());
- }
-
private JsonElement getJsonElement(InputStream inputStream) {
return JsonParser.parseReader(new InputStreamReader(inputStream));
}
public static final String MANAGED_ELEMENT_ID_PARAM = "managed_element_id";
public static final String TYPE_NAME_PARAM = "type_name";
public static final String COMPATIBLE_WITH_VERSION_PARAM = "compatible_with_version";
- public static final String REGEXP_PARAM = "regexp";
public static final String V2_API_ROOT = "/a1-policy/v2";
description = "Select types with the given type name (type identity has the format <typename_version>)") //
@RequestParam(name = Consts.TYPE_NAME_PARAM, required = false) String typeName,
- @Parameter(name = Consts.REGEXP_PARAM, required = false, //
- description = "Select types with type identity that matches a regular expression.") //
- @RequestParam(name = Consts.REGEXP_PARAM, required = false) String regexp,
-
@Parameter(name = Consts.COMPATIBLE_WITH_VERSION_PARAM, required = false, //
description = "Select types that are compatible with the given version. This parameter is only applicable in conjunction with "
+ Consts.TYPE_NAME_PARAM
Collection<PolicyType> types =
ricId != null ? rics.getRic(ricId).getSupportedPolicyTypes() : this.policyTypes.getAll();
- types = PolicyTypes.filterTypes(types, typeName, regexp, compatibleWithVersion);
+ types = PolicyTypes.filterTypes(types, typeName, compatibleWithVersion);
return new ResponseEntity<>(toPolicyTypeIdsJson(types), HttpStatus.OK);
}
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
*
* @param types the types to select from
* @param typeName select types with given type name
- * @param regexp select types where the ID matches a regular
- * expression
* @param compatibleWithVersion select types that are compatible with given
* version string (major.minor.patch)
* @return the types that matches given criterias
* @throws ServiceException if there are errors in the given input
*/
public static Collection<PolicyType> filterTypes(Collection<PolicyType> types, @Nullable String typeName,
- @Nullable String regexp, @Nullable String compatibleWithVersion) throws ServiceException {
+ @Nullable String compatibleWithVersion) throws ServiceException {
if (typeName != null) {
types = filterTypeName(types, typeName);
}
- if (regexp != null) {
- types = filterRegexp(types, regexp);
- }
if (compatibleWithVersion != null) {
types = filterCompatibleWithVersion(types, compatibleWithVersion);
}
return Path.of(getDatabaseDirectory());
}
- private static Collection<PolicyType> filterRegexp(Collection<PolicyType> types, String regexp) {
- Collection<PolicyType> result = new ArrayList<>();
- Pattern pattern = Pattern.compile(regexp);
- for (PolicyType type : types) {
- Matcher matcher = pattern.matcher(type.getId());
- if (matcher.find()) {
- result.add(type);
- }
- }
- return result;
- }
-
private static Collection<PolicyType> filterTypeName(Collection<PolicyType> types, String typeName) {
Collection<PolicyType> result = new ArrayList<>();
for (PolicyType type : types) {
private final PolicyTypes policyTypes;
private final AsyncRestClientFactory restClientFactory;
+ private long fileLastModified = 0;
+
@Autowired
public RefreshConfigTask(ConfigurationFile configurationFile, ApplicationConfig appConfig, Rics rics,
Policies policies, Services services, PolicyTypes policyTypes, A1ClientFactory a1ClientFactory) {
* Reads the configuration from file.
*/
Flux<JsonObject> loadConfigurationFromFile() {
+ if (configurationFile.getLastModified() == fileLastModified) {
+ return Flux.empty();
+ }
+ fileLastModified = configurationFile.getLastModified();
Optional<JsonObject> readJson = configurationFile.readFile();
if (readJson.isPresent()) {
return Flux.just(readJson.get());
url = "/policy-types?compatible_with_version=1.5.0";
testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST, "type_name");
-
- url = "/policy-types?regexp=type3_.*";
- rsp = restClient().get(url).block();
- expResp = createPolicyTypesJson(TYPE_ID_4);
- assertThat(rsp).isEqualTo(expResp);
}
@Test
new Services(appConfig), new PolicyTypes(appConfig), new A1ClientFactory(appConfig)));
if (stubConfigFileExists) {
when(configurationFileMock.readFile()).thenReturn(Optional.empty());
+ doReturn(123L).when(configurationFileMock).getLastModified();
}
return obj;
}
"description": "Select types with the given type name (type identity has the format <typename_version>)",
"required": false
},
- {
- "schema": {"type": "string"},
- "in": "query",
- "name": "regexp",
- "description": "Select types with type identity that matches a regular expression.",
- "required": false
- },
{
"schema": {"type": "string"},
"in": "query",