Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
  protected void processSetting(
      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 {
    String setting = null;

    // Check for permission in placement
    String allowSetting = pitch.getProperty(LTIService.LTI_ALLOWSETTINGS);
    if (!"on".equals(allowSetting)) {
      doError(
          request,
          response,
          theMap,
          "outcomes.invalid",
          "lti_message_type=" + lti_message_type,
          null);
      return;
    }

    SakaiBLTIUtil.pushAdvisor();
    boolean success = false;
    try {
      if ("basic-lti-loadsetting".equals(lti_message_type)) {
        setting = pitch.getProperty(LTIService.LTI_SETTINGS_EXT);
        // Remove this after the DB conversion for SAK-25621 is completed
        // It is harmless until LTI 2.0 starts to get heavy use.
        if (setting == null) {
          setting = pitch.getProperty(LTIService.LTI_SETTINGS);
        }
        if (setting != null) {
          theMap.put("/message_response/setting/value", setting);
        }
        success = true;
      } else {
        if (SakaiBLTIUtil.isPlacement(placement_id)) {
          ToolConfiguration placement = SiteService.findTool(placement_id);
          if ("basic-lti-savesetting".equals(lti_message_type)) {
            setting = request.getParameter("setting");
            if (setting == null) {
              M_log.warn("No setting parameter");
              doError(request, response, theMap, "setting.empty", "", null);
            } else {
              if (setting.length() > 8096) setting = setting.substring(0, 8096);
              placement.getPlacementConfig().setProperty("toolsetting", setting);
            }
          } else if ("basic-lti-deletesetting".equals(lti_message_type)) {
            placement.getPlacementConfig().remove("toolsetting");
          }
          try {
            placement.save();
            success = true;
          } catch (Exception e) {
            doError(request, response, theMap, "setting.save.fail", "", e);
          }
        } else {
          Map<String, Object> content = null;
          String contentStr = pitch.getProperty("contentKey");
          Long contentKey = foorm.getLongKey(contentStr);
          if (contentKey >= 0) content = ltiService.getContentDao(contentKey, siteId);
          if (content != null) {
            if ("basic-lti-savesetting".equals(lti_message_type)) {
              setting = request.getParameter("setting");
              if (setting == null) {
                M_log.warn("No setting parameter");
                doError(request, response, theMap, "setting.empty", "", null);
              } else {
                if (setting.length() > 8096) setting = setting.substring(0, 8096);
                content.put(LTIService.LTI_SETTINGS_EXT, setting);
                success = true;
              }
            } else if ("basic-lti-deletesetting".equals(lti_message_type)) {
              content.put(LTIService.LTI_SETTINGS_EXT, null);
              success = true;
            }
            if (success) {
              Object result = ltiService.updateContentDao(contentKey, content, siteId);
              if (result instanceof String) {
                M_log.warn("Setting update failed: " + result);
                doError(request, response, theMap, "setting.fail", "", null);
                success = false;
              }
            }
          }
        }
      }
    } catch (Exception e) {
      doError(request, response, theMap, "setting.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);
  }