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;
  }
 public void deleteEntity(EntityReference ref, Map<String, Object> params) {
   // TODO Auto-generated method stub
   if (isAllowedAccessEvalTemplateItem(ref)
       && authoringService.canRemoveTemplate(
           developerHelperService.getCurrentUserId(), new Long(ref.getId()))) {
     authoringService.deleteTemplate(
         new Long(ref.getId()), developerHelperService.getCurrentUserId());
   }
 }
 protected boolean isAllowedAccessEvalTemplateItem(EntityReference ref) {
   // check if the current user can access this
   String userRef = developerHelperService.getCurrentUserReference();
   if (userRef == null) {
     throw new SecurityException("Anonymous users may not view this Eval-item");
   } else {
     if (!developerHelperService.isUserAllowedInEntityReference(userRef, "VIEW", ref.getId())) {
       throw new SecurityException(
           "This Eval-item is not accessible for the current user: " + userRef);
     }
   }
   return true;
 }
 public Object getEntity(EntityReference ref) {
   // TODO Auto-generated method stub
   EvalTemplate item = authoringService.getTemplateById(new Long(ref.getId()));
   if (item != null && isAllowedAccessEvalTemplateItem(ref)) {
     return (developerHelperService.cloneBean(item, 1, new String[] {}));
   } else throw new IllegalArgumentException("id is invalid.");
 }
 public RenderedTemplate getRenderedTemplateForUser(
     String key, String userReference, Map<String, String> replacementValues) {
   log.debug("getRenderedTemplateForUser(" + key + ", " + userReference);
   String userId = developerHelperService.getUserIdFromRef(userReference);
   Locale loc = getUserLocale(userId);
   return getRenderedTemplate(key, loc, replacementValues);
 }
  private List<User> getUsersEmail(List<String> userIds) {
    // we have a group of references
    List<String> ids = new ArrayList<String>();

    for (int i = 0; i < userIds.size(); i++) {
      String userReference = userIds.get(i);
      String userId = developerHelperService.getUserIdFromRef(userReference);
      ids.add(userId);
    }
    return userDirectoryService.getUsers(ids);
  }
  public Map<EmailTemplateLocaleUsers, RenderedTemplate> getRenderedTemplates(
      String key, List<String> userReferences, Map<String, String> replacementValues) {

    List<Locale> foundLocales = new ArrayList<Locale>();
    Map<Locale, EmailTemplateLocaleUsers> mapStore =
        new HashMap<Locale, EmailTemplateLocaleUsers>();

    for (int i = 0; i < userReferences.size(); i++) {
      String userReference = userReferences.get(i);
      String userId = developerHelperService.getUserIdFromRef(userReference);
      Locale loc = getUserLocale(userId);
      // have we found this locale?
      if (!foundLocales.contains(loc)) {
        // create a new EmailTemplateLocalUser
        EmailTemplateLocaleUsers etlu = new EmailTemplateLocaleUsers();
        log.debug("adding users " + userReference + " to new object");
        etlu.setLocale(loc);
        etlu.addUser(userReference);
        mapStore.put(loc, etlu);
        foundLocales.add(loc);
      } else {
        EmailTemplateLocaleUsers etlu = mapStore.get(loc);
        log.debug("adding users " + userReference + " to existing object");
        etlu.addUser(userReference);
        mapStore.remove(loc);
        mapStore.put(loc, etlu);
      }
    }

    Map<EmailTemplateLocaleUsers, RenderedTemplate> ret =
        new HashMap<EmailTemplateLocaleUsers, RenderedTemplate>();

    // now for each locale we need a rendered template
    Set<Entry<Locale, EmailTemplateLocaleUsers>> es = mapStore.entrySet();
    Iterator<Entry<Locale, EmailTemplateLocaleUsers>> it = es.iterator();
    while (it.hasNext()) {
      Entry<Locale, EmailTemplateLocaleUsers> entry = it.next();
      Locale loc = entry.getKey();
      RenderedTemplate rt = this.getRenderedTemplate(key, loc, replacementValues);
      if (rt != null) {
        ret.put(entry.getValue(), rt);
      } else {
        log.error("No template found for key: " + key + " in locale: " + loc);
      }
    }
    return ret;
  }
 public void notifySiteImportCompleted(
     String toEmail, Locale locale, String siteId, String siteTitle) {
   if (toEmail != null && !"".equals(toEmail)) {
     String headerTo = toEmail;
     String replyTo = toEmail;
     String link = developerHelperService.getLocationReferenceURL(SITE_REF_PREFIX + siteId);
     ResourceLoader rb = new ResourceLoader("UserNotificationProvider");
     String message_subject =
         rb.getFormattedMessage("java.siteImport.confirmation.subject", new Object[] {siteTitle});
     String message_body =
         rb.getFormattedMessage("java.siteImport.confirmation", new Object[] {siteTitle, link});
     emailService.send(
         getSetupRequestEmailAddress(),
         toEmail,
         message_subject,
         message_body,
         headerTo,
         replyTo,
         null);
   }
 }