protected String[] getAllowedFileExtensions(
      PortletConfig portletConfig, PortletRequest portletRequest, PortletResponse portletResponse)
      throws PortalException {

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
      return PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA);
    } else {
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      DLPortletInstanceSettings dlPortletInstanceSettings =
          DLPortletInstanceSettings.getInstance(themeDisplay.getLayout(), portletDisplay.getId());

      Set<String> extensions = new HashSet<>();

      String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

      for (String mimeType : mimeTypes) {
        extensions.addAll(MimeTypesUtil.getExtensions(mimeType));
      }

      return extensions.toArray(new String[extensions.size()]);
    }
  }
Example #2
0
  public static boolean isViewableMessage(
      ThemeDisplay themeDisplay, MBMessage message, MBMessage parentMessage) throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!MBMessagePermission.contains(permissionChecker, parentMessage, ActionKeys.VIEW)) {

      return false;
    }

    if ((message.getMessageId() != parentMessage.getMessageId())
        && !MBMessagePermission.contains(permissionChecker, message, ActionKeys.VIEW)) {

      return false;
    }

    if (!message.isApproved()
        && !Validator.equals(message.getUserId(), themeDisplay.getUserId())
        && !permissionChecker.isGroupAdmin(themeDisplay.getScopeGroupId())) {

      return false;
    }

    return true;
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

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

      User user = themeDisplay.getUser();

      long portletPlid =
          PortalUtil.getPlidFromPortletId(user.getGroupId(), true, PortletKeys.TASKS);

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              liferayPortletRequest, PortletKeys.TASKS, portletPlid, PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/tasks/view.jsp");

      return portletURL.toString();
    } catch (Exception e) {
    }

    return null;
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig, ActionRequest actionRequest, DDMStructure structure)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/dynamic_data_mapping/copy_structure");

    long classNameId = PortalUtil.getClassNameId(DDMStructure.class);

    portletURL.setParameter("classNameId", String.valueOf(classNameId), false);

    portletURL.setParameter("classPK", String.valueOf(structure.getStructureId()), false);
    portletURL.setParameter(
        "copyFormTemplates", ParamUtil.getString(actionRequest, "copyFormTemplates"), false);
    portletURL.setParameter(
        "copyDisplayTemplates", ParamUtil.getString(actionRequest, "copyDisplayTemplates"), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
Example #5
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);
  }
Example #6
0
  protected String getAssetPublisherURL(PortletRequest portletRequest) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    StringBundler sb = new StringBundler(7);

    String layoutFriendlyURL =
        GetterUtil.getString(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));

    if (!layoutFriendlyURL.startsWith(Http.HTTP_WITH_SLASH)
        && !layoutFriendlyURL.startsWith(Http.HTTPS_WITH_SLASH)) {

      sb.append(themeDisplay.getPortalURL());
    }

    sb.append(layoutFriendlyURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("asset_publisher/");
    sb.append(portletDisplay.getInstanceId());
    sb.append(StringPool.SLASH);

    return sb.toString();
  }
  @Override
  public String getThumbnailPath(PortletRequest portletRequest) throws Exception {

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

    return themeDisplay.getPathThemeImages() + "/file_system/large/bookmark.png";
  }
