From ecc614fa0f2b52a9ffaae9fe753b8a24a686d00b Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Mon, 23 Oct 2023 22:18:01 +0200 Subject: [PATCH] Add API to list plugin descriptions --- .gitignore | 12 ++---- pom.xml | 10 +++++ .../playwall/PlaywallServerApplication.java | 17 ++++++++ .../PluginDescriptionController.java | 24 +++++++++++ .../playwall/model/PluginDescription.java | 16 ++++++++ .../PluginDescriptionRepository.java | 40 +++++++++++++++++++ 6 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java create mode 100644 src/main/java/de/tobias/playwall/model/PluginDescription.java create mode 100644 src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java diff --git a/.gitignore b/.gitignore index 307df11..856fccf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,4 @@ /.idea/ - -/settings.properties -/target -/deploy -/build/ -/deploy_docker/ -/storage/ - -.env \ No newline at end of file +.env +target/ +config/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index f7afa1b..5c1d591 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,16 @@ <artifactId>spring-boot-starter-web</artifactId> </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <optional>true</optional> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/src/main/java/de/tobias/playwall/PlaywallServerApplication.java b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java index dbdf3b8..67865c0 100644 --- a/src/main/java/de/tobias/playwall/PlaywallServerApplication.java +++ b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java @@ -1,12 +1,29 @@ package de.tobias.playwall; +import lombok.SneakyThrows; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.FileUrlResource; +import org.springframework.core.io.Resource; @SpringBootApplication public class PlaywallServerApplication { + @SneakyThrows + @Bean + public static PropertySourcesPlaceholderConfigurer properties() + { + PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); + Resource[] resources = new Resource[]{new FileUrlResource("/Users/tobias/Documents/Programmieren/Projects/PlayWall/PlayWallServer/config/plugins.yaml")}; + pspc.setLocations(resources); + pspc.setIgnoreUnresolvablePlaceholders(true); + return pspc; + } + public static void main(String[] args) { SpringApplication.run(PlaywallServerApplication.class, args); diff --git a/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java b/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java new file mode 100644 index 0000000..3683f29 --- /dev/null +++ b/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java @@ -0,0 +1,24 @@ +package de.tobias.playwall.controller; + +import de.tobias.playwall.model.PluginDescription; +import de.tobias.playwall.repository.PluginDescriptionRepository; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/plugins") +@AllArgsConstructor +public class PluginDescriptionController +{ + private final PluginDescriptionRepository repository; + + @GetMapping + List<PluginDescription> getAllPlugins() + { + return repository.findAll(); + } +} diff --git a/src/main/java/de/tobias/playwall/model/PluginDescription.java b/src/main/java/de/tobias/playwall/model/PluginDescription.java new file mode 100644 index 0000000..6b33fbc --- /dev/null +++ b/src/main/java/de/tobias/playwall/model/PluginDescription.java @@ -0,0 +1,16 @@ +package de.tobias.playwall.model; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class PluginDescription +{ + private String name; + private String displayName; + private String icon; + private String description; +} diff --git a/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java b/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java new file mode 100644 index 0000000..4509c53 --- /dev/null +++ b/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java @@ -0,0 +1,40 @@ +package de.tobias.playwall.repository; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import de.tobias.playwall.model.PluginDescription; +import jakarta.annotation.PostConstruct; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.util.List; + +@Service +@EnableConfigurationProperties +public class PluginDescriptionRepository +{ + @Value("${playwall.plugin.description}") + private Resource pluginDescriptionFile; + + private ObjectMapper mapper; + + @PostConstruct + private void init() + { + mapper = new ObjectMapper(new YAMLFactory()); + mapper.findAndRegisterModules(); + } + + @SneakyThrows + public List<PluginDescription> findAll() + { + return mapper.readValue(pluginDescriptionFile.getContentAsString(StandardCharsets.UTF_8), new TypeReference<List<PluginDescription>>() + { + }); + } +} -- GitLab