Search in sources :

Example 11 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams 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();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Subscriber(org.olat.core.commons.services.notifications.Subscriber) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) FolderVO(org.olat.restapi.support.vo.FolderVO) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CollaborationTools(org.olat.collaboration.CollaborationTools) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findManagedGroups.

@Test
public void findManagedGroups() {
    // create a managed group with an external ID
    String externalId = UUID.randomUUID().toString();
    String managedFlags = "title,description";
    BusinessGroup managedGroup = businessGroupDao.createAndPersist(null, "managed-grp-1", "managed-grp-1-desc", externalId, managedFlags, 0, 5, true, false, true, false, false);
    BusinessGroup freeGroup = businessGroupDao.createAndPersist(null, "free-grp-1", "free-grp-1-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    // search managed group
    SearchBusinessGroupParams paramsManaged = new SearchBusinessGroupParams();
    paramsManaged.setManaged(Boolean.TRUE);
    List<BusinessGroup> managedGroups = businessGroupDao.findBusinessGroups(paramsManaged, null, 0, 0);
    Assert.assertNotNull(managedGroups);
    Assert.assertTrue(managedGroups.size() >= 1);
    Assert.assertTrue(managedGroups.contains(managedGroup));
    Assert.assertFalse(managedGroups.contains(freeGroup));
    // search free group
    SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams();
    paramsAll.setManaged(Boolean.FALSE);
    List<BusinessGroup> freeGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0);
    Assert.assertNotNull(freeGroups);
    Assert.assertTrue(freeGroups.size() >= 1);
    Assert.assertTrue(freeGroups.contains(freeGroup));
    Assert.assertFalse(freeGroups.contains(managedGroup));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 13 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroupsByIdentity.

@Test
public void findBusinessGroupsByIdentity() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id, "is-in-grp-1", "is-in-grp-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "is-in-grp-2", "is-in-grp-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "is-in-grp-3", "is-in-grp-3-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(id, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id, group3, GroupRoles.waiting.name());
    dbInstance.commitAndCloseSession();
    // check owner
    SearchBusinessGroupParams paramsOwner = new SearchBusinessGroupParams();
    paramsOwner.setIdentity(id);
    paramsOwner.setOwner(true);
    List<BusinessGroup> ownedGroups = businessGroupDao.findBusinessGroups(paramsOwner, null, 0, 0);
    Assert.assertNotNull(ownedGroups);
    Assert.assertEquals(1, ownedGroups.size());
    Assert.assertTrue(ownedGroups.contains(group1));
    // check attendee
    SearchBusinessGroupParams paramsAttendee = new SearchBusinessGroupParams();
    paramsAttendee.setIdentity(id);
    paramsAttendee.setAttendee(true);
    List<BusinessGroup> attendeeGroups = businessGroupDao.findBusinessGroups(paramsAttendee, null, 0, 0);
    Assert.assertNotNull(attendeeGroups);
    Assert.assertEquals(1, attendeeGroups.size());
    Assert.assertTrue(attendeeGroups.contains(group2));
    // check waiting
    SearchBusinessGroupParams paramsWaiting = new SearchBusinessGroupParams();
    paramsWaiting.setIdentity(id);
    paramsWaiting.setWaiting(true);
    List<BusinessGroup> waitingGroups = businessGroupDao.findBusinessGroups(paramsWaiting, null, 0, 0);
    Assert.assertNotNull(waitingGroups);
    Assert.assertEquals(1, waitingGroups.size());
    Assert.assertTrue(waitingGroups.contains(group3));
    // check all
    SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams();
    paramsAll.setIdentity(id);
    paramsAll.setOwner(true);
    paramsAll.setAttendee(true);
    paramsAll.setWaiting(true);
    List<BusinessGroup> allGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0);
    Assert.assertNotNull(allGroups);
    Assert.assertEquals(3, allGroups.size());
    Assert.assertTrue(allGroups.contains(group1));
    Assert.assertTrue(allGroups.contains(group2));
    Assert.assertTrue(allGroups.contains(group3));
    // The same tests with the views
    // check owner on views
    BusinessGroupQueryParams queryParamsOwner = new BusinessGroupQueryParams();
    queryParamsOwner.setOwner(true);
    List<BusinessGroupRow> ownedGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryParamsOwner, id);
    Assert.assertNotNull(ownedGroupViews);
    Assert.assertEquals(1, ownedGroupViews.size());
    Assert.assertTrue(contains(ownedGroupViews, group1));
    // check attendee on views
    BusinessGroupQueryParams queryParamsAttendee = new BusinessGroupQueryParams();
    queryParamsAttendee.setAttendee(true);
    List<BusinessGroupRow> attendeeGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryParamsAttendee, id);
    Assert.assertNotNull(attendeeGroupViews);
    Assert.assertEquals(1, attendeeGroupViews.size());
    Assert.assertTrue(contains(attendeeGroupViews, group2));
    // check waiting on views
    BusinessGroupQueryParams queryParamsWaiting = new BusinessGroupQueryParams();
    queryParamsWaiting.setWaiting(true);
    List<BusinessGroupRow> waitingGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryParamsWaiting, id);
    Assert.assertNotNull(waitingGroupViews);
    Assert.assertEquals(1, waitingGroupViews.size());
    Assert.assertTrue(contains(waitingGroupViews, group3));
    // check all on views
    BusinessGroupQueryParams queryParamsAll = new BusinessGroupQueryParams();
    queryParamsAll.setOwner(true);
    queryParamsAll.setAttendee(true);
    queryParamsAll.setWaiting(true);
    List<BusinessGroupRow> allGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryParamsAll, id);
    Assert.assertNotNull(allGroupViews);
    Assert.assertEquals(3, allGroupViews.size());
    Assert.assertTrue(contains(allGroupViews, group1));
    Assert.assertTrue(contains(allGroupViews, group2));
    Assert.assertTrue(contains(allGroupViews, group3));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 14 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroups.

