protected void runScript(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String language = ParamUtil.getString(actionRequest, "language");
    String script = ParamUtil.getString(actionRequest, "script");

    PortletContext portletContext = portletConfig.getPortletContext();

    Map<String, Object> portletObjects =
        ScriptingUtil.getPortletObjects(
            portletConfig, portletContext, actionRequest, actionResponse);

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(unsyncByteArrayOutputStream);

    portletObjects.put("out", unsyncPrintWriter);

    try {
      SessionMessages.add(actionRequest, "language", language);
      SessionMessages.add(actionRequest, "script", script);

      ScriptingUtil.exec(null, portletObjects, language, script);

      unsyncPrintWriter.flush();

      SessionMessages.add(actionRequest, "scriptOutput", unsyncByteArrayOutputStream.toString());
    } catch (ScriptingException se) {
      SessionErrors.add(actionRequest, ScriptingException.class.getName(), se);

      _log.error(se.getMessage());
    }
  }
  public void editScope(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences =
        ActionUtil.getLayoutPortletSetup(actionRequest, portlet);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    updateScope(actionRequest, portlet);

    if (!SessionErrors.isEmpty(actionRequest)) {
      return;
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
  }
  public void editSharing(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences =
        ActionUtil.getLayoutPortletSetup(actionRequest, portlet);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    updateAnyWebsite(actionRequest, portletPreferences);
    updateFacebook(actionRequest, portletPreferences);
    updateFriends(actionRequest, portletPreferences);
    updateGoogleGadget(actionRequest, portletPreferences);
    updateNetvibes(actionRequest, portletPreferences);

    portletPreferences.store();

    if (!SessionErrors.isEmpty(actionRequest)) {
      return;
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
  }
Пример #4
0
  /**
   * This method inserts new TerminationReason record into the database table
   *
   * @param actionRequest
   * @param actionResponse
   * @throws IOException
   * @throws PortletException
   * @throws SystemException
   */
  public void saveTerminationReasons(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, SystemException {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {
      TerminationReasons terminationReasons =
          TerminationReasonsLocalServiceUtil.createTerminationReasons(
              CounterLocalServiceUtil.increment());

      String id = ParamUtil.getString(actionRequest, "terminationreasonsId");
      String name = ParamUtil.getString(actionRequest, "terminationreasonsName");
      String terminationReason = name.trim();
      if (terminationReason.equals("") || terminationReason == null) {

        System.out.println("Empty value in TerminationReason...");
        SessionMessages.add(actionRequest.getPortletSession(), "termination-form-error");
        actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp");
      } else {

        System.out.println("id == " + id + "Name = " + name);
        if (id == "" || id == null) {

          DynamicQuery dynamicQuery =
              DynamicQueryFactoryUtil.forClass(
                  TerminationReasons.class, PortalClassLoaderUtil.getClassLoader());

          dynamicQuery.add(RestrictionsFactoryUtil.eq("terminationreasonsName", name));
          List<TerminationReasons> list =
              TerminationReasonsLocalServiceUtil.dynamicQuery(dynamicQuery);

          if (list.size() > 0) {
            TerminationReasons terminationReasons2 = list.get(0);

            if (terminationReasons2 != null) {

              SessionMessages.add(
                  actionRequest.getPortletSession(), "termination-form-duplicate-error");
              actionResponse.setRenderParameter("mvcPath", "/html/terminationreasons/add.jsp");
            }
          } else {

            terminationReasons.setTerminationreasonsName(
                ParamUtil.getString(actionRequest, "terminationreasonsName"));
            terminationReasons.setCreateDate(date);
            terminationReasons.setModifiedDate(date);
            terminationReasons.setCompanyId(themeDisplay.getCompanyId());
            terminationReasons.setGroupId(themeDisplay.getCompanyGroupId());
            terminationReasons.setUserId(themeDisplay.getUserId());
            terminationReasons =
                TerminationReasonsLocalServiceUtil.addTerminationReasons(terminationReasons);
          }
        }
      }
    } catch (SystemException e) {

      e.printStackTrace();
    }
  }
  public void saveEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      doSaveEntry(actionRequest, actionResponse);

      long entryId = ParamUtil.getLong(actionRequest, "entryId");

      if (entryId <= 0) {
        SessionMessages.add(actionRequest, "announcementAdded");
      } else {
        SessionMessages.add(actionRequest, "announcementUpdated");
      }

      LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

      PortletURL portletURL = liferayPortletResponse.createRenderURL();

      portletURL.setParameter("mvcPath", "/manage_entries.jsp");
      portletURL.setParameter(
          "distributionScope", ParamUtil.getString(actionRequest, "distributionScope"));

      jsonObject.put("redirect", portletURL.toString());

      jsonObject.put("success", true);
    } catch (Exception e) {
      String message = null;

      if (e instanceof EntryContentException) {
        message = "please-enter-valid-content";
      } else if (e instanceof EntryDisplayDateException) {
        message = "please-enter-a-valid-display-date";
      } else if (e instanceof EntryExpirationDateException) {
        message = "please-enter-a-valid-expiration-date";
      } else if (e instanceof EntryTitleException) {
        message = "please-enter-a-valid-title";
      } else if (e instanceof EntryURLException) {
        message = "please-enter-a-valid-url";
      } else {
        throw new PortletException(e);
      }

      SessionErrors.clear(actionRequest);

      jsonObject.put("message", translate(actionRequest, message));
      jsonObject.put("success", false);
    }

    writeJSON(actionRequest, actionResponse, jsonObject);
  }
  protected void deleteEntries(ActionRequest actionRequest, boolean moveToTrash) throws Exception {

    long[] deleteEntryIds = null;

    long entryId = ParamUtil.getLong(actionRequest, "entryId");

    if (entryId > 0) {
      deleteEntryIds = new long[] {entryId};
    } else {
      deleteEntryIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteEntryIds"), 0L);
    }

    List<TrashedModel> trashedModels = new ArrayList<>();

    for (long deleteEntryId : deleteEntryIds) {
      if (moveToTrash) {
        BlogsEntry entry = BlogsEntryServiceUtil.moveEntryToTrash(deleteEntryId);

        trashedModels.add(entry);
      } else {
        BlogsEntryServiceUtil.deleteEntry(deleteEntryId);
      }
    }

    if (moveToTrash && !trashedModels.isEmpty()) {
      TrashUtil.addTrashSessionMessages(actionRequest, trashedModels);

      SessionMessages.add(
          actionRequest,
          PortalUtil.getPortletId(actionRequest)
              + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
    }
  }
  public void restoreArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    portletInstanceModifiableSettings.reset();

    portletInstanceModifiableSettings.setValues(archivedSettings);

    portletInstanceModifiableSettings.store();

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    PortletPreferences preferences = actionRequest.getPreferences();

    String[] symbols =
        StringUtil.split(ParamUtil.getString(actionRequest, "symbols").toUpperCase());

    preferences.setValues("symbols", symbols);

    try {
      preferences.store();
    } catch (ValidatorException ve) {
      SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve);

      return;
    }

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doEdit");
  }
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    boolean allAssetVocabularies = ParamUtil.getBoolean(actionRequest, "allAssetVocabularies");
    long[] assetVocabularyIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "assetVocabularyIds"), 0L);

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

    preferences.setValue("all-asset-vocabularies", String.valueOf(allAssetVocabularies));
    preferences.setValues("asset-vocabulary-ids", ArrayUtil.toStringArray(assetVocabularyIds));

    preferences.store();

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
  }
