예제 #1
0
  private void appendGroupCalendars(
      Identity identity,
      List<KalendarRenderWrapper> calendars,
      Map<CalendarKey, CalendarUserConfiguration> configMap) {
    // get group calendars
    if (calendarModule.isEnableGroupCalendar()) {
      SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(identity, true, false);
      groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
      List<BusinessGroup> ownerGroups =
          businessGroupService.findBusinessGroups(groupParams, null, 0, -1);
      addCalendars(ownerGroups, true, false, calendars, configMap);

      SearchBusinessGroupParams groupParams2 = new SearchBusinessGroupParams(identity, false, true);
      groupParams2.addTools(CollaborationTools.TOOL_CALENDAR);
      List<BusinessGroup> attendedGroups =
          businessGroupService.findBusinessGroups(groupParams2, null, 0, -1);
      attendedGroups.removeAll(ownerGroups);
      addCalendars(attendedGroups, false, true, calendars, configMap);
    }
  }
  /**
   * Perform a search for the given search value in the search result providers and clear any GUI
   * errors that might be on the page
   *
   * @param searchValue
   * @param ureq
   */
  private void doSearchGroups(String searchValue, UserRequest ureq) {
    if (StringHelper.containsNonWhitespace(searchValue)) {
      SearchBusinessGroupParams param1s = new SearchBusinessGroupParams();
      param1s.setNameOrDesc(searchValue);
      List<BusinessGroup> group1s = businessGroupService.findBusinessGroups(param1s, null, 0, -1);
      filterGroups(group1s);

      SearchBusinessGroupParams param2s = new SearchBusinessGroupParams();
      param2s.setCourseTitle(searchValue);
      List<BusinessGroup> group2s = businessGroupService.findBusinessGroups(param2s, null, 0, -1);
      filterGroups(group2s);

      List<BusinessGroup> groups = new ArrayList<BusinessGroup>(group1s.size() + group2s.size());
      groups.addAll(group1s);
      groups.addAll(group2s);

      List<Long> groupKeysWithRelations = PersistenceHelper.toKeys(groups);
      List<BGRepositoryEntryRelation> resources =
          businessGroupService.findRelationToRepositoryEntries(groupKeysWithRelations, 0, -1);

      List<GroupWrapper> groupWrappers = new ArrayList<GroupWrapper>();
      for (BusinessGroup group : groups) {
        StringBuilder sb = new StringBuilder();
        for (BGRepositoryEntryRelation resource : resources) {
          if (resource.getGroupKey().equals(group.getKey())) {
            if (sb.length() > 0) sb.append(", ");
            sb.append(resource.getRepositoryEntryDisplayName());
          }
        }

        GroupWrapper wrapper = new GroupWrapper(group, sb.toString());
        wrapper.setTutor(createSelection("tutor_" + group.getKey()));
        wrapper.setParticipant(createSelection("participant_" + group.getKey()));
        groupWrappers.add(wrapper);
      }

      table.reset();
      tableDataModel.setObjects(groupWrappers);
      errorComp.clearError();
    }
  }
