Search in sources :

Example 1 with RealtimeSearchVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO in project Gargoyle by callakrsos.

the class NrchRealtimeSrchFlowComposite method defineService.

private void defineService() {
    /*
		 * 비동기 실시간 검색어 조회 처리가 기술.
		 */
    service = new Service<List<RealtimeSearchVO>>() {

        @Override
        protected Task<List<RealtimeSearchVO>> createTask() {
            return new Task<List<RealtimeSearchVO>>() {

                @Override
                protected List<RealtimeSearchVO> call() throws Exception {
                    List<RealtimeSearchVO> meta = Collections.emptyList();
                    try {
                        meta = NaverRealtimeSrchSupplier.getInstance().getMeta();
                    } catch (Exception e) {
                        DialogUtil.showExceptionDailog(e);
                    }
                    return meta;
                }
            };
        }
    };
    service.setOnCancelled(stat -> {
        if (State.CANCELLED == stat.getSource().getState()) {
            LOGGER.debug("Cancel Requested");
        }
    });
    service.setOnSucceeded(stat -> {
        applyResponseTime(DateUtil.getCurrentDateString());
        FlowCardComposite value = new FlowCardComposite();
        flowCardComposite.set(value);
        this.getParent().setCenter(flowCardComposite.get());
        FlowCardComposite tmp = flowCardComposite.get();
        ObservableList<Node> flowChildrens = tmp.getFlowChildrens();
        tmp.setLimitColumn(20);
        data.setAll((List<RealtimeSearchVO>) stat.getSource().getValue());
        List<VBox> collect = data.stream().map(nodeConverter::apply).flatMap(v -> v.stream()).collect(Collectors.toList());
        flowChildrens.setAll(collect);
        if (isRecycle.get()) {
            WaitThread waitThread = new WaitThread(THREAD_RUNNER_GROUP, choWaitItems.getValue()) {

                @Override
                public boolean isContinue() {
                    return isRecycle.get();
                }

                @Override
                public void execute() {
                    Platform.runLater(() -> {
                        if (isContinue())
                            service.restart();
                    });
                }

                @Override
                public boolean isRecycle() {
                    return isRecycle.get();
                }
            };
            waitThread.setDaemon(true);
            waitThread.start();
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) MouseButton(javafx.scene.input.MouseButton) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DialogUtil(com.kyj.fx.voeditor.visual.util.DialogUtil) VBox(javafx.scene.layout.VBox) Function(java.util.function.Function) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Task(javafx.concurrent.Task) Insets(javafx.geometry.Insets) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) State(javafx.concurrent.Worker.State) ExecutorService(java.util.concurrent.ExecutorService) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) TitledPane(javafx.scene.control.TitledPane) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) Node(javafx.scene.Node) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Service(javafx.concurrent.Service) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) GoogleTrendComposite(com.kyj.fx.voeditor.visual.component.google.trend.GoogleTrendComposite) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) NaverRealtimeSrchSupplier(com.kyj.fx.voeditor.visual.suppliers.NaverRealtimeSrchSupplier) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) Collections(java.util.Collections) ExecutorDemons(com.kyj.fx.voeditor.visual.framework.thread.ExecutorDemons) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) Task(javafx.concurrent.Task) Node(javafx.scene.Node) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) FlowCardComposite(com.kyj.fx.voeditor.visual.component.FlowCardComposite) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Example 2 with RealtimeSearchVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO in project Gargoyle by callakrsos.

the class NaverRealtimeSearchFactory method parse.

public List<RealtimeSearchVO> parse(String htmlBody) {
    Document doc = Jsoup.parse(htmlBody);
    Elements r = doc.select("[class*='realtime_srch']");
    Elements select = r.select(".lst_realtime_srch");
    List<RealtimeSearchVO> realtimeSearchItems = select.stream().map(e -> {
        RealtimeSearchVO realtimeSearchVO = null;
        Element previousElementSibling = e.previousElementSibling();
        if (previousElementSibling != null) {
            realtimeSearchVO = new RealtimeSearchVO();
            String text = previousElementSibling.text();
            if (text.length() >= 15) {
                realtimeSearchVO.setTitle(text.substring(0, 15) + "...");
            } else {
                realtimeSearchVO.setTitle(text);
            }
            Elements liTags = e.getElementsByTag("li");
            List<RealtimeSearchItemVO> items = liTags.stream().map(li -> {
                RealtimeSearchItemVO item = new RealtimeSearchItemVO();
                Element aTag = li.getElementsByTag("a").first();
                Elements elementsByAttribute = aTag.getElementsByAttribute("href");
                String url = elementsByAttribute.attr("href");
                Element numElement = li.getElementsByClass("num").first();
                String num = numElement.text();
                Element titElement = li.getElementsByClass("tit").first();
                String title = titElement.text();
                item.setRank(Integer.parseInt(num, 10));
                item.setKeyword(title);
                item.setLink(url);
                LOGGER.debug("title [{}] num [{}]  url : [{}] , toString : {}", title, num, url, li.toString());
                return item;
            }).collect(Collectors.toList());
            realtimeSearchVO.setItems(items);
        }
        return realtimeSearchVO;
    }).filter(v -> v != null).collect(Collectors.toList());
    return realtimeSearchItems;
}
Also used : Logger(org.slf4j.Logger) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) ResponseHandler(com.kyj.fx.voeditor.visual.util.ResponseHandler) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) RequestUtil(com.kyj.fx.voeditor.visual.util.RequestUtil) LoggerFactory(org.slf4j.LoggerFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) JSONArray(org.json.simple.JSONArray) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) List(java.util.List) Document(org.jsoup.nodes.Document) Element(org.jsoup.nodes.Element) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Collections(java.util.Collections) InputStream(java.io.InputStream) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) Element(org.jsoup.nodes.Element) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

RealtimeSearchItemVO (com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO)2 RealtimeSearchVO (com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO)2 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 FlowCardComposite (com.kyj.fx.voeditor.visual.component.FlowCardComposite)1 GoogleTrendComposite (com.kyj.fx.voeditor.visual.component.google.trend.GoogleTrendComposite)1 ExecutorDemons (com.kyj.fx.voeditor.visual.framework.thread.ExecutorDemons)1 CloseableParent (com.kyj.fx.voeditor.visual.main.layout.CloseableParent)1 SharedMemory (com.kyj.fx.voeditor.visual.momory.SharedMemory)1 NaverRealtimeSrchSupplier (com.kyj.fx.voeditor.visual.suppliers.NaverRealtimeSrchSupplier)1 DateUtil (com.kyj.fx.voeditor.visual.util.DateUtil)1 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)1 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)1 RequestUtil (com.kyj.fx.voeditor.visual.util.RequestUtil)1 ResponseHandler (com.kyj.fx.voeditor.visual.util.ResponseHandler)1 IOException (java.io.IOException)1