コード例 #1
0
  /**
   * Adds attendees to an existing event with a given role Common logic for addAttendeesToEvent and
   * addChairAttendeestoEvent
   *
   * @param vevent the VEvent to add the attendess too
   * @param attendees list of Users that have been invited to the event
   * @param role the role with which to add each user
   * @return the VEvent for the given event or null if there was an error
   */
  protected VEvent addAttendeesToEventWithRole(VEvent vevent, List<User> attendees, Role role) {

    if (!isIcsEnabled()) {
      log.debug(
          "ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
      return null;
    }

    // add attendees to event with 'required participant' role
    if (attendees != null) {
      for (User u : attendees) {
        Attendee a = new Attendee(createMailURI(u.getEmail()));
        a.getParameters().add(role);
        a.getParameters().add(new Cn(u.getDisplayName()));
        a.getParameters().add(PartStat.ACCEPTED);
        a.getParameters().add(Rsvp.FALSE);

        vevent.getProperties().add(a);
      }
    }

    if (log.isDebugEnabled()) {
      log.debug("VEvent with attendees:" + vevent);
    }

    return vevent;
  }
コード例 #2
0
  /** {@inheritDoc} */
  public void notifyCourseRequestRequester(
      String requestEmail, String supportEmailContent, String termTitle) {
    User currentUser = userDirectoryService.getCurrentUser();
    String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : "";
    String currentUserDisplayId = currentUser != null ? currentUser.getDisplayId() : "";
    String currentUserId = currentUser != null ? currentUser.getId() : "";
    String currentUserEmail = currentUser != null ? currentUser.getEmail() : "";

    ResourceLoader rb = new ResourceLoader(currentUserId, "UserNotificationProvider");

    String from = requestEmail;
    String to = currentUserEmail;
    String headerTo = to;
    String replyTo = to;
    // message subject
    String message_subject =
        rb.getString("java.sitereqfrom")
            + " "
            + currentUserDisplayName
            + " "
            + rb.getString("java.for")
            + " "
            + termTitle;

    StringBuffer buf = new StringBuffer();
    buf.append(rb.getString("java.isbeing") + " ");
    buf.append(rb.getString("java.meantime") + "\n\n");
    buf.append(rb.getString("java.copy") + "\n\n");
    buf.append(supportEmailContent);
    buf.append("\n" + rb.getString("java.wish") + " " + requestEmail);
    emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null);
  }
コード例 #3
0
 public String getUserNameForDisplay(User user) {
   if (isSortUsersByDisplayName()) {
     return user.getDisplayName();
   } else {
     return user.getSortName();
   }
 }
コード例 #4
0
  protected Map<String, String> getCurrentUserFields() {
    Map<String, String> rv = new HashMap<String, String>();
    String userRef = developerHelperService.getCurrentUserReference();
    if (userRef != null) {
      User user = (User) developerHelperService.fetchEntity(userRef);
      try {
        String email = user.getEmail();
        if (email == null) email = "";
        String first = user.getFirstName();
        if (first == null) first = "";
        String last = user.getLastName();
        if (last == null) last = "";

        rv.put(CURRENT_USER_EMAIL, email);
        rv.put(CURRENT_USER_FIRST_NAME, first);
        rv.put(CURRENT_USER_LAST_NAME, last);
        rv.put(CURRENT_USER_DISPLAY_NAME, user.getDisplayName());
        rv.put(CURRENT_USER_DISPLAY_ID, user.getDisplayId());
        rv.put("currentUserDispalyId", user.getDisplayId());

      } catch (Exception e) {
        log.warn("Failed to get current user replacements: " + userRef, e);
      }
    }
    /*NoN user fields */
    rv.put(LOCAL_SAKAI_NAME, serverConfigurationService.getString("ui.service", "Sakai"));
    rv.put(
        LOCAL_SAKAI_SUPPORT_MAIL,
        serverConfigurationService.getString(
            "support.email", "help@" + serverConfigurationService.getServerUrl()));
    rv.put(LOCAL_SAKAI_URL, serverConfigurationService.getServerUrl());

    return rv;
  }