Example #8
0
  @Override
  public void addContainerModelBreadcrumbEntries(
      HttpServletRequest request, String className, long classPK, PortletURL containerModelURL)
      throws PortalException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    String rootContainerModelName =
        LanguageUtil.get(themeDisplay.getLocale(), trashHandler.getRootContainerModelName());

    if (classPK == 0) {
      PortalUtil.addPortletBreadcrumbEntry(request, rootContainerModelName, null);

      return;
    }

    containerModelURL.setParameter("containerModelId", "0");

    PortalUtil.addPortletBreadcrumbEntry(
        request, rootContainerModelName, containerModelURL.toString());

    addBreadcrumbEntries(request, className, classPK, "containerModelId", containerModelURL);
  }
  public static void updateLanguage(HttpServletRequest request, HttpServletResponse response) {

    String languageId =
        ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE);

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    List<Locale> availableLocales = ListUtil.fromArray(LanguageUtil.getAvailableLocales());

    if (!availableLocales.contains(locale)) {
      return;
    }

    HttpSession session = request.getSession();

    session.setAttribute(Globals.LOCALE_KEY, locale);
    session.setAttribute(WebKeys.SETUP_WIZARD_DEFAULT_LOCALE, languageId);

    LanguageUtil.updateCookie(request, response, locale);

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

    themeDisplay.setLanguageId(languageId);
    themeDisplay.setLocale(locale);
  }
  protected String getSaveAndContinueRedirect(
      ActionRequest actionRequest, JournalArticle article, String redirect) throws Exception {

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

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            JournalPortletKeys.JOURNAL,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcPath", "/edit_article.jsp");
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("referringPortletResource", referringPortletResource, false);
    portletURL.setParameter("resourcePrimKey", String.valueOf(article.getResourcePrimKey()), false);
    portletURL.setParameter("groupId", String.valueOf(article.getGroupId()), false);
    portletURL.setParameter("folderId", String.valueOf(article.getFolderId()), false);
    portletURL.setParameter("articleId", article.getArticleId(), false);
    portletURL.setParameter("version", String.valueOf(article.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
Example #11
0
  @Override
  public String getNewName(
      ThemeDisplay themeDisplay, String className, long classPK, String oldName)
      throws PortalException {

    TrashRenderer trashRenderer = null;

    if (Validator.isNotNull(className) && (classPK > 0)) {
      TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

      trashRenderer = trashHandler.getTrashRenderer(classPK);
    }

    Format dateFormatDateTime =
        FastDateFormatFactoryUtil.getDateTime(themeDisplay.getLocale(), themeDisplay.getTimeZone());

    StringBundler sb = new StringBundler(3);

    sb.append(StringPool.OPEN_PARENTHESIS);
    sb.append(
        StringUtil.replace(dateFormatDateTime.format(new Date()), CharPool.SLASH, CharPool.PERIOD));
    sb.append(StringPool.CLOSE_PARENTHESIS);

    if (trashRenderer != null) {
      return trashRenderer.getNewName(oldName, sb.toString());
    } else {
      return getNewName(oldName, sb.toString());
    }
  }
  protected void downloadApp(
      PortletRequest portletRequest,
      PortletResponse portletResponse,
      long appPackageId,
      boolean unlicensed,
      File file)
      throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setBaseRequestParameters(portletRequest, portletResponse, oAuthRequest);

    String serverNamespace = getServerNamespace();

    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("appPackageId"), String.valueOf(appPackageId));
    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2");

    if (unlicensed) {
      addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveUnlicensedApp");
    } else {
      addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveApp");
    }

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    FileUtil.write(file, response.getStream());
  }
  public static OAuthService getOAuthService(HttpServletRequest request, ThemeDisplay themeDisplay)
      throws SystemException {

    OAuthService service = null;
    String consumerKey = StringPool.BLANK;
    String consumerSecret = StringPool.BLANK;

    // Set up the Scribe OAuthService.
    String cbUrl = PortalUtil.getCurrentCompleteURL(request);

    Class<? extends EvernoteApi> providerClass =
        (EVERNOTE_SERVICE == EvernoteService.PRODUCTION)
            ? org.scribe.builder.api.EvernoteApi.class
            : EvernoteApi.Sandbox.class;
    // Get consumer key and consumer secret

    consumerKey = EvernoteKeys.getConsumerKey(themeDisplay.getCompanyId());
    consumerSecret = EvernoteKeys.getConsumerSecret(themeDisplay.getCompanyId());

    service =
        new ServiceBuilder()
            .provider(providerClass)
            .apiKey(consumerKey)
            .apiSecret(consumerSecret)
            .callback(cbUrl)
            .build();

    return service;
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      FileEntry fileEntry,
      String redirect)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/document_library/edit_file_entry");
    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("groupId", String.valueOf(fileEntry.getGroupId()), false);
    portletURL.setParameter("fileEntryId", String.valueOf(fileEntry.getFileEntryId()), false);
    portletURL.setParameter("version", String.valueOf(fileEntry.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    if (Validator.isNotNull(_article.getLayoutUuid())) {
      layout =
          LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId(
              _article.getLayoutUuid(), _article.getCompanyId());
    }

    String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String linkToLayoutUuid =
        GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null));

    if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) {

      Group group = themeDisplay.getScopeGroup();

      if (group.getGroupId() != _article.getGroupId()) {
        group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
      }

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay);

      return PortalUtil.addPreservedParameters(
          themeDisplay,
          groupFriendlyURL
              .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
              .concat(_article.getUrlTitle()));
    }

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId());

    if (!hitLayoutIds.isEmpty()) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
  private static void _updateCompany(HttpServletRequest request) throws Exception {

    Company company = CompanyLocalServiceUtil.getCompanyById(PortalInstances.getDefaultCompanyId());

    Account account = company.getAccount();

    String currentName = account.getName();

    String newName = ParamUtil.getString(request, "companyName", PropsValues.COMPANY_DEFAULT_NAME);

    if (!currentName.equals(newName)) {
      account.setName(newName);

      AccountLocalServiceUtil.updateAccount(account);
    }

    String languageId =
        ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE);

    User defaultUser = company.getDefaultUser();

    defaultUser.setLanguageId(languageId);

    UserLocalServiceUtil.updateUser(defaultUser);

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

    themeDisplay.setCompany(company);
  }
  private void _init(
      HttpServletRequest request, DLFileEntryType dlFileEntryType, FileEntry fileEntry)
      throws PortalException {

    _request = request;
    _dlFileEntryType = dlFileEntryType;
    _fileEntry = fileEntry;

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    _dlPortletInstanceSettings =
        DLPortletInstanceSettings.getInstance(themeDisplay.getLayout(), portletDisplay.getId());
    _fileEntryDisplayContextHelper =
        new FileEntryDisplayContextHelper(themeDisplay.getPermissionChecker(), _fileEntry);

    if ((_dlFileEntryType == null) && (_fileEntry != null)) {
      _dlFileEntryType = _fileEntryDisplayContextHelper.getDLFileEntryType();
    }

    if (fileEntry != null) {
      _fileVersion = fileEntry.getFileVersion();
    }

    _fileVersionDisplayContextHelper = new FileVersionDisplayContextHelper(_fileVersion);
  }
  protected void deleteLDAPServer(ActionRequest actionRequest) throws Exception {

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

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

    // Remove preferences

    String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId);

    String[] keys = new String[_KEYS.length];

    for (int i = 0; i < _KEYS.length; i++) {
      keys[i] = _KEYS[i] + postfix;
    }

    CompanyServiceUtil.removePreferences(themeDisplay.getCompanyId(), keys);

    // Update preferences

    PortletPreferences preferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId());

    UnicodeProperties properties = new UnicodeProperties();

    String ldapServerIds = preferences.getValue("ldap.server.ids", StringPool.BLANK);

    ldapServerIds = StringUtil.remove(ldapServerIds, String.valueOf(ldapServerId));

    properties.put("ldap.server.ids", ldapServerIds);

    CompanyServiceUtil.updatePreferences(themeDisplay.getCompanyId(), properties);
  }