Пример #10
0
  protected void updatePreferences(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    PortletPreferences preferences = actionRequest.getPreferences();

    String[] symbols =
        StringUtil.split(
            ParamUtil.getString(actionRequest, "symbols").toUpperCase(), StringPool.SPACE);

    Arrays.sort(symbols);

    preferences.setValues("symbols", symbols);

    try {
      preferences.store();
    } catch (ValidatorException ve) {
      SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve);

      return;
    }

    PortletConfig portletConfig = getPortletConfig();

    SessionMessages.add(
        actionRequest,
        portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES);
  }
Пример #11
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException, IOException {

    try {
      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = getResourcePrimKey(renderRequest);

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass().getName());

        PortletConfig portletConfig = getPortletConfig();

        SessionMessages.add(
            renderRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
Пример #12
0
  public static void sendPassword(
      ActionRequest actionRequest,
      String fromName,
      String fromAddress,
      String toAddress,
      String subject,
      String body)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    if (!company.isSendPassword() && !company.isSendPasswordResetLink()) {
      return;
    }

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    UserLocalServiceUtil.sendPassword(
        company.getCompanyId(), toAddress, fromName, fromAddress, subject, body, serviceContext);

    SessionMessages.add(actionRequest, "request_processed", toAddress);
  }
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    String selectionMethod = ParamUtil.getString(actionRequest, "selectionMethod");
    String organizationId = ParamUtil.getString(actionRequest, "organizationId");
    String displayStyle = ParamUtil.getString(actionRequest, "displayStyle");
    int max = ParamUtil.getInteger(actionRequest, "max");

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

    preferences.setValue("selection-method", selectionMethod);
    preferences.setValue("organization-id", organizationId);
    preferences.setValue("display-style", displayStyle);
    preferences.setValue("max", String.valueOf(max));

    preferences.store();

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
  }
