public void event(UserRequest ureq, Controller source, Event event) {
    if (source == logFileChooserForm) {
      if (event == Event.DONE_EVENT) {
        final boolean logAdminChecked = logFileChooserForm.logAdminChecked();
        final boolean logUserChecked = logFileChooserForm.logUserChecked();
        final boolean logStatisticChecked = logFileChooserForm.logStatChecked();

        final Date begin = logFileChooserForm.getBeginDate();
        final Date end = logFileChooserForm.getEndDate();

        if (end != null) {
          // shift time from beginning to end of day
          end.setTime(end.getTime() + 24 * 60 * 60 * 1000);
        }

        UserManager um = UserManager.getInstance();
        final String charset = um.getUserCharset(ureq.getIdentity());

        ICourse course = CourseFactory.loadCourse(ores);
        final String courseTitle = course.getCourseTitle();
        final String targetDir =
            CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), courseTitle).getPath();

        final Long resId = ores.getResourceableId();
        final Locale theLocale = ureq.getLocale();
        final String email =
            ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());

        AsyncExportManager.getInstance()
            .asyncArchiveCourseLogFiles(
                ureq.getIdentity(),
                new Runnable() {

                  @Override
                  public void run() {
                    showExportFinished();
                  }
                },
                resId,
                targetDir,
                begin,
                end,
                logAdminChecked,
                logUserChecked,
                logStatisticChecked,
                charset,
                theLocale,
                email);

        showExportOngoing(true);
      } else if (event == Event.DONE_EVENT) {
        myPanel.setContent(myContent);
      }
    }
  }
  private void doInsert(UserRequest ureq, TreePosition tp) {
    ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());

    int insertPos = tp.getChildpos();
    CourseNode selectedNode = getCourseNode(tp.getParentTreeNode());
    CourseEditorTreeNode insertParent =
        course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getIdent());

    // check if insert position is within the to-be-copied tree
    if (course.getEditorTreeModel().checkIfIsChild(insertParent, moveCopyFrom)) {
      showError("movecopynode.error.overlap");
      fireEvent(ureq, Event.CANCELLED_EVENT);
    } else if (copy) { // do a copy
      // copy subtree and save model
      recursiveCopy(
          moveCopyFrom,
          insertParent,
          insertPos,
          true,
          CourseFactory.getCourseEditSession(ores.getResourceableId()));
      CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());

      ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_COPIED, getClass());
      fireEvent(ureq, Event.DONE_EVENT);
    } else { // move only
      if (insertParent.getIdent().equals(moveCopyFrom.getParent().getIdent())) {
        // same parent, adjust insertPos
        if (insertPos > moveCopyFrom.getPosition()) insertPos--;
      }
      insertParent.insert(moveCopyFrom, insertPos);

      moveCopyFrom.setDirty(true);
      // mark subtree as dirty
      TreeVisitor tv =
          new TreeVisitor(
              new Visitor() {
                @Override
                public void visit(INode node) {
                  CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
                  cetn.setDirty(true);
                }
              },
              moveCopyFrom,
              true);
      tv.visitAll();
      CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
      showInfo("movecopynode.info.condmoved");

      ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_MOVED, getClass());
      fireEvent(ureq, Event.DONE_EVENT);
    }
  }
  /**
   * 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);
  }
  private void loadModel(UserRequest ureq) {
    IdentityEnvironment identityEnv = ureq.getUserSession().getIdentityEnvironment();

    List<Binder> currentBinders =
        portfolioService.searchOwnedBindersFromCourseTemplate(getIdentity());
    Set<CurrentBinder> currentSet = new HashSet<>();
    for (Binder currentBinder : currentBinders) {
      Long courseEntryKey = currentBinder.getEntry().getKey();
      String nodeIdent = currentBinder.getSubIdent();
      currentSet.add(new CurrentBinder(courseEntryKey, nodeIdent));
    }

    List<RepositoryEntry> entries = portfolioService.searchCourseWithBinderTemplates(getIdentity());
    List<CourseTemplateRow> rows = new ArrayList<>(entries.size());
    for (RepositoryEntry entry : entries) {
      ICourse course = CourseFactory.loadCourse(entry);
      UserCourseEnvironment uce =
          new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
      uce.getScoreAccounting().evaluateAll();

      CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode();
      loadCourseModel(rootNode, uce, rows, currentSet);
    }

    model.setObjects(rows);
    tableEl.reset();
    tableEl.reloadData();
  }
  public MembersManagementMainController(
      UserRequest ureq, WindowControl wControl, RepositoryEntry re) {
    super(ureq, wControl);
    this.repoEntry = re;
    acModule = CoreSpringFactory.getImpl(AccessControlModule.class);
    acService = CoreSpringFactory.getImpl(ACService.class);

    // logging
    getUserActivityLogger().setStickyActionType(ActionType.admin);
    ICourse course = CourseFactory.loadCourse(re.getOlatResource());
    addLoggingResourceable(LoggingResourceable.wrap(course));

    // ui stuff
    menuTree = new MenuTree("menuTree");
    menuTree.setTreeModel(buildTreeModel());
    menuTree.setRootVisible(false);
    menuTree.addListener(this);

    mainVC = createVelocityContainer("main_members");

    columnLayoutCtr =
        new LayoutMain3ColsController(
            ureq, getWindowControl(), menuTree, null, mainVC, "members-" + repoEntry.getKey());
    listenTo(columnLayoutCtr);
    putInitialPanel(columnLayoutCtr.getInitialComponent());

    selectMenuItem(ureq, CMD_MEMBERS);
  }
예제 #6
0
 private AssessableCourseNode getCourseNode() {
   ICourse course = CourseFactory.loadCourse(courseRes);
   CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
   if (node instanceof AssessableCourseNode) {
     return (AssessableCourseNode) node;
   }
   return null;
 }
예제 #7
0
 @Override
 protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
   if (nodeSelections.contains(source)) {
     MultipleSelectionElement nodeSelection = (MultipleSelectionElement) source;
     if (nodeSelection.isMultiselect()) {
       selectRec(nodeSelection, nodeSelection.isSelected(0));
     }
   } else if (source == selectAll) {
     for (MultipleSelectionElement nodeSelection : nodeSelections) {
       if (nodeSelection.isMultiselect() && !nodeSelection.isSelected(0)) {
         SelectNodeObject treeNode = (SelectNodeObject) nodeSelection.getUserObject();
         String id = treeNode.getId();
         nodeSelection.select(id, true);
       }
     }
   } else if (source == deselectAll) {
     for (MultipleSelectionElement nodeSelection : nodeSelections) {
       if (nodeSelection.isMultiselect() && nodeSelection.isSelected(0)) {
         SelectNodeObject treeNode = (SelectNodeObject) nodeSelection.getUserObject();
         String id = treeNode.getId();
         nodeSelection.select(id, false);
       }
     }
   } else if (source == asChild) {
     position = -1;
     ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
     create(rootSelection, course, selectedNode.getCourseNode());
     fireEvent(ureq, Event.CHANGED_EVENT);
   } else if (source == sameLevel) {
     ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
     CourseEditorTreeNode parentNode = (CourseEditorTreeNode) selectedNode.getParent();
     position = 0;
     for (position = parentNode.getChildCount(); position-- > 0; ) {
       if (selectedNode.getIdent().equals(parentNode.getChildAt(position).getIdent())) {
         position++;
         break;
       }
     }
     create(rootSelection, course, parentNode.getCourseNode());
     fireEvent(ureq, Event.CHANGED_EVENT);
   } else {
     super.formInnerEvent(ureq, source, event);
   }
 }
  /**
   * @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)
   */
  public void event(UserRequest ureq, Component source, Event event) {
    if (source == showFileButton) {
      ICourse course = CourseFactory.loadCourse(ores);
      String personalFolderDir = CourseFactory.getPersonalDirectory(ureq.getIdentity()).getPath();
      String targetDir =
          CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), course.getCourseTitle())
              .getPath();

      String relPath = "";

      if (targetDir.startsWith(personalFolderDir)) {
        // that should always be the case

        relPath = targetDir.substring(personalFolderDir.length()).replace("\\", "/");
        targetDir = targetDir.substring(0, personalFolderDir.length());
      }

      VFSContainer targetFolder = new LocalFolderImpl(new File(targetDir));
      FolderRunController bcrun =
          new FolderRunController(targetFolder, true, ureq, getWindowControl());
      Component folderComponent = bcrun.getInitialComponent();
      if (relPath.length() != 0) {
        if (!relPath.endsWith("/")) {
          relPath = relPath + "/";
        }
        bcrun.activatePath(ureq, relPath);
      }

      String personalFolder =
          Util.createPackageTranslator(HomeMainController.class, ureq.getLocale(), null)
              .translate("menu.bc");

      removeAsListenerAndDispose(cmc);
      cmc =
          new CloseableModalController(
              getWindowControl(), translate("close"), folderComponent, true, personalFolder);
      listenTo(cmc);

      cmc.activate();
    }
  }
  protected void showExportFinished() {
    ICourse course = CourseFactory.loadCourse(ores);
    VelocityContainer vcFeedback = createVelocityContainer("courselogs_feedback");
    showFileButton = LinkFactory.createButton("showfile", vcFeedback, this);
    vcFeedback.contextPut("body", translate("course.logs.feedback", course.getCourseTitle()));
    myPanel.setContent(vcFeedback);

    // note: polling can't be switched off unfortunatelly
    //       this is due to the fact that the jsandcsscomponent can only modify
    //       certain parts of the page and it would require a full page refresh
    //       to get rid of the poller - and that's not possible currently

    showInfo("course.logs.finished", course.getCourseTitle());
  }