Example #19
0
  protected String getEntryURLViewInContext(
      PortletRequest portletRequest, PortletResponse portletResponse, AssetEntry assetEntry)
      throws Exception {

    AssetRendererFactory assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetEntry.getClassName());

    AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

    String viewInContextURL =
        assetRenderer.getURLViewInContext(
            (LiferayPortletRequest) portletRequest, (LiferayPortletResponse) portletResponse, null);

    if (Validator.isNotNull(viewInContextURL)
        && !viewInContextURL.startsWith(Http.HTTP_WITH_SLASH)
        && !viewInContextURL.startsWith(Http.HTTPS_WITH_SLASH)) {

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

      viewInContextURL = themeDisplay.getPortalURL() + viewInContextURL;
    }

    return viewInContextURL;
  }
  protected long getResourcePrimKey(RenderRequest renderRequest) throws Exception {

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

    PortletPreferences preferences = renderRequest.getPreferences();

    long defaultValue = GetterUtil.getLong(preferences.getValue("resourcePrimKey", null));

    String mvcPath = ParamUtil.getString(renderRequest, "mvcPath");

    if (((defaultValue == 0) && mvcPath.equals(viewTemplate))
        || mvcPath.equals("/display/select_configuration_article.jsp")) {

      return 0;
    }

    long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey", defaultValue);

    if ((resourcePrimKey == 0) || (resourcePrimKey != defaultValue)) {
      return resourcePrimKey;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!KBArticlePermission.contains(permissionChecker, defaultValue, ActionKeys.VIEW)) {

      return 0;
    }

    return defaultValue;
  }
  protected String[][] getCategorySectionLabels() {
    if (_categorySections != null) {
      return _categorySections;
    }

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

    String[] categoryKeys = getCategoryKeys();

    String[][] categorySectionLabels = new String[0][];

    for (int i = 0; i < categoryKeys.length; i++) {
      String categoryKey = categoryKeys[i];

      categorySectionLabels =
          ArrayUtil.append(
              categorySectionLabels,
              FormNavigatorEntryUtil.getLabels(
                  _id,
                  categoryKey,
                  themeDisplay.getUser(),
                  _formModelBean,
                  themeDisplay.getLocale()));
    }

    return categorySectionLabels;
  }
  protected int getStatus(RenderRequest renderRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!themeDisplay.isSignedIn()) {
      return WorkflowConstants.STATUS_APPROVED;
    }

    String value = renderRequest.getParameter("status");
    int status = GetterUtil.getInteger(value);

    if ((value != null) && (status == WorkflowConstants.STATUS_APPROVED)) {
      return WorkflowConstants.STATUS_APPROVED;
    }

    long resourcePrimKey = getResourcePrimKey(renderRequest);

    if (resourcePrimKey == 0) {
      return WorkflowConstants.STATUS_APPROVED;
    }

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (KBArticlePermission.contains(permissionChecker, resourcePrimKey, ActionKeys.UPDATE)) {

      return ParamUtil.getInteger(renderRequest, "status", WorkflowConstants.STATUS_ANY);
    }

    return WorkflowConstants.STATUS_APPROVED;
  }
