diff options
Diffstat (limited to 'juick-demo/src/main/java/com/juick/demo/DemoApp.java')
-rw-r--r-- | juick-demo/src/main/java/com/juick/demo/DemoApp.java | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/juick-demo/src/main/java/com/juick/demo/DemoApp.java b/juick-demo/src/main/java/com/juick/demo/DemoApp.java deleted file mode 100644 index ccc86a40..00000000 --- a/juick-demo/src/main/java/com/juick/demo/DemoApp.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.juick.demo; - -import com.juick.Tag; -import com.juick.User; -import com.juick.server.protocol.JuickProtocol; -import com.juick.server.protocol.ProtocolReply; -import com.juick.service.MessagesService; -import com.juick.service.PMQueriesService; -import com.juick.service.TagService; -import com.juick.service.UserService; -import jline.UnsupportedTerminal; -import jline.console.ConsoleReader; -import org.springframework.context.ApplicationContext; -import org.springframework.jdbc.core.JdbcTemplate; - -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; - -/** - * Created by vitalyster on 19.12.2016. - */ -public class DemoApp { - UserService userService; - MessagesService messagesService; - PMQueriesService pmQueriesService; - TagService tagService; - JdbcTemplate jdbcTemplate; - JuickProtocol juickProtocol; - - public DemoApp(ApplicationContext context) { - userService = context.getBean(UserService.class); - messagesService = context.getBean(MessagesService.class); - pmQueriesService = context.getBean(PMQueriesService.class); - tagService = context.getBean(TagService.class); - jdbcTemplate = context.getBean(JdbcTemplate.class); - juickProtocol = context.getBean(JuickProtocol.class); - } - public void start() { - Integer ugnich_id = userService.createUser("ugnich", "secret"); - Integer ugn_mid = messagesService.createMessage(ugnich_id, "Hi, I am ugnich", null, - new ArrayList<Tag>() {{add(tagService.getTag("yo", true)); add(tagService.getTag("people", true));}}); - - Integer juick_id = userService.createUser("juick", "secret"); - messagesService.createMessage(juick_id, "New demo juick was created", null, - new ArrayList<Tag>() {{add(tagService.getTag("yo", true)); add(tagService.getTag("readonly", true));}}); - Integer freefd_id = userService.createUser("freefd", "secret"); - messagesService.createReply(ugn_mid, 0, freefd_id, "I am freefd and this is my reply", null); - messagesService.recommendMessage(ugn_mid, freefd_id); - messagesService.recommendMessage(ugn_mid, juick_id); - messagesService.setMessagePopular(ugn_mid, 1); - pmQueriesService.createPM(freefd_id, ugnich_id, "Hi ugnich!"); - jdbcTemplate.execute("UPDATE tags SET top=1"); - jline.TerminalFactory.registerFlavor(jline.TerminalFactory.Flavor.WINDOWS, UnsupportedTerminal.class); - try (ConsoleReader reader = new ConsoleReader()) { - reader.setPrompt("ugnich>"); - PrintWriter out = new PrintWriter(reader.getOutput()); - User ugnich = userService.getUserByUID(ugnich_id).get(); - out.println(String.format("logged in as @%s", ugnich.getName())); - out.flush(); - String input; - while ((input = reader.readLine()) != null) { - ProtocolReply reply = juickProtocol.getReply(ugnich, input); - out.println(reply.getResult()); - out.flush(); - } - } catch (IOException | NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } -} |