예제 #10
0
  private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
    if (task == null) {
      log.error("Haven't a task to know creator and modifiers of the task", null);
      return;
    }

    Identity creator = task.getCreator();
    String language = creator.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
    Translator translator =
        Util.createPackageTranslator(
            BulkAssessmentOverviewController.class,
            locale,
            Util.createPackageTranslator(AssessmentManager.class, locale));
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);

    String feedbackStr = renderFeedback(feedbacks, translator);

    MailBundle mail = new MailBundle();
    mail.setToId(creator);
    mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
    List<Identity> modifiers = taskManager.getModifiers(task);
    if (modifiers.size() > 0) {
      ContactList cc = new ContactList("CC");
      cc.addAllIdentites(modifiers);
      mail.setContactList(cc);
    }

    String businessPath = "";
    ICourse course = CourseFactory.loadCourse(courseRes);
    CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
    String courseTitle = course.getCourseTitle();
    String nodeTitle = node.getShortTitle();
    String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
    String date = Formatter.getInstance(locale).formatDateAndTime(new Date());

    mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
    String subject =
        translator.translate("confirmation.mail.subject", new String[] {courseTitle, nodeTitle});
    String body =
        translator.translate(
            "confirmation.mail.body",
            new String[] {courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date});
    mail.setContent(subject, body);
    mailManager.sendMessage(mail);
  }
  public MoveCopySubtreeController(
      UserRequest ureq,
      WindowControl wControl,
      OLATResourceable ores,
      CourseEditorTreeNode moveCopyFrom,
      boolean copy) {
    super(ureq, wControl);
    this.ores = ores;
    this.moveCopyFrom = moveCopyFrom;
    this.copy = copy;

    ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
    addLoggingResourceable(LoggingResourceable.wrap(course));
    addLoggingResourceable(LoggingResourceable.wrap(moveCopyFrom.getCourseNode()));

    insertTree = new MenuTree(null, "copy_node_selection", this);
    insertTree.enableInsertTool(true);
    insertModel = new InsertTreeModel(course.getEditorTreeModel().getRootNode(), moveCopyFrom);
    insertTree.setTreeModel(insertModel);

    VelocityContainer mainVC = createVelocityContainer("moveCopyNode");

    selectButton = LinkFactory.createButton("insertAtSelectedTreepos", mainVC, this);
    selectButton.setCustomEnabledLinkCSS("btn btn-primary");
    selectButton.setCustomDisabledLinkCSS("btn btn-default");
    selectButton.setEnabled(false);
    cancelButton = LinkFactory.createButton("cancel", mainVC, this);

    int numOfNodes = TreeHelper.totalNodeCount(insertModel.getRootNode());
    if (numOfNodes > CourseModule.getCourseNodeLimit()) {
      String msg =
          getTranslator()
              .translate(
                  "warning.containsXXXormore.nodes",
                  new String[] {
                    String.valueOf(numOfNodes),
                    String.valueOf(CourseModule.getCourseNodeLimit() + 1)
                  });
      Controller tmp = MessageUIFactory.createWarnMessage(ureq, wControl, null, msg);
      listenTo(tmp);
      mainVC.put("nodelimitexceededwarning", tmp.getInitialComponent());
    }

    mainVC.put("selection", insertTree);
    putInitialPanel(mainVC);
  }
 private void doEditNodeAssessment(UserRequest ureq, AssessableCourseNode courseNode) {
   if (mayEdit) {
     ICourse course = CourseFactory.loadCourse(ores);
     UserCourseInformationsManager userCourseInformationsManager =
         CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
     Date initialLaunchDate =
         userCourseInformationsManager.getInitialLaunchDate(
             ores.getResourceableId(),
             assessedUserCourseEnvironment.getIdentityEnvironment().getIdentity());
     AssessedIdentityWrapper assessedIdentityWrapper =
         AssessmentHelper.wrapIdentity(
             assessedUserCourseEnvironment, initialLaunchDate, courseNode);
     assessmentEditCtr =
         new AssessmentEditController(
             ureq, getWindowControl(), stackPanel, course, courseNode, assessedIdentityWrapper);
     listenTo(assessmentEditCtr);
     main.setContent(assessmentEditCtr.getInitialComponent());
   } else {
     throw new OLATSecurityException(
         "doEditNodeAssessment() called but controller configured with mayEdit=false");
   }
 }