Example #23
0
  public static String getCreateAccountHREF(HttpServletRequest request, ThemeDisplay themeDisplay)
      throws Exception {

    if (Validator.isNull(PropsValues.COMPANY_SECURITY_STRANGERS_URL)) {
      PortletURL createAccountURL =
          new PortletURLImpl(
              request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      createAccountURL.setWindowState(WindowState.MAXIMIZED);
      createAccountURL.setPortletMode(PortletMode.VIEW);

      createAccountURL.setParameter("saveLastPath", "0");
      createAccountURL.setParameter("struts_action", "/login/create_account");

      return createAccountURL.toString();
    }

    try {
      Layout layout =
          LayoutLocalServiceUtil.getFriendlyURLLayout(
              themeDisplay.getScopeGroupId(), false, PropsValues.COMPANY_SECURITY_STRANGERS_URL);

      return PortalUtil.getLayoutURL(layout, themeDisplay);
    } catch (NoSuchLayoutException nsle) {
    }

    return StringPool.BLANK;
  }
Example #24
0
  public void updateKBArticlesPriorities(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    Enumeration<String> enu = actionRequest.getParameterNames();

    Map<Long, Double> resourcePrimKeyToPriorityMap = new HashMap<Long, Double>();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      if (!name.startsWith("priority")) {
        continue;
      }

      double priority = ParamUtil.getDouble(actionRequest, name);

      long resourcePrimKey = GetterUtil.getLong(name.substring(8));

      resourcePrimKeyToPriorityMap.put(resourcePrimKey, priority);
    }

    KBArticleServiceUtil.updateKBArticlesPriorities(
        themeDisplay.getScopeGroupId(), resourcePrimKeyToPriorityMap);
  }
