示例#1
0
  public static java.lang.String siteGroupReference(
      java.lang.String param0, java.lang.String param1) {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return null;

    return service.siteGroupReference(param0, param1);
  }
示例#2
0
  public static org.sakaiproject.site.api.Site getSite(java.lang.String param0)
      throws org.sakaiproject.exception.IdUnusedException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return null;

    return service.getSite(param0);
  }
示例#3
0
  public static void setUserSecurity(
      java.lang.String param0, java.util.Set param1, java.util.Set param2, java.util.Set param3) {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return;

    service.setUserSecurity(param0, param1, param2, param3);
  }
示例#4
0
  public static java.lang.String merge(
      java.lang.String param0, org.w3c.dom.Element param1, java.lang.String param2) {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return null;

    return service.merge(param0, param1, param2);
  }
示例#5
0
  public static void removeSite(org.sakaiproject.site.api.Site param0)
      throws org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.IdUnusedException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return;

    service.removeSite(param0);
  }
示例#6
0
  public static void saveGroupMembership(org.sakaiproject.site.api.Site param0)
      throws org.sakaiproject.exception.IdUnusedException,
          org.sakaiproject.exception.PermissionException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return;

    service.saveGroupMembership(param0);
  }
示例#7
0
  public static void saveSiteInfo(
      java.lang.String param0, java.lang.String param1, java.lang.String param2)
      throws org.sakaiproject.exception.IdUnusedException,
          org.sakaiproject.exception.PermissionException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return;

    service.saveSiteInfo(param0, param1, param2);
  }
示例#8
0
  public static void join(java.lang.String param0)
      throws org.sakaiproject.exception.IdUnusedException,
          org.sakaiproject.exception.PermissionException,
          org.sakaiproject.exception.InUseException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return;

    service.join(param0);
  }
示例#9
0
  public static int countSites(
      org.sakaiproject.site.api.SiteService.SelectionType param0,
      java.lang.Object param1,
      java.lang.String param2,
      java.util.Map param3) {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return 0;

    return service.countSites(param0, param1, param2, param3);
  }
示例#10
0
  public static org.sakaiproject.site.api.Site addSite(
      java.lang.String param0, org.sakaiproject.site.api.Site param1)
      throws org.sakaiproject.exception.IdInvalidException,
          org.sakaiproject.exception.IdUsedException,
          org.sakaiproject.exception.PermissionException {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return null;

    return service.addSite(param0, param1);
  }
示例#11
0
  public static java.util.List getSites(
      org.sakaiproject.site.api.SiteService.SelectionType param0,
      java.lang.Object param1,
      java.lang.String param2,
      java.util.Map param3,
      org.sakaiproject.site.api.SiteService.SortType param4,
      org.sakaiproject.javax.PagingPosition param5) {
    org.sakaiproject.site.api.SiteService service = getInstance();
    if (service == null) return null;

    return service.getSites(param0, param1, param2, param3, param4, param5);
  }
示例#12
0
 private boolean isAdmin(String siteId) {
   if (siteId == null) {
     throw new java.lang.RuntimeException("isAdmin() requires non-null siteId");
   }
   if (!"!admin".equals(siteId)) return false;
   return siteService.allowUpdateSite(siteId);
 }
 /** get announcement group information */
 private String getAnnouncementGroup(AnnouncementMessage a) {
   if (a.getProperties().getProperty(ResourceProperties.PROP_PUBVIEW) != null
       && a.getProperties()
           .getProperty(ResourceProperties.PROP_PUBVIEW)
           .equals(Boolean.TRUE.toString())) {
     return rb.getString("Public");
   } else if (a.getAnnouncementHeader().getAccess().equals(MessageHeader.MessageAccess.CHANNEL)) {
     return rb.getString("Allgroups");
   } else {
     int count = 0;
     String allGroupString = "";
     try {
       Site site = siteService.getSite(entityManager.newReference(a.getReference()).getContext());
       for (Iterator i = a.getAnnouncementHeader().getGroups().iterator(); i.hasNext(); ) {
         Group aGroup = site.getGroup((String) i.next());
         if (aGroup != null) {
           count++;
           if (count > 1) {
             allGroupString = allGroupString.concat(", ").concat(aGroup.getTitle());
           } else {
             allGroupString = aGroup.getTitle();
           }
         }
       }
     } catch (IdUnusedException e) {
       // No site available.
     }
     return allGroupString;
   }
 }