예제 #13
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();
    }
예제 #14
0
  /**
   * @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)
   */
  public void event(UserRequest ureq, Component source, Event event) {
    if (source == startButton && startButton.isEnabled() && startButton.isVisible()) {
      long courseResId = userCourseEnv.getCourseEnvironment().getCourseResourceableId().longValue();
      String courseNodeIdent = courseNode.getIdent();
      removeAsListenerAndDispose(displayController);

      OLATResourceable ores = OresHelper.createOLATResourceableTypeWithoutCheck("test");
      ThreadLocalUserActivityLogger.addLoggingResourceInfo(
          LoggingResourceable.wrapBusinessPath(ores));
      WindowControl bwControl = addToHistory(ureq, ores, null);
      Controller returnController =
          iqManager.createIQDisplayController(
              modConfig, secCallback, ureq, bwControl, courseResId, courseNodeIdent, this);
      /*
       * either returnController is a MessageController or it is a IQDisplayController
       * this should not serve as pattern to be copy&pasted.
       * FIXME:2008-11-21:pb INTRODUCED because of read/write QTI Lock solution for scalability II, 6.1.x Release
       */
      if (returnController instanceof IQDisplayController) {
        displayController = (IQDisplayController) returnController;
        listenTo(displayController);
        if (displayController.isClosed()) {
          // do nothing
        } else if (displayController.isReady()) {
          // in case displayController was unable to initialize, a message was set by
          // displayController
          // this is the case if no more attempts or security check was unsuccessfull
          displayContainerController =
              new LayoutMain3ColsController(ureq, getWindowControl(), displayController);
          listenTo(displayContainerController); // autodispose

          // need to wrap a course restart controller again, because IQDisplay
          // runs on top of GUIStack
          ICourse course = CourseFactory.loadCourse(courseResId);
          RepositoryEntry courseRepositoryEntry =
              course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
          Panel empty = new Panel("empty"); // empty panel set as "menu" and "tool"
          Controller courseCloser =
              new DisposedCourseRestartController(ureq, getWindowControl(), courseRepositoryEntry);
          Controller disposedRestartController =
              new LayoutMain3ColsController(
                  ureq,
                  getWindowControl(),
                  empty,
                  courseCloser.getInitialComponent(),
                  "disposed course whily in iqRun" + courseResId);
          displayContainerController.setDisposedMessageController(disposedRestartController);

          final boolean fullWindow =
              modConfig.getBooleanSafe(IQEditController.CONFIG_FULLWINDOW, true);
          if (fullWindow) {
            displayContainerController.setAsFullscreen(ureq);
          }
          displayContainerController.activate();

          if (modConfig
              .get(IQEditController.CONFIG_KEY_TYPE)
              .equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
            assessmentStopped = false;
            singleUserEventCenter.registerFor(this, getIdentity(), assessmentInstanceOres);
            singleUserEventCenter.fireEventToListenersOf(
                new AssessmentEvent(AssessmentEvent.TYPE.STARTED, ureq.getUserSession()),
                assessmentEventOres);
          }
        } // endif isReady

      } else {
        // -> qti file was locked -> show info message
        // user must click again on course node to activate
        mainPanel.pushContent(returnController.getInitialComponent());
      }
    } else if (source == showResultsButton) {
      AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
      Long assessmentID = am.getAssessmentID(courseNode, ureq.getIdentity());
      if (assessmentID == null) {
        // fallback solution: if the assessmentID is not available via AssessmentManager than try to
        // get it via IQManager
        long callingResId =
            userCourseEnv.getCourseEnvironment().getCourseResourceableId().longValue();
        String callingResDetail = courseNode.getIdent();
        assessmentID =
            iqManager.getLastAssessmentID(ureq.getIdentity(), callingResId, callingResDetail);
      }
      if (assessmentID != null && !assessmentID.equals("")) {
        Document doc =
            iqManager.getResultsReportingFromFile(ureq.getIdentity(), type, assessmentID);
        // StringBuilder resultsHTML =
        // LocalizedXSLTransformer.getInstance(ureq.getLocale()).renderResults(doc);
        String summaryConfig = (String) modConfig.get(IQEditController.CONFIG_KEY_SUMMARY);
        int summaryType = AssessmentInstance.getSummaryType(summaryConfig);
        String resultsHTML =
            iqManager.transformResultsReporting(doc, ureq.getLocale(), summaryType);
        myContent.contextPut("displayreporting", resultsHTML);
        myContent.contextPut("resreporting", resultsHTML);
        myContent.contextPut("showResults", Boolean.TRUE);
      }
    } else if (source == hideResultsButton) {
      myContent.contextPut("showResults", Boolean.FALSE);
    }
  }
 /**
  * Utility method.<br>
  * Load an instance of <code>ICourse</code> given its numeric resourceable id
  */
 private ICourse loadCourseFromId(Long courseId) {
   return CourseFactory.loadCourse(courseId);
 }
  private void applyChanges(boolean setAsDone) {
    List<AssessmentRow> rows = model.getObjects();
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseResourceableId());
    if (applyToAllEl.isAtLeastSelected(1)) {
      Float score = null;

      if (withScore) {
        String scoreValue = groupScoreEl.getValue();
        if (StringHelper.containsNonWhitespace(scoreValue)) {
          score = Float.parseFloat(scoreValue);
        }
      }

      Boolean passed = null;
      if (withPassed) {
        if (cutValue == null) {
          passed = groupPassedEl.isSelected(0);
        } else if (score != null) {
          passed = (score.floatValue() >= cutValue.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
        }
      }

      for (AssessmentRow row : rows) {
        UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);
        ScoreEvaluation newScoreEval;
        if (setAsDone) {
          newScoreEval = new ScoreEvaluation(score, passed, AssessmentEntryStatus.done, true, null);
        } else {
          newScoreEval = new ScoreEvaluation(score, passed);
        }
        gtaNode.updateUserScoreEvaluation(newScoreEval, userCourseEnv, getIdentity(), false);
      }

      if (withComment) {
        String comment = groupCommentEl.getValue();
        if (StringHelper.containsNonWhitespace(comment)) {
          for (AssessmentRow row : rows) {
            UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);
            gtaNode.updateUserUserComment(comment, userCourseEnv, getIdentity());
          }
        }
      }

    } else {
      for (AssessmentRow row : rows) {
        UserCourseEnvironment userCourseEnv = row.getUserCourseEnvironment(course);

        Float score = null;
        if (withScore) {
          String value = row.getScoreEl().getValue();
          if (StringHelper.containsNonWhitespace(value)) {
            score = Float.parseFloat(value);
          }
        }

        Boolean passed = null;
        if (withPassed) {
          if (cutValue == null) {
            passed = row.getPassedEl().isSelected(0);
          } else if (score != null) {
            passed = (score.floatValue() >= cutValue.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
          }
        }

        ScoreEvaluation newScoreEval;
        if (setAsDone) {
          newScoreEval = new ScoreEvaluation(score, passed, AssessmentEntryStatus.done, true, null);
        } else {
          newScoreEval = new ScoreEvaluation(score, passed);
        }
        gtaNode.updateUserScoreEvaluation(newScoreEval, userCourseEnv, getIdentity(), false);

        if (withComment) {
          String comment = row.getComment();
          if (StringHelper.containsNonWhitespace(comment)) {
            gtaNode.updateUserUserComment(comment, userCourseEnv, getIdentity());
          }
        }
      }
    }
  }
  /** @return True if all results are the same */
  private ModelInfos loadModel() {
    // load participants, load datas
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseResourceableId());
    List<Identity> identities =
        businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());

    Map<Identity, AssessmentEntry> identityToEntryMap = new HashMap<>();
    List<AssessmentEntry> entries =
        course
            .getCourseEnvironment()
            .getAssessmentManager()
            .getAssessmentEntries(assessedGroup, gtaNode);
    for (AssessmentEntry entry : entries) {
      identityToEntryMap.put(entry.getIdentity(), entry);
    }

    int count = 0;
    boolean same = true;
    StringBuilder duplicateWarning = new StringBuilder();
    Float scoreRef = null;
    Boolean passedRef = null;
    String commentRef = null;

    List<AssessmentRow> rows = new ArrayList<>(identities.size());
    for (Identity identity : identities) {
      AssessmentEntry entry = identityToEntryMap.get(identity);

      ScoreEvaluation scoreEval = null;
      if (withScore || withPassed) {
        scoreEval = gtaNode.getUserScoreEvaluation(entry);
        if (scoreEval == null) {
          scoreEval = ScoreEvaluation.EMPTY_EVALUATION;
        }
      }

      String comment = null;
      if (withComment && entry != null) {
        comment = entry.getComment();
      }

      boolean duplicate = duplicateMemberKeys.contains(identity.getKey());
      if (duplicate) {
        if (duplicateWarning.length() > 0) duplicateWarning.append(", ");
        duplicateWarning.append(StringHelper.escapeHtml(userManager.getUserDisplayName(identity)));
      }

      AssessmentRow row = new AssessmentRow(identity, duplicate);
      rows.add(row);

      if (withScore) {
        Float score = scoreEval.getScore();
        String pointVal = AssessmentHelper.getRoundedScore(score);
        TextElement pointEl = uifactory.addTextElement("point" + count, null, 5, pointVal, flc);
        pointEl.setDisplaySize(5);
        row.setScoreEl(pointEl);
        if (count == 0) {
          scoreRef = score;
        } else if (!same(scoreRef, score)) {
          same = false;
        }
      }

      if (withPassed && cutValue == null) {
        Boolean passed = scoreEval.getPassed();
        MultipleSelectionElement passedEl =
            uifactory.addCheckboxesHorizontal("check" + count, null, flc, onKeys, onValues);
        if (passed != null && passed.booleanValue()) {
          passedEl.select(onKeys[0], passed.booleanValue());
        }
        row.setPassedEl(passedEl);
        if (count == 0) {
          passedRef = passed;
        } else if (!same(passedRef, passed)) {
          same = false;
        }
      }

      if (withComment) {
        FormLink commentLink =
            uifactory.addFormLink(
                "comment-" + CodeHelper.getRAMUniqueID(),
                "comment",
                "comment",
                null,
                flc,
                Link.LINK);
        if (StringHelper.containsNonWhitespace(comment)) {
          commentLink.setIconLeftCSS("o_icon o_icon_comments");
        } else {
          commentLink.setIconLeftCSS("o_icon o_icon_comments_none");
        }
        commentLink.setUserObject(row);
        row.setComment(comment);
        row.setCommentEditLink(commentLink);

        if (count == 0) {
          commentRef = comment;
        } else if (!same(commentRef, comment)) {
          same = false;
        }
      }

      count++;
    }

    model.setObjects(rows);
    table.reset();

    return new ModelInfos(same, scoreRef, passedRef, commentRef, duplicateWarning.toString());
  }