Пример #14
0
  protected void sendRedirect(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String redirect,
      String closeRedirect)
      throws IOException {

    if (isDisplaySuccessMessage(actionRequest)) {
      addSuccessMessage(actionRequest, actionResponse);
    }

    if (Validator.isNull(redirect)) {
      redirect = (String) actionRequest.getAttribute(WebKeys.REDIRECT);
    }

    if (Validator.isNull(redirect)) {
      redirect = ParamUtil.getString(actionRequest, "redirect");
    }

    if ((portletConfig != null)
        && Validator.isNotNull(redirect)
        && Validator.isNotNull(closeRedirect)) {

      redirect = HttpUtil.setParameter(redirect, "closeRedirect", closeRedirect);

      SessionMessages.add(
          actionRequest,
          PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_CLOSE_REDIRECT,
          closeRedirect);
    }

    if (Validator.isNull(redirect)) {
      return;
    }

    // LPS-1928

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    if (BrowserSnifferUtil.isIe(request)
        && (BrowserSnifferUtil.getMajorVersion(request) == 6.0)
        && redirect.contains(StringPool.POUND)) {

      String redirectToken = "&#";

      if (!redirect.contains(StringPool.QUESTION)) {
        redirectToken = StringPool.QUESTION + redirectToken;
      }

      redirect = StringUtil.replace(redirect, StringPool.POUND, redirectToken);
    }

    redirect = PortalUtil.escapeRedirect(redirect);

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
Пример #15
0
  /**
   * Takes a submitted contact and adds it to the database if it passes validation.
   *
   * @param request
   * @param response
   */
  public void registerContact(ActionRequest request, ActionResponse response) throws Exception {

    _log.debug("registerContact");

    Contact contact = ActionUtil.contactFromRequest(request);
    ArrayList<String> errors = new ArrayList();
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String community = "";
    try {
      community = themeDisplay.getScopeGroupName();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    boolean regValid = ContactMeRegValidator.validateRegistration(contact, errors);

    if (regValid) {

      long userId = themeDisplay.getUserId();

      contact.setCreateDate(new Date(System.currentTimeMillis()));
      contact.setUserId(userId);
      contact.setStatus(Constants.CONTACT_RECEIVED);
      contact.setCommunity(community);

      ContactLocalServiceUtil.addContact(contact);
      SessionMessages.add(request, "thank-you-message");

      PortletPreferences preferences = request.getPreferences();

      long companyId = PortalUtil.getCompanyId(request);

      Message message = new Message();

      message.put("from-name", preferences.getValue("fromName", ""));
      message.put("from-address", preferences.getValue("fromEMail", ""));
      message.put("subject", preferences.getValue("subject", ""));
      message.put("body", preferences.getValue("body", ""));
      message.put("signature", preferences.getValue("signature", ""));
      message.put("to-name", contact.getFullname());
      message.put("to-address", contact.getEmail());
      message.put("community", contact.getCommunity());
      message.put("companyId", companyId);

      MessageBusUtil.sendMessage("liferay/contactme", message);

      response.setRenderParameter("jspPage", viewThankYouJSP);

    } else {
      for (String error : errors) {
        SessionErrors.add(request, error);
      }
      SessionErrors.add(request, "error-saving-contact");
      response.setRenderParameter("jspPage", viewAddContactJSP);
      request.setAttribute("cmContact", contact);
    }
  }
Пример #16
0
  public void deletePermission(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    String name = ParamUtil.getString(actionRequest, "name");
    int scope = ParamUtil.getInteger(actionRequest, "scope");
    String primKey = ParamUtil.getString(actionRequest, "primKey");
    String actionId = ParamUtil.getString(actionRequest, "actionId");

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    if (ResourceBlockLocalServiceUtil.isSupported(name)) {
      if (scope == ResourceConstants.SCOPE_GROUP) {
        ResourceBlockServiceUtil.removeGroupScopePermission(
            themeDisplay.getScopeGroupId(),
            themeDisplay.getCompanyId(),
            GetterUtil.getLong(primKey),
            name,
            roleId,
            actionId);
      } else {
        ResourceBlockServiceUtil.removeCompanyScopePermission(
            themeDisplay.getScopeGroupId(), themeDisplay.getCompanyId(), name, roleId, actionId);
      }
    } else {
      ResourcePermissionServiceUtil.removeResourcePermission(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getCompanyId(),
          name,
          scope,
          primKey,
          roleId,
          actionId);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionDeleted");

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
Пример #17
0
  public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    _log.info("***processAction****");

    boolean error = false;

    String saveButton = (String) request.getParameter("saveButton");
    String resetButton = (String) request.getParameter("resetButton");

    _log.info("saveButton: " + saveButton);
    _log.info("resetButton: " + resetButton);

    String nameTelescope = (String) request.getParameter("nameTelescope");
    String nameObservatory = (String) request.getParameter("nameObservatory");
    String briefDescription = (String) request.getParameter("briefDescription");
    String nameCountry = (String) request.getParameter("nameCountry");
    String nameCity = (String) request.getParameter("nameCity");
    String latitude = (String) request.getParameter("latitude");
    String longitude = (String) request.getParameter("longitude");
    String urlTelescope = (String) request.getParameter("urlTelescope");

    _log.info("nameTelescope: " + nameTelescope);
    _log.info("nameObservatory: " + nameObservatory);
    _log.info("briefDescription: " + briefDescription);
    _log.info("nameCountry: " + nameCountry);
    _log.info("nameCity: " + nameCity);
    _log.info("latitude: " + latitude);
    _log.info("longitude: " + longitude);
    _log.info("urlTelescope: " + urlTelescope);

    ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    User user = td.getUser();
    _log.info("user: "******"error01");
    }

    try {
      repository.registerObservatory(nameObservatory, nameCity, nameCountry);
    } catch (RTRepositoryException_Exception e) {
      error = true;
      _log.error(e.getMessage());
    } catch (Exception e) {
      _log.error(e.getMessage());
    } finally {
      SessionErrors.add(request, "error01");
    }

    if (!error) SessionMessages.add(request, "success");
  }
Пример #18
0
  public boolean validateUserData(ActionRequest request) {
    if (isNullOrEmpty(getGivenname())) {
      SessionMessages.add(request, "request_processed", "First name cannot be empty");
      return false;
    }
    if (isNullOrEmpty(getLastname())) {
      SessionMessages.add(request, "request_processed", "Last name cannot be empty");
      return false;
    }
    if (!Validator.isEmailAddress(getEmail())) {
      SessionMessages.add(request, "request_processed", "Email is not valid");
      return false;
    }
    if (isNullOrEmpty(getDepartment())) {
      SessionMessages.add(request, "request_processed", "Department cannot be empty");
      return false;
    }
    if (isNullOrEmpty(getExternalid())) {
      SessionMessages.add(request, "request_processed", "External ID cannot be empty");
      return false;
    }
    if (isNullOrEmpty(password)) {
      SessionMessages.add(request, "request_processed", "Password cannot be empty");
      return false;
    }
    try {
      SW360Assert.assertEquals(password, password2);
    } catch (SW360Exception e) {
      SessionMessages.add(request, "request_processed", "Passwords don't match");
      return false;
    }

    return true;
  }
  public void deleteEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long entryId = ParamUtil.getLong(actionRequest, "entryId");

    AnnouncementsEntryServiceUtil.deleteEntry(entryId);

    SessionMessages.add(actionRequest, "announcementDeleted");

    sendRedirect(actionRequest, actionResponse);
  }
Пример #20
0
  protected void deleteFolders(
      LiferayPortletConfig liferayPortletConfig, ActionRequest actionRequest, boolean moveToTrash)
      throws Exception {

    long[] deleteFolderIds = null;

    long folderId = ParamUtil.getLong(actionRequest, "folderId");

    if (folderId > 0) {
      deleteFolderIds = new long[] {folderId};
    } else {
      deleteFolderIds = StringUtil.split(ParamUtil.getString(actionRequest, "folderIds"), 0L);
    }

    for (long deleteFolderId : deleteFolderIds) {
      if (moveToTrash) {
        JournalFolderServiceUtil.moveFolderToTrash(deleteFolderId);
      } else {
        JournalFolderServiceUtil.deleteFolder(deleteFolderId);
      }

      AssetPublisherUtil.removeRecentFolderId(
          actionRequest, JournalArticle.class.getName(), deleteFolderId);
    }

    if (moveToTrash && (deleteFolderIds.length > 0)) {
      Map<String, String[]> data = new HashMap<String, String[]>();

      data.put("restoreFolderIds", ArrayUtil.toStringArray(deleteFolderIds));

      SessionMessages.add(
          actionRequest,
          liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA,
          data);

      SessionMessages.add(
          actionRequest,
          liferayPortletConfig.getPortletId()
              + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
    }
  }
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    long maxFileSize = ParamUtil.getLong(actionRequest, "maxFileSize");

    try {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

        throw new PortalException(uploadException.getCause());
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        FileEntry tempImageFileEntry = addTempImageFileEntry(actionRequest);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("tempImageFileName", tempImageFileEntry.getTitle());

        writeJSON(actionRequest, actionResponse, jsonObject);
      } else {
        FileEntry fileEntry = null;

        boolean imageUploaded = ParamUtil.getBoolean(actionRequest, "imageUploaded");

        if (imageUploaded) {
          fileEntry = saveTempImageFileEntry(actionRequest);

          if (fileEntry.getSize() > maxFileSize) {
            throw new FileSizeException();
          }
        }

        SessionMessages.add(actionRequest, "imageUploaded", fileEntry);

        sendRedirect(actionRequest, actionResponse);
      }
    } catch (Exception e) {
      handleUploadException(actionRequest, actionResponse, cmd, maxFileSize, e);
    }
  }