示例#14
0
  /** @inheritDoc */
  public List getSectionMembers(final String sectionUuid) {
    Group group = siteService.findGroup(sectionUuid);
    CourseSection section = new CourseSectionImpl(group);
    Set taRoles = getSectionTaRoles(group);
    Set studentRoles = getSectionStudentRoles(group);
    Set members = group.getMembers();

    List<ParticipationRecord> sectionMembershipRecords = new ArrayList<ParticipationRecord>();
    for (Iterator iter = members.iterator(); iter.hasNext(); ) {
      Member member = (Member) iter.next();
      String roleString = member.getRole().getId();
      User user = SakaiUtil.getUserFromSakai(member.getUserId());
      if (user != null) {
        ParticipationRecord record = null;
        if (taRoles.contains(roleString)) {
          record = new TeachingAssistantRecordImpl(section, user);
        } else if (studentRoles.contains(roleString)) {
          record = new EnrollmentRecordImpl(section, null, user);
        }
        if (record != null) {
          sectionMembershipRecords.add(record);
        }
      }
    }
    return sectionMembershipRecords;
  }
示例#15
0
  private List getSectionEnrollments(String sectionUuid) {
    Group group = siteService.findGroup(sectionUuid);
    CourseSection section = getSection(sectionUuid);
    if (section == null) {
      return new ArrayList();
    }
    if (log.isDebugEnabled()) log.debug("Getting section enrollments in " + sectionUuid);
    Set studentRoles = getSectionStudentRoles(group);
    if (studentRoles == null || studentRoles.isEmpty()) {
      return new ArrayList();
    }
    Set<String> sakaiUserUids = new HashSet<String>();
    for (Iterator iter = studentRoles.iterator(); iter.hasNext(); ) {
      String role = (String) iter.next();
      sakaiUserUids.addAll(group.getUsersHasRole(role));
    }
    List sakaiUsers = userDirectoryService.getUsers(sakaiUserUids);

    List<EnrollmentRecord> membersList = new ArrayList<EnrollmentRecord>();
    for (Iterator iter = sakaiUsers.iterator(); iter.hasNext(); ) {
      User user = SakaiUtil.convertUser((org.sakaiproject.user.api.User) iter.next());
      if (user != null) {
        EnrollmentRecordImpl record = new EnrollmentRecordImpl(section, null, user);
        membersList.add(record);
      }
    }
    return membersList;
  }
示例#16
0
  private List getSectionTeachingAssistants(String sectionUuid) {
    Group group = siteService.findGroup(sectionUuid);
    CourseSection section = getSection(sectionUuid);
    if (section == null) {
      return new ArrayList();
    }
    if (log.isDebugEnabled()) log.debug("Getting section enrollments in " + sectionUuid);
    Set taRoles = getSectionTaRoles(group);
    if (taRoles == null || taRoles.isEmpty()) {
      if (log.isDebugEnabled())
        log.debug("There is no role for TAs in this site... returning an empty list");
      return new ArrayList();
    }
    Set sakaiUserUids = new HashSet();
    for (Iterator iter = taRoles.iterator(); iter.hasNext(); ) {
      String role = (String) iter.next();
      sakaiUserUids.addAll(group.getUsersHasRole(role));
    }
    List sakaiUsers = userDirectoryService.getUsers(sakaiUserUids);

    List<TeachingAssistantRecordImpl> membersList = new ArrayList<TeachingAssistantRecordImpl>();
    for (Iterator iter = sakaiUsers.iterator(); iter.hasNext(); ) {
      User user = SakaiUtil.convertUser((org.sakaiproject.user.api.User) iter.next());
      if (user != null) {
        TeachingAssistantRecordImpl record = new TeachingAssistantRecordImpl(section, user);
        membersList.add(record);
      }
    }
    return membersList;
  }
  /** {@inheritDoc} */
  public boolean canViewAllPurposeItem(Assignment a) {
    boolean rv = false;

    if (a != null) {
      AssignmentAllPurposeItem aItem = getAllPurposeItem(a.getId());
      if (aItem != null) {
        if (!aItem.getHide()) {
          Time now = TimeService.newTime();
          Date releaseDate = aItem.getReleaseDate();
          Date retractDate = aItem.getRetractDate();

          if (releaseDate == null && retractDate == null) {
            // no time limitation on showing the item
            rv = true;
          } else if (releaseDate != null && retractDate == null) {
            // has relase date but not retract date
            rv = now.getTime() > releaseDate.getTime();
          } else if (releaseDate == null && retractDate != null) {
            // has retract date but not release date
            rv = now.getTime() < retractDate.getTime();
          } else if (now != null) {
            // both releaseDate and retract date are not null
            // has both release and retract dates
            rv = now.getTime() > releaseDate.getTime() && now.getTime() < retractDate.getTime();
          }
        } else {
          rv = false;
        }
      }

      if (rv) {
        // reset rv
        rv = false;

        // need to check role/user permission only if the above time test returns true
        List<String> access = getAccessListForAllPurposeItem(aItem);
        User u = m_userDirectoryService.getCurrentUser();
        if (u != null) {
          if (access.contains(u.getId())) rv = true;
          else {
            try {
              String role =
                  m_authzGroupService.getUserRole(
                      u.getId(), m_siteService.siteReference(a.getContext()));
              if (access.contains(role)) rv = true;
            } catch (Exception e) {
              Log.warn(
                  this
                      + ".callViewAllPurposeItem() Hibernate cannot access user role for user id= "
                      + u.getId());
              return rv;
            }
          }
        }
      }
    }

    return rv;
  }