예제 #18
0
  private void appendCourseCalendars(
      UserRequest ureq,
      WindowControl wControl,
      List<KalendarRenderWrapper> calendars,
      Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar()
        || calendarModule.isEnableCourseToolCalendar()) {

      // add course calendars
      List<Object[]> resources = getCourses(ureq.getIdentity());
      Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());

      Set<Long> duplicates = new HashSet<>();

      for (Object[] resource : resources) {
        RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
        if (duplicates.contains(courseEntry.getKey())) {
          continue;
        }
        duplicates.add(courseEntry.getKey());

        String role = (String) resource[1];
        Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
        try {
          ICourse course = CourseFactory.loadCourse(courseEntry);
          if (isCourseCalendarEnabled(course)) {
            // calendar course aren't enabled per default but course node of type calendar are
            // always possible
            // REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled())
            // continue;
            // add course calendar
            KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
            boolean isPrivileged =
                GroupRoles.owner.name().equals(role)
                    || editoredResources.contains(courseEntry.getOlatResource());
            if (isPrivileged) {
              courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
            } else {
              courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
            }

            if (role != null
                && (GroupRoles.owner.name().equals(role)
                    || GroupRoles.coach.name().equals(role)
                    || GroupRoles.participant.name().equals(role))) {
              courseCalendarWrapper.setPrivateEventsVisible(true);
            }

            CalendarUserConfiguration config =
                configMap.get(courseCalendarWrapper.getCalendarKey());
            if (config != null) {
              courseCalendarWrapper.setConfiguration(config);
            }
            courseCalendarWrapper.setLinkProvider(
                new CourseLinkProviderController(
                    course, Collections.singletonList(course), ureq, wControl));
            calendars.add(courseCalendarWrapper);
          }
        } catch (CorruptedCourseException e) {
          OLATResource olatResource = courseEntry.getOlatResource();
          log.error(
              "Corrupted course: "
                  + olatResource.getResourceableTypeName()
                  + " :: "
                  + courseResourceableID,
              null);
        }
      }
    }
  }