Пример #22
0
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

      long membershipRequestId = ParamUtil.getLong(actionRequest, "membershipRequestId");

      int statusId = ParamUtil.getInteger(actionRequest, "statusId");
      String replyComments = ParamUtil.getString(actionRequest, "replyComments");

      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      MembershipRequestServiceUtil.updateStatus(
          membershipRequestId, replyComments, statusId, serviceContext);

      if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
        MembershipRequest membershipRequest =
            MembershipRequestServiceUtil.getMembershipRequest(membershipRequestId);

        LiveUsers.joinGroup(
            themeDisplay.getCompanyId(),
            membershipRequest.getGroupId(),
            new long[] {membershipRequest.getUserId()});
      }

      SessionMessages.add(actionRequest, "membership_reply_sent");

      sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
      if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.sites_admin.error");
      } else if (e instanceof MembershipRequestCommentsException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.sites_admin.reply_membership_request");
      } else {
        throw e;
      }
    }
  }
  protected FileEntry updateFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    String sourceFileName = uploadPortletRequest.getFileName("imageEditorFileName");

    FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId);

    InputStream inputStream = uploadPortletRequest.getFileAsStream("imageEditorFileName");
    String contentType = uploadPortletRequest.getContentType("imageEditorFileName");
    long size = uploadPortletRequest.getSize("imageEditorFileName");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

    fileEntry =
        _dlAppService.updateFileEntry(
            fileEntryId,
            sourceFileName,
            contentType,
            fileEntry.getTitle(),
            fileEntry.getDescription(),
            StringPool.BLANK,
            false,
            inputStream,
            size,
            serviceContext);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("success", Boolean.TRUE);

    ResourceBundle resourceBundle =
        _resourceBundleLoader.loadResourceBundle(
            LanguageUtil.getLanguageId(themeDisplay.getLocale()));

    SessionMessages.add(
        actionRequest,
        "requestProcessed",
        LanguageUtil.get(resourceBundle, "the-image-was-edited-successfully"));

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

    return fileEntry;
  }
 /**
  * Default article.
  *
  * @param request the request
  * @param response the response
  */
 public void defaultArticle(ActionRequest request, ActionResponse response) {
   String defaultArticle = ParamUtil.getString(request, ARTICLE_ID);
   PortletPreferences preferences = request.getPreferences();
   try {
     preferences.setValue(DEFAULT_ARTICLE, defaultArticle);
     preferences.store();
   } catch (ReadOnlyException e) {
     LOG.error(e);
   } catch (ValidatorException e) {
     LOG.error(e);
   } catch (IOException e) {
     LOG.error(e);
   }
   SessionMessages.add(request, ARTICLE_DEAFULT);
 }
  public void postMembershipRequest(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    String comments = ParamUtil.getString(actionRequest, "comments");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _membershipRequestService.addMembershipRequest(groupId, comments, serviceContext);

    SessionMessages.add(actionRequest, "membershipRequestSent");

    addSuccessMessage(actionRequest, actionResponse);

    sendRedirect(actionRequest, actionResponse);
  }
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      String portletResource = ParamUtil.getString(actionRequest, "portletResource");

      PortletPreferences preferences =
          PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

      if (cmd.equals("add-selection")) {
        AssetPublisherUtil.addSelection(actionRequest, preferences);
      } else if (cmd.equals("move-selection-down")) {
        moveSelectionDown(actionRequest, preferences);
      } else if (cmd.equals("move-selection-up")) {
        moveSelectionUp(actionRequest, preferences);
      } else if (cmd.equals("remove-selection")) {
        removeSelection(actionRequest, preferences);
      } else if (cmd.equals("selection-style")) {
        setSelectionStyle(actionRequest, preferences);
      } else if (cmd.equals(Constants.UPDATE)) {
        String selectionStyle = preferences.getValue("selection-style", "dynamic");

        if (selectionStyle.equals("dynamic")) {
          updateDynamicSettings(actionRequest, preferences);
        } else if (selectionStyle.equals("manual")) {
          updateManualSettings(actionRequest, preferences);
        }
      }

      if (SessionErrors.isEmpty(actionRequest)) {
        preferences.store();

        SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
      }

      actionResponse.sendRedirect(ParamUtil.getString(actionRequest, "redirect"));
    } catch (Exception e) {
      if (e instanceof AssetTagException) {
        SessionErrors.add(actionRequest, e.getClass().getName(), e);
      } else {
        throw e;
      }
    }
  }
