Skip to content

Commit

Permalink
Merge pull request #845 from dromara i18nName_verify
Browse files Browse the repository at this point in the history
[refactor] avoid i18nName null
  • Loading branch information
Carpe-Wang authored Apr 6, 2023
2 parents 5e1f786 + 3b7d815 commit 97bdfb7
Showing 1 changed file with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,18 @@ public Map<String, String> getI18nResources(String lang) {
// 后面需要支持指标名称
Map<String, String> name = job.getName();
if (name != null && !name.isEmpty()) {
String i18nName = name.get(lang);
if (i18nName == null) {
i18nName = name.values().stream().findFirst().get();
String i18nName = Optional.ofNullable(name.get(lang)).orElse(name.values().stream().findFirst().orElse(null));
if (i18nName != null) {
i18nMap.put("monitor.app." + job.getApp(), i18nName);
}
i18nMap.put("monitor.app." + job.getApp(), i18nName);
}
for (ParamDefine paramDefine : job.getParams()) {
Map<String, String> paramDefineName = paramDefine.getName();
if (paramDefineName != null && !paramDefineName.isEmpty()) {
String i18nName = paramDefineName.get(lang);
if (i18nName == null) {
i18nName = paramDefineName.values().stream().findFirst().get();
String i18nName = Optional.ofNullable(paramDefineName.get(lang)).orElse(paramDefineName.values().stream().findFirst().orElse(null));
if (i18nName != null) {
i18nMap.put("monitor.app." + job.getApp() + ".param." + paramDefine.getField(), i18nName);
}
i18nMap.put("monitor.app." + job.getApp() + ".param." + paramDefine.getField(), i18nName);
}
}
}
Expand All @@ -146,12 +144,11 @@ public List<Hierarchy> getAllAppHierarchy(String lang) {
hierarchyApp.setCategory(job.getCategory());
hierarchyApp.setValue(job.getApp());
Map<String, String> nameMap = job.getName();
if (nameMap != null) {
String i18nName = nameMap.get(lang);
if (i18nName == null) {
i18nName = nameMap.values().stream().findFirst().get();
if (nameMap != null && !nameMap.isEmpty()) {
String i18nName = Optional.ofNullable(nameMap.get(lang)).orElse(nameMap.values().stream().findFirst().orElse(null));
if (i18nName != null) {
hierarchyApp.setLabel(i18nName);
}
hierarchyApp.setLabel(i18nName);
}
List<Hierarchy> hierarchyMetricList = new LinkedList<>();
if (job.getMetrics() != null) {
Expand Down Expand Up @@ -181,11 +178,11 @@ public List<Hierarchy> getAllAppHierarchy(String lang) {

@Override
public String getMonitorDefineFileContent(String app) {
String classpath = this.getClass().getClassLoader().getResource("").getPath();
String classpath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath();
String defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
File defineAppFile = new File(defineAppPath);
if (!defineAppFile.exists() || !defineAppFile.isFile()) {
classpath = this.getClass().getResource(File.separator).getPath();
classpath = Objects.requireNonNull(this.getClass().getResource(File.separator)).getPath();
defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
defineAppFile = new File(defineAppPath);
if (!defineAppFile.exists() || !defineAppFile.isFile()) {
Expand Down Expand Up @@ -224,7 +221,7 @@ public void applyMonitorDefineYml(String ymlContent) {
}
// app params verify
verifyDefineAppContent(app);
String classpath = this.getClass().getClassLoader().getResource("").getPath();
String classpath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath();
String defineAppPath = classpath + "define" + File.separator + "app-" + app.getApp() + ".yml";
File defineAppFile = new File(defineAppPath);
try {
Expand Down Expand Up @@ -252,7 +249,7 @@ public void deleteMonitorDefine(String app) {
if (monitors != null && !monitors.isEmpty()) {
throw new IllegalArgumentException("Can not delete define which has monitoring instances.");
}
String classpath = this.getClass().getClassLoader().getResource("").getPath();
String classpath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath();
String defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
File defineAppFile = new File(defineAppPath);
if (defineAppFile.exists() && defineAppFile.isFile()) {
Expand Down

0 comments on commit 97bdfb7

Please sign in to comment.