Search in sources :

Example 11 with Storage

use of com.google.gwt.storage.client.Storage in project gwt-test-utils by gwt-test-utils.

the class StorageTest method itemLocalStorage.

@Test
public void itemLocalStorage() {
    // Given
    Storage local = Storage.getLocalStorageIfSupported();
    // When
    local.setItem("test", "my test");
    // Then
    assertThat(local.getItem("test")).isEqualTo("my test");
}
Also used : Storage(com.google.gwt.storage.client.Storage) Test(org.junit.Test)

Example 12 with Storage

use of com.google.gwt.storage.client.Storage in project gwt-test-utils by gwt-test-utils.

the class StorageTest method getLengthSessionStorage.

@Test
public void getLengthSessionStorage() {
    // Given
    Storage session = Storage.getSessionStorageIfSupported();
    session.setItem("test", "my test");
    session.setItem("test", "my test bis");
    session.setItem("test2", "my test 2");
    // When
    int length = session.getLength();
    // Then
    assertThat(length).isEqualTo(2);
}
Also used : Storage(com.google.gwt.storage.client.Storage) Test(org.junit.Test)

Example 13 with Storage

use of com.google.gwt.storage.client.Storage in project gwt-test-utils by gwt-test-utils.

the class StorageTest method keySessionStorage.

@Test
public void keySessionStorage() {
    // Given
    Storage session = Storage.getSessionStorageIfSupported();
    session.setItem("test0", "my test 0");
    session.setItem("test1", "my test 1");
    session.setItem("test2", "my test 2");
    // When
    String key0 = session.key(0);
    String key1 = session.key(1);
    String key2 = session.key(2);
    // Then
    assertThat(key0).isEqualTo("test0");
    assertThat(key1).isEqualTo("test1");
    assertThat(key2).isEqualTo("test2");
}
Also used : Storage(com.google.gwt.storage.client.Storage) Test(org.junit.Test)

Example 14 with Storage

use of com.google.gwt.storage.client.Storage in project perun by CESNET.

the class WebGui method loadPerunPrincipal.

/**
 * Performs a login into the RPC, loads user and his roles into session and enables GUI.
 */