Пример #27
0
  protected void addSuccessMessage(ActionRequest actionRequest, ActionResponse actionResponse) {

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    boolean addProcessActionSuccessMessage =
        GetterUtil.getBoolean(
            portletConfig.getInitParameter("add-process-action-success-action"), true);

    if (!addProcessActionSuccessMessage) {
      return;
    }

    String successMessage = ParamUtil.getString(actionRequest, "successMessage");

    SessionMessages.add(actionRequest, "requestProcessed", successMessage);
  }
Пример #28
0
  public void processAction(PortletConfig config, ActionRequest request, ActionResponse response)
      throws Exception {
    String portletResource = ParamUtil.getString(request, "portletResource");

    PortletPreferences pref =
        PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);

    String actionVanBanNoiBo = ParamUtil.getString(request, "actionVanBanNoiBo", "");
    pref.setValue("actionVanBanNoiBo", String.valueOf(actionVanBanNoiBo));

    String kyHieuVaoSo = ParamUtil.getString(request, "kyHieuVaoSo", "");
    pref.setValue("kyHieuVaoSo", String.valueOf(kyHieuVaoSo));

    if (SessionErrors.isEmpty(request)) {
      pref.store();
      SessionMessages.add(request, config.getPortletName() + ".doConfigure");
    }
  }
