diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index abcc439b00c..23d3230c5b2 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -118,20 +118,18 @@ public Map getI18nResources(String lang) { // 后面需要支持指标名称 Map 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 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); } } } @@ -146,12 +144,11 @@ public List getAllAppHierarchy(String lang) { hierarchyApp.setCategory(job.getCategory()); hierarchyApp.setValue(job.getApp()); Map 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 hierarchyMetricList = new LinkedList<>(); if (job.getMetrics() != null) { @@ -181,11 +178,11 @@ public List 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()) { @@ -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 { @@ -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()) {