示例#18
0
 /** {@inheritDoc} */
 public boolean hasAdmin() {
   boolean superUser = securityService.isSuperUser();
   return (superUser)
       || ("true"
               .equals(
                   serverConfigurationService.getString("search.allow.maintain.admin", "false"))
           && siteService.allowUpdateSite(siteId));
 }
示例#19
0
 /**
  * Get all the sites a user has access to.
  *
  * @return An array of site IDs.
  */
 protected String[] getAllUsersSites() {
   List<Site> sites =
       siteService.getSites(
           org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
           null,
           null,
           null,
           null,
           null);
   List<String> siteIds = new ArrayList<String>(sites.size());
   for (Site site : sites) {
     if (site != null && site.getId() != null) {
       siteIds.add(site.getId());
     }
   }
   siteIds.add(siteService.getUserSiteId(currentUser));
   return siteIds.toArray(new String[siteIds.size()]);
 }
示例#20
0
 /** @inheritDoc */
 public CourseSection getSection(final String sectionUuid) {
   Group group;
   group = siteService.findGroup(sectionUuid);
   if (group == null) {
     log.error("Unable to find section " + sectionUuid);
     return null;
   }
   return new CourseSectionImpl(group);
 }
  @Override
  protected String plainTextContent(Event event) {
    StringBuilder buf = new StringBuilder();
    String newline = "\n\r";

    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    String url = ServerConfigurationService.getPortalUrl() + "/site/" + siteId;

    // get a site title
    String title = siteId;
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {

    }

    // Now build up the message text.
    if (AnnouncementService.SECURE_ANNC_ADD.equals(event.getEvent())) {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.add", new Object[] {title, url})));

    } else {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.update", new Object[] {title, url})));
    }

    buf.append(" " + rb.getString("at_date") + " ");
    buf.append(hdr.getDate().toStringLocalFull());
    buf.append(newline);
    buf.append(FormattedText.convertFormattedTextToPlaintext(msg.getBody()));
    buf.append(newline);

    // add any attachments
    List attachments = hdr.getAttachments();
    if (attachments.size() > 0) {
      buf.append(newline + rb.getString("Attachments") + newline);
      for (Iterator iAttachments = attachments.iterator(); iAttachments.hasNext(); ) {
        Reference attachment = (Reference) iAttachments.next();
        String attachmentTitle =
            attachment.getProperties().getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
        buf.append(attachmentTitle + ": " + attachment.getUrl() + newline);
      }
    }

    return buf.toString();
  }
