From 15b69a44ae51ff6093fbf252f2bfde76834d57b6 Mon Sep 17 00:00:00 2001 From: "michael.breu" <michael.breu@uibk.ac.at> Date: Mon, 1 Mar 2021 14:03:39 +0100 Subject: [PATCH] Intermediate commit --- .../service/PluginManagementService.java | 59 ++++++++++ .../service/ShoppingBasketService.java | 110 +----------------- 2 files changed, 62 insertions(+), 107 deletions(-) create mode 100644 src/main/java/at/ac/uibk/gitsearch/service/PluginManagementService.java diff --git a/src/main/java/at/ac/uibk/gitsearch/service/PluginManagementService.java b/src/main/java/at/ac/uibk/gitsearch/service/PluginManagementService.java new file mode 100644 index 000000000..3f1e6eb82 --- /dev/null +++ b/src/main/java/at/ac/uibk/gitsearch/service/PluginManagementService.java @@ -0,0 +1,59 @@ +package at.ac.uibk.gitsearch.service; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import org.codeability.sharing.plugins.api.SharingPluginConfig; +import org.glassfish.jersey.client.ClientConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +/** + * management services for plugins. + * @author Michael Breu + * + */ +@Service +public class PluginManagementService { + + private static String[] registeredPlugins = new String[] { + "http://localhost:8081/api/sharing/config" + }; + + private static SharingPluginConfig[] registeredPluginConfigs; + + private final Logger log = LoggerFactory.getLogger(PluginManagementService.class); + + + @PostConstruct + public void registerPlugins() { + List<SharingPluginConfig> results = new ArrayList<>(); + + for(String registeredPlugin: registeredPlugins) { + ClientConfig restClientConfig = new ClientConfig(); + + Client client = ClientBuilder.newClient(restClientConfig); + + WebTarget target = client.target(registeredPlugin); + + try { + SharingPluginConfig config = target. + request(). + accept(MediaType.APPLICATION_JSON). + get(SharingPluginConfig.class); + results.add(config); + } catch (Exception e) { + log.error("Cannot load plugin at {}", registeredPlugin, e); + } + registeredPluginConfigs = (SharingPluginConfig[]) results.toArray(); + } + } + + +} diff --git a/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java b/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java index 8980f5dfe..dcd2266dc 100644 --- a/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java +++ b/src/main/java/at/ac/uibk/gitsearch/service/ShoppingBasketService.java @@ -1,5 +1,8 @@ package at.ac.uibk.gitsearch.service; +import org.codeability.sharing.plugins.api.ShoppingBasket; +import org.codeability.sharing.plugins.api.ShoppingBasket.ExerciseInfo; +import org.codeability.sharing.plugins.api.ShoppingBasket.UserInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -11,113 +14,6 @@ import org.springframework.stereotype.Service; @Service public class ShoppingBasketService { - public static class ShoppingBasket { - private UserInfo userInfo; - private ExerciseInfo[] exerciseInfo; - - - public ShoppingBasket(UserInfo userInfo, ExerciseInfo[] exerciseInfo) { - super(); - this.userInfo = userInfo; - this.exerciseInfo = exerciseInfo; - } - /** - * @return the userInfo - */ - public UserInfo getUserInfo() { - return userInfo; - } - /** - * @param userInfo the userInfo to set - */ - public void setUserInfo(UserInfo userInfo) { - this.userInfo = userInfo; - } - /** - * @return the exerciseInfo - */ - public ExerciseInfo[] getExerciseInfo() { - return exerciseInfo; - } - /** - * @param exerciseInfo the exerciseInfo to set - */ - public void setExerciseInfo(ExerciseInfo[] exerciseInfo) { - this.exerciseInfo = exerciseInfo; - } - } - public static class UserInfo { - String email; - - public UserInfo(String email) { - super(); - this.email = email; - } - - /** - * @return the email - */ - public String getEmail() { - return email; - } - - /** - * @param email the email to set - */ - public void setEmail(String email) { - this.email = email; - } - } - - public static class ExerciseInfo { - private String gitLabURI; - private int gitLabProjectId; - private String title; - - public ExerciseInfo(String title, int gitLabProjectId, String gitLabURI) { - super(); - this.title = title; - this.setGitLabProjectId(gitLabProjectId); - this.gitLabURI = gitLabURI; - } - - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param title the title to set - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * @return the gitLabURI - */ - public String getGitLabURI() { - return gitLabURI; - } - - /** - * @param gitLabURI the gitLabURI to set - */ - public void setGitLabURI(String gitLabURI) { - this.gitLabURI = gitLabURI; - } - - public int getGitLabProjectId() { - return gitLabProjectId; - } - - public void setGitLabProjectId(int gitLabProjectId) { - this.gitLabProjectId = gitLabProjectId; - } - - } private final Logger log = LoggerFactory.getLogger(ShoppingBasketService.class); -- GitLab