public String getDisplayName(User user) {
   if (!UNADVISED_USER_EID.equals(user.getEid())) {
     return user.getFirstName() + " " + user.getLastName() + DISPLAY_ADVISED_SUFFIX;
   } else {
     return null;
   }
 }
  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 String getUserDisplayName(User user, String contextReference) {
   if (contextualSiteUid.equals(contextReference)) {
     if (!NOT_IN_SITE_USER_EID.equals(user.getEid())) {
       return user.getFirstName() + " " + user.getLastName() + CONTEXTUAL_SITE_NAME;
     }
   }
   return null;
 }
 private void checkExplicitContextualService(User user) {
   Assert.assertEquals(null, contextualUserDisplayService.getUserDisplayId(user, standardSiteUid));
   Assert.assertEquals(
       null, contextualUserDisplayService.getUserDisplayName(user, standardSiteUid));
   Assert.assertEquals(
       user.getEid() + CONTEXTUAL_SITE_NAME,
       contextualUserDisplayService.getUserDisplayId(user, contextualSiteUid));
   Assert.assertEquals(
       user.getFirstName() + " " + user.getLastName() + CONTEXTUAL_SITE_NAME,
       contextualUserDisplayService.getUserDisplayName(user, contextualSiteUid));
 }
  /**
   * @see org.sakaiproject.api.common.edu.person.SakaiPersonManager#create(java.lang.String,
   *     java.lang.String, org.sakaiproject.api.common.type.Type)
   */
  public SakaiPerson create(String userId, Type recordType) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("create(String " + userId + ",  Type " + recordType + ")");
    }
    if (userId == null || userId.length() < 1)
      throw new IllegalArgumentException("Illegal agentUuid argument passed!");
    ; // a null uid is valid
    if (!isSupportedType(recordType))
      throw new IllegalArgumentException("Illegal recordType argument passed!");

    SakaiPersonImpl spi = new SakaiPersonImpl();
    persistableHelper.createPersistableFields(spi);
    spi.setUuid(IdManager.createUuid());
    spi.setAgentUuid(userId);
    spi.setUid(userId);
    spi.setTypeUuid(recordType.getUuid());
    spi.setLocked(Boolean.valueOf(false));
    this.getHibernateTemplate().save(spi);

    // log the event
    String ref = getReference(spi);
    eventTrackingService.post(eventTrackingService.newEvent("profile.new", ref, true));

    // do not do this for system profiles
    if (serverConfigurationService.getBoolean("profile.updateUser", false)) {
      try {
        User u = userDirectoryService.getUser(userId);
        spi.setGivenName(u.getFirstName());
        spi.setSurname(u.getLastName());
        spi.setMail(u.getEmail());
      } catch (UserNotDefinedException uue) {
        LOG.error("User " + userId + "doesn't exist");
      }
    }

    LOG.debug("return spi;");
    return spi;
  }
  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);
  }
 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());
 }
 private void checkForUnadvisedProperties(User user) {
   Assert.assertEquals(user.getEid(), user.getDisplayId());
   Assert.assertEquals(user.getFirstName() + " " + user.getLastName(), user.getDisplayName());
 }
 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());
 }