Пример #29
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = getResourcePrimKey(renderRequest);

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      } else {
        List<KBArticle> kbArticles =
            KBArticleLocalServiceUtil.getGroupKBArticles(
                themeDisplay.getScopeGroupId(), status, 0, 1, new KBArticlePriorityComparator());

        if (!kbArticles.isEmpty()) {
          kbArticle = kbArticles.get(0);
        }
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());

        SessionMessages.add(
            renderRequest,
            PortalUtil.getPortletId(renderRequest)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
      return;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    ShoppingPreferences preferences =
        ShoppingPreferences.getInstance(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId());

    String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
    String tabs3 = ParamUtil.getString(actionRequest, "tabs3");

    if (tabs2.equals("payment-settings")) {
      updatePayment(actionRequest, preferences);
    } else if (tabs2.equals("shipping-calculation")) {
      updateShippingCalculation(actionRequest, preferences);
    } else if (tabs2.equals("insurance-calculation")) {
      updateInsuranceCalculation(actionRequest, preferences);
    } else if (tabs2.equals("emails")) {
      if (tabs3.equals("email-from")) {
        updateEmailFrom(actionRequest, preferences);
      } else if (tabs3.equals("confirmation-email")) {
        updateEmailOrderConfirmation(actionRequest, preferences);
      } else if (tabs3.equals("shipping-email")) {
        updateEmailOrderShipping(actionRequest, preferences);
      }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
      preferences.store();

      SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
    }
  }