예제 #3
0
  @Override
  public List<CalendarFileInfos> getListOfCalendarsFiles(Identity identity) {
    List<CalendarFileInfos> aggregatedFiles = new ArrayList<>();

    Map<CalendarKey, CalendarUserConfiguration> configMap =
        calendarManager.getCalendarUserConfigurationsMap(identity);

    // personal calendar
    CalendarKey personalCalendarKey =
        new CalendarKey(identity.getName(), CalendarManager.TYPE_USER);
    CalendarUserConfiguration personalCalendarConfig = configMap.get(personalCalendarKey);
    if (calendarModule.isEnablePersonalCalendar()
        && (personalCalendarConfig == null || personalCalendarConfig.isInAggregatedFeed())) {
      File iCalFile =
          calendarManager.getCalendarICalFile(CalendarManager.TYPE_USER, identity.getName());
      if (iCalFile != null) {
        aggregatedFiles.add(
            new CalendarFileInfos(identity.getName(), CalendarManager.TYPE_USER, iCalFile));
      }

      // reload every hour
      List<CalendarFileInfos> importedCalendars =
          importCalendarManager.getImportedCalendarInfosForIdentity(identity, true);
      aggregatedFiles.addAll(importedCalendars);
    }

    // group calendars
    if (calendarModule.isEnableGroupCalendar()) {
      SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(identity, true, true);
      groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
      List<BusinessGroup> groups =
          businessGroupService.findBusinessGroups(groupParams, null, 0, -1);
      for (BusinessGroup group : groups) {
        String calendarId = group.getKey().toString();
        CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_GROUP);
        CalendarUserConfiguration calendarConfig = configMap.get(key);
        if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
          File iCalFile =
              calendarManager.getCalendarICalFile(CalendarManager.TYPE_GROUP, calendarId);
          if (iCalFile != null) {
            aggregatedFiles.add(
                new CalendarFileInfos(calendarId, CalendarManager.TYPE_GROUP, iCalFile));
          }
        }
      }
    }

    if (calendarModule.isEnableCourseElementCalendar()
        || calendarModule.isEnableCourseToolCalendar()) {
      List<Object[]> resources = getCourses(identity);
      for (Object[] resource : resources) {
        RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
        String calendarId = courseEntry.getOlatResource().getResourceableId().toString();
        CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_COURSE);
        CalendarUserConfiguration calendarConfig = configMap.get(key);
        if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
          File iCalFile =
              calendarManager.getCalendarICalFile(CalendarManager.TYPE_COURSE, calendarId);
          if (iCalFile != null) {
            aggregatedFiles.add(
                new CalendarFileInfos(calendarId, CalendarManager.TYPE_COURSE, iCalFile));
          }
        }
      }
    }

    return aggregatedFiles;
  }
  @Test
  public void deleteCourseSoftly() {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("re-soft-");
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();

    // add business group
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            coachGroup, "Relation 1", "tg", null, null, false, false, re);
    businessGroupService.addResourceTo(group, re);
    dbInstance.commit();

    // catalog
    List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
    CatalogEntry catEntry = catalogManager.createCatalogEntry();
    catEntry.setName("Soft");
    catEntry.setRepositoryEntry(re);
    catEntry.setParent(rootEntries.get(0));
    catEntry.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
    catalogManager.saveCatalogEntry(catEntry);
    dbInstance.commit();

    // check the catalog
    List<CatalogEntry> catEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(catEntries);
    Assert.assertEquals(1, catEntries.size());

    // add owner, coach...
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
    dbInstance.commit();

    // kill it softly like A. Keys
    repositoryService.deleteSoftly(re, initialAuthor, false);
    dbInstance.commit();

    // check that the members are removed
    List<Identity> coachAndParticipants =
        repositoryEntryRelationDao.getMembers(
            re,
            RepositoryEntryRelationType.both,
            GroupRoles.coach.name(),
            GroupRoles.participant.name());
    Assert.assertNotNull(coachAndParticipants);
    Assert.assertEquals(0, coachAndParticipants.size());

    // check the relations between course and business groups
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, re, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(0, groups.size());

    // check the catalog
    List<CatalogEntry> removedCatEntries = catalogManager.getCatalogCategoriesFor(re);
    Assert.assertNotNull(removedCatEntries);
    Assert.assertEquals(0, removedCatEntries.size());

    RepositoryEntry reloadEntry = repositoryService.loadByKey(re.getKey());
    Assert.assertNotNull(reloadEntry);
    Assert.assertEquals(0, reloadEntry.getAccess());
    Assert.assertNotNull(reloadEntry.getDeletionDate());
    Assert.assertEquals(initialAuthor, reloadEntry.getDeletedBy());
  }