Example #25
0
  public static String getAbsolutePath(PortletRequest portletRequest, long mbCategoryId)
      throws PortalException, SystemException {

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

    if (mbCategoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      return themeDisplay.translate("home");
    }

    MBCategory mbCategory = MBCategoryLocalServiceUtil.fetchMBCategory(mbCategoryId);

    List<MBCategory> categories = mbCategory.getAncestors();

    Collections.reverse(categories);

    StringBundler sb = new StringBundler((categories.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (MBCategory curCategory : categories) {
      sb.append(StringPool.RAQUO);
      sb.append(StringPool.SPACE);
      sb.append(curCategory.getName());
    }

    sb.append(StringPool.RAQUO);
    sb.append(StringPool.SPACE);
    sb.append(mbCategory.getName());

    return sb.toString();
  }
Example #26
0
  public void updateKBComment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    if (!themeDisplay.isSignedIn()) {
      return;
    }

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

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

    long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
    long classPK = ParamUtil.getLong(actionRequest, "classPK");
    String content = ParamUtil.getString(actionRequest, "content");
    boolean helpful = ParamUtil.getBoolean(actionRequest, "helpful");

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

    if (cmd.equals(Constants.ADD)) {
      KBCommentLocalServiceUtil.addKBComment(
          themeDisplay.getUserId(), classNameId, classPK, content, helpful, serviceContext);
    } else if (cmd.equals(Constants.UPDATE)) {
      KBCommentLocalServiceUtil.updateKBComment(
          kbCommentId, classNameId, classPK, content, helpful, serviceContext);
    }
  }
  @Override
  public void serveResource(ResourceRequest request, ResourceResponse response)
      throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    String layoutPK = String.valueOf(themeDisplay.getLayout().getPrimaryKey());

    String action = ParamUtil.getString(request, CMD);

    if (action.equals(NOTCOMPLETED)) {
      String userId = ParamUtil.getString(request, USER_ID);
      Date currentDate = new Date();

      AnnouncerTools.addToNotCompleted(userId, layoutPK, currentDate);

    } else if (action.equals(COMPLETED)) {
      String userId = ParamUtil.getString(request, USER_ID);
      String articleSerial = ParamUtil.getString(request, ARTICLE_SERIAL);

      AnnouncerTools.addToCompleted(userId, layoutPK, articleSerial);

    } else if (UPDATE_ARTICLE_SELECTION.equalsIgnoreCase(action)) {

      String articleId = ParamUtil.getString(request, ARTICLE_ID);
      updateArticleSelection(request, response, articleId);
    } else if (IS_CHECKED.equalsIgnoreCase(action)) {
      String articleId = ParamUtil.getString(request, ARTICLE_ID);
      isChecked(request, response, articleId);
    }

    super.serveResource(request, response);
  }
  @Override
  public String getPortletFileEntryURL(
      ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString, boolean absoluteURL) {

    StringBundler sb = new StringBundler(10);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(WebServerServlet.PATH_PORTLET_FILE_ENTRY);
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getGroupId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH) && !queryString.contains("status=")) {

          if (Validator.isNotNull(queryString)) {
            queryString += StringPool.AMPERSAND;
          }

          queryString += "status=" + WorkflowConstants.STATUS_IN_TRASH;
        }
      }
    }

    if (Validator.isNotNull(queryString)) {
      sb.append(StringPool.QUESTION);
      sb.append(queryString);
    }

    String portletFileEntryURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(portletFileEntryURL, themeDisplay.getSessionId());
    }

    return portletFileEntryURL;
  }
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    Set<Long> messages = new HashSet<Long>();
    ThemeDisplay themedisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long userId = themedisplay.getUserId();
    String redirect = ParamUtil.getString(actionRequest, MessageConstants.REDIRECT);
    String[] msgs =
        ParamUtil.getString(actionRequest, MessageConstants.MOVE_MESSAGE_IDS, "").split(",");

    for (String s : msgs) {
      if (s.trim().length() == 0) continue;
      long messageId = Long.parseLong(s);
      Message m = MessageLocalServiceUtil.getMessage(messageId);
      if (!m.isArchived(userId)) {
        m.setArchived(userId);
      }
    }
    actionResponse.sendRedirect(redirect);
  }
  protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      _dlAppService.deleteTempFileEntry(
          themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName);

      jsonObject.put("deleted", Boolean.TRUE);
    } catch (Exception e) {
      String errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file");

      jsonObject.put("deleted", Boolean.FALSE);
      jsonObject.put("errorMessage", errorMessage);
    }

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
  }