use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class MyForumsWebService method getForums.
/**
* Retrieves a list of forums on a user base. All forums of groups
* where the user is participant/tutor + all forums in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}forumVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The forums
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
* @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 forums
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
Roles roles;
Identity retrievedUser = getIdentity(httpRequest);
if (retrievedUser == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identityKey.equals(retrievedUser.getKey())) {
if (isAdmin(httpRequest)) {
retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
Map<Long, Long> groupNotified = new HashMap<Long, Long>();
Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
final Set<Long> subscriptions = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subscriptions.add(forumKey);
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, forumKey);
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<Long>());
}
courseNotified.get(courseKey).add(forumKey);
}
}
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<Long> forumKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
if (forumKeys.contains(forumVo.getForumKey())) {
forumVOs.add(forumVo);
}
}
}
}, 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 FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode)node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
forumVOs.add(forumVo);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
params.addTools(CollaborationTools.TOOL_FORUM);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
// list forum keys
List<Long> groupIds = new ArrayList<Long>();
Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
for (BusinessGroup group : groups) {
if (groupNotified.containsKey(group.getKey())) {
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(groupNotified.get(group.getKey()));
forumVo.setSubscribed(true);
forumVOs.add(forumVo);
groupIds.remove(group.getKey());
} else {
groupIds.add(group.getKey());
groupsMap.put(group.getKey(), group);
}
}
PropertyManager pm = PropertyManager.getInstance();
List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
for (Property prop : forumProperties) {
Long forumKey = prop.getLongValue();
if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(prop.getLongValue());
forumVo.setSubscribed(false);
forumVOs.add(forumVo);
}
}
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class ViteroUserToGroupController method getIdentitiesInResource.
private ResourceMembers getIdentitiesInResource(ViteroGroupRoles groupRoles) {
Set<Identity> owners = new HashSet<Identity>();
Set<Identity> coaches = new HashSet<Identity>();
Set<Identity> participants = new HashSet<Identity>();
Set<Identity> selfParticipants = new HashSet<Identity>();
if (group != null) {
owners.addAll(businessGroupService.getMembers(group, GroupRoles.coach.name()));
participants.addAll(businessGroupService.getMembers(group, GroupRoles.participant.name()));
} else {
RepositoryEntry repoEntry = repositoryManager.lookupRepositoryEntry(ores, false);
if ("CourseModule".equals(ores.getResourceableTypeName())) {
if (courseGroupManager == null) {
ICourse course = CourseFactory.loadCourse(repoEntry);
courseGroupManager = course.getCourseEnvironment().getCourseGroupManager();
}
coaches.addAll(courseGroupManager.getCoachesFromAreas());
coaches.addAll(courseGroupManager.getCoachesFromBusinessGroups());
participants.addAll(courseGroupManager.getParticipantsFromAreas());
participants.addAll(courseGroupManager.getParticipantsFromBusinessGroups());
}
List<Identity> repoOwners = repositoryService.getMembers(repoEntry, GroupRoles.owner.name());
owners.addAll(repoOwners);
List<Identity> repoParticipants = repositoryService.getMembers(repoEntry, GroupRoles.participant.name());
participants.addAll(repoParticipants);
List<Identity> repoTutors = repositoryService.getMembers(repoEntry, GroupRoles.coach.name());
coaches.addAll(repoTutors);
}
// add all self signed participants
if (booking.isAutoSignIn()) {
List<String> emailsOfParticipants = new ArrayList<>(groupRoles.getEmailsOfParticipants());
// remove owners, coaches and already participating users
for (Identity owner : owners) {
emailsOfParticipants.remove(owner.getUser().getProperty(UserConstants.EMAIL, null));
}
for (Identity coach : coaches) {
emailsOfParticipants.remove(coach.getUser().getProperty(UserConstants.EMAIL, null));
}
for (Identity participant : participants) {
emailsOfParticipants.remove(participant.getUser().getProperty(UserConstants.EMAIL, null));
}
if (!emailsOfParticipants.isEmpty()) {
List<Identity> selfSignedParticipants = UserManager.getInstance().findIdentitiesByEmail(emailsOfParticipants);
selfParticipants.addAll(selfSignedParticipants);
}
}
return new ResourceMembers(owners, coaches, participants, selfParticipants);
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class FeedNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
String title;
try {
RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
if ("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if (node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
} else {
title = getHeader(translator, displayName);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
return notificationsManager.getNoSubscriptionInfo();
}
OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
Feed feed = feedManager.loadFeed(feedOres);
List<Item> listItems = feedManager.loadItems(feed);
List<SubscriptionListItem> items = new ArrayList<>();
for (Item item : listItems) {
if (!item.isDraft()) {
appendSubscriptionItem(item, p, compareDate, translator, items);
}
}
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
} else {
// no news
si = notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Unknown Exception", e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseAssessmentWebService method getCourseNodeResultsForNode.
/**
* Returns the results of a student at a specific assessable node
* @response.representation.200.qname {http://www.example.com}assessableResultsVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The result of a user at a specific node
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_ASSESSABLERESULTSVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity or the course not found
* @param courseId The course resourceable's id
* @param nodeId The ident of the course building block
* @param identityKey The id of the user
* @param httpRequest The HTTP request
* @param request The REST request
* @return
*/
@GET
@Path("{nodeId}/users/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseNodeResultsForNode(@PathParam("courseId") Long courseId, @PathParam("nodeId") Long nodeId, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest, @Context Request request) {
if (!RestSecurityHelper.isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
try {
Identity userIdentity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (userIdentity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
AssessableResultsVO results = getNodeResult(userIdentity, course, nodeId);
if (results.getLastModifiedDate() != null) {
Response.ResponseBuilder response = request.evaluatePreconditions(results.getLastModifiedDate());
if (response != null) {
return response.build();
}
return Response.ok(results).lastModified(results.getLastModifiedDate()).cacheControl(cc).build();
}
return Response.ok(results).build();
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseAssessmentWebService method attachAssessableResults.
private void attachAssessableResults(Long courseResourceableId, String nodeKey, Identity requestIdentity, AssessableResultsVO resultsVO) {
try {
ICourse course = CourseFactory.openCourseEditSession(courseResourceableId);
CourseNode node = getParentNode(course, nodeKey);
if (!(node instanceof AssessableCourseNode)) {
throw new IllegalArgumentException("The supplied node key does not refer to an AssessableCourseNode");
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity userIdentity = securityManager.loadIdentityByKey(resultsVO.getIdentityKey());
// create an identenv with no roles, no attributes, no locale
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(userIdentity);
UserCourseEnvironment userCourseEnvironment = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
// Fetch all score and passed and calculate score accounting for the
// entire course
userCourseEnvironment.getScoreAccounting().evaluateAll();
if (node instanceof IQTESTCourseNode) {
importTestItems(course, nodeKey, requestIdentity, resultsVO);
} else {
AssessableCourseNode assessableNode = (AssessableCourseNode) node;
// not directly pass this key
ScoreEvaluation scoreEval = new ScoreEvaluation(resultsVO.getScore(), Boolean.TRUE, Boolean.TRUE, new Long(nodeKey));
assessableNode.updateUserScoreEvaluation(scoreEval, userCourseEnvironment, requestIdentity, true, Role.coach);
}
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
Aggregations