Example #10
0
  public List /* EmailGroup */ getEmailGroupsByType(String roletypefilter) {
    List /* EmailGroup */ thegroups = new ArrayList();
    List emailroles = this.getEmailRoles();
    for (Iterator i = emailroles.iterator(); i.hasNext(); ) {
      EmailRole emailrole = (EmailRole) i.next();
      if (emailrole.roletype.equals("role") && roletypefilter.equals("role")) {
        String realmid = emailrole.getRealmid();
        AuthzGroup therealm = null;
        try {
          therealm = m_realmService.getAuthzGroup(realmid);
        } catch (GroupNotDefinedException e1) {
          log.debug("GroupNotDefinedException: Mailtool.getEmailGroups() #1, ", e1);
          return thegroups;
        } catch (Exception e2) {
          log.debug("Exception: Mailtool.getEmailGroups() #1, " + e2.getMessage());
          return thegroups;
        }
        Set users = therealm.getUsersHasRole(emailrole.getRoleid());
        List /* EmailUser */ mailusers = new ArrayList();
        for (Iterator j = users.iterator(); j.hasNext(); ) {
          String userid = (String) j.next();
          try {
            User theuser = m_userDirectoryService.getUser(userid);
            String firstname_for_display = "";
            String lastname_for_display = "";
            if (theuser.getFirstName().trim().equals("")) {
              if (theuser.getEmail().trim().equals("") && theuser.getLastName().trim().equals(""))
                firstname_for_display = theuser.getDisplayId(); // fix for SAK-7539
              else firstname_for_display = theuser.getEmail(); // fix for SAK-7356
            } else {
              firstname_for_display = theuser.getFirstName();
            }
            lastname_for_display = theuser.getLastName();
            EmailUser emailuser =
                new EmailUser(
                    theuser.getId(),
                    firstname_for_display,
                    lastname_for_display,
                    theuser.getEmail());
            mailusers.add(emailuser);
          } catch (Exception e) {
            log.debug("Exception: OptionsBean.getEmailGroupsByType() #2, " + e.getMessage());
          }
        }
        Collections.sort(mailusers);
        EmailGroup thegroup = new EmailGroup(emailrole, mailusers);
        thegroups.add(thegroup);
      } else if (emailrole.roletype.equals("group") && roletypefilter.equals("group")) {
        String sid = getSiteID();
        Site currentSite = null;
        try {
          currentSite = siteService.getSite(sid);
        } catch (IdUnusedException e1) {
          log.debug("IdUnusedException: Mailtool.getEmailGroups() #3, ", e1);
          return thegroups;
        } catch (Exception e2) {
          log.debug("Exception: Mailtool.getEmailGroups() #3, " + e2.getMessage());
          return thegroups;
        }
        Collection groups = currentSite.getGroups();
        Group agroup = null;
        for (Iterator groupIterator = groups.iterator(); groupIterator.hasNext(); ) {
          agroup = (Group) groupIterator.next();
          String groupname = agroup.getTitle();
          if (emailrole.getRoleid().equals(groupname)) break;
        }
        Set users2 = agroup.getUsersHasRole(groupAwareRoleFound);
        List mailusers2 = new ArrayList();
        for (Iterator k = users2.iterator(); k.hasNext(); ) {
          String userid2 = (String) k.next();
          try {
            User theuser2 = m_userDirectoryService.getUser(userid2);
            String firstname_for_display = "";
            String lastname_for_display = "";
            if (theuser2.getFirstName().trim().equals("")) {
              if (theuser2.getEmail().trim().equals("") && theuser2.getLastName().trim().equals(""))
                firstname_for_display = theuser2.getDisplayId(); // fix for SAK-7539
              else firstname_for_display = theuser2.getEmail(); // fix for SAK-7356
            } else {
              firstname_for_display = theuser2.getFirstName();
            }

            lastname_for_display = theuser2.getLastName();

            EmailUser emailuser2 =
                new EmailUser(
                    theuser2.getId(),
                    firstname_for_display,
                    lastname_for_display,
                    theuser2.getEmail());

            mailusers2.add(emailuser2);
          } catch (Exception e) {
            log.debug("Exception: OptionsBean.getEmailGroupsByType() #3-1, " + e.getMessage());
          }
        }
        Collections.sort(mailusers2);
        EmailGroup thegroup2 = new EmailGroup(emailrole, mailusers2);
        thegroups.add(thegroup2);
      } // else
      else if (emailrole.roletype.equals("section") && roletypefilter.equals("section")) {
        String sid = getSiteID();
        Site currentSite = null;
        try {
          currentSite = siteService.getSite(sid);
        } catch (IdUnusedException e1) {
          log.debug("IdUnusedException: Mailtool.getEmailGroups() #4, ", e1);
          return thegroups;
        } catch (Exception e2) {
          log.debug("Exception: Mailtool.getEmailGroups() #4, " + e2.getMessage());
          return thegroups;
        }

        Collection groups = currentSite.getGroups();
        Group agroup = null;
        for (Iterator groupIterator = groups.iterator(); groupIterator.hasNext(); ) {
          agroup = (Group) groupIterator.next();
          String groupname = agroup.getTitle();
          if (emailrole.getRoleid().equals(groupname)) break;
        }
        Set users2 = agroup.getUsersHasRole(groupAwareRoleFound);
        List mailusers2 = new ArrayList();
        for (Iterator k = users2.iterator(); k.hasNext(); ) {
          String userid2 = (String) k.next();
          try {
            User theuser2 = m_userDirectoryService.getUser(userid2);
            String firstname_for_display = "";
            String lastname_for_display = "";
            if (theuser2.getFirstName().trim().equals("")) {
              if (theuser2.getEmail().trim().equals("") && theuser2.getLastName().trim().equals(""))
                firstname_for_display = theuser2.getDisplayId(); // fix for SAK-7539
              else firstname_for_display = theuser2.getEmail(); // fix for SAK-7356
            } else {
              firstname_for_display = theuser2.getFirstName();
            }
            lastname_for_display = theuser2.getLastName();
            EmailUser emailuser2 =
                new EmailUser(
                    theuser2.getId(),
                    firstname_for_display,
                    lastname_for_display,
                    theuser2.getEmail());
            mailusers2.add(emailuser2);
          } catch (Exception e) {
            log.debug("Exception: OptionsBean.getEmailGroupsByType() #4-1, " + e.getMessage());
          }
        }
        Collections.sort(mailusers2);
        EmailGroup thegroup2 = new EmailGroup(emailrole, mailusers2);
        thegroups.add(thegroup2);
      } // else
      else if (emailrole.roletype.equals("role_groupaware")
          && roletypefilter.equals("role_groupaware")) {
        String realmid = emailrole.getRealmid();

        AuthzGroup therealm = null;
        try {
          therealm = m_realmService.getAuthzGroup(realmid);
        } catch (GroupNotDefinedException e1) {
          log.debug("GroupNotDefinedException: Mailtool.getEmailGroupsByType() #5, ", e1);
          return thegroups;
        } catch (Exception e2) {
          log.debug("Exception: Mailtool.getEmailGroupsByType() #5, " + e2.getMessage());
          return thegroups;
        }
        Set users = therealm.getUsersHasRole(emailrole.getRoleid());
        List /* EmailUser */ mailusers = new ArrayList();
        for (Iterator j = users.iterator(); j.hasNext(); ) {
          String userid = (String) j.next();
          try {
            User theuser = m_userDirectoryService.getUser(userid);
            String firstname_for_display = "";
            String lastname_for_display = "";
            if (theuser.getFirstName().trim().equals("")) {
              if (theuser.getEmail().trim().equals("") && theuser.getLastName().trim().equals(""))
                firstname_for_display = theuser.getDisplayId(); // fix for SAK-7539
              else firstname_for_display = theuser.getEmail(); // fix for SAK-7356
            } else {
              firstname_for_display = theuser.getFirstName();
            }
            lastname_for_display = theuser.getLastName();
            EmailUser emailuser =
                new EmailUser(
                    theuser.getId(),
                    firstname_for_display,
                    lastname_for_display,
                    theuser.getEmail());
            mailusers.add(emailuser);
          } catch (Exception e) {
            log.debug("Exception: OptionsBean.getEmailGroupsByType() #5-1, " + e.getMessage());
          }
        }
        Collections.sort(mailusers);
        EmailGroup thegroup = new EmailGroup(emailrole, mailusers);
        thegroups.add(thegroup);
      } // else
    }
    return thegroups;
  }