Example usage for com.vaadin.server VaadinSession getCurrent

List of usage examples for com.vaadin.server VaadinSession getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession getCurrent.

Prototype

public static VaadinSession getCurrent() 

Source Link

Document

Gets the currently used session.

Usage

From source file:com.dungnv.streetfood.view.RestaurantView.java

public RestaurantView() {
    user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
    setLocale(VaadinSession.getCurrent().getLocale());
    setSizeFull();/*w  w  w.j av a2 s. c  o m*/
    root = new VerticalLayout();
    root.setSizeFull();
    root.setMargin(true);
    root.addStyleName("dashboard-view");
    setContent(root);
    Responsive.makeResponsive(root);
    init();
    root.addComponent(header);

    builAction();
    dtoSearch = new RestaurantDTO();
    onSearch(true);

}

From source file:com.dungnv.streetfood.view.SlideShowInsert.java

public SlideShowInsert(SlideShowDTO dto, SlideShowView view, Constants.ACTION action) {

    setLocale(VaadinSession.getCurrent().getLocale());
    if (dto != null && !StringUtils.isNullOrEmpty(dto.getId())) {
        UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
        dto = ClientServiceImpl.getInstance().getSlideShowDetail(user.getUsername()//
                , getLocale().getLanguage(), getLocale().getCountry(), null, dto.getId());
    } else {//from w  w w.  j  av a 2s .c  o m
        dto = null;
    }

    this.dto = dto == null ? new SlideShowDTO() : dto;
    this.view = view;
    this.action = action;
    init();
    setContent(layout);
}

From source file:com.dungnv.streetfood.view.SlideShowInsert.java

@Override
public void wizardCompleted(WizardCompletedEvent event) {
    UserDTO user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
    ResultDTO result = null;//w  w  w .ja v  a  2s  . c  om
    if (null != action) {
        switch (action) {
        case INSERT:
            result = ClientServiceImpl.getInstance().insertSlideShow(user.getUsername()//
                    , getLocale().getLanguage(), getLocale().getCountry(), null, dto);
            break;
        case UPDATE:
            result = ClientServiceImpl.getInstance().updateSlideShow(user.getUsername()//
                    , getLocale().getLanguage(), getLocale().getCountry(), null, dto);
            break;
        default:
            UI.getCurrent().removeWindow(event.getWizard().findAncestor(Window.class));
            return;
        }
    }

    if (result != null && Constants.SUCCESS.equals(result.getMessage())) {
        view.onSearch(Boolean.TRUE);
        UI.getCurrent().removeWindow(event.getWizard().findAncestor(Window.class));
    } else {
        Notification.show(result == null || result.getKey() == null ? Constants.FAIL : result.getKey(),
                Notification.Type.ERROR_MESSAGE);
    }
}

From source file:com.dungnv.streetfood.view.SlideShowView.java

public SlideShowView() {
    user = (UserDTO) VaadinSession.getCurrent().getAttribute(UserDTO.class.getName());
    setLocale(VaadinSession.getCurrent().getLocale());
    setSizeFull();/*from   w  w  w. jav a2 s .com*/
    root = new VerticalLayout();
    root.setSizeFull();
    root.setMargin(true);
    root.addStyleName("dashboard-view");
    setContent(root);
    Responsive.makeResponsive(root);
    init();
    root.addComponent(header);

    builAction();
    dtoSearch = new SlideShowDTO();
    onSearch(true);

}

From source file:com.dungnv.utils.BundleUtils.java

public static String getResourceConfig(String key, Locale... locale) {
    Locale mlocale = (Locale) VaadinSession.getCurrent().getSession().getAttribute("locale");
    if (mlocale == null) {
        Locale viVN = new Locale("vi-VN");
        VaadinSession.getCurrent().getSession().setAttribute("locale", viVN);
        mlocale = viVN;//from  ww w  . j ava2s .  c  o  m
    }
    try {
        if (locale != null) {
            if (locale.length == 0) {
                rsConfig = ResourceBundle.getBundle("resourceConfig", mlocale);
            } else {
                rsConfig = ResourceBundle.getBundle("resourceConfig", locale[0]);
            }
        } else {
            rsConfig = ResourceBundle.getBundle("resourceConfig", mlocale);
        }

        return rsConfig.getString(key);
    } catch (Exception e) {
        return key;
    }
}

From source file:com.dungnv.utils.BundleUtils.java

public static String getResourceConfig(String key, String defaultKey, Locale... locale) {
    Locale mlocale = (Locale) VaadinSession.getCurrent().getSession().getAttribute("locale");
    if (mlocale == null) {
        Locale viVN = new Locale("vi-VN");
        VaadinSession.getCurrent().getSession().setAttribute("locale", viVN);
        mlocale = viVN;//from w w  w .  jav a  2s .  co m
    }
    try {
        if (locale != null) {
            if (locale.length == 0) {
                rsConfig = ResourceBundle.getBundle("resourceConfig", mlocale);
            } else {
                rsConfig = ResourceBundle.getBundle("resourceConfig", locale[0]);
            }
        } else {
            rsConfig = ResourceBundle.getBundle("resourceConfig", mlocale);
        }

        return rsConfig.getString(key);
    } catch (Exception e) {
        return defaultKey == null ? null : defaultKey;
    }
}

From source file:com.dungnv.utils.BundleUtils.java

