Search in sources :

Example 91 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class BusinessGroupImportExportTest method importLearningGroupsAndAreasWithResource.

@Test
public void importLearningGroupsAndAreasWithResource() throws URISyntaxException {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_3.xml");
    File importXml = new File(input.toURI());
    businessGroupService.importGroups(resource, importXml);
    dbInstance.commitAndCloseSession();
    // check if all three groups are imported
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(3, groups.size());
    // check if all three areas are imported
    List<BGArea> areas = areaManager.findBGAreasInContext(resource.getOlatResource());
    Assert.assertNotNull(areas);
    Assert.assertEquals(3, areas.size());
    // check first area
    BGArea area1 = areaManager.findBGArea("Area 1", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 1", area1.getName());
    Assert.assertEquals("<p>Area 1 description</p>", area1.getDescription());
    // check relation to groups
    List<BusinessGroup> groupArea1 = areaManager.findBusinessGroupsOfArea(area1);
    Assert.assertNotNull(groupArea1);
    Assert.assertEquals(2, groupArea1.size());
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 1") || groupArea1.get(1).getName().equals("Export group 1"));
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 2") || groupArea1.get(1).getName().equals("Export group 2"));
    // check empty area
    BGArea area3 = areaManager.findBGArea("Area 3", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 3", area3.getName());
    // check relation to groups
    List<BusinessGroup> groupArea3 = areaManager.findBusinessGroupsOfArea(area3);
    Assert.assertNotNull(groupArea3);
    Assert.assertEquals(0, groupArea3.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 92 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method findAndCountBusinessGroups.

@Test
public void findAndCountBusinessGroups() {
    // prepare 2 resources + 3 groups with 3 owners
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString());
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, resource1);
    businessGroupRelationDao.addRelationToResource(group1, resource2);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, resource1);
    BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group3, resource2);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    // check resource 1
    int count1_1 = businessGroupDao.countBusinessGroups(params, resource1);
    Assert.assertEquals(2, count1_1);
    List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, resource1, 0, -1);
    Assert.assertNotNull(groups1_1);
    Assert.assertEquals(2, groups1_1.size());
    Assert.assertTrue(groups1_1.contains(group1));
    Assert.assertTrue(groups1_1.contains(group2));
    // check owner 1 + resource 1
    SearchBusinessGroupParams paramsRestricted = new SearchBusinessGroupParams(id1, true, true);
    int count3_1 = businessGroupDao.countBusinessGroups(paramsRestricted, resource1);
    Assert.assertEquals(1, count3_1);
    List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(paramsRestricted, resource1, 0, -1);
    Assert.assertNotNull(groups3_1);
    Assert.assertEquals(1, groups3_1.size());
    Assert.assertEquals(group1, groups3_1.get(0));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 93 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method addRelation.

@Test
public void addRelation() {
    // create a relation
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group, resource);
    dbInstance.commitAndCloseSession();
    // check
    List<RepositoryEntry> resources = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group), 0, -1);
    Assert.assertNotNull(resources);
    Assert.assertEquals(1, resources.size());
    Assert.assertTrue(resources.contains(resource));
    int count = businessGroupRelationDao.countResources(group);
    Assert.assertEquals(1, count);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 94 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method addGroupsAndRelations.

@Test
public void addGroupsAndRelations() {
    // create a relation
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-1", "rel-bg-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, resource1);
    businessGroupRelationDao.addRelationToResource(group1, resource2);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-2", "rel-bg-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, resource2);
    businessGroupRelationDao.addRelationToResource(group2, resource3);
    dbInstance.commitAndCloseSession();
    // check group1
    List<RepositoryEntry> resources1 = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group1), 0, -1);
    Assert.assertNotNull(resources1);
    Assert.assertEquals(2, resources1.size());
    Assert.assertTrue(resources1.contains(resource1));
    Assert.assertTrue(resources1.contains(resource2));
    Assert.assertFalse(resources1.contains(resource3));
    // check group2
    List<RepositoryEntry> resources2 = businessGroupRelationDao.findRepositoryEntries(Collections.singletonList(group2), 0, -1);
    Assert.assertNotNull(resources2);
    Assert.assertEquals(2, resources2.size());
    Assert.assertFalse(resources2.contains(resource1));
    Assert.assertTrue(resources2.contains(resource2));
    Assert.assertTrue(resources2.contains(resource3));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 95 with RepositoryEntry

use of org.olat.repository.RepositoryEntry in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method countResourcesOfBusinessGroups.

@Test
public void countResourcesOfBusinessGroups() {
    // create 3 entries and 1 group
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-repo", "rel-repo-desc", 0, 10, true, false, false, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRelationToResource(group, re1);
    businessGroupRelationDao.addRelationToResource(group, re2);
    businessGroupRelationDao.addRelationToResource(group, re3);
    dbInstance.commitAndCloseSession();
    // check with empty list of groups
    boolean numOfResources1 = businessGroupRelationDao.hasResources(Collections.<BusinessGroup>emptyList());
    Assert.assertFalse(numOfResources1);
    // check with the group
    boolean numOfResources2 = businessGroupRelationDao.hasResources(Collections.singletonList(group));
    Assert.assertTrue(numOfResources2);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

RepositoryEntry (org.olat.repository.RepositoryEntry)2108 Test (org.junit.Test)922 Identity (org.olat.core.id.Identity)888 BusinessGroup (org.olat.group.BusinessGroup)344 ArrayList (java.util.ArrayList)258 File (java.io.File)246 ICourse (org.olat.course.ICourse)246 Date (java.util.Date)234 OLATResource (org.olat.resource.OLATResource)200 URI (java.net.URI)176 HttpResponse (org.apache.http.HttpResponse)172 OLATResourceable (org.olat.core.id.OLATResourceable)132 RepositoryManager (org.olat.repository.RepositoryManager)122 Roles (org.olat.core.id.Roles)104 RepositoryService (org.olat.repository.RepositoryService)104 LectureBlock (org.olat.modules.lecture.LectureBlock)94 Path (javax.ws.rs.Path)90 URL (java.net.URL)84 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 WindowControl (org.olat.core.gui.control.WindowControl)74