示例#22
0
  /**
   * doImport called when "eventSubmit_doBatch_Archive_PreProcess" is in the request parameters to
   * do the prep work for archiving a bunch of sites that match the criteria
   */
  public void doBatch_Archive_PreProcess(RunData data, Context context) {

    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.batch.auth"));
      return;
    }

    // if we have a selected term then use that as the batch export param
    String selectedTerm = data.getParameters().getString("archive-term");

    log.debug("selectedTerm: " + selectedTerm);

    if (StringUtils.isBlank(selectedTerm)) {
      addAlert(state, rb.getString("archive.batch.term.text.missingterm"));
      state.setAttribute(STATE_MODE, BATCH_MODE);
      return;
    }

    // set the message
    state.setAttribute(
        "confirmString",
        rb.getFormattedMessage("archive.batch.term.text.confirm.1", new Object[] {selectedTerm}));

    // get the sites that match the criteria
    Map<String, String> propertyCriteria = new HashMap<String, String>();
    propertyCriteria.put("term_eid", selectedTerm);
    List<Site> sites =
        siteService.getSites(
            SelectionType.ANY, null, null, propertyCriteria, SortType.TITLE_ASC, null);

    if (sites.isEmpty()) {
      addAlert(
          state,
          rb.getFormattedMessage("archive.batch.term.text.nosites", new Object[] {selectedTerm}));
      state.setAttribute(STATE_MODE, BATCH_MODE);
      return;
    }

    // convert to new list so that we dont load entire sites into context
    List<SparseSite> ssites = new ArrayList<SparseSite>();
    for (Site s : sites) {
      ssites.add(new SparseSite(s.getId(), s.getTitle()));
    }

    state.setAttribute("sites", ssites);

    // put into state for next pass
    state.setAttribute("selectedTerm", selectedTerm);

    // set mode so we go to next template
    state.setAttribute(STATE_MODE, BATCH_ARCHIVE_CONFIRM_MODE);
  }
示例#23
0
 private Scope getDefaultSearchScope() {
   log.debug("setting default scope!");
   String siteId = toolManager.getCurrentPlacement().getContext();
   if (siteService.isUserSite(siteId)) {
     log.debug("got scope of Mine");
     return Scope.MINE;
   } else {
     log.debug("got scope of Site");
     return Scope.SITE;
   }
 }
示例#24
0
 private Course getCourse(final String siteContext) {
   if (log.isDebugEnabled()) log.debug("Getting course for context " + siteContext);
   Site site;
   try {
     site = siteService.getSite(siteContext);
   } catch (IdUnusedException e) {
     log.error("Could not find site with id = " + siteContext);
     return null;
   }
   return new CourseImpl(site);
 }
  public void setUp() throws Exception {
    userDirectoryService = getService(UserDirectoryService.class);
    siteService = getService(SiteService.class);
    authzGroupService = getService(AuthzGroupService.class);

    actAsUserEid("admin");

    // Add test users.
    addUserWithEid(NOT_IN_SITE_USER_EID);
    addUserWithEid(UNADVISED_USER_EID);
    addUserWithEid(DISPLAY_ADVISED_USER_EID);

    // Add test sites.
    Site site = siteService.addSite(STANDARD_SITE_NAME, "project");
    siteService.save(site);
    standardSiteUid = site.getReference();

    site = siteService.addSite(CONTEXTUAL_SITE_NAME, "project");
    siteService.save(site);
    contextualSiteUid = site.getReference();
  }
示例#26
0
 /** @inheritDoc */
 public List getSections(final String siteContext) {
   if (log.isDebugEnabled()) log.debug("Getting sections for context " + siteContext);
   List<CourseSectionImpl> sectionList = new ArrayList<CourseSectionImpl>();
   Collection<Group> sections;
   try {
     sections = siteService.getSite(siteContext).getGroups();
   } catch (IdUnusedException e) {
     log.error("No site with id = " + siteContext);
     return sectionList;
   }
   for (Iterator<Group> iter = sections.iterator(); iter.hasNext(); ) {
     Group group = (Group) iter.next();
     sectionList.add(new CourseSectionImpl(group));
   }
   Collections.sort(sectionList);
   return sectionList;
 }