@Test
public void findBusinessGroups() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gduo", "gduo-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "gdvo", "gdvo-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertTrue(groups.size() >= 2);
    Assert.assertTrue(groups.contains(group1));
    Assert.assertTrue(groups.contains(group2));
    BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
    List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, identity);
    Assert.assertNotNull(groupViews);
    Assert.assertTrue(groupViews.size() >= 2);
    Assert.assertTrue(contains(groupViews, group1));
    Assert.assertTrue(contains(groupViews, group2));
    List<StatisticsBusinessGroupRow> groupToSelect = businessGroupDao.searchBusinessGroupsForSelection(searchParams, identity);
    Assert.assertNotNull(groupToSelect);
    Assert.assertTrue(groupToSelect.size() >= 2);
    List<OpenBusinessGroupRow> openGroups = businessGroupDao.searchPublishedBusinessGroups(searchParams, identity);
    Assert.assertNotNull(openGroups);
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroup(org.olat.group.BusinessGroup) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 15 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroupsByExactName.

@Test
public void findBusinessGroupsByExactName() {
    String exactName = UUID.randomUUID().toString();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, exactName, "gdwo-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, exactName + "x", "gdxo-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "y" + exactName, "gdyo-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setExactName(exactName);
    List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(1, groups.size());
    Assert.assertTrue(groups.contains(group1));
    Assert.assertFalse(groups.contains(group2));
    Assert.assertFalse(groups.contains(group3));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Aggregations

SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)92 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)26 BusinessGroupService (org.olat.group.BusinessGroupService)18 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)16 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)16 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)16 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)16 RepositoryEntry (org.olat.repository.RepositoryEntry)16 HashSet (java.util.HashSet)12 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)10 Roles (org.olat.core.id.Roles)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)6 ICourse (org.olat.course.ICourse)6