예제 #19
0
  private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
    final DB dbInstance = DBFactory.getInstance();
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
    final ICourse course = CourseFactory.loadCourse(courseRes);
    final AssessableCourseNode courseNode = getCourseNode();
    final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);

    final boolean hasUserComment = courseNode.hasCommentConfigured();
    final boolean hasScore = courseNode.hasScoreConfigured();
    final boolean hasPassed = courseNode.hasPassedConfigured();
    final boolean hasReturnFiles =
        (StringHelper.containsNonWhitespace(datas.getReturnFiles())
            && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));

    if (hasReturnFiles) {
      try {
        OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
        String tmp = FolderConfig.getCanonicalTmpDir();
        unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
        unzipped.mkdirs();
        ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
      } catch (Exception e) {
        log.error("Cannot unzip the return files during bulk assessment", e);
      }
    }

    Float min = null;
    Float max = null;
    Float cut = null;
    if (hasScore) {
      min = courseNode.getMinScoreConfiguration();
      max = courseNode.getMaxScoreConfiguration();
    }
    if (hasPassed) {
      cut = courseNode.getCutValueConfiguration();
    }

    int count = 0;
    List<BulkAssessmentRow> rows = datas.getRows();
    for (BulkAssessmentRow row : rows) {
      Long identityKey = row.getIdentityKey();
      if (identityKey == null) {
        feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
        continue; // nothing to do
      }

      Identity identity = securityManager.loadIdentityByKey(identityKey);
      IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
      UserCourseEnvironment uce =
          new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());

      // update comment, empty string will reset comment
      String userComment = row.getComment();
      if (hasUserComment && userComment != null) {
        // Update userComment in db
        courseNode.updateUserUserComment(userComment, uce, coachIdentity);
        // LD: why do we have to update the efficiency statement?
        // EfficiencyStatementManager esm =	EfficiencyStatementManager.getInstance();
        // esm.updateUserEfficiencyStatement(uce);
      }

      // update score
      Float score = row.getScore();
      if (hasScore && score != null) {
        // score < minimum score
        if ((min != null && score.floatValue() < min.floatValue())
            || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
          // "bulk.action.lessThanMin";
        }
        // score > maximum score
        else if ((max != null && score.floatValue() > max.floatValue())
            || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
          // "bulk.action.greaterThanMax";
        } else {
          // score between minimum and maximum score
          ScoreEvaluation se;
          if (hasPassed && cut != null) {
            Boolean passed =
                (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
            se = new ScoreEvaluation(score, passed);
          } else {
            se = new ScoreEvaluation(score, null);
          }

          // Update score,passed properties in db, and the user's efficiency statement
          courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false);
        }
      }

      Boolean passed = row.getPassed();
      if (hasPassed
          && passed != null
          && cut
              == null) { // Configuration of manual assessment --> Display passed/not passed: yes,
        // Type of display: Manual by tutor
        ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
        Float oldScore = seOld.getScore();
        ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
        // Update score,passed properties in db, and the user's efficiency statement
        boolean incrementAttempts = false;
        courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts);
      }

      boolean identityHasReturnFile = false;
      if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
        String assessedId = row.getAssessedId();
        File assessedFolder = new File(unzipped, assessedId);
        identityHasReturnFile = assessedFolder.exists();
        if (identityHasReturnFile) {
          processReturnFile(courseNode, row, uce, assessedFolder);
        }
      }

      if (courseNode instanceof GTACourseNode) {
        // push the state further
        GTACourseNode gtaNode = (GTACourseNode) courseNode;
        if ((hasScore && score != null) || (hasPassed && passed != null)) {
          // pushed to graded
          updateTasksState(gtaNode, uce, TaskProcess.grading);
        } else if (hasReturnFiles) {
          // push to revised
          updateTasksState(gtaNode, uce, TaskProcess.correction);
        }
      }

      if (count++ % 5 == 0) {
        dbInstance.commitAndCloseSession();
      } else {
        dbInstance.commit();
      }
    }
  }