示例#27
0
 /** @inheritDoc */
 public List getSectionsInCategory(final String siteContext, final String categoryId) {
   if (log.isDebugEnabled())
     log.debug("Getting " + categoryId + " sections for context " + siteContext);
   List<CourseSection> sectionList = new ArrayList<CourseSection>();
   Collection groups;
   try {
     groups = siteService.getSite(siteContext).getGroups();
   } catch (IdUnusedException e) {
     log.error("No site with id = " + siteContext);
     return new ArrayList();
   }
   for (Iterator iter = groups.iterator(); iter.hasNext(); ) {
     Group group = (Group) iter.next();
     if (categoryId.equals(group.getProperties().getProperty(CourseSectionImpl.CATEGORY))) {
       sectionList.add(new CourseSectionImpl(group));
     }
   }
   return sectionList;
 }
  /**
   * Format the announcement notification subject line.
   *
   * @param event The event that matched criteria to cause the notification.
   * @return the announcement notification subject line.
   */
  protected String getSubject(Event event) {
    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    // get a site title
    String title = siteId;
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {
    }

    // use the message's subject
    return rb.getFormattedMessage("noti.subj", new Object[] {title, hdr.getSubject()});
  }
示例#29
0
  /**
   * Checks whether the current user can access this site and whether they can see the forums tool.
   *
   * @param siteId
   * @throws EntityException
   */
  private void checkSiteAndToolAccess(String siteId) throws EntityException {

    // check user can access this site
    Site site;
    try {
      site = siteService.getSiteVisit(siteId);
    } catch (IdUnusedException e) {
      throw new EntityException(
          "Invalid siteId: " + siteId, "", HttpServletResponse.SC_BAD_REQUEST);
    } catch (PermissionException e) {
      throw new EntityException(
          "No access to site: " + siteId, "", HttpServletResponse.SC_UNAUTHORIZED);
    }

    // check user can access the tool, it might be hidden
    ToolConfiguration toolConfig = site.getToolForCommonId("sakai.forums");
    if (!toolManager.isVisible(site, toolConfig)) {
      throw new EntityException(
          "No access to tool in site: " + siteId, "", HttpServletResponse.SC_UNAUTHORIZED);
    }
  }
示例#30
0
  /** build the context for batch archive confirm */
  public String buildDownloadContext(
      VelocityPortlet portlet, Context context, RunData rundata, SessionState state) {
    context.put("tlang", rb);
    buildMenu(context);

    // get list of existing archives
    Collection<File> files = Collections.<File>emptySet();
    File archiveBaseDir =
        new File(serverConfigurationService.getString("archive.storage.path", "sakai/archive"));

    if (archiveBaseDir.exists() && archiveBaseDir.isDirectory()) {
      files = FileUtils.listFiles(archiveBaseDir, new SuffixFileFilter(".zip"), null);
    }

    List<SparseFile> zips = new ArrayList<SparseFile>();

    SimpleDateFormat dateFormatIn = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat dateFormatOut = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Calendar calendar = Calendar.getInstance();

    // porcess the list. also get the hash for the file if it exists
    for (File f : files) {

      String absolutePath = f.getAbsolutePath();

      SparseFile sf = new SparseFile();
      sf.setFilename(f.getName());
      sf.setAbsolutePath(absolutePath);
      sf.setSize(FileUtils.byteCountToDisplaySize(f.length()));

      // get the datetime string, its the last part of the file name, convert back to a date that we
      // can display
      String dateTimeStr =
          StringUtils.substringAfterLast(StringUtils.removeEnd(f.getName(), ".zip"), "-");

      try {
        Date date = dateFormatIn.parse(dateTimeStr);
        sf.setDateCreated(dateFormatOut.format(date));
      } catch (ParseException pe) {
        // ignore, just don't set the date
      }

      // get siteId, first part of name
      String siteId = StringUtils.substringBeforeLast(f.getName(), "-");
      sf.setSiteId(siteId);

      // try to get site title if the site still exists
      try {
        Site site = siteService.getSite(siteId);
        sf.setSiteTitle(site.getTitle());
      } catch (IdUnusedException e) {
        // ignore, no site available
      }

      // get the hash. need to read it from the file. Same filename but diff extension
      String hashFilePath = StringUtils.removeEnd(absolutePath, ".zip");
      hashFilePath = hashFilePath + ".sha1";

      File hashFile = new File(hashFilePath);
      try {
        String hash = FileUtils.readFileToString(hashFile);
        sf.setHash(hash);
      } catch (IOException e) {
        // ignore, dont use the hash
      }

      zips.add(sf);
    }

    context.put("archives", zips);

    return "-download";
  }