use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.
the class EPFrontendManager method submitMap.
private void submitMap(PortfolioStructureMap map, boolean logActivity, Role by) {
// add an exception
if (!(map instanceof EPStructuredMap))
return;
EPStructuredMap submittedMap = (EPStructuredMap) map;
structureManager.submitMap(submittedMap);
EPTargetResource resource = submittedMap.getTargetResource();
OLATResourceable courseOres = resource.getOLATResourceable();
ICourse course = CourseFactory.loadCourse(courseOres);
AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
CourseNode courseNode = course.getRunStructure().getNode(resource.getSubPath());
List<Identity> owners = policyManager.getOwners(submittedMap);
for (Identity owner : owners) {
if (courseNode != null) {
// courseNode might have been deleted meanwhile
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(owner);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
if (logActivity) {
am.incrementNodeAttempts(courseNode, owner, uce, by);
} else {
am.incrementNodeAttemptsInBackground(courseNode, owner, uce);
}
RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
assessmentService.updateAssessmentEntry(owner, courseEntry, courseNode.getIdent(), referenceEntry, AssessmentEntryStatus.inReview);
}
assessmentNotificationsHandler.markPublisherNews(owner, course.getResourceableId());
log.audit("Map " + map + " from " + owner.getName() + " has been submitted.");
}
}
use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.
the class UserFoldersWebService method getFolders.
/**
* Retrieves a list of folders on a user base. All folders of groups
* where the user is participant/tutor + all folders in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}folderVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The folders
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param identityKey The key of the user (IdentityImpl)
* @param httpRequest The HTTP request
* @return The folders
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
Roles roles;
Identity ureqIdentity = getIdentity(httpRequest);
if (ureqIdentity == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identity.getKey().equals(ureqIdentity.getKey())) {
if (isAdmin(httpRequest)) {
ureqIdentity = identity;
roles = BaseSecurityManager.getInstance().getRoles(identity);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, sub.getPublisher().getResId());
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<String>());
}
courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
}
}
}
final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<String> nodeKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
if (nodeKeys.contains(bcNode.getIdent())) {
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
}
}, new VisibleTreeFilter());
}
/*
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
for(RepositoryEntry entry:entries) {
AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
if(result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if(node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode)node;
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
params.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : groups) {
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
FolderVO folderVo = new FolderVO();
folderVo.setName(group.getName());
folderVo.setGroupKey(group.getKey());
folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
folderVo.setRead(container.getLocalSecurityCallback().canRead());
folderVo.setList(container.getLocalSecurityCallback().canList());
folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
folderVOs.add(folderVo);
}
FolderVOes voes = new FolderVOes();
voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
voes.setTotalCount(folderVOs.size());
return Response.ok(voes).build();
}
use of org.olat.core.id.IdentityEnvironment in project OpenOLAT by OpenOLAT.
the class CheckListCourseNode method updateScorePassedOnPublish.
private void updateScorePassedOnPublish(Identity assessedIdentity, Identity coachIdentity, CheckboxManager checkboxManager, ICourse course) {
AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
Float currentScore = am.getNodeScore(this, assessedIdentity);
Boolean currentPassed = am.getNodePassed(this, assessedIdentity);
Float updatedScore = null;
Boolean updatedPassed = null;
ModuleConfiguration config = getModuleConfiguration();
Boolean scoreGrantedBool = (Boolean) config.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
if (scoreGrantedBool != null && scoreGrantedBool.booleanValue()) {
updatedScore = checkboxManager.calculateScore(assessedIdentity, course, getIdent());
} else {
updatedScore = null;
}
Boolean passedBool = (Boolean) config.get(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD);
if (passedBool != null && passedBool.booleanValue()) {
Float cutValue = (Float) config.get(MSCourseNode.CONFIG_KEY_PASSED_CUT_VALUE);
Boolean sumCheckbox = (Boolean) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_SUM_CHECKBOX);
if (sumCheckbox != null && sumCheckbox.booleanValue()) {
Integer minValue = (Integer) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_SUM_CUTVALUE);
int checkedBox = checkboxManager.countChecked(assessedIdentity, course, getIdent());
if (minValue != null && minValue.intValue() <= checkedBox) {
updatedPassed = Boolean.TRUE;
} else {
updatedPassed = Boolean.FALSE;
}
} else if (cutValue != null) {
if (updatedScore == null) {
updatedScore = checkboxManager.calculateScore(assessedIdentity, course, getIdent());
}
if (updatedScore != null && cutValue.floatValue() <= updatedScore.floatValue()) {
updatedPassed = Boolean.TRUE;
} else {
updatedPassed = Boolean.FALSE;
}
}
} else {
updatedPassed = null;
}
boolean needUpdate = false;
Boolean manualCorrection = (Boolean) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_MANUAL_CORRECTION);
if (manualCorrection == null || !manualCorrection.booleanValue()) {
// update passed
if ((currentPassed == null && updatedPassed != null && updatedScore != null && updatedScore.floatValue() > 0f) || (currentPassed != null && updatedPassed == null) || (currentPassed != null && !currentPassed.equals(updatedPassed))) {
needUpdate = true;
}
}
if ((currentScore == null && updatedScore != null && updatedScore.floatValue() > 0f) || (currentScore != null && updatedScore == null) || (currentScore != null && !currentScore.equals(updatedScore))) {
needUpdate = true;
}
if (needUpdate) {
ScoreEvaluation scoreEval = new ScoreEvaluation(updatedScore, updatedPassed);
IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, null);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
am.saveScoreEvaluation(this, coachIdentity, assessedIdentity, scoreEval, uce, false, Role.coach);
}
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class UserSessionManager method internSignOffAndClear.
private void internSignOffAndClear(UserSession usess) {
boolean isDebug = log.isDebug();
if (isDebug)
log.debug("signOffAndClear() START");
signOffAndClearWithout(usess);
// handle safely
try {
if (usess.isAuthenticated()) {
SessionInfo sessionInfo = usess.getSessionInfo();
IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
Identity identity = identityEnvironment.getIdentity();
log.audit("Logged off: " + sessionInfo);
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, false), ORES_USERSESSION);
if (isDebug)
log.debug("signOffAndClear() deregistering usersession from eventbus, id=" + sessionInfo);
// fxdiff FXOLAT-231: event on GUI Preferences extern changes
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Preferences.class, identity.getKey());
CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(usess, ores);
}
} catch (Exception e) {
log.error("exception in signOffAndClear: while sending signonoffevent!", e);
}
// clear all instance variables, set authenticated to false
usess.init();
if (isDebug)
log.debug("signOffAndClear() END");
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class EvalAttributeFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 2) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.providetwo.attrvalue"));
} else if (inStack.length < 2) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.providetwo.attrvalue"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attributename", "solution.example.name.infunction"));
if (!(inStack[1] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.attribvalue", "solution.example.name.infunction"));
String attributeId = (String) inStack[0];
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
// remember the reference to the attribute for this condtion
cev.addSoftReference("attribute", attributeId, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
String attName = (String) inStack[0];
String attValue = (String) inStack[1];
IdentityEnvironment ienv = getUserCourseEnv().getIdentityEnvironment();
Identity ident = ienv.getIdentity();
Map<String, String> attributes = ienv.getAttributes();
if (attributes == null)
return ConditionInterpreter.INT_FALSE;
String value = attributes.get(attName);
boolean match = false;
boolean debug = log.isDebug();
if (debug) {
log.debug("value : " + value);
log.debug("attrValue: " + attValue);
log.debug("fT : " + functionType);
}
if (value != null) {
if (functionType <= FUNCTION_TYPE_IS_NOT_IN_ATTRIBUTE) {
match = findExpressionInMultiValue(attValue, value, functionType);
} else if (functionType == FUNCTION_TYPE_HAS_NOT_ATTRIBUTE) {
match = !findExpressionInMultiValue(attValue, value, FUNCTION_TYPE_HAS_ATTRIBUTE);
}
}
if (debug) {
log.debug("identity '" + ident.getName() + "' tested on attribute '" + attName + "' to have value '" + attValue + "' user's value was '" + value + "', match=" + match);
}
return match ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
Aggregations