private RepositoryStatisticsVO getRepositoryStatistics() {
   RepositoryStatisticsVO stats = new RepositoryStatisticsVO();
   RepositoryManager repoMgr = CoreSpringFactory.getImpl(RepositoryManager.class);
   int allCourses =
       repoMgr.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_OWNERS);
   int publishedCourses =
       repoMgr.countByTypeLimitAccess(CourseModule.ORES_TYPE_COURSE, RepositoryEntry.ACC_USERS);
   stats.setCoursesCount(allCourses);
   stats.setPublishedCoursesCount(publishedCourses);
   return stats;
 }
  /** Same workflow as the repository. This workflow is pretty critical. */
  @Test
  public void isStructuredMapOwner() {
    final OLATResource resource = epStructureManager.createPortfolioMapTemplateResource();

    // create a repository entry
    final RepositoryEntry addedEntry =
        repositoryManager.createRepositoryEntryInstance(ident1.getName());

    addedEntry.setCanDownload(false);
    addedEntry.setCanLaunch(true);
    addedEntry.setDisplayname("test repo");
    addedEntry.setResourcename("-");
    addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);

    // Set the resource on the repository entry and save the entry.
    final OLATResource ores = resourceManager.findOrPersistResourceable(resource);
    addedEntry.setOlatResource(ores);

    // create security group
    final SecurityGroup newGroup = securityManager.createAndPersistSecurityGroup();
    securityManager.createAndPersistPolicy(newGroup, Constants.PERMISSION_ACCESS, newGroup);
    securityManager.createAndPersistPolicy(
        newGroup, Constants.PERMISSION_HASROLE, EPStructureManager.ORES_MAPOWNER);
    securityManager.addIdentityToSecurityGroup(ident1, newGroup);
    addedEntry.setOwnerGroup(newGroup);

    repositoryManager.saveRepositoryEntry(addedEntry);
    dbInstance.commitAndCloseSession();

    // create the template owned by ident1
    final PortfolioStructureMap template =
        epStructureManager.createAndPersistPortfolioMapTemplateFromEntry(ident1, addedEntry);
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(template, "Page title", "Page description");
    assertNotNull(page1);

    dbInstance.commitAndCloseSession();

    // assign the template to ident2
    final PortfolioStructureMap map =
        epFrontendManager.assignStructuredMapToUser(ident2, template, null, null, null, null);
    assertNotNull(map);
    dbInstance.commitAndCloseSession();

    // check if ident2 is owner of the map
    assertTrue(epFrontendManager.isMapOwner(ident2, map.getOlatResource()));
    // check if ident1 is not the owner of the map
    assertFalse(epFrontendManager.isMapOwner(ident1, map.getOlatResource()));
    // check if ident1 is owner of the template
    assertTrue(epFrontendManager.isMapOwner(ident1, template.getOlatResource()));
  }
  /**
   * Constructor for the course logs archive controller
   *
   * @param ureq
   * @param wControl
   * @param course
   */
  public CourseLogsArchiveController(
      UserRequest ureq, WindowControl wControl, OLATResourceable ores) {
    super(ureq, wControl);
    this.ores = ores;
    this.myPanel = new Panel("myPanel");
    myPanel.addListener(this);

    myContent = createVelocityContainer("start_courselogs");

    Identity identity = ureq.getIdentity();
    Roles roles = ureq.getUserSession().getRoles();

    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(ores, false);
    boolean isOLATAdmin = ureq.getUserSession().getRoles().isOLATAdmin();
    boolean isOresOwner = RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identity, re);
    boolean isOresInstitutionalManager =
        RepositoryManager.getInstance().isInstitutionalRessourceManagerFor(identity, roles, re);
    boolean aLogV = isOresOwner || isOresInstitutionalManager;
    boolean uLogV = isOLATAdmin;
    boolean sLogV = isOresOwner || isOresInstitutionalManager;

    if (AsyncExportManager.getInstance().asyncArchiveCourseLogOngoingFor(ureq.getIdentity())) {
      // then show the ongoing feedback
      showExportOngoing(false);
    } else if (isOLATAdmin || aLogV || uLogV || sLogV) {
      myContent.contextPut("hasLogArchiveAccess", true);
      logFileChooserForm = new LogFileChooserForm(ureq, wControl, isOLATAdmin, aLogV, uLogV, sLogV);
      listenTo(logFileChooserForm);
      myContent.put("logfilechooserform", logFileChooserForm.getInitialComponent());
      ICourse course = CourseFactory.loadCourse(ores);
      myContent.contextPut(
          "body", translate("course.logs.existingarchiveintro", course.getCourseTitle()));
      showFileButton = LinkFactory.createButton("showfile", myContent, this);
      File exportDir =
          CourseFactory.getDataExportDirectory(ureq.getIdentity(), course.getCourseTitle());
      boolean exportDirExists = false;
      if (exportDir != null && exportDir.exists() && exportDir.isDirectory()) {
        exportDirExists = true;
      }
      myContent.contextPut("hascourselogarchive", new Boolean(exportDirExists));
      myPanel.setContent(myContent);
    } else {
      myContent.contextPut("hasLogArchiveAccess", new Boolean(false));
      myPanel.setContent(myContent);
    }

    putInitialPanel(myPanel);
  }
 /**
  * @see
  *     org.olat.repository.handlers.RepositoryHandler#getLaunchController(org.olat.core.id.OLATResourceable,
  *     java.lang.String, org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
  */
 @Override
 public MainLayoutController createLaunchController(
     final OLATResourceable res,
     final String initialViewIdentifier,
     final UserRequest ureq,
     final WindowControl wControl) {
   final RepositoryEntry repoEntry =
       RepositoryManager.getInstance().lookupRepositoryEntry(res, false);
   final boolean isAdmin = ureq.getUserSession().getRoles().isOLATAdmin();
   final boolean isOwner =
       RepositoryManager.getInstance().isOwnerOfRepositoryEntry(ureq.getIdentity(), repoEntry);
   final FeedSecurityCallback callback = new FeedResourceSecurityCallback(isAdmin, isOwner);
   final Controller blogCtr =
       BlogUIFactory.getInstance(ureq.getLocale())
           .createMainController(res, ureq, wControl, callback);
   final LayoutMain3ColsController layoutCtr =
       new LayoutMain3ColsController(
           ureq, wControl, null, null, blogCtr.getInitialComponent(), null);
   layoutCtr.addDisposableChildController(blogCtr);
   return layoutCtr;
 }
  @Test
  public void testRemoveCoach_withBusinessGroups() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");

    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());

    BusinessGroup businessGroup =
        businessGroupDao.createAndPersist(
            coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);

    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();

    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(coach, context, publisherData);
    dbInstance.commitAndCloseSession();

    // remove member and coach as coach of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(coach);
    repositoryManager.removeTutors(owner, removeIdentities, re);

    // wait for the remove of subscription
    waitForCondition(
        new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
    sleep(1000);

    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertFalse(subscribedMember);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
  }
 @Override
 public String createTitleInfo(Subscriber subscriber, Locale locale) {
   try {
     Long resId = subscriber.getPublisher().getResId();
     String displayName =
         RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(resId);
     Translator trans = Util.createPackageTranslator(AssessmentNotificationsHandler.class, locale);
     String title = trans.translate("notifications.title", new String[] {displayName});
     return title;
   } catch (Exception e) {
     log.error(
         "Error while creating assessment notifications for subscriber: " + subscriber.getKey(),
         e);
     checkPublisher(subscriber.getPublisher());
     return "-";
   }
 }
  /**
   * @see org.olat.course.nodes.GenericCourseNode#archiveNodeData(java.util.Locale,
   *     org.olat.course.ICourse, java.io.File, java.lang.String)
   */
  @Override
  public boolean archiveNodeData(
      final Locale locale, final ICourse course, final File exportDirectory, final String charset) {
    final String repoRef = (String) this.getModuleConfiguration().get("reporef");
    final OLATResourceable ores =
        RepositoryManager.getInstance()
            .lookupRepositoryEntryBySoftkey(repoRef, true)
            .getOlatResource();

    if (WikiManager.getInstance().getOrLoadWiki(ores).getAllPagesWithContent().size() > 0) {
      // OK, there is somthing to archive
      final VFSContainer exportContainer = new LocalFolderImpl(exportDirectory);
      VFSContainer wikiExportContainer =
          (VFSContainer) exportContainer.resolve(WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      if (wikiExportContainer == null) {
        wikiExportContainer =
            exportContainer.createChildContainer(WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      }
      final String exportDirName =
          getShortTitle()
              + "_"
              + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
      final VFSContainer destination = wikiExportContainer.createChildContainer(exportDirName);
      if (destination == null) {
        Tracing.logError(
            "archiveNodeData: Could not create destination directory: wikiExportContainer="
                + wikiExportContainer
                + ", exportDirName="
                + exportDirName,
            getClass());
      }

      final VFSContainer container =
          WikiManager.getInstance().getWikiContainer(ores, WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      if (container
          != null) { // the container could be null if the wiki is an old empty one - so nothing to
                     // archive
        final VFSContainer parent = container.getParentContainer();
        final VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(parent);
        destination.copyFrom(wikiZip);
      }
      return true;
    }
    // empty wiki, no need to archive
    return false;
  }
  @Test
  public void testRemoveParticipant() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");

    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());

    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();

    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(participant, context, publisherData);
    dbInstance.commitAndCloseSession();

    // remove member and participant as participant of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(participant);
    MailPackage mailing = new MailPackage(false);
    repositoryManager.removeParticipants(owner, removeIdentities, re, mailing, false);

    // wait for the remove of subscription
    waitForCondition(
        new CheckUnsubscription(participant, context, dbInstance, notificationManager), 5000);
    sleep(1000);

    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedPart = notificationManager.isSubscribed(participant, context);
    Assert.assertFalse(subscribedPart);
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertTrue(subscribedMember);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
  }
Example #9
0
    @Override
    protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
      fic =
          FormLayoutContainer.createCustomFormLayout(
              "cc01", this.getTranslator(), this.velocity_root + "/CcStep01_form.html");
      formLayout.add(fic);

      // load course
      ICourse course = CourseFactory.loadCourse(getRepoEntry());

      // show catalog selection tree
      if (course != null) {
        cic =
            new CatalogInsertController(
                ureq,
                getWindowControl(),
                RepositoryManager.getInstance().lookupRepositoryEntry(course, false),
                getCourseConfig());
        cic.addControllerListener(this);
        fic.put("cc", cic.getInitialComponent());
      }
      cic.init();
    }
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Component source, Event event) {
    if (source == onCommand) {
      // toggle on
      Preferences prefs = ureq.getUserSession().getGuiPreferences();
      prefs.put(CourseGlossaryToolLinkController.class, guiPrefsKey, Boolean.TRUE);
      prefs.save();
      // update gui
      mainVC.remove(onCommand);
      offCommand = LinkFactory.createLink("command.glossary.off", mainVC, this);
      offCommand.setTitle("command.glossary.off.alt");
      offCommand.setCustomEnabledLinkCSS("b_toolbox_toggle");
      // notify textmarker controller
      glossMarkupItmCtr.setTextMarkingEnabled(true);
      fireEvent(ureq, new Event("glossaryOn"));

    } else if (source == offCommand) {
      // toggle off
      Preferences prefs = ureq.getUserSession().getGuiPreferences();
      prefs.put(CourseGlossaryToolLinkController.class, guiPrefsKey, Boolean.FALSE);
      prefs.save();
      // update gui
      mainVC.remove(offCommand);
      onCommand = LinkFactory.createLink("command.glossary.on", mainVC, this);
      onCommand.setTitle("command.glossary.on.alt");
      onCommand.setCustomEnabledLinkCSS("b_toolbox_toggle");
      // notify textmarker controller
      glossMarkupItmCtr.setTextMarkingEnabled(false);
      fireEvent(ureq, new Event("glossaryOff"));
    } else if (source == mainVC && event.getCommand().equals("command.glossary")) {
      // start glossary in window
      final CourseConfig cc = courseEnvir.getCourseConfig(); // do not cache cc, not save

      // if glossary had been opened from LR as Tab before, warn user:
      DTabs dts = Windows.getWindows(ureq).getWindow(ureq).getDTabs();
      RepositoryEntry repoEntry =
          RepositoryManager.getInstance()
              .lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
      DTab dt = dts.getDTab(repoEntry.getOlatResource());
      if (dt != null) {
        List<ContextEntry> entries =
            BusinessControlFactory.getInstance()
                .createCEListFromResourceType(allowGlossaryEditing ? "true" : "false");
        dts.activate(ureq, dt, entries);
      } else {
        ControllerCreator ctrlCreator =
            new ControllerCreator() {
              public Controller createController(UserRequest lureq, WindowControl lwControl) {
                GlossaryMainController glossaryController =
                    CourseGlossaryFactory.createCourseGlossaryMainRunController(
                        lwControl, lureq, cc, allowGlossaryEditing);
                listenTo(glossaryController);
                if (glossaryController == null) {
                  // happens in the unlikely event of a user who is in a course and
                  // now
                  // tries to access the glossary
                  String text = translate("error.noglossary");
                  return MessageUIFactory.createInfoMessage(lureq, lwControl, null, text);
                } else {
                  // use a one-column main layout
                  LayoutMain3ColsController layoutCtr =
                      new LayoutMain3ColsController(
                          lureq,
                          lwControl,
                          null,
                          null,
                          glossaryController.getInitialComponent(),
                          null);
                  // dispose glossary on layout dispose
                  layoutCtr.addDisposableChildController(glossaryController);
                  return layoutCtr;
                }
              }
            };

        ControllerCreator layoutCtrlr =
            BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator);
        // open in new browser window
        openInNewBrowserWindow(ureq, layoutCtrlr);
        return; // immediate return after opening new browser window!
      }
    }
  }