Example usage for com.liferay.portal.kernel.servlet SessionMessages add

List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionMessages add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:io.gatling.liferay.controller.RecorderViewController.java

License:Apache License

/**
 * Perform the action of toggle a record by setting the record state to
 * the next record state.//from w w w .  ja  v  a 2s .  co m
 * 
 * @param request
 * @param response
 * @param model
 */
@ActionMapping(params = "action=toggleRecord2")
public void toggleRecordAction(final ActionRequest request, final ActionResponse response, final Model model) {
    final String recordState = ParamUtil.getString(request, "nextRecordState");
    LOG.debug("Toggle Record from smooth called");
    response.setRenderParameter("recordState", recordState);
    //hack, only work this way ....
    //response.setRenderParameter("p_p_state", "pop_up");
    PortalUtil.copyRequestParameters(request, response);
    response.setRenderParameter("render", "renderRecorderView");
    //Hide success message for this action

    //request.setAttribute("NEXT_STATE", nextState);
    SessionMessages.add(request,
            PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
}

From source file:it.dfa.unict.CodeRadePortlet.java

/**
 *
 * @param actionRequest//from w  w  w  . j  av  a 2s  .  c  o  m
 * @param actionResponse
 * @throws IOException
 * @throws PortletException 
 */
@ProcessAction(name = "submit")
public void submit(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    AppInput appInput = new AppInput();
    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;

    SimpleDateFormat dateFormat = new SimpleDateFormat(TS_FORMAT);
    String timestamp = dateFormat.format(Calendar.getInstance().getTime());
    appInput.setTimestamp(timestamp);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    User user = themeDisplay.getUser();
    String username = user.getScreenName();
    appInput.setUsername(username);
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String appServerPath = actionRequest.getPortletSession().getPortletContext().getRealPath(File.separator);

    try {
        String uploadedModel = processInputFile(uploadPortletRequest, username, timestamp, appInput);
        appInput.setInputSandbox(uploadedModel);
        String jobIdentifier = ParamUtil.getString(actionRequest, "jobIdentifier",
                appInput.getModelName() + "_" + appInput.getTimestamp());
        appInput.setJobIdentifier(jobIdentifier);
        _log.info(appInput);

        InfrastructureInfo[] enabledInfrastructures = getEnabledInfrastructures(
                appInfrastructureInfoPreferences);

        submitJob(appServerPath, appInput, enabledInfrastructures);

        PortalUtil.copyRequestParameters(actionRequest, actionResponse);
        actionResponse.setRenderParameter("jobIdentifier", jobIdentifier);
        actionResponse.setRenderParameter("jspPage", "/jsps/submit.jsp");
    } catch (CodeRadePortletException ex) {
        _log.warn(ex.getMessage());
        SessionErrors.add(actionRequest, ex.getMessage());
    }

    SessionMessages.add(actionRequest,
            liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
}

From source file:it.dfa.unict.CodeRadePortlet.java

/**
*
* @param actionRequest//from w w  w.ja va 2  s  .c o m
* @param actionResponse
* @throws IOException
*/
@ProcessAction(name = "editInfrastructure")
public void editInfrastructure(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException {
    _log.debug("editInfrastructure()");

    boolean missedFields = false;

    if (ParamUtil.getString(actionRequest, "pref_nameInfrastructure").equals("")) {
        _log.warn("Empty infrastructure name");
        SessionErrors.add(actionRequest, "empty-infra-name");
        missedFields = true;
    }

    if (ParamUtil.getString(actionRequest, "pref_acronymInfrastructure").equals("")) {
        _log.warn("Empty infrastructure acronym");
        SessionErrors.add(actionRequest, "empty-infra-acronym");
        missedFields = true;
    }

    if (!missedFields) {
        boolean enabledInfrastructure = ParamUtil.getBoolean(actionRequest, "pref_enabledInfrastructure", true);
        int currInfrastructure = ParamUtil.getInteger(actionRequest, "pref_currInfrastructure", -1);
        String nameInfrastructure = ParamUtil.getString(actionRequest, "pref_nameInfrastructure");
        String acronymInfrastructure = ParamUtil.getString(actionRequest, "pref_acronymInfrastructure");
        String bdiiHost = ParamUtil.getString(actionRequest, "pref_bdiiHost", "");
        String wmsHosts = ParamUtil.getString(actionRequest, "pref_wmsHosts", "");
        String pxServerHost = ParamUtil.getString(actionRequest, "pref_pxServerHost", "");
        String pxServerPort = ParamUtil.getString(actionRequest, "pref_pxServerPort", "");
        boolean pxServerSecure = ParamUtil.getBoolean(actionRequest, "pref_pxServerSecure", true);
        String pxRobotId = ParamUtil.getString(actionRequest, "pref_pxRobotId", "");
        String pxRobotVO = ParamUtil.getString(actionRequest, "pref_pxRobotVO", "");
        String pxRobotRole = ParamUtil.getString(actionRequest, "pref_pxRobotRole", "");
        boolean pxRobotRenewalFlag = ParamUtil.getBoolean(actionRequest, "pref_pxRobotRenewalFlag", true);
        String pxUserProxy = ParamUtil.getString(actionRequest, "pref_pxUserProxy", "");
        String softwareTags = ParamUtil.getString(actionRequest, "pref_softwareTags", "");
        if (currInfrastructure > 0) {
            AppInfrastructureInfo appInfrastructureInfo = new AppInfrastructureInfo(currInfrastructure,
                    enabledInfrastructure, nameInfrastructure, acronymInfrastructure, bdiiHost, wmsHosts,
                    pxServerHost, pxServerPort, pxServerSecure, pxRobotId, pxRobotVO, pxRobotRole,
                    pxRobotRenewalFlag, pxUserProxy, softwareTags);

            PortletPreferences preferences = actionRequest.getPreferences();

            if (appInfrastructureInfo.getId() <= appInfrastructureInfoPreferences.size()) {
                _log.debug("Updating infrastructure: " + appInfrastructureInfo.dump());
                appInfrastructureInfoPreferences.set(appInfrastructureInfo.getId() - 1, appInfrastructureInfo);
            } else {
                _log.debug("Adding infrastructure: " + appInfrastructureInfo.dump());
                appInfrastructureInfoPreferences.add(appInfrastructureInfo);
            }

            JSONArray jsonArray = createJSONArray(appInfrastructureInfoPreferences);

            try {
                storeInfrastructureInfo(actionRequest, preferences, jsonArray);
                SessionMessages.add(actionRequest, "infra-saved-success");
            } catch (ReadOnlyException e) {
                e.printStackTrace();
            } catch (ValidatorException e) {
                e.printStackTrace();
            }
        } else {
            SessionMessages.add(actionRequest, "");
            _log.debug("No action preformed");
        }
    } else {
        PortalUtil.copyRequestParameters(actionRequest, actionResponse);
        actionResponse.setRenderParameter("jspPage", "/jsps/edit-infrastructure.jsp");
    }

}

From source file:it.dfa.unict.CodeRadePortlet.java

@ProcessAction(name = "disableInfra")
public void disableInfra(ActionRequest actionRequest, ActionResponse actionResponse) {
    _log.debug("disableInfra()");
    int infraId = ParamUtil.getInteger(actionRequest, "id", -1);
    if (infraId > 0 && infraId <= appInfrastructureInfoPreferences.size()) {
        PortletPreferences preferences = actionRequest.getPreferences();

        appInfrastructureInfoPreferences.get(infraId - 1).setEnableInfrastructure(
                !appInfrastructureInfoPreferences.get(infraId - 1).isEnableInfrastructure());
        _log.debug("Infrastructure " + (infraId - 1) + " is enabled: "
                + appInfrastructureInfoPreferences.get(infraId - 1).isEnableInfrastructure());
        JSONArray jsonArray = createJSONArray(appInfrastructureInfoPreferences);
        try {//from w ww . ja  v a  2s. c  o m
            storeInfrastructureInfo(actionRequest, preferences, jsonArray);
            SessionMessages.add(actionRequest, "infra-toggle-success");
        } catch (ReadOnlyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ValidatorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        SessionMessages.add(actionRequest, "");
        _log.debug("No action preformed");
    }
}

From source file:it.dfa.unict.CodeRadePortlet.java

@ProcessAction(name = "deleteInfra")
public void deleteInfra(ActionRequest actionRequest, ActionResponse actionResponse) {

    int infraId = ParamUtil.getInteger(actionRequest, "id", -1);
    _log.debug("deleteInfra()");
    if (infraId > 0) {
        PortletPreferences preferences = actionRequest.getPreferences();

        AppInfrastructureInfo[] tmp_appInfrastructureInfoPreferences = new AppInfrastructureInfo[appInfrastructureInfoPreferences
                .size()];//  w w  w  . j ava 2s .  co  m
        appInfrastructureInfoPreferences.toArray(tmp_appInfrastructureInfoPreferences);
        appInfrastructureInfoPreferences = new ArrayList<AppInfrastructureInfo>();
        int c = 1;
        for (int i = 0; i < tmp_appInfrastructureInfoPreferences.length; i++) {
            AppInfrastructureInfo appInfrastructureInfo = tmp_appInfrastructureInfoPreferences[i];
            if (appInfrastructureInfo.getId() == infraId) {
                _log.debug("Deleting Infrastructure: " + appInfrastructureInfo.dump());
                c = 0;
            } else {
                appInfrastructureInfo.setId(i + c);
                appInfrastructureInfoPreferences.add(appInfrastructureInfo);
            }
        }

        JSONArray jsonArray = createJSONArray(appInfrastructureInfoPreferences);

        try {
            storeInfrastructureInfo(actionRequest, preferences, jsonArray);
            SessionMessages.add(actionRequest, "infra-delete-success");
        } catch (ReadOnlyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ValidatorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        SessionMessages.add(actionRequest, "");
        _log.debug("No action preformed");
    }
}

From source file:it.dfa.unict.CodeRadePortlet.java

@ProcessAction(name = "pilotScript")
public void pilotScript(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException {
    _log.debug("pilotScript()");
    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;

    String pilotScript = ParamUtil.getString(actionRequest, "pilotScript");
    _log.debug("pilotScript() " + pilotScript);
    String appServerPath = actionRequest.getPortletSession().getPortletContext().getRealPath(File.separator);

    PortalUtil.copyRequestParameters(actionRequest, actionResponse);
    actionResponse.setRenderParameter("jspPage", "/jsps/view-pilot.jsp");
    actionRequest.setAttribute("pilotScript", updateString(appServerPath + "WEB-INF/job/" + pilotScript));

    SessionMessages.add(actionRequest,
            liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

}

From source file:it.dfa.unict.CodeRadePortlet.java

private void storeInfrastructureInfo(ActionRequest actionRequest, PortletPreferences preferences,
        JSONArray jsonArray) throws ReadOnlyException, ValidatorException, IOException {
    String JSONAppInfrastructureInfosPreferences_new = JSONFactoryUtil.looseSerialize(jsonArray);
    _log.debug(JSONAppInfrastructureInfosPreferences_new);

    preferences.setValue(APP_INFRASTRUCTURE_INFO_PREFERENCES, JSONAppInfrastructureInfosPreferences_new);
    preferences.store();/*from  w  w  w. j av a 2 s . c om*/
    SessionMessages.add(actionRequest, "saved-infra");
    _log.debug(preferences.getValue(APP_INFRASTRUCTURE_INFO_PREFERENCES, null));

}

From source file:it.dontesta.liferay.messagebus.example.mvc.SendEmail.java

License:Open Source License

/**
 * Send a list of no active user by SubscriptionSender
 * //from  w w  w  .j a  v  a  2s . com
 * @param actionRequest
 * @param actionResponse
 * @throws IOException
 * @throws PortletException
 * @throws SystemException
 */
public void sendEmailBySubscriptionSender(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException, SystemException {

    User user = (User) actionRequest.getAttribute(WebKeys.USER);

    List<User> userList = getInactiveUsers(user);
    String emailBody = getEmailBody(userList);

    if (userList.size() > 0) {
        SubscriptionSender subscriptionSender = new SubscriptionSender();

        subscriptionSender.setSubject("List of disabled users");
        subscriptionSender.setBody(emailBody.toString());
        subscriptionSender.setUserId(user.getUserId());
        subscriptionSender.setCompanyId(user.getCompanyId());
        subscriptionSender.setFrom("noreply@liferay.com", "Liferay Portal");
        subscriptionSender.setHtmlFormat(false);
        subscriptionSender.setMailId("user", user.getUserId());

        subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());

        List<EmailAddress> emails = (List<EmailAddress>) user.getEmailAddresses();
        if (emails.size() > 0) {
            if (_log.isInfoEnabled()) {
                _log.info("User " + user.getUserId() + " has additional emails address");
            }
            for (EmailAddress emailAddress : emails) {
                subscriptionSender.addRuntimeSubscribers(emailAddress.getAddress(),
                        (String) user.getFullName());

            }
        }

        subscriptionSender.flushNotificationsAsync();
        SessionMessages.add(actionRequest, "email-userlist-no-active-send-successfully");
    } else {
        SessionErrors.add(actionRequest, "email-userlist-no-active-count-zero");
    }
}

From source file:it.dontesta.liferay.messagebus.example.mvc.SendEmail.java

License:Open Source License

/**
 * Send a list of no active user by Email Sender
 * //w  ww  . j a v a 2 s . co m
 * @param actionRequest
 * @param actionResponse
 * @throws IOException
 * @throws PortletException
 * @throws SystemException
 */
public void sendEmailByEmailSender(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException, SystemException {
    User user = (User) actionRequest.getAttribute(WebKeys.USER);

    List<User> userList = getInactiveUsers(user);
    String emailBody = getEmailBody(userList);

    if (userList.size() > 0) {
        InternetAddress from = new InternetAddress("noreply@liferay.com", "Liferay Portale");
        InternetAddress to = new InternetAddress(user.getEmailAddress(), user.getFullName());

        MailMessage message = new MailMessage(from, to, "List of disabled users", emailBody, false);

        Message myMessage = new Message();
        myMessage.setDestinationName(DestinationNames.MAIL);
        myMessage.setPayload(message);
        MessageBusUtil.sendMessage(myMessage.getDestinationName(), myMessage);

        SessionMessages.add(actionRequest, "email-userlist-no-active-send-successfully");
    } else {
        SessionErrors.add(actionRequest, "email-userlist-no-active-count-zero");
    }

}

From source file:it.gebhard.qa.QAPortlet.java

License:Open Source License

@ProcessAction(name = "askNewQuestion")
public void askNewQuestion(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {
    try {/*w  w  w . j a va2s .  c o m*/
        // Get user input
        String guestName = actionRequest.getParameter("qa-guest-name");
        String guestEmail = actionRequest.getParameter("qa-guest-email");
        String message = actionRequest.getParameter("qa-question-detail");
        String title = actionRequest.getParameter("qa-question-title");
        String tags = actionRequest.getParameter("qa-question-tags");

        // Validate data
        if (!validateAskNewQuestionData(actionRequest, actionResponse, guestName, guestEmail, message, title,
                tags))
            return;

        // Create the Question instance
        Question question = QuestionLocalServiceUtil
                .createQuestion(CounterLocalServiceUtil.increment(Question.class.getName()));
        question.setTitle(title);
        question.setMessage(message);
        question.setCreated(new Date(System.currentTimeMillis()));
        question.setModified(null);
        question.setViewCounter(0);
        if (!isGuest(actionRequest)) {
            question.setUserId(getUser(actionRequest).getUserId());
        } else {
            GuestUser guest = GuestUserLocalServiceUtil.getGuestUserByNameAndEmail(guestName, guestEmail);
            question.setGuestUserId(guest.getGuestUserId());
        }
        question.persist();

        // Update tags
        updateTags(question, tags);

        SessionMessages.add(actionRequest, "success");
        actionResponse.setRenderParameter("questionId", String.valueOf(question.getQuestionId()));
        actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp");
    } catch (Exception e) {
        e.printStackTrace();
        SessionErrors.add(actionRequest, "error");
        actionResponse.setRenderParameter("jspPage", "/html/qa/view.jsp");
        actionResponse.setRenderParameter("qa-sort-value", "newest");
        actionResponse.setRenderParameter("qa-search-input", "");
    }
}