コード例 #5
0
  /**
   * Format the announcement notification from address.
   *
   * @param event The event that matched criteria to cause the notification.
   * @return the announcement notification from address.
   */
  protected String getFromAddress(Event event) {
    Reference ref = EntityManager.newReference(event.getResource());

    // SAK-14831, yorkadam, make site title reflected in 'From:' name instead of default
    // ServerConfigurationService.getString("ui.service", "Sakai");
    String siteId = (getSite() != null) ? getSite() : ref.getContext();
    String title = "";
    try {
      Site site = SiteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {
    }

    String userEmail = "no-reply@" + ServerConfigurationService.getServerName();
    String userDisplay = ServerConfigurationService.getString("ui.service", "Sakai");
    // String no_reply = "From: \"" + userDisplay + "\" <" + userEmail + ">";
    // String no_reply_withTitle = "From: \"" + title + "\" <" + userEmail + ">";
    String from = "From: Sakai"; // fallback value
    if (title != null && !title.equals("")) {
      from = "From: \"" + title + "\" <" + userEmail + ">";
    } else {
      String fromVal = getFrom(event); // should not return null but better safe than sorry
      if (fromVal != null) {
        from = fromVal;
      }
    }

    // get the message
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    String userId = msg.getAnnouncementHeader().getFrom().getDisplayId();

    // checks if "from" email id has to be included? and whether the notification is a delayed
    // notification?. SAK-13512
    // SAK-20988 - emailFromReplyable@org.sakaiproject.event.api.NotificationService is deprecated
    boolean notificationEmailFromReplyable =
        ServerConfigurationService.getBoolean("notify.email.from.replyable", false);
    if (notificationEmailFromReplyable && from.contains("no-reply@") && userId != null) {
      try {
        User u = UserDirectoryService.getUser(userId);
        userDisplay = u.getDisplayName();
        userEmail = u.getEmail();
        if ((userEmail != null) && (userEmail.trim().length()) == 0) userEmail = null;

      } catch (UserNotDefinedException e) {
      }

      // some fallback positions
      if (userEmail == null) userEmail = "no-reply@" + ServerConfigurationService.getServerName();
      if (userDisplay == null)
        userDisplay = ServerConfigurationService.getString("ui.service", "Sakai");
      from = "From: \"" + userDisplay + "\" <" + userEmail + ">";
    }

    return from;
  }
コード例 #6
0
 /** @return return the current user */
 public EmailUser getCurrentUser() {
   EmailUser euser = null;
   User curU = null;
   try {
     curU = m_userDirectoryService.getCurrentUser();
     euser = new EmailUser(curU.getId(), curU.getDisplayName(), curU.getEmail());
   } catch (Exception e) {
     log.debug("Exception: Mailtool.getCurrentUser(), " + e.getMessage());
   }
   return euser;
 }
コード例 #7
0
  public RankImage createRankImageAttachmentObject(String attachId, String name) {
    if (!isRanksEnabled()) {
      LOG.warn("createRankImageAttachmentObject invoked, but ranks are disabled");
      return null;
    }
    try {
      RankImage attach = new RankImageImpl();
      attach.setCreated(new Date());
      attach.setModified(new Date());

      ContentResource cr = contentHostingService.getResource(attachId);

      User creator =
          userDirectoryService.getUser(
              cr.getProperties().getProperty(cr.getProperties().getNamePropCreator()));
      attach.setCreatedBy(creator.getDisplayName());
      User modifier =
          userDirectoryService.getUser(
              cr.getProperties().getProperty(cr.getProperties().getNamePropModifiedBy()));
      attach.setModifiedBy(modifier.getDisplayName());

      attach.setAttachmentSize((Long.valueOf(cr.getContentLength())).toString());
      attach.setAttachmentId(attachId);
      attach.setAttachmentName(name);
      attach.setAttachmentType(cr.getContentType());
      String tempString = cr.getUrl();
      attach.setAttachmentUrl(resourceUrlEscaping(tempString));

      getHibernateTemplate().saveOrUpdate(attach);

      return attach;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
コード例 #8
0
  public void notifyNewUserEmail(User user, String newUserPassword, String siteTitle) {

    String from = getSetupRequestEmailAddress();
    String productionSiteName = serverConfigurationService.getString("ui.service", "");
    String newUserEmail = user.getEmail();
    String to = newUserEmail;
    String headerTo = newUserEmail;
    String replyTo = newUserEmail;

    String content = "";

    if (from != null && newUserEmail != null) {
      /*
       * $userName
       * $localSakaiName
       * $currentUserName
       * $localSakaiUrl
       */
      Map<String, String> replacementValues = new HashMap<String, String>();
      replacementValues.put("userName", user.getDisplayName());
      replacementValues.put(
          "localSakaiName", serverConfigurationService.getString("ui.service", ""));
      replacementValues.put(
          "currentUserName", userDirectoryService.getCurrentUser().getDisplayName());
      replacementValues.put("userEid", user.getEid());
      replacementValues.put("localSakaiUrl", serverConfigurationService.getPortalUrl());
      replacementValues.put("newPassword", newUserPassword);
      replacementValues.put("siteName", siteTitle);
      replacementValues.put("productionSiteName", productionSiteName);
      RenderedTemplate template =
          emailTemplateService.getRenderedTemplateForUser(
              NOTIFY_NEW_USER, user.getReference(), replacementValues);
      if (template == null) return;
      content = template.getRenderedMessage();

      String message_subject = template.getRenderedSubject();
      List<String> headers = new ArrayList<String>();
      headers.add("Precedence: bulk");
      emailService.send(from, to, message_subject, content, headerTo, replyTo, headers);
    }
  }
コード例 #9
0
  /** {@inheritDoc} */
  public void notifyNewUserEmail(User user, String newUserPassword, Site site) {
    ResourceLoader rb = new ResourceLoader("UserNotificationProvider");
    // set the locale to individual receipient's setting
    rb.setContextLocale(rb.getLocale(user.getId()));

    String from = getSetupRequestEmailAddress();
    String productionSiteName = serverConfigurationService.getString("ui.service", "");
    String productionSiteUrl = serverConfigurationService.getPortalUrl();

    String newUserEmail = user.getEmail();
    String to = newUserEmail;
    String headerTo = newUserEmail;
    // UVa: change Reply-To to be the From (collab support) address
    String replyTo = from;
    String message_subject = productionSiteName + " " + rb.getString("java.newusernoti");
    String content = "";

    if (from != null && newUserEmail != null) {
      StringBuilder buf = new StringBuilder();
      buf.setLength(0);

      // email body
      buf.append(user.getDisplayName() + ":\n\n");

      buf.append(
          rb.getString("java.addedto")
              + " "
              + productionSiteName
              + " ("
              + productionSiteUrl
              + ") ");
      buf.append(rb.getString("java.simpleby") + " ");
      buf.append(userDirectoryService.getCurrentUser().getDisplayName() + ". \n\n");
      buf.append(rb.getString("java.passwordis1") + "\n" + newUserPassword + "\n\n");
      buf.append(rb.getString("java.passwordis2") + "\n\n");

      content = buf.toString();
      emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
    }
  }
コード例 #10
0
  /** {@inheritDoc} */
  public void notifyTemplateUse(Site templateSite, User currentUser, Site site) {
    // send an email to track who are using the template
    String from = getSetupRequestEmailAddress();
    // send it to the email archive of the template site
    // TODO: need a better way to get the email archive address
    // String domain = from.substring(from.indexOf('@'));
    String templateEmailArchive =
        templateSite.getId() + "@" + serverConfigurationService.getServerName();
    String to = templateEmailArchive;
    String headerTo = templateEmailArchive;
    String replyTo = templateEmailArchive;
    String message_subject = templateSite.getId() + ": copied by " + currentUser.getDisplayId();

    if (from != null && templateEmailArchive != null) {
      StringBuffer buf = new StringBuffer();
      buf.setLength(0);

      // email body
      buf.append("Dear template maintainer,\n\n");
      buf.append("Congratulations!\n\n");
      buf.append("The following user just created a new site based on your template.\n\n");
      buf.append("Template name: " + templateSite.getTitle() + "\n");
      buf.append(
          "User         : "******" ("
              + currentUser.getDisplayId()
              + ")\n");
      buf.append("Date         : " + new java.util.Date() + "\n");
      buf.append("New site Id  : " + site.getId() + "\n");
      buf.append("New site name: " + site.getTitle() + "\n\n");
      buf.append("Cheers,\n");
      buf.append("Alliance Team\n");
      String content = buf.toString();

      emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
    }
  }
コード例 #11
0
  protected void processRoster(
      HttpServletRequest request,
      HttpServletResponse response,
      String lti_message_type,
      Site site,
      String siteId,
      String placement_id,
      Properties pitch,
      String user_id,
      Map<String, Object> theMap)
      throws java.io.IOException {
    // Check for permission in placement
    String allowRoster = pitch.getProperty(LTIService.LTI_ALLOWROSTER);
    if (!"on".equals(allowRoster)) {
      doError(
          request,
          response,
          theMap,
          "outcomes.invalid",
          "lti_message_type=" + lti_message_type,
          null);
      return;
    }

    String roleMapProp = pitch.getProperty("rolemap");
    String releaseName = pitch.getProperty(LTIService.LTI_SENDNAME);
    String releaseEmail = pitch.getProperty(LTIService.LTI_SENDEMAILADDR);
    String assignment = pitch.getProperty("assignment");
    String allowOutcomes =
        ServerConfigurationService.getString(
            SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED,
            SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED_DEFAULT);
    if (!"true".equals(allowOutcomes)) allowOutcomes = null;

    String maintainRole = site.getMaintainRole();

    SakaiBLTIUtil.pushAdvisor();
    boolean success = false;
    try {
      List<Map<String, Object>> lm = new ArrayList<Map<String, Object>>();
      Set<Member> members = site.getMembers();
      Map<String, String> roleMap = SakaiBLTIUtil.convertRoleMapPropToMap(roleMapProp);
      for (Member member : members) {
        Map<String, Object> mm = new TreeMap<String, Object>();
        Role role = member.getRole();
        String ims_user_id = member.getUserId();
        mm.put("/user_id", ims_user_id);
        String ims_role = "Learner";

        // If there is a role mapping, it has precedence over site.update
        if (roleMap.containsKey(role.getId())) {
          ims_role = roleMap.get(role.getId());
        } else if (ComponentManager.get(AuthzGroupService.class)
            .isAllowed(ims_user_id, SiteService.SECURE_UPDATE_SITE, "/site/" + siteId)) {
          ims_role = "Instructor";
        }

        // Using "/role" is inconsistent with to
        // http://developers.imsglobal.org/ext_membership.html. It
        // should be roles. If we can determine that nobody is using
        // the role tag, we should remove it.

        mm.put("/role", ims_role);
        mm.put("/roles", ims_role);
        User user = null;
        if ("true".equals(allowOutcomes) && assignment != null) {
          user = UserDirectoryService.getUser(ims_user_id);
          String placement_secret = pitch.getProperty(LTIService.LTI_PLACEMENTSECRET);
          String result_sourcedid =
              SakaiBLTIUtil.getSourceDID(user, placement_id, placement_secret);
          if (result_sourcedid != null) mm.put("/lis_result_sourcedid", result_sourcedid);
        }

        if ("on".equals(releaseName) || "on".equals(releaseEmail)) {
          if (user == null) user = UserDirectoryService.getUser(ims_user_id);
          if ("on".equals(releaseName)) {
            mm.put("/person_name_given", user.getFirstName());
            mm.put("/person_name_family", user.getLastName());
            mm.put("/person_name_full", user.getDisplayName());
          }
          if ("on".equals(releaseEmail)) {
            mm.put("/person_contact_email_primary", user.getEmail());
            mm.put("/person_sourcedid", user.getEid());
          }
        }

        Collection groups = site.getGroupsWithMember(ims_user_id);

        if (groups.size() > 0) {
          List<Map<String, Object>> lgm = new ArrayList<Map<String, Object>>();
          for (Iterator i = groups.iterator(); i.hasNext(); ) {
            Group group = (Group) i.next();
            Map<String, Object> groupMap = new HashMap<String, Object>();
            groupMap.put("/id", group.getId());
            groupMap.put("/title", group.getTitle());
            groupMap.put("/set", new HashMap(groupMap));
            lgm.add(groupMap);
          }
          mm.put("/groups/group", lgm);
        }

        lm.add(mm);
      }
      theMap.put("/message_response/members/member", lm);
      success = true;
    } catch (Exception e) {
      doError(request, response, theMap, "memberships.fail", "", e);
    } finally {
      SakaiBLTIUtil.popAdvisor();
    }

    if (!success) return;

    theMap.put("/message_response/statusinfo/codemajor", "Success");
    theMap.put("/message_response/statusinfo/severity", "Status");
    theMap.put("/message_response/statusinfo/codeminor", "fullsuccess");
    String theXml = XMLMap.getXML(theMap, true);
    PrintWriter out = response.getWriter();
    out.println(theXml);
    M_log.debug(theXml);
  }
コード例 #12
0
ファイル: CommentsProducer.java プロジェクト: yllyx/sakai
  public void printComment(
      SimplePageComment comment,
      UIContainer tofill,
      boolean highlight,
      boolean anonymous,
      boolean showModifiers,
      CommentsViewParameters params,
      SimplePageItem commentsItem,
      SimplePage currentPage) {
    if (canEditPage && itemToPageowner != null && comment.getItemId() != lastTitle) {
      UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
      UIOutput.make(
          commentContainer,
          "commentTitle",
          messageLocator
              .getMessage("simplepage.comments-grading")
              .replace("{}", itemToPageowner.get(comment.getItemId())));
      lastTitle = comment.getItemId();
    }

    // print title if this is a comment on a different page. Normally this
    // shold only happen for subpages of student pages
    String pageTitle = null;
    if (currentPage.getPageId() != comment.getPageId()) {
      SimplePage commentPage = simplePageBean.getPage(comment.getPageId());
      pageTitle = commentPage.getTitle();
    }

    UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
    UIOutput.make(commentContainer, "commentDiv");
    if (highlight) commentContainer.decorate(new UIStyleDecorator("highlight-comment"));

    if (!filter && params.author != null && params.author.equals(comment.getAuthor())) {
      commentContainer.decorate(new UIStyleDecorator("backgroundHighlight"));
    }

    String author;

    if (!anonymous) {
      try {
        User user = UserDirectoryService.getUser(comment.getAuthor());
        author = user.getDisplayName();
      } catch (Exception ex) {
        author = messageLocator.getMessage("simplepage.comment-unknown-user");
        ex.printStackTrace();
      }
    } else {
      author = anonymousLookup.get(comment.getAuthor());

      if (comment.getAuthor().equals(owner)) {
        author = messageLocator.getMessage("simplepage.comment-author-owner");
      }

      if (author == null) author = "Anonymous User"; // Shouldn't ever occur

      if (simplePageBean.getEditPrivs() == 0) {
        try {
          User user = UserDirectoryService.getUser(comment.getAuthor());
          author += " (" + user.getDisplayName() + ")";
        } catch (Exception ex) {
          author += " (" + messageLocator.getMessage("simplepage.comment-unknown-user") + ")";
        }
      } else if (comment.getAuthor().equals(currentUserId)) {
        author += " (" + messageLocator.getMessage("simplepage.comment-you") + ")";
      }
    }

    UIOutput authorOutput = UIOutput.make(commentContainer, "userId", author);

    if (comment.getAuthor().equals(currentUserId)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("personalComment"));
    } else if (comment.getAuthor().equals(owner)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("ownerComment"));
    }

    if (pageTitle != null) UIOutput.make(commentContainer, "pageTitle", pageTitle);

    String timeDifference = getTimeDifference(comment.getTimePosted().getTime());

    UIOutput.make(commentContainer, "timePosted", timeDifference);

    if (showModifiers) {
      UIOutput.make(commentContainer, "deleteSpan");

      CommentsViewParameters eParams = (CommentsViewParameters) params.copy();
      eParams.placementId = params.placementId;
      eParams.deleteComment = comment.getUUID();
      eParams.pageId = params.pageId;
      eParams.siteId = params.siteId;

      UIInternalLink.make(commentContainer, "deleteCommentURL", eParams);
      UIOutput.make(commentContainer, "deleteComment")
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-delete").replace("{}", author)));
      UIOutput.make(commentContainer, "editComment")
          .decorate(
              new UIFreeAttributeDecorator("onclick", "edit($(this), " + comment.getId() + ");"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-edit").replace("{}", author)));

      if (!filter && simplePageBean.getEditPrivs() == 0 && commentsItem.getGradebookId() != null) {
        UIOutput.make(commentContainer, "gradingSpan");
        UIOutput.make(commentContainer, "commentsUUID", comment.getUUID());
        UIOutput.make(
            commentContainer,
            "commentPoints",
            (comment.getPoints() == null ? "" : String.valueOf(comment.getPoints())));
        UIOutput.make(commentContainer, "pointsBox")
            .decorate(
                new UIFreeAttributeDecorator(
                    "title",
                    messageLocator
                        .getMessage("simplepage.grade-for-student")
                        .replace("{}", author)));

        UIOutput.make(commentContainer, "maxpoints", " / " + commentsItem.getGradebookPoints());
        UIOutput.make(commentContainer, "authorUUID", comment.getAuthor());
      }
    }

    if (filter && simplePageBean.getEditPrivs() == 0) {
      UIOutput.make(commentContainer, "contextSpan");

      // because this is called via /faces, the full Sakai context is not set up.
      // in particular, UIInternalLink will generate the wrong thing. Thus we
      // make up a full URL ourselves.
      String pars =
          "/portal/tool/"
              + URLEncoder.encode(params.placementId)
              + "/ShowPage?path=none"
              + "&author="
              + URLEncoder.encode(comment.getAuthor());
      // Need to provide the item ID
      if (!params.studentContentItem && params.pageItemId != -1L) {
        pars += "&itemId=" + URLEncoder.encode(Long.toString(params.pageItemId));
      }
      UILink contextLink =
          UILink.make(
              commentContainer,
              "contextLink",
              messageLocator.getMessage("simplepage.show-context"),
              pars);
      if (itemToPageowner == null)
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-1")
                    .replace("{}", author)));
      else
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-2")
                    .replace("{1}", author)
                    .replace("{2}", itemToPageowner.get(comment.getItemId()))));
    }

    String dateString = df.format(comment.getTimePosted());

    if (!filter)
      UIOutput.make(commentContainer, "replyTo")
          .decorate(
              new UIFreeAttributeDecorator(
                  "onclick",
                  "replyToComment($(this),'"
                      + messageLocator
                          .getMessage("simplepage.in-reply-to")
                          .replace("{1}", author)
                          .replace("{2}", dateString)
                      + "')"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-reply").replace("{}", author)));

    if (!comment.getHtml()) {
      UIOutput.make(commentContainer, "comment", comment.getComment());
    } else {
      UIVerbatim.make(commentContainer, "comment", comment.getComment());
    }
  }
コード例 #13
0
  /** {@inheritDoc} */
  public void notifySiteCreation(
      Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail) {
    // send emails
    String id = site.getId();
    String title = site.getTitle();

    SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
    dform.applyPattern("yyyy-MM-dd HH:mm:ss");
    String dateDisplay = dform.format(new Date());

    User currentUser = userDirectoryService.getCurrentUser();
    String currentUserName = currentUser.getDisplayName();
    String currentUserId = currentUser.getId();
    String currentUserEmail = currentUser.getEmail();

    ResourceLoader rb = new ResourceLoader("UserNotificationProvider");

    String message_subject =
        courseSite
            ? rb.getString("java.official")
                + " "
                + currentUserName
                + " "
                + rb.getString("java.for")
                + " "
                + termTitle
            : rb.getString("java.site.createdBy") + " " + currentUserName;

    String from = currentUser.getEmail();
    String to = requestEmail;
    String headerTo = requestEmail;
    String replyTo = currentUserEmail;
    StringBuilder buf = new StringBuilder();
    buf.append(
        "\n"
            + rb.getString("java.fromwork")
            + " "
            + serverConfigurationService.getServerName()
            + " "
            + rb.getString("java.supp")
            + ":\n\n");
    buf.append(courseSite ? rb.getString("java.off") : rb.getString("java.site"));
    buf.append(" '" + title + "' (id " + id + "), " + rb.getString("java.wasset") + " ");
    buf.append(
        currentUserName
            + " ("
            + currentUserId
            + ", "
            + rb.getString("java.email2")
            + " "
            + replyTo
            + ") ");
    buf.append(rb.getString("java.on") + " " + dateDisplay);
    if (courseSite) {
      buf.append(rb.getString("java.for") + " " + termTitle + ", ");
    }
    if (notifySites != null) {
      int nbr_sections = notifySites.size();
      if (nbr_sections > 1) {
        buf.append(
            rb.getString("java.withrost")
                + " "
                + Integer.toString(nbr_sections)
                + " "
                + rb.getString("java.sections")
                + "\n\n");
      } else {
        buf.append(" " + rb.getString("java.withrost2") + "\n\n");
      }

      for (int i = 0; i < nbr_sections; i++) {
        String course = (String) notifySites.get(i);
        buf.append(rb.getString("java.course2") + " " + course + "\n");
      }
    }
    emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null);

    // send a confirmation email to site creator
    from = requestEmail;
    to = currentUserEmail;
    headerTo = currentUserEmail;
    replyTo =
        serverConfigurationService.getString(
            "setup.request", "no-reply@" + serverConfigurationService.getServerName());
    String content =
        rb.getFormattedMessage(
            "java.siteCreation.confirmation",
            new Object[] {title, serverConfigurationService.getServerName()});
    content += "\n\n" + buf.toString();
    emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
  }
