Add System component with table display for custom and all beans
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
package com.jambotronGroup.jambotron;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.event.Level;
|
||||
import org.slf4j.helpers.BasicMarker;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@SpringBootApplication
|
||||
public class JambotronApplication {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JambotronApplication.class);
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(JambotronApplication.class, args);
|
||||
|
||||
|
||||
logger.error("Application Run.");
|
||||
logger.debug("Application Run.");
|
||||
logger.info("Application Run.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.jambotronGroup.jambotron.ZhiPuAi;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
//import org.springframework.web.reactive.function.client.WebClient;
|
||||
//
|
||||
//@Service
|
||||
//public class ZhiPuAiImageService {
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.base-url}")
|
||||
// private String baseUrl;
|
||||
//
|
||||
// @Value("${spring.ai.zhipuai.api-key}")
|
||||
// private String apiKey;
|
||||
//
|
||||
// private final WebClient webClient;
|
||||
//
|
||||
// public ZhiPuAiImageService(WebClient.Builder webClientBuilder) {
|
||||
// this.webClient = webClientBuilder.baseUrl(baseUrl).build();
|
||||
// }
|
||||
//
|
||||
// public String generateImage(String prompt) {
|
||||
// return webClient.post()
|
||||
// .uri("/image/generate")
|
||||
// .header("Authorization", "Bearer " + apiKey)
|
||||
// .bodyValue(new ImageRequest(prompt))
|
||||
// .retrieve()
|
||||
// .bodyToMono(String.class)
|
||||
// .block();
|
||||
// }
|
||||
//
|
||||
// private static class ImageRequest {
|
||||
// private final String prompt;
|
||||
//
|
||||
// public ImageRequest(String prompt) {
|
||||
// this.prompt = prompt;
|
||||
// }
|
||||
//
|
||||
// public String getPrompt() {
|
||||
// return prompt;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
import com.jambotronGroup.jambotron.model.Setting;
|
||||
import com.jambotronGroup.jambotron.system.SystemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/system")
|
||||
public class SystemController {
|
||||
|
||||
@Autowired
|
||||
SystemService systemService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/beans")
|
||||
public ResponseEntity<List<Bean>> getLoadedBeans(@RequestParam(required = false) String title) {
|
||||
try {
|
||||
List<Bean> beans = systemService.getLodedBeans();
|
||||
//userRepository.findAll().forEach(users::add);
|
||||
|
||||
|
||||
if (beans.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(beans, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@GetMapping("/beans/custom")
|
||||
public ResponseEntity<List<Bean>> getLoadedCustomBeans(@RequestParam(required = false) String title) {
|
||||
try {
|
||||
List<Bean> beans = systemService.getLodedCustomBeans();
|
||||
//userRepository.findAll().forEach(users::add);
|
||||
|
||||
|
||||
if (beans.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(beans, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jambotronGroup.jambotron.controllers;
|
||||
|
||||
public class ZhiPuAiController {
|
||||
|
||||
// This class is a placeholder for the ZhiPuAiController.
|
||||
// You can implement methods to handle requests related to ZhiPuAi functionality.
|
||||
// For example, you might want to add methods for generating images or processing text.
|
||||
|
||||
// Example method (to be implemented):
|
||||
// @GetMapping("/generate-image")
|
||||
// public ResponseEntity<String> generateImage(@RequestParam String prompt) {
|
||||
// String imageUrl = zhiPuAiService.generateImage(prompt);
|
||||
// return new ResponseEntity<>(imageUrl, HttpStatus.OK);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.jambotronGroup.jambotron.model;
|
||||
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.ToString;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
public class Bean {
|
||||
|
||||
|
||||
private String name;
|
||||
@Id
|
||||
private String shortName;
|
||||
private String type;
|
||||
private String typeShortName;
|
||||
private String scope;
|
||||
|
||||
public Bean(String name, String type, String scope) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.scope = scope;
|
||||
|
||||
this.shortName = getAfterLastDot(name);
|
||||
this.typeShortName = getAfterLastDot(type);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("name = %s type= %s", this.shortName, this.typeShortName);
|
||||
}
|
||||
|
||||
public String getAfterLastDot(String input) {
|
||||
if (input == null || !input.contains(".")) {
|
||||
return input; // Return the input if it's null or doesn't contain a dot
|
||||
}
|
||||
return input.substring(input.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
public void setShortName(String shortName) {
|
||||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
public String getTypeShortName() {
|
||||
return typeShortName;
|
||||
}
|
||||
|
||||
public void setTypeShortName(String typeShortName) {
|
||||
this.typeShortName = typeShortName;
|
||||
}
|
||||
}
|
||||
@@ -110,13 +110,16 @@ public class WebSecurityConfig {// extends WebSecurityConfigurerAdapter {
|
||||
.requestMatchers("/api/test/**").permitAll()
|
||||
.requestMatchers("/api/tutorials").permitAll()
|
||||
|
||||
.requestMatchers("api/users").permitAll()
|
||||
.requestMatchers("api/users/**").permitAll()
|
||||
.requestMatchers("/api/users").permitAll()
|
||||
.requestMatchers("/api/users/**").permitAll()
|
||||
|
||||
.requestMatchers("api/roles").permitAll()
|
||||
.requestMatchers("api/roles/**").permitAll()
|
||||
.requestMatchers("/api/roles").permitAll()
|
||||
.requestMatchers("/api/roles/**").permitAll()
|
||||
|
||||
.requestMatchers("/api/tutorials/**").permitAll()
|
||||
|
||||
.requestMatchers("/api/settings").permitAll()
|
||||
.requestMatchers("/api/system/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.jambotronGroup.jambotron.system;
|
||||
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SystemService {
|
||||
List<Bean> getLodedBeans();
|
||||
|
||||
List<Bean> getLodedCustomBeans();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.jambotronGroup.jambotron.system;
|
||||
|
||||
import com.jambotronGroup.jambotron.JambotronApplication;
|
||||
import com.jambotronGroup.jambotron.model.Bean;
|
||||
import com.jambotronGroup.jambotron.utils.EntityLoggingConsumer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class SystemServiceImpl implements SystemService {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class);
|
||||
|
||||
|
||||
@Override
|
||||
public List<Bean> getLodedBeans() {
|
||||
// Get all bean names from the application context and map them to Bean objects
|
||||
List<Bean> beans = Arrays.stream(applicationContext.getBeanDefinitionNames()).map(
|
||||
name -> new Bean(name, applicationContext.getType(name).getName(),applicationContext.getApplicationName()))
|
||||
|
||||
.toList();
|
||||
beans.forEach(new EntityLoggingConsumer(logger));
|
||||
return beans;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Bean> getLodedCustomBeans() {
|
||||
List<Bean> beans = getLodedBeans();
|
||||
|
||||
beans = beans.stream()
|
||||
.filter(bean -> bean.getName() != null &&
|
||||
bean.getType().contains(
|
||||
environment.getRequiredProperty("spring.application.name")
|
||||
)
|
||||
)
|
||||
.sorted((o1, o2) -> o1.getName().compareTo(o2.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return beans;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.jambotronGroup.jambotron.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
|
||||
public class EntityLoggingConsumer implements Consumer {
|
||||
|
||||
private Logger _logger;
|
||||
public EntityLoggingConsumer(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void accept(Object o) {
|
||||
_logger.info(o.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user