Example usage for com.vaadin.server VaadinPortletService getCurrentPortletRequest

List of usage examples for com.vaadin.server VaadinPortletService getCurrentPortletRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinPortletService getCurrentPortletRequest.

Prototype

public static PortletRequest getCurrentPortletRequest() 

Source Link

Document

Gets the currently processed portlet request.

Usage

From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java

License:Apache License

public static void logLifecycleEvent(LifecycleEvent event) {
    String now = new SimpleDateFormat(LIFECYCLE_DATEFORMAT).format(new Date());

    String uiId = "";
    String url = "";
    UI ui = UI.getCurrent();/*from   w ww.j  av a2 s.com*/
    if (ui != null) {
        url = ui.getPage().getLocation().toString();
        uiId = ui.getId();
    }

    String sessionId = "";
    PortletRequest portletRequest = VaadinPortletService.getCurrentPortletRequest();
    if (portletRequest != null) {
        PortletSession session = portletRequest.getPortletSession(false);
        sessionId = session == null ? portletRequest.getRequestedSessionId() : session.getId();
    }

    LIFECYCLE_LOGGER.info(MessageFormat.format("{0};{1};{2};{3};{4};{5}", now, INSTANCE_ID, uiId, url,
            sessionId, event.name()));
}

From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java

License:Apache License

protected ApplicationContext getSpringContext(VaadinRequest request) {
    PortletRequest currentRequest = VaadinPortletService.getCurrentPortletRequest();
    if (currentRequest != null) {
        PortletContext pc = currentRequest.getPortletSession().getPortletContext();
        org.springframework.context.ApplicationContext springContext = PortletApplicationContextUtils
                .getRequiredWebApplicationContext(pc);
        return springContext;

    } else {/*w ww.j  a va2s  .  com*/
        throw new IllegalStateException(
                "Found no current portlet request. Did you subclass PortletApplication in your Vaadin Application?");
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java

License:Apache License

private void cachePortletTitle(String title) {
    PortletPreferences preferences = VaadinPortletService.getCurrentPortletRequest().getPreferences();
    String oldTitle = preferences.getValue(CrudVaadinPortlet.PORTLET_TITLE_PREF_KEY, null);
    if (oldTitle == null || !oldTitle.equals(title)) {
        try {/*from w ww. ja  v  a 2s.  com*/
            preferences.setValue(CrudVaadinPortlet.PORTLET_TITLE_PREF_KEY, title);
            preferences.store();

        } catch (ReadOnlyException e) {
            LOG.error("Failed to update portlet title in preferences", e);
        } catch (ValidatorException e) {
            LOG.error("Failed to update portlet title in preferences", e);
        } catch (IOException e) {
            LOG.error("Failed to update portlet title in preferences", e);
        }
    }

}

From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java

License:Apache License

private ConfigStatus getConfigStatus(Config portletConfig) {
    if (portletConfig == null) {
        return ConfigStatus.NO_CONFIG;
    } else {/*w w  w  . ja  v a2s . com*/
        if (configurationService.isConfigured(portletConfig,
                VaadinPortletService.getCurrentPortletRequest().getPreferences())) {
            return ConfigStatus.CONFIGURED;
        } else {
            return ConfigStatus.UNCONFIGURED;
        }
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.CrudUI.java

License:Apache License

/**
 * @return model preferences taken from portlet instance preferences
 *///w  w w. j  a va 2 s  . com
ModelPreferences createModelPreferences() {
    PortletPreferences prefs = VaadinPortletService.getCurrentPortletRequest().getPreferences();
    ModelPreferences modelPrefs = new ModelPreferences();

    String pageHeight = prefs.getValue("portlet.page.height", null);
    modelPrefs.setPageHeight(pageHeight);

    String minimumHeight = prefs.getValue("portlet.page.minimum-height", null);
    if (minimumHeight != null) {
        modelPrefs.setPageMinimumHeight(Integer.parseInt(minimumHeight));
    }
    return modelPrefs;
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.authentication.Realm.java

License:Apache License

/**
 * Applies credentials to target {@link HttpClient} with Basic
 * Authentication (PLEASE ONLY USE THIS TOGETHER WITH SSL).
 * //from w  ww. j  a v a2s .co  m
 * @param httpClient
 */
public void applyBasicAuthentication(DefaultHttpClient httpClient) {
    String username = null;
    String password = null;
    Cryptor cryptor = null;

    PortletPreferences preferences = VaadinPortletService.getCurrentPortletRequest().getPreferences();

    CredentialsConfig credentials = config.getCredentials();
    String usernameKey = credentials.getUsername().getPreferenceKey();
    if (usernameKey != null) {
        username = preferences.getValue(usernameKey, null);
    }

    String passwordKey = credentials.getPassword().getPreferenceKey();
    if (passwordKey != null) {
        password = preferences.getValue(passwordKey, null);
    }

    String encryptionAlgorithm = credentials.getPassword().getEncryptionAlgorithm();
    if (encryptionAlgorithm != null) {
        cryptor = cryptorFactory.getCryptor(encryptionAlgorithm);
    }

    String plaintextPassword = cryptor == null ? password : cryptor.decrypt(password);
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(username, plaintextPassword));
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.PortalRole.java

License:Apache License

/**
 * {@inheritDoc}//from w  ww  .  ja  v a 2  s  .  c o  m
 */
@Override
public boolean isMember(User user) {
    PortletRequest request = VaadinPortletService.getCurrentPortletRequest();
    Principal principal = request.getUserPrincipal();
    if ((user == null && principal == null)
            || (user.getName() != null && principal != null && user.getName().equals(principal.getName()))) {
        return request.isUserInRole(portalRoleName);
    } else {
        throw new IllegalArgumentException("Membership can only be checked for current user!");
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.Preference.java

License:Apache License

/**
 * @return the value from the portlet preferences, or the configured default
 *         value if not set/*from   w  w  w .j a v  a  2  s . co m*/
 */
public String getValue() {
    PortletPreferences liferayPreferences = VaadinPortletService.getCurrentPortletRequest().getPreferences();
    return liferayPreferences.getValue(getKey(), config.getDefault());
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.TextArea.java

License:Apache License

/**
 * @param config//from  w w w  .ja  va  2 s .co  m
 *            the component's configuration.
 * @param editable
 */
public TextArea(TextAreaConfig config, boolean editable) {
    this.config = config;
    this.editable = editable;

    if (config.getPreferenceKey() != null) {
        content = VaadinPortletService.getCurrentPortletRequest().getPreferences()
                .getValue(config.getPreferenceKey(), null);
    }
    if (content == null) {
        if (config.getContent() != null) {
            if (config.getContent().getContent().size() > 0) {
                content = convertNodeListToString(config.getContent().getContent());
            }
        }
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.TextArea.java

License:Apache License

private void storeToPreferences(String changedContent) {
    try {//from   www  . jav  a2s . co  m
        PortletPreferences preferences = VaadinPortletService.getCurrentPortletRequest().getPreferences();

        preferences.setValue(config.getPreferenceKey(), changedContent);
        preferences.store();

    } catch (ReadOnlyException e) {
        throw new IllegalStateException("Error updating content", e);
    } catch (ValidatorException e) {
        throw new IllegalStateException("Error updating content", e);
    } catch (IOException e) {
        throw new IllegalStateException("Error updating content", e);
    }
}