コード例 #14
0
  /** {@inheritDoc} */
  public boolean notifyCourseRequestAuthorizer(
      String instructorId,
      String requestEmail,
      String replyToEmail,
      String termTitle,
      String requestSectionInfo,
      String siteTitle,
      String siteId,
      String additionalInfo,
      String serverName) {
    try {
      User instructor = userDirectoryService.getUserByEid(instructorId);

      ResourceLoader rb = new ResourceLoader(instructorId, "UserNotificationProvider");

      StringBuffer buf = new StringBuffer();

      String to = instructor.getEmail();
      String from = requestEmail;
      String headerTo = to;
      String replyTo = replyToEmail;

      User currentUser = userDirectoryService.getCurrentUser();
      String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : "";

      // message subject
      String message_subject =
          rb.getString("java.sitereqfrom")
              + " "
              + currentUserDisplayName
              + " "
              + rb.getString("java.for")
              + " "
              + termTitle;

      buf.append(rb.getString("java.hello") + " \n\n");
      buf.append(rb.getString("java.receiv") + " " + currentUserDisplayName + ", ");
      buf.append(rb.getString("java.who") + "\n");
      if (!termTitle.isEmpty()) {
        buf.append(termTitle + "\n");
      }

      // course section information
      buf.append(requestSectionInfo);

      buf.append(rb.getString("java.sitetitle") + "\t" + siteTitle + "\n");
      buf.append(rb.getString("java.siteid") + "\t" + siteId + "\n\n");
      buf.append(rb.getString("java.siteinstr") + "\n" + additionalInfo + "\n\n");
      buf.append(
          rb.getString("java.according")
              + " "
              + currentUserDisplayName
              + " "
              + rb.getString("java.record"));
      buf.append(
          " "
              + rb.getString("java.canyou")
              + " "
              + currentUserDisplayName
              + " "
              + rb.getString("java.assoc")
              + "\n\n");
      buf.append(
          rb.getString("java.respond")
              + " "
              + currentUserDisplayName
              + rb.getString("java.appoint")
              + "\n\n");
      buf.append(rb.getString("java.thanks") + "\n");
      buf.append(serverName + " " + rb.getString("java.support"));

      try {
        // send the email
        emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null);
        return true;
      } catch (Exception ee) {
        M_log.warn(
            this
                + " problem occurs with sending course request email to authorizer "
                + instructorId);
        return false;
      }
    } catch (Exception e) {
      M_log.warn(this + " cannot find user " + instructorId);
      return false;
    }
  }
