Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
refactor: remove the use of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
flyisland committed Mar 16, 2021
1 parent 962db26 commit 43933e6
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/java/semp/cfg/model/JsonSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import semp.cfg.Utils;

import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class JsonSpec {
private static final Logger logger = LoggerFactory.getLogger(JsonSpec.class);
private DocumentContext jsonPathCtx;
private List<String> pathsList;

Expand Down Expand Up @@ -50,8 +47,7 @@ protected boolean isPathExist(String specPath){

protected void assertPathExist(String specPath){
if (! isPathExist(specPath)){
logger.error("Path '{}' is NOT found inside the SEMPv2 specification!", specPath);
System.exit(1);
Utils.errPrintlnAndExit("Path '%s' is NOT found inside the SEMPv2 specification!", specPath);
}
}

Expand Down Expand Up @@ -204,15 +200,15 @@ protected Map<String, Object> getMapOfAttributesWithDefaultValue(String collecti


if (Objects.isNull(ref)){
logger.warn("Unable to find path:{}", refPath);
Utils.errPrintlnAndExit("Unable to find path %s in the SEMPv2 specification.", refPath);
return null;
}

// "#/definitions/MsgVpn" -> "$.definitions.MsgVpn.properties"
var propertiesPath = ref.get(0).replace("#", "$").replace("/", ".") + ".properties";
Map<String, Map<String, ?>> result = jsonPathRead(propertiesPath, Map.class);
if (Objects.isNull(result)){
logger.warn("Unable to find path:{}", propertiesPath);
Utils.errPrintlnAndExit("Unable to find path %s in the SEMPv2 specification.", propertiesPath);
}
return result;
}
Expand All @@ -232,7 +228,7 @@ protected Map<String, Object> getAttributesWithDefaultValueFromJProperties(Map<S
case "string" -> result.put(attr, value.substring(1, value.length() - 1));
case "integer" -> result.put(attr, Integer.parseInt(value));
case "boolean" -> result.put(attr, Boolean.parseBoolean(value));
default -> logger.error("Unknown type '{}' of property '{}', the default value is {}",
default -> Utils.errPrintlnAndExit("Unknown type '%s' of property '%s', the default value is '%s'",
type, attr, value);
}
});
Expand Down

0 comments on commit 43933e6

Please sign in to comment.