Skip to content

Commit

Permalink
bugfix npe when get undefined name monitor template yml (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Aug 11, 2023
1 parent defd718 commit 6c3c0eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
@Slf4j
public class AppServiceImpl implements AppService, CommandLineRunner {

private static final String JAVA_PATH_SEPARATOR = "/";

@Autowired
private MonitorDao monitorDao;

Expand Down Expand Up @@ -193,22 +195,25 @@ public String getMonitorDefineFileContent(String app) {
String defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
File defineAppFile = new File(defineAppPath);
if (!defineAppFile.exists() || !defineAppFile.isFile()) {
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()) {
try {
// load define app yml in jar
log.info("load define app yml in internal jar");
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource resource = resolver.getResource("classpath:define/" + app + ".yml");
InputStream inputStream = resource.getInputStream();
String content = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
inputStream.close();
return content;
} catch (Exception e) {
log.error(e.getMessage());
}
URL resourceUrl = this.getClass().getResource(JAVA_PATH_SEPARATOR);
if (resourceUrl != null) {
classpath = resourceUrl.getPath();
defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml";
defineAppFile = new File(defineAppPath);
if (!defineAppFile.exists() || !defineAppFile.isFile()) {
try {
// load define app yml in jar
log.info("load define app yml in internal jar");
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource resource = resolver.getResource("classpath:define/" + app + ".yml");
InputStream inputStream = resource.getInputStream();
String content = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
inputStream.close();
return content;
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
}
log.info("load {} define app yml in file: {}", app, defineAppPath);
Expand Down
4 changes: 3 additions & 1 deletion web-app/src/app/routes/setting/define/define.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class DefineComponent implements OnInit {
ngOnInit(): void {
this.route.queryParamMap.subscribe((paramMap: ParamMap) => {
this.currentApp = paramMap.get('app') || undefined;
this.loadAppDefineContent(this.currentApp);
if (this.currentApp != undefined) {
this.loadAppDefineContent(this.currentApp);
}
});
this.loadMenus();
this.code = `${this.i18nSvc.fanyi('define.new.code')}\n\n\n\n\n`;
Expand Down

0 comments on commit 6c3c0eb

Please sign in to comment.