private void loadPerunPrincipal() {
    // WEB PAGE SPLITTER
    final DockLayoutPanel bodySplitter = new DockLayoutPanel(Unit.PX);
    body.add(bodySplitter);
    // MAIN CONTENT WRAPPER - make content resize-able
    final ResizeLayoutPanel contentWrapper = new ResizeLayoutPanel();
    contentWrapper.setSize("100%", "100%");
    // MAIN CONTENT
    AbsolutePanel contentPanel = new AbsolutePanel();
    contentPanel.setSize("100%", "100%");
    // put content into wrapper
    contentWrapper.setWidget(contentPanel);
    // SETUP SESSION
    // store handler for main contetn's elements (tabs etc.) into session
    session.setUiElements(new UiElements(contentPanel));
    // Store TabManager into session for handling tabs (add/remove/close...)
    session.setTabManager(new TabManager());
    // Store this class into session
    session.setWebGui(webgui);
    // Set this class as browser's History handler
    History.addValueChangeHandler(webgui);
    // show loading box
    final PopupPanel loadingBox = session.getUiElements().perunLoadingBox();
    loadingBox.show();
    // events after getting PerunPrincipal from RPC
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // store perun principal into session for future use
            final PerunPrincipal pp = (PerunPrincipal) jso;
            session.setPerunPrincipal(pp);
            GetGuiConfiguration getConfig = new GetGuiConfiguration(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    session.setConfiguration((BasicOverlayType) jso.cast());
                    String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert");
                    if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) {
                        DOM.getElementById("perun-new-gui-alert").setInnerHTML(newGuiAlertContent);
                        DOM.getElementById("perun-new-gui-alert").setClassName("newGuiAlertActive");
                    }
                    // check if user exists
                    if (session.getUser() == null && !pp.getRoles().hasAnyRole()) {
                        // if not and no role, redraw page body
                        RootLayoutPanel body = RootLayoutPanel.get();
                        loadingBox.hide();
                        body.clear();
                        body.add(new NotUserOfPerunWidget());
                        return;
                    }
                    // check if user exists
                    if (session.getUser().isServiceUser()) {
                        // if not and no role, redraw page body
                        RootLayoutPanel body = RootLayoutPanel.get();
                        loadingBox.hide();
                        body.clear();
                        body.add(new CantLogAsServiceUserWidget());
                        return;
                    }
                    // Sets URL mapper for loading proper tabs
                    urlMapper = new UrlMapper();
                    // MENU WRAPPER
                    VerticalPanel menuWrapper = new VerticalPanel();
                    menuWrapper.setHeight("100%");
                    // add menu
                    menuWrapper.add(session.getUiElements().getMenu().getWidget());
                    menuWrapper.setCellVerticalAlignment(session.getUiElements().getMenu().getWidget(), HasVerticalAlignment.ALIGN_TOP);
                    // Put all panels into web page splitter
                    // bodySplitter.addNorth(session.getUiElements().getHeader(), 78);
                    bodySplitter.addNorth(session.getUiElements().getHeader(), 64);
                    bodySplitter.addSouth(session.getUiElements().getFooter(), 30);
                    bodySplitter.addWest(menuWrapper, 202);
                    // content must be added as last !!
                    bodySplitter.add(contentWrapper);
                    // Append more GUI elements from UiElements class which are not part of splitted design
                    if ("true".equalsIgnoreCase(Location.getParameter("log"))) {
                        // log
                        bodySplitter.getElement().appendChild(session.getUiElements().getLog().getElement());
                    }
                    // status
                    bodySplitter.getElement().appendChild(session.getUiElements().getStatus().getElement());
                    // keep alive
                    VerticalPanel vp = new VerticalPanel();
                    vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
                    vp.add(new HTML("<h2>Connection to Perun has been lost.</h2><strong>Please check your internet connection.</strong>"));
                    final FlexTable layout = new FlexTable();
                    layout.setVisible(false);
                    layout.setHTML(0, 0, "<p>You can also try to <strong>refresh the browser window</strong>. However, all <strong>unsaved changes will be lost</strong>.");
                    layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
                    vp.add(layout);
                    vp.setSpacing(10);
                    final Confirm c = new Confirm("", vp, true);
                    c.setAutoHide(false);
                    c.setHideOnButtonClick(false);
                    c.setOkIcon(SmallIcons.INSTANCE.arrowRefreshIcon());
                    c.setOkButtonText("Re-connect");
                    c.setNonScrollable(true);
                    c.setOkClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            KeepAlive call = new KeepAlive(JsonCallbackEvents.disableButtonEvents(c.getOkButton(), new JsonCallbackEvents() {

                                @Override
                                public void onLoadingStart() {
                                    checkPending = true;
                                }

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    BasicOverlayType type = jso.cast();
                                    checkPending = false;
                                    connected = true;
                                    keepAliveCounter = 0;
                                    if (type.getString().equals("OK")) {
                                        if (c.isShowing()) {
                                            c.hide();
                                        }
                                    }
                                    // If ok, append new keepalive checker
                                    appendKeepAliveChecker(c);
                                }

                                @Override
                                public void onError(PerunError error) {
                                    checkPending = false;
                                    // connection lost only IF TIMEOUT
                                    if (error != null && error.getErrorId().equals("0")) {
                                        keepAliveCounter++;
                                        if (keepAliveCounter >= keepAliveTreshold) {
                                            connected = false;
                                            if (!c.isShowing()) {
                                                c.show();
                                            }
                                            layout.setVisible(true);
                                            c.getOkButton().setText("Reload");
                                            c.getOkButton().addClickHandler(new ClickHandler() {

                                                @Override
                                                public void onClick(ClickEvent event) {
                                                    Window.Location.reload();
                                                }
                                            });
                                        } else {
                                            // not connected but under treshold
                                            appendKeepAliveChecker(c);
                                        }
                                    }
                                }
                            }));
                            call.retrieveData();
                        }
                    });
                    appendKeepAliveChecker(c);
                    // store users roles and editable entities into session
                    session.setRoles(pp.getRoles());
                    // display logged user
                    session.getUiElements().setLoggedUserInfo(pp);
                    session.getUiElements().setLogText("Welcome " + pp.getUser().getFullNameWithTitles());
                    // show extended info ?
                    boolean showExtendedInfo = false;
                    // is perun admin ?
                    if (session.isPerunAdmin()) {
                        showExtendedInfo = true;
                    }
                    // replace by local storage if possible
                    Storage localStorage = Storage.getLocalStorageIfSupported();
                    if (localStorage != null) {
                        String value = localStorage.getItem("urn:perun:gui:preferences:extendedInfo");
                        if (value != null) {
                            showExtendedInfo = Boolean.parseBoolean(value);
                        }
                    }
                    // finally set it
                    JsonUtils.setExtendedInfoVisible(showExtendedInfo);
                    // set extended info button
                    session.getUiElements().getExtendedInfoButtonWidget().setDown(showExtendedInfo);
                    // Specific GDPR approval is required only from admins
                    if (session.isFacilityAdmin() || session.isVoAdmin() || session.isVoObserver() || session.isGroupAdmin() || session.isPerunAdmin() || session.isSecurityAdmin()) {
                        checkGdprApproval(new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // FINISH LOADING UI ONCE ITS CHECKED
                                // perun loaded = true
                                perunLoaded = true;
                                // loads the page based on URL or default
                                loadPage();
                                // hides the loading box
                                loadingBox.hide();
                                // load proper parts of menu (based on roles)
                                session.getUiElements().getMenu().prepare();
                            }

                            @Override
                            public void onError(PerunError error) {
                                // hides the loading box
                                loadingBox.hide();
                                // shows error box
                                PopupPanel loadingFailedBox;
                                if (error != null) {
                                    loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
                                } else {
                                    String checkFailed = session.getConfiguration().getGDPRproperty("check_failed");
                                    loadingFailedBox = session.getUiElements().perunLoadingFailedBox(checkFailed);
                                }
                                loadingFailedBox.show();
                            }
                        });
                    } else {
                        // NO GDPR CHECK NEEDED
                        // perun loaded = true
                        perunLoaded = true;
                        // loads the page based on URL or default
                        loadPage();
                        // hides the loading box
                        loadingBox.hide();
                        // load proper parts of menu (based on roles)
                        session.getUiElements().getMenu().prepare();
                    }
                }

                @Override
                public void onError(PerunError error) {
                    // hides the loading box
                    loadingBox.hide();
                    // shows error box
                    PopupPanel loadingFailedBox;
                    if (error != null) {
                        loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
                    } else {
                        if (error.getName().contains("UserNotExistsException")) {
                            loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
                        } else {
                            loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
                        }
                    }
                    if (!error.getErrorId().equals("0")) {
                        loadingFailedBox.show();
                    }
                }
            });
            getConfig.retrieveData();
        }

        @Override
        public void onError(PerunError error) {
            // hides the loading box
            loadingBox.hide();
            // shows error box
            PopupPanel loadingFailedBox;
            if (error == null) {
                loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
            } else {
                if (error.getName().contains("UserNotExistsException")) {
                    loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
                } else {
                    loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
                }
            }
            loadingFailedBox.show();
        }
    };
    GetPerunPrincipal loggedUserRequst = new GetPerunPrincipal(events);
    loggedUserRequst.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TabManager(cz.metacentrum.perun.webgui.tabs.TabManager) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) CantLogAsServiceUserWidget(cz.metacentrum.perun.webgui.widgets.CantLogAsServiceUserWidget) GetPerunPrincipal(cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal) PerunPrincipal(cz.metacentrum.perun.webgui.model.PerunPrincipal) GetPerunPrincipal(cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal) GetGuiConfiguration(cz.metacentrum.perun.webgui.json.GetGuiConfiguration) UrlMapper(cz.metacentrum.perun.webgui.tabs.UrlMapper) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Storage(com.google.gwt.storage.client.Storage) NotUserOfPerunWidget(cz.metacentrum.perun.webgui.widgets.NotUserOfPerunWidget) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) KeepAlive(cz.metacentrum.perun.webgui.json.authzResolver.KeepAlive) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

Storage (com.google.gwt.storage.client.Storage)14 Test (org.junit.Test)8 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)2 StorableBreakpointDto (org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto)2 Optional (com.google.common.base.Optional)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 UrlBuilder (com.google.gwt.http.client.UrlBuilder)1 GetGuiConfiguration (cz.metacentrum.perun.webgui.json.GetGuiConfiguration)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetPerunPrincipal (cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal)1 KeepAlive (cz.metacentrum.perun.webgui.json.authzResolver.KeepAlive)1 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 PerunPrincipal (cz.metacentrum.perun.webgui.model.PerunPrincipal)1 TabManager (cz.metacentrum.perun.webgui.tabs.TabManager)1 UrlMapper (cz.metacentrum.perun.webgui.tabs.UrlMapper)1 CantLogAsServiceUserWidget (cz.metacentrum.perun.webgui.widgets.CantLogAsServiceUserWidget)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1