示例#1
0
  private Document getPublicDocument(User user) {
    try {
      Document doc = new Document();
      String entryId = getType() + String.valueOf(user.getId());
      doc.add(new Field(_TYPE_ID, getType(), Store.YES, Index.NOT_ANALYZED));
      doc.add(new Field(_ENTRY_ID, entryId, Store.YES, Index.NOT_ANALYZED));
      doc.add(new Field("id", String.valueOf(user.getId()), Store.YES, Index.NOT_ANALYZED));
      Field userIdField = new Field("userId", user.getUserId(), Store.YES, Index.NOT_ANALYZED);
      userIdField.setBoost(10.0F);
      doc.add(userIdField);
      Field emailField =
          new Field(
              "email",
              (user.getEmail() != null) ? user.getEmail() : user.getUserId(),
              Store.YES,
              Index.NOT_ANALYZED);
      emailField.setBoost(10.0F);
      doc.add(emailField);
      Field uriField = new Field("uri", user.getUri().toLowerCase(), Store.YES, Index.NOT_ANALYZED);
      uriField.setBoost(10.0F);
      doc.add(uriField);
      Field displayNameField = new Field("displayName", user.getName(), Store.YES, Index.ANALYZED);
      displayNameField.setBoost(10.0F);
      doc.add(displayNameField);
      doc.add(
          new Field(
              "createDate",
              DateUtil.format(user.getCreateDate(), "yyyy/MM/dd HH:mm:ss"),
              Store.YES,
              Index.NOT_ANALYZED));
      doc.add(
          new Field(
              "date",
              DateUtil.format(user.getLastLoginDate(), "yyyy/MM/dd HH:mm:ss"),
              Store.YES,
              Index.NOT_ANALYZED));
      UserProfile profile = getUserService().getUserProfileById(user.getId());
      if (profile != null && StringUtils.isNotEmpty(profile.getFirstName())) {
        Field nameField = new Field("name", profile.getFirstName(), Store.YES, Index.ANALYZED);
        nameField.setBoost(10.0F);
        doc.add(nameField);
        doc.add(
            new Field(
                "sortName", profile.getFirstName().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
      } else {
        Field nameField = new Field("name", user.getName(), Store.YES, Index.ANALYZED);
        nameField.setBoost(10.0F);
        doc.add(nameField);
        doc.add(new Field("sortName", user.getName().toLowerCase(), Store.YES, Index.NOT_ANALYZED));
      }

      if (user.getPhotoUrl() != null) {
        doc.add(new Field("photoUrl", user.getPhotoUrl(), Store.YES, Index.NO));
      }

      if (profile != null) {
        if (StringUtils.isNotEmpty(profile.getHeadline())) {
          doc.add(new Field("headline", profile.getHeadline(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getAboutMe())) {
          doc.add(new Field("aboutMe", profile.getAboutMe(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getHometown())) {
          doc.add(new Field("hometown", profile.getHometown(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getInterests())) {
          doc.add(new Field("interests", profile.getInterests(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getLikeToMeet())) {
          doc.add(new Field("likeToMeet", profile.getLikeToMeet(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getOccupation())) {
          doc.add(new Field("occupation", profile.getOccupation(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getReligion())) {
          doc.add(new Field("religion", profile.getReligion(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getMovies())) {
          doc.add(new Field("movie", profile.getMovies(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getMusic())) {
          doc.add(new Field("music", profile.getMusic(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getTelevision())) {
          doc.add(new Field("television", profile.getTelevision(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getBooks())) {
          doc.add(new Field("book", profile.getBooks(), Store.NO, Index.ANALYZED));
        }
        if (StringUtils.isNotEmpty(profile.getHeroes())) {
          doc.add(new Field("hero", profile.getHeroes(), Store.NO, Index.ANALYZED));
        }
      }
      List<UserTag> tags = this.getUserService().getUserTags(user.getId(), _OBJECT_TYPE_USER);
      for (UserTag tag : tags) {
        if (StringUtils.isNotEmpty(tag.getTag())) {
          doc.add(new Field("tag", tag.getTag(), Store.NO, Index.ANALYZED));
        }
      }
      return doc;
    } catch (Exception e) {
      return null;
    }
  }
  protected void doView(RenderRequest request, RenderResponse response)
      throws PortletException, java.io.IOException {
    String page = request.getParameter("pageId");
    if (page == null || page.trim().length() < 1) page = "1";
    int pageId = Integer.parseInt(page);
    if (request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE) == null
        || request.getParameter("refresh") != null
        || request.getParameter("newPage") != null) {
      PortletPreferences portletPreferences = request.getPreferences();
      UserProfile userProfile =
          this.getUserService(request).getUserProfileById(this.getUser(request).getId());
      String name = null;
      if (userProfile != null) name = userProfile.getName();
      if ((name == null || name.length() <= 0) && this.getUser(request) != null)
        name = this.getUser(request).getDisplayName();
      String fullName = portletPreferences.getValue("fullName", name);
      String incomingType = portletPreferences.getValue("incomingType", null);
      String incoming = portletPreferences.getValue("incoming", null);
      String incomingPort = portletPreferences.getValue("incomingPort", null);
      String incomingSSL = portletPreferences.getValue("incomingSSL", null);
      String outgoing = portletPreferences.getValue("outgoing", null);
      String outgoingPort = portletPreferences.getValue("outgoingPort", null);
      String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
      String email = portletPreferences.getValue("email", null);
      String password = portletPreferences.getValue("password", null);
      String number = portletPreferences.getValue("number", "10");
      if (incoming == null || outgoing == null || email == null || password == null) {
        request.setAttribute("incomingPort", "110");
        request.setAttribute("outgoingPort", "25");
        request.setAttribute("number", number);
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletConfig.jsp")
            .include(request, response);
      } else {
        int row = Integer.parseInt(number);
        if (request.getParameter("refresh") != null) pageId = 1;
        List<MailBean> mails = null;
        EmailClient client =
            new EmailClient(
                email,
                password,
                incomingType,
                incoming,
                incomingPort,
                incomingSSL,
                outgoing,
                outgoingPort,
                outgoingPort);
        try {
          mails = client.getMessage(EmailClient.SHOW_MESSAGES, pageId, row);
        } catch (Exception e) {
          request.setAttribute("error", e.getMessage());
        }
        int count = 0;
        int unread = 0;
        if (mails != null && mails.size() > 0) {
          count = mails.get(0).getTotal();
          unread = mails.get(0).getUnreadCount();
        }
        int pages = count / row;
        if (count % row != 0) pages++;

        request.getPortletSession().setAttribute("mails", mails, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("totalCount", count, PortletSession.PORTLET_SCOPE);
        request
            .getPortletSession()
            .setAttribute("unreadCount", unread, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("pages", pages, PortletSession.PORTLET_SCOPE);
        request.getPortletSession().setAttribute("row", row, PortletSession.PORTLET_SCOPE);
        request.setAttribute("pageId", pageId);
        request.setAttribute("totalCount", count);
        request.setAttribute("unreadCount", unread);
        request.setAttribute("pages", pages);
        request.setAttribute("row", row);
        request.setAttribute("mails", mails);
        if (request.getWindowState().equals(WindowState.MAXIMIZED))
          this.getPortletContext()
              .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletMaxView.jsp")
              .include(request, response);
        else
          this.getPortletContext()
              .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletView.jsp")
              .include(request, response);
      }
    } else {
      if (request.getParameter("mailId") != null) {
        int index = Integer.parseInt(request.getParameter("mailId"));
        List<MailBean> mails =
            (List<MailBean>)
                request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE);
        MailBean mail = mails.get(index);
        if (mail.getContent() == null) {
          PortletPreferences portletPreferences = request.getPreferences();
          String incomingType = portletPreferences.getValue("incomingType", null);
          String incoming = portletPreferences.getValue("incoming", null);
          String incomingPort = portletPreferences.getValue("incomingPort", null);
          String incomingSSL = portletPreferences.getValue("incomingSSL", null);
          String outgoing = portletPreferences.getValue("outgoing", null);
          String outgoingPort = portletPreferences.getValue("outgoingPort", null);
          String outgoingSSL = portletPreferences.getValue("outgoingSSL", null);
          String email = portletPreferences.getValue("email", null);
          String password = portletPreferences.getValue("password", null);
          EmailClient client =
              new EmailClient(
                  email,
                  password,
                  incomingType,
                  incoming,
                  incomingPort,
                  incomingSSL,
                  outgoing,
                  outgoingPort,
                  outgoingPort);
          try {
            mail = client.getMessageDetail(mails.get(index).getMsg());
            int unread =
                (Integer)
                    request
                        .getPortletSession()
                        .getAttribute("unreadCount", PortletSession.PORTLET_SCOPE);
            if (mails.get(index).getFlag() == 1) unread--;
            if (unread < 0) unread = 0;
            request
                .getPortletSession()
                .setAttribute("unreadCount", unread, PortletSession.PORTLET_SCOPE);
            // request.getPortletSession().removeAttribute("mails",PortletSession.PORTLET_SCOPE);
          } catch (Exception e) {
            request.setAttribute("error", e.getMessage());
          }
          mails.set(index, mail);
        }
        request.setAttribute("currentMail", mail);
        request.setAttribute("pageId", pageId);
      } else {

        List<MailBean> mails =
            (List<MailBean>)
                request.getPortletSession().getAttribute("mails", PortletSession.PORTLET_SCOPE);
        int row =
            (Integer) request.getPortletSession().getAttribute("row", PortletSession.PORTLET_SCOPE);
        int count =
            (Integer)
                request
                    .getPortletSession()
                    .getAttribute("totalCount", PortletSession.PORTLET_SCOPE);
        int unread =
            (Integer)
                request
                    .getPortletSession()
                    .getAttribute("unreadCount", PortletSession.PORTLET_SCOPE);
        int pages =
            (Integer)
                request.getPortletSession().getAttribute("pages", PortletSession.PORTLET_SCOPE);
        List<MailBean> pageMails = new ArrayList<MailBean>();
        request.setAttribute("pageId", pageId);
        request.setAttribute("totalCount", count);
        request.setAttribute("unreadCount", unread);
        request.setAttribute("pages", pages);
        request.setAttribute("row", row);
        request.setAttribute("mails", mails);
      }
      if (request.getWindowState().equals(WindowState.MAXIMIZED))
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletMaxView.jsp")
            .include(request, response);
      else
        this.getPortletContext()
            .getRequestDispatcher(_PORTLET_JSP_PATH + "/email/emailPortletView.jsp")
            .include(request, response);
    }
  }