コード例 #15
0
  public void notifyAddedParticipant(boolean newNonOfficialAccount, User user, String siteTitle) {

    String from =
        serverConfigurationService.getBoolean(NOTIFY_FROM_CURRENT_USER, false)
            ? getCurrentUserEmailAddress()
            : getSetupRequestEmailAddress();
    // we need to get the template

    if (from != null) {
      String productionSiteName = serverConfigurationService.getString("ui.service", "");
      String emailId = user.getEmail();
      String to = emailId;
      String headerTo = emailId;
      String replyTo = emailId;
      Map<String, String> rv = new HashMap<String, String>();
      rv.put("productionSiteName", productionSiteName);

      String content = "";
      /*
       * $userName
       * $localSakaiName
       * $currentUserName
       * $localSakaiUrl
       */
      Map<String, String> replacementValues = new HashMap<String, String>();
      replacementValues.put("userName", user.getDisplayName());
      replacementValues.put("userEid", user.getEid());
      replacementValues.put(
          "localSakaiName", serverConfigurationService.getString("ui.service", ""));
      replacementValues.put(
          "currentUserName", userDirectoryService.getCurrentUser().getDisplayName());
      replacementValues.put("localSakaiUrl", serverConfigurationService.getPortalUrl());
      String nonOfficialAccountUrl =
          serverConfigurationService.getString("nonOfficialAccount.url", null);
      replacementValues.put(
          "hasNonOfficialAccountUrl",
          nonOfficialAccountUrl != null
              ? Boolean.TRUE.toString().toLowerCase()
              : Boolean.FALSE.toString().toLowerCase());
      replacementValues.put("nonOfficialAccountUrl", nonOfficialAccountUrl);
      replacementValues.put("siteName", siteTitle);
      replacementValues.put("productionSiteName", productionSiteName);
      replacementValues.put(
          "newNonOfficialAccount", Boolean.valueOf(newNonOfficialAccount).toString().toLowerCase());

      M_log.debug("getting template: sitemange.notifyAddedParticipant");
      RenderedTemplate template = null;
      try {
        template =
            emailTemplateService.getRenderedTemplateForUser(
                NOTIFY_ADDED_PARTICIPANT, user.getReference(), replacementValues);
        if (template == null) return;
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
      List<String> headers = new ArrayList<String>();
      headers.add("Precedence: bulk");

      content = template.getRenderedMessage();
      emailService.send(
          from, to, template.getRenderedSubject(), content, headerTo, replyTo, headers);
    } // if
  }
コード例 #16
0
  /** {@inheritDoc} */
  public String notifyCourseRequestSupport(
      String requestEmail,
      String serverName,
      String request,
      String termTitle,
      int requestListSize,
      String requestSectionInfo,
      String officialAccountName,
      String siteTitle,
      String siteId,
      String additionalInfo,
      boolean requireAuthorizer,
      String authorizerNotified,
      String authorizerNotNotified) {
    ResourceLoader rb = new ResourceLoader("UserNotificationProvider");

    User currentUser = userDirectoryService.getCurrentUser();
    String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : "";
    String currentUserDisplayId = currentUser != null ? currentUser.getDisplayId() : "";
    String currentUserEmail = currentUser != null ? currentUser.getEmail() : "";

    // To Support
    String from = currentUserEmail;
    String to = requestEmail;
    String headerTo = requestEmail;
    String replyTo = currentUserEmail;

    StringBuffer buf = new StringBuffer();
    buf.append(
        rb.getString("java.to") + "\t\t" + serverName + " " + rb.getString("java.supp") + "\n");
    buf.append("\n" + rb.getString("java.from") + "\t" + currentUserDisplayName + "\n");
    if ("new".equals(request)) {
      buf.append(rb.getString("java.subj") + "\t" + rb.getString("java.sitereq") + "\n");
    } else {
      buf.append(rb.getString("java.subj") + "\t" + rb.getString("java.sitechreq") + "\n");
    }
    SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
    dform.applyPattern("yyyy-MM-dd HH:mm:ss");
    String dateDisplay = dform.format(new Date());

    buf.append(rb.getString("java.date") + "\t" + dateDisplay + "\n\n");
    if ("new".equals(request)) {
      buf.append(
          rb.getString("java.approval")
              + " "
              + serverName
              + " "
              + rb.getString("java.coursesite")
              + " ");
    } else {
      buf.append(
          rb.getString("java.approval2")
              + " "
              + serverName
              + " "
              + rb.getString("java.coursesite")
              + " ");
    }
    if (!termTitle.isEmpty()) {
      buf.append(termTitle);
    }
    if (requestListSize > 1) {
      buf.append(
          " "
              + rb.getString("java.forthese")
              + " "
              + requestListSize
              + " "
              + rb.getString("java.sections")
              + "\n\n");
    } else {
      buf.append(" " + rb.getString("java.forthis") + "\n\n");
    }
    // the course section information
    buf.append(requestSectionInfo);

    buf.append(
        rb.getString("java.name")
            + "\t"
            + currentUserDisplayName
            + " ("
            + officialAccountName
            + " "
            + currentUserDisplayId
            + ")\n");
    buf.append(rb.getString("java.email") + "\t" + replyTo + "\n");
    buf.append(rb.getString("java.sitetitle") + "\t" + siteTitle + "\n");
    buf.append(rb.getString("java.siteid") + "\t" + siteId + "\n\n");
    buf.append(rb.getString("java.siteinstr") + "\n" + additionalInfo + "\n\n");

    if (requireAuthorizer) {
      // if authorizer is required
      if (!authorizerNotified.isEmpty()) {
        buf.append(
            rb.getString("java.authoriz")
                + " "
                + authorizerNotified
                + " "
                + rb.getString("java.asreq"));
      }
      if (!authorizerNotNotified.isEmpty()) {
        buf.append(
            rb.getString("java.thesiteemail")
                + " "
                + authorizerNotNotified
                + " "
                + rb.getString("java.asreq"));
      }
    }
    String content = buf.toString();

    // message subject
    String message_subject =
        rb.getString("java.sitereqfrom")
            + " "
            + currentUserDisplayName
            + " "
            + rb.getString("java.for")
            + " "
            + termTitle;

    try {
      emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
      return content;
    } catch (Exception e) {
      M_log.warn(
          this + " problem in send site request email to support for " + currentUserDisplayName);
      return "";
    }
  }
コード例 #17
0
 private void checkForContextualProperties(User user) {
   Assert.assertEquals(user.getEid() + CONTEXTUAL_SITE_NAME, user.getDisplayId());
   Assert.assertEquals(
       user.getFirstName() + " " + user.getLastName() + CONTEXTUAL_SITE_NAME,
       user.getDisplayName());
 }
コード例 #18
0
 private void checkForUnadvisedProperties(User user) {
   Assert.assertEquals(user.getEid(), user.getDisplayId());
   Assert.assertEquals(user.getFirstName() + " " + user.getLastName(), user.getDisplayName());
 }
コード例 #19
0
 private void checkForAdvisedProperties(User user) {
   Assert.assertEquals(user.getEid() + DISPLAY_ADVISED_SUFFIX, user.getDisplayId());
   Assert.assertEquals(
       user.getFirstName() + " " + user.getLastName() + DISPLAY_ADVISED_SUFFIX,
       user.getDisplayName());
 }
コード例 #20
0
  /** {@inheritDoc} */
  public void notifyAddedParticipant(boolean newNonOfficialAccount, User user, Site site) {
    ResourceLoader rb = new ResourceLoader(user.getId(), "UserNotificationProvider");

    String from =
        serverConfigurationService.getBoolean(NOTIFY_FROM_CURRENT_USER, false)
            ? getCurrentUserEmailAddress()
            : getSetupRequestEmailAddress();
    if (from != null) {
      String productionSiteName = serverConfigurationService.getString("ui.service", "");
      String productionSiteUrl = serverConfigurationService.getPortalUrl();
      String nonOfficialAccountUrl =
          serverConfigurationService.getString("nonOfficialAccount.url", null);
      String emailId = user.getEmail();
      String to = emailId;
      String headerTo = emailId;
      // UVa: change Reply-To to be the user adding the new participant
      String replyTo = from;
      String message_subject = productionSiteName + " " + rb.getString("java.sitenoti");
      String content = "";
      StringBuilder buf = new StringBuilder();
      buf.setLength(0);

      // email bnonOfficialAccounteen newly added nonOfficialAccount account
      // and other users
      buf.append(user.getDisplayName() + ":\n\n");
      buf.append(
          rb.getString("java.following")
              + " "
              + productionSiteName
              + " "
              + rb.getString("java.simplesite")
              + "\n");
      buf.append(site.getTitle() + "\n");
      buf.append(rb.getString("java.simpleby") + " ");
      buf.append(userDirectoryService.getCurrentUser().getDisplayName() + ". \n\n");
      if (newNonOfficialAccount) {
        buf.append(serverConfigurationService.getString("nonOfficialAccountInstru", "") + "\n");

        if (nonOfficialAccountUrl != null) {
          buf.append(rb.getString("java.togeta1") + "\n" + nonOfficialAccountUrl + "\n");
          buf.append(rb.getString("java.togeta2") + "\n\n");
        }
        buf.append(rb.getString("java.once") + " " + productionSiteName + ": \n");
        buf.append(
            rb.getString("java.loginhow1")
                + " "
                + productionSiteName
                + ": "
                + productionSiteUrl
                + "\n");
        buf.append(rb.getString("java.loginhow2") + "\n");
        buf.append(rb.getString("java.loginhow3") + "\n");
      } else {
        buf.append(rb.getString("java.tolog") + "\n");
        buf.append(
            rb.getString("java.loginhow1")
                + " "
                + productionSiteName
                + ": "
                + productionSiteUrl
                + "\n");
        buf.append(rb.getString("java.loginhow2") + "\n");
        buf.append(rb.getString("java.loginhow3u") + "\n");
      }
      buf.append(rb.getString("java.tabscreen"));
      content = buf.toString();
      emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
    } // if
  }
コード例 #21
0
  public void sendRenderedMessages(
      String key,
      List<String> userReferences,
      Map<String, String> replacementValues,
      String fromEmail,
      String fromName) {

    Map<EmailTemplateLocaleUsers, RenderedTemplate> tMap =
        this.getRenderedTemplates(key, userReferences, replacementValues);
    Set<Entry<EmailTemplateLocaleUsers, RenderedTemplate>> set = tMap.entrySet();
    Iterator<Entry<EmailTemplateLocaleUsers, RenderedTemplate>> it = set.iterator();

    while (it.hasNext()) {

      Entry<EmailTemplateLocaleUsers, RenderedTemplate> entry = it.next();
      RenderedTemplate rt = entry.getValue();
      EmailTemplateLocaleUsers etlu = entry.getKey();
      List<User> toAddress = getUsersEmail(etlu.getUserIds());
      log.info(
          "sending template "
              + key
              + " for locale "
              + etlu.getLocale().toString()
              + " to "
              + toAddress.size()
              + " users");
      StringBuilder message = new StringBuilder();
      message.append(MIME_ADVISORY);
      if (rt.getRenderedMessage() != null) {
        message.append(BOUNDARY_LINE);
        message.append("Content-Type: text/plain; charset=iso-8859-1\n");
        message.append(rt.getRenderedMessage());
      }
      if (rt.getRenderedHtmlMessage() != null) {
        // append the HMTL part
        message.append(BOUNDARY_LINE);
        message.append("Content-Type: text/html; charset=iso-8859-1\n");
        message.append(rt.getRenderedHtmlMessage());
      }

      message.append(TERMINATION_LINE);

      // we need to manually construct the headers
      List<String> headers = new ArrayList<String>();
      // the template may specify a from address
      if (StringUtils.isNotBlank(rt.getFrom())) {
        headers.add("From: \"" + rt.getFrom());
      } else {
        headers.add("From: \"" + fromName + "\" <" + fromEmail + ">");
      }
      // Add a To: header of either the recipient (if only 1), or the sender (if multiple)
      String toName = fromName;
      String toEmail = fromEmail;

      if (toAddress.size() == 1) {
        User u = toAddress.get(0);
        toName = u.getDisplayName();
        toEmail = u.getEmail();
      }

      headers.add("To: \"" + toName + "\" <" + toEmail + ">");

      // SAK-21742 we need the rendered subject
      headers.add("Subject: " + rt.getRenderedSubject());
      headers.add("Content-Type: multipart/alternative; boundary=\"" + MULTIPART_BOUNDARY + "\"");
      headers.add("Mime-Version: 1.0");
      headers.add("Precedence: bulk");

      String body = message.toString();
      log.debug("message body " + body);
      emailService.sendToUsers(toAddress, headers, body);
    }
  }