public static String getLanguage(String key, Locale... locale) {
    Locale mlocale = (Locale) VaadinSession.getCurrent().getSession().getAttribute("locale");
    if (mlocale == null) {
        Locale viVN = new Locale("vi-VN");
        VaadinSession.getCurrent().getSession().setAttribute("locale", viVN);
        mlocale = viVN;//ww w . j  a  va 2 s . c o m
    }
    try {
        if (locale != null) {
            if (locale.length == 0) {
                rsConfig = ResourceBundle.getBundle("language", mlocale);
            } else {
                rsConfig = ResourceBundle.getBundle("language", locale[0]);
            }
        } else {
            rsConfig = ResourceBundle.getBundle("language", mlocale);
        }

        return rsConfig.getString(key);
    } catch (Exception e) {
        return key;
    }
}

From source file:com.dungnv.utils.BundleUtils.java

public static String getLanguage(String key, String defaultKey, Locale... locale) {
    Locale mlocale = (Locale) VaadinSession.getCurrent().getSession().getAttribute("locale");
    if (mlocale == null) {
        Locale viVN = new Locale("vi-VN");
        VaadinSession.getCurrent().getSession().setAttribute("locale", viVN);
        mlocale = viVN;//from  w  w w . ja  v  a 2 s .co m
    }
    try {
        if (locale != null) {
            if (locale.length == 0) {
                rsConfig = ResourceBundle.getBundle("language", mlocale);
            } else {
                rsConfig = ResourceBundle.getBundle("language", locale[0]);
            }
        } else {
            rsConfig = ResourceBundle.getBundle("language", mlocale);
        }

        return rsConfig.getString(key);
    } catch (Exception e) {
        return defaultKey == null ? null : defaultKey;
    }
}

From source file:com.dungnv.ws.provider.CxfWsClientInInterceptor.java

@Override
public void handleMessage(Message message) throws Fault {
    //        Logger log = getMessageLogger(message);
    //        if ((this.writer != null) || (log.isLoggable(Level.INFO))) {
    //            logging(log, message);
    //        }/*from   w  w w .j  a v  a  2 s  .co  m*/
    try {

        String id = (String) message.getExchange().get(LoggingMessage.ID_KEY);
        if (id == null) {
            id = LoggingMessage.nextId();
            message.getExchange().put(LoggingMessage.ID_KEY, id);
        }

        String method = CxfWsClientOutInterceptor.mapMethodWS.get(id);
        String startLog = CxfWsClientOutInterceptor.mapLogWS.get(id);
        Date startDate = CxfWsClientOutInterceptor.mapDateWS.get(id);
        Date endDate = new Date();
        //            System.out.println(startDate);
        //            System.out.println(endDate);
        //            System.out.println(endDate.getTime() - startDate.getTime());
        Long responeTime = (endDate.getTime() - startDate.getTime()) / 1000;

        String endLog = "end_action|GNOC"
                //                    + "|" + DateTimeUtils.convertDateToString(new Date(), "dd/MM/yyyy HH:mm:ss")
                //                    + "|" + user.getUserName()
                + "|" + UI.getCurrent().getPage().getWebBrowser().getAddress() + "|"
                + UI.getCurrent().getPage().getLocation().getHost() + ":"
                + UI.getCurrent().getPage().getLocation().getPort() + "|" + method + ".do" + "|" + "" + "|"
                + method + "|" + responeTime + "|[RequestId=" + VaadinSession.getCurrent().getCsrfToken() + "_"
                + id
                //                    + "][Unit=" + user.getUnitCode()
                + "][VTS-KPIID=null]";
        logger.info(startLog.replace("{responeTime}", responeTime.toString()));
        logger.info(endLog);
        CxfWsClientOutInterceptor.mapLogWS.remove(id);
        CxfWsClientOutInterceptor.mapDateWS.remove(id);
        CxfWsClientOutInterceptor.mapMethodWS.remove(id);
    } catch (Exception e) {
        //            e.printStackTrace();
    }
}

From source file:com.dungnv.ws.provider.CxfWsClientOutInterceptor.java

@Override
public void handleMessage(Message message) {
    try {/* w w  w. j ava 2s.c  o m*/
        UserDTO user = (UserDTO) VaadinSession.getCurrent().getSession().getAttribute("user");
        String id = (String) message.getExchange().get(LoggingMessage.ID_KEY);
        if (id == null) {
            id = LoggingMessage.nextId();
            message.getExchange().put(LoggingMessage.ID_KEY, id);
            System.out.println("id: " + id);
        }

        try {
            List<String> listRequest = new ArrayList<>();
            listRequest.add(VaadinSession.getCurrent().getCsrfToken() + "_" + id);
            Map<String, List<String>> protocolHeader = (TreeMap) message.get(Message.PROTOCOL_HEADERS);
            if (protocolHeader == null) {
                protocolHeader = new TreeMap<>();
            }
            protocolHeader.put("RequestId", listRequest);
            message.put(Message.PROTOCOL_HEADERS, protocolHeader);
        } catch (Exception e) {
            //            ex.printStackTrace();
        }

        String log = "start_action|GNOC" + "|"
                + DateTimeUtils.convertDateToString(new Date(), "dd/MM/yyyy HH:mm:ss") + "|"
                + user.getUsername() + "|" + UI.getCurrent().getPage().getWebBrowser().getAddress() + "|"
                + UI.getCurrent().getPage().getLocation().getHost() + ":"
                + UI.getCurrent().getPage().getLocation().getPort() + "|" + getMethod(message) + ".do" + "|"
                + "" + "|" + getMethod(message) + "|{responeTime}|[RequestId="
                + VaadinSession.getCurrent().getCsrfToken() + "_" + id
                //                    + "][Unit=" + user.getUnitCode()
                + "][VTS-KPIID=null]";

        mapDateWS.put(id, new Date());
        mapMethodWS.put(id, getMethod(message));
        mapLogWS.put(id, log);

    } catch (Exception ex) {
        //            ex.printStackTrace();
    }
}