use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class NavigationHandler method doEvaluateJumpTo.
private NodeClickedRef doEvaluateJumpTo(UserRequest ureq, WindowControl wControl, CourseNode courseNode, ControllerEventListener listeningController, String nodecmd, String nodeSubCmd, Controller currentNodeController) {
NodeClickedRef nclr;
if (log.isDebug()) {
log.debug("evaluateJumpTo courseNode = " + courseNode.getIdent() + ", " + courseNode.getShortName());
}
// build the new treemodel by evaluating the preconditions
TreeEvaluation treeEval = new TreeEvaluation();
GenericTreeModel treeModel = new GenericTreeModel();
CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
TreeNode treeRoot = rootNodeEval.getTreeNode();
treeModel.setRootNode(treeRoot);
// find the treenode that corresponds to the node (!= selectedTreeNode since
// we built the TreeModel anew in the meantime
TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
if (newCalledTreeNode == null) {
// the clicked node is not visible anymore!
// if the new calculated model does not contain the selected node anymore
// (because of visibility changes of at least one of the ancestors
// -> issue an user infomative msg
// nclr: the new treemodel, not visible, no selected nodeid, no
// calledcoursenode, no nodeconstructionresult
nclr = new NodeClickedRef(treeModel, false, null, null, null, null, false);
} else {
// calculate the NodeClickedRef
// 1. get the correct (new) nodeevaluation
NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
if (nodeEval.getCourseNode() != courseNode) {
throw new AssertException("error in structure");
}
if (!nodeEval.isVisible()) {
throw new AssertException("node eval not visible!!");
}
// 2. start with the current NodeEvaluation, evaluate overall accessiblity
// per node bottom-up to see if all ancestors still grant access to the
// desired node
boolean mayAccessWholeTreeUp = mayAccessWholeTreeUp(nodeEval);
String newSelectedNodeId = newCalledTreeNode.getIdent();
Controller controller;
AdditionalConditionManager addMan = null;
if (courseNode instanceof AbstractAccessableCourseNode) {
Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
CourseNodePasswordManager cnpm = CourseNodePasswordManagerImpl.getInstance();
Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
AdditionalConditionAnswerContainer answerContainer = cnpm.getAnswerContainer(identity);
addMan = new AdditionalConditionManager((AbstractAccessableCourseNode) courseNode, courseId, answerContainer);
}
if (!mayAccessWholeTreeUp || (addMan != null && !addMan.evaluateConditions())) {
if (nodeEval.oldStyleConditionsOk()) {
controller = addMan.nextUserInputController(ureq, wControl, userCourseEnv);
if (listeningController != null) {
controller.addControllerListener(listeningController);
}
} else {
// NOTE: we do not take into account what node caused the non-access by
// being !isAtLeastOneAccessible, but always state the
// NoAccessExplanation of the Node originally called by the user
String explan = courseNode.getNoAccessExplanation();
String sExplan = (explan == null ? "" : Formatter.formatLatexFormulas(explan));
controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, sExplan);
// write log information
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_NO_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
}
NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
// nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
// nodeconstructionresult
nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
} else if (!CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).isEnabled()) {
Translator pT = Util.createPackageTranslator(EditorMainController.class, ureq.getLocale());
controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, pT.translate("course.building.block.disabled.user"));
NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
} else {
if (STCourseNode.isDelegatingSTCourseNode(courseNode) && (courseNode.getChildCount() > 0)) {
// the clicked node is a STCourse node and is set to "delegate", so
// delegate to its first visible child; if no child is visible, just skip and do normal eval
INode child;
for (int i = 0; i < courseNode.getChildCount(); i++) {
child = courseNode.getChildAt(i);
if (child instanceof CourseNode) {
CourseNode cn = (CourseNode) child;
NodeEvaluation cnEval = cn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
if (cnEval.isVisible()) {
return doEvaluateJumpTo(ureq, wControl, cn, listeningController, nodecmd, nodeSubCmd, currentNodeController);
}
}
}
}
// access the node, display its result in the right pane
NodeRunConstructionResult ncr;
// calculate the new businesscontext for the coursenode being called.
// type: class of node; key = node.getIdent;
// don't use the concrete instance since for the course: to jump to a coursenode with a given id is all there is to know
Class<CourseNode> oresC = CourseNode.class;
Long oresK = new Long(Long.parseLong(courseNode.getIdent()));
final OLATResourceable ores = OresHelper.createOLATResourceableInstance(oresC, oresK);
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
if (previewMode) {
ncr = new NodeRunConstructionResult(courseNode.createPreviewController(ureq, bwControl, userCourseEnv, nodeEval));
} else {
// cleanup already existing controllers with external models for this node first, never disposed otherwise
if (externalTreeModels.containsKey(courseNode.getIdent()) && !(TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd))) {
SubTree subTree = externalTreeModels.get(courseNode.getIdent());
ControllerEventListener existingSubtreemodelListener = subTree.getTreeModelListener();
if (existingSubtreemodelListener != null && currentNodeController != null && !currentNodeController.isDisposed()) {
currentNodeController.dispose();
}
}
ncr = courseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, nodeEval, nodecmd);
// remember as instance variable for next click
ControllerEventListener subtreemodelListener = ncr.getSubTreeListener();
if (subtreemodelListener != null) {
GenericTreeModel subTreeModel = (GenericTreeModel) ncr.getSubTreeModel();
externalTreeModels.put(courseNode.getIdent(), new SubTree(ncr.getRunController(), subTreeModel, subtreemodelListener));
if (!newSelectedNodeId.equals(ncr.getSelectedTreeNodeId())) {
if (ncr.getSelectedTreeNodeId() != null) {
TreeNode selectedNode = subTreeModel.getNodeById(ncr.getSelectedTreeNodeId());
if (selectedNode != null && selectedNode.getUserObject() instanceof String) {
openCourseNodeIds.add((String) selectedNode.getUserObject());
}
}
}
}
}
if (TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd)) {
openCourseNodeIds.add(courseNode.getIdent());
newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
} else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) {
removeChildrenFromOpenNodes(courseNode);
newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
if (!isInParentLine(courseNode)) {
selectedCourseNodeId = courseNode.getIdent();
} else {
selectedCourseNodeId = null;
newSelectedNodeId = null;
}
} else {
// add the selected node to the open one, if not, strange behaviour
selectedCourseNodeId = courseNode.getIdent();
openCourseNodeIds.add(selectedCourseNodeId);
if (ncr != null) {
String subNodeId = ncr.getSelectedTreeNodeId();
if (subNodeId != null) {
openCourseNodeIds.add(subNodeId);
}
}
}
openTreeNodeIds = convertToTreeNodeIds(treeEval, openCourseNodeIds);
reattachExternalTreeModels(treeEval);
if ((TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) && currentNodeController != null && !currentNodeController.isDisposed()) {
nclr = new NodeClickedRef(treeModel, true, null, openTreeNodeIds, null, null, false);
} else {
// nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
// nodeconstructionresult
nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, openTreeNodeIds, courseNode, ncr, false);
// attach listener; we know we have a runcontroller here
if (listeningController != null) {
nclr.getRunController().addControllerListener(listeningController);
}
}
// write log information
ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
}
}
return nclr;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class TaskFolderCallback method sendNotificationEmail.
private void sendNotificationEmail(UserRequest ureq, MailTemplate mailTemplate, List<Identity> recipients) {
// send the notification mail
if (mailTemplate != null) {
Identity sender = ureq.getIdentity();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
String metaId = UUID.randomUUID().toString().replace("-", "");
MailBundle[] bundles = mailManager.makeMailBundles(context, recipients, mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, sender, mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class TaskFolderCallback method removeAssignedTask.
/**
* Cancel the task assignment for this task and all Identities.
* @param course
* @param task
* @return Returns the Identities list that have had this task assigned.
*/
private List<Identity> removeAssignedTask(ICourse course, String task) {
// identities to be notified
List<Identity> identityList = new ArrayList<Identity>();
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
List<Property> properties = cpm.listCourseNodeProperties(node, null, null, TaskController.PROP_ASSIGNED);
if (properties != null && properties.size() > 0) {
for (Object propetyObj : properties) {
Property propety = (Property) propetyObj;
identityList.add(propety.getIdentity());
cpm.deleteProperty(propety);
}
}
return identityList;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertAssessmentDatas.
private void convertAssessmentDatas(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
CourseEnvironment courseEnv = course.getCourseEnvironment();
CoursePropertyManager propertyMgr = courseEnv.getCoursePropertyManager();
Map<Long, AssessmentEntry> datas = new HashMap<>();
List<AssessmentEntry> properties = courseEnv.getAssessmentManager().getAssessmentEntries(sourceNode);
for (AssessmentEntry property : properties) {
Identity identity = property.getIdentity();
datas.put(identity.getKey(), property);
}
properties = null;
DBFactory.getInstance().getCurrentEntityManager().clear();
AssessmentManager assessmentMgr = courseEnv.getAssessmentManager();
for (AssessmentEntry assessmentData : datas.values()) {
Identity assessedIdentity = securityManager.loadIdentityByKey(assessmentData.getIdentity().getKey());
if (assessmentData.getPassed() != null || assessmentData.getScore() != null) {
UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
Float score = assessmentData.getScore() == null ? null : assessmentData.getScore().floatValue();
ScoreEvaluation scoreEval = new ScoreEvaluation(score, assessmentData.getPassed());
assessmentMgr.saveScoreEvaluation(gtaNode, null, assessedIdentity, scoreEval, userCourseEnv, false, Role.auto);
// set graded
Task task = gtaManager.getTask(assessedIdentity, taskList);
if (task == null) {
gtaManager.createTask(null, taskList, TaskProcess.graded, null, assessedIdentity, gtaNode);
} else {
gtaManager.updateTask(task, TaskProcess.graded, gtaNode, Role.auto);
}
}
if (assessmentData.getAttempts() != null) {
assessmentMgr.saveNodeAttempts(gtaNode, null, assessedIdentity, assessmentData.getAttempts().intValue(), Role.auto);
}
if (StringHelper.containsNonWhitespace(assessmentData.getCoachComment())) {
assessmentMgr.saveNodeCoachComment(gtaNode, assessedIdentity, assessmentData.getCoachComment());
}
if (StringHelper.containsNonWhitespace(assessmentData.getComment())) {
assessmentMgr.saveNodeComment(gtaNode, null, assessedIdentity, assessmentData.getComment());
}
}
DBFactory.getInstance().getCurrentEntityManager().clear();
// copy log entries
List<Property> logEntries = propertyMgr.listCourseNodeProperties(sourceNode, null, null, UserNodeAuditManager.LOG_IDENTIFYER);
for (Property logEntry : logEntries) {
String logText = logEntry.getTextValue();
Identity identity = securityManager.loadIdentityByKey(logEntry.getIdentity().getKey());
Property targetProp = propertyMgr.findCourseNodeProperty(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER);
if (targetProp == null) {
targetProp = propertyMgr.createCourseNodePropertyInstance(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER, null, null, null, logText);
} else {
targetProp.setTextValue(logText);
}
propertyMgr.saveProperty(targetProp);
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertDropbox.
private void convertDropbox(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, CourseEnvironment courseEnv) {
String dropbox = DropboxController.getDropboxPathRelToFolderRoot(courseEnv, sourceNode);
OlatRootFolderImpl dropboxContainer = new OlatRootFolderImpl(dropbox, null);
for (VFSItem userDropbox : dropboxContainer.getItems()) {
if (userDropbox instanceof VFSContainer) {
VFSContainer userDropContainer = (VFSContainer) userDropbox;
String username = userDropContainer.getName();
Identity assessedIdentity = securityManager.findIdentityByName(username);
if (assessedIdentity != null) {
VFSContainer sumbitContainer = gtaManager.getSubmitContainer(courseEnv, gtaNode, assessedIdentity);
boolean dropped = false;
for (VFSItem dropppedItem : userDropContainer.getItems()) {
if (dropppedItem instanceof VFSLeaf) {
VFSLeaf submittedDocument = sumbitContainer.createChildLeaf(dropppedItem.getName());
VFSManager.copyContent((VFSLeaf) dropppedItem, submittedDocument);
convertMetada(userDropContainer, sumbitContainer, dropppedItem.getName(), null, null);
dropped = true;
}
}
if (dropped) {
setTaskStatus(taskList, assessedIdentity, TaskProcess.submit, gtaNode);
}
}
}
}
}
Aggregations