Search in sources :

Example 36 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_3_0 method upgradeExportFodler.

private boolean upgradeExportFodler(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_EXPORT_FOLDER)) {
        int counter = 0;
        final Roles roles = new Roles(true, true, true, true, false, true, false);
        final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
        params.setRoles(roles);
        params.setResourceTypes(Collections.singletonList("CourseModule"));
        List<RepositoryEntry> courses;
        do {
            courses = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, BATCH_SIZE, true);
            for (RepositoryEntry course : courses) {
                processExportFolder(course);
            }
            counter += courses.size();
            log.audit("Course export folder processed: " + courses.size() + ", total processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_EXPORT_FOLDER, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 37 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_11_0_0 method upgradeAssessmentPropertyTable.

private boolean upgradeAssessmentPropertyTable(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    boolean allOk = true;
    if (!uhd.getBooleanDataValue(ASSESSMENT_DATAS)) {
        int counter = 0;
        final Roles roles = new Roles(true, true, true, true, false, true, false);
        final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
        params.setRoles(roles);
        params.setResourceTypes(Collections.singletonList("CourseModule"));
        List<RepositoryEntry> courses;
        do {
            courses = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, 50, true);
            for (RepositoryEntry course : courses) {
                try {
                    allOk &= processCourseAssessmentData(course);
                } catch (CorruptedCourseException e) {
                    log.error("Corrupted course: " + course.getKey(), e);
                }
            }
            counter += courses.size();
            log.audit("Assessment data migration processed: " + courses.size() + ", total courses processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(ASSESSMENT_DATAS, allOk);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return allOk;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CorruptedCourseException(org.olat.course.CorruptedCourseException) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 38 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method genericANDQueryWithRolesRestrictionMembersOnly.

@Test
public void genericANDQueryWithRolesRestrictionMembersOnly() {
    // create 2 identities (repo owner and tutor)
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-3-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true);
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(id2, group, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // check for id 1 (owner of the repository entry)
    SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters();
    params1.setIdentity(id1);
    params1.setRoles(new Roles(false, false, false, false, false, false, false));
    params1.setOnlyExplicitMember(true);
    List<RepositoryEntry> entries1 = repositoryManager.genericANDQueryWithRolesRestriction(params1, 0, -1, true);
    Assert.assertNotNull(entries1);
    Assert.assertFalse(entries1.isEmpty());
    Assert.assertTrue(entries1.contains(re));
    for (RepositoryEntry entry : entries1) {
        if (!entry.equals(re)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
    // check for id2 (tutor)
    SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters();
    params2.setIdentity(id2);
    params2.setRoles(new Roles(false, false, false, false, false, false, false));
    params2.setOnlyExplicitMember(true);
    List<RepositoryEntry> entries2 = repositoryManager.genericANDQueryWithRolesRestriction(params2, 0, -1, true);
    Assert.assertNotNull(entries2);
    Assert.assertFalse(entries2.isEmpty());
    Assert.assertTrue(entries2.contains(re));
    for (RepositoryEntry entry : entries2) {
        if (!entry.equals(re)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
    // check for id3 (negative test)
    SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters();
    params3.setIdentity(id3);
    params3.setRoles(new Roles(false, false, false, false, false, false, false));
    params3.setOnlyExplicitMember(true);
    List<RepositoryEntry> entries3 = repositoryManager.genericANDQueryWithRolesRestriction(params3, 0, -1, true);
    Assert.assertNotNull(entries3);
    Assert.assertFalse(entries3.contains(re));
    for (RepositoryEntry entry : entries3) {
        Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) BusinessGroup(org.olat.group.BusinessGroup) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 39 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method genericANDQueryWithRolesWithStandardUser.

@Test
public void genericANDQueryWithRolesWithStandardUser() {
    // create 2 identities (repo owner and tutor)
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("re-gen-2-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry(true);
    repositoryEntryRelationDao.addRole(id1, re2, GroupRoles.participant.name());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "teacherg", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // check for guest (negative test)
    SearchRepositoryEntryParameters params1 = new SearchRepositoryEntryParameters();
    params1.setRoles(new Roles(false, false, false, false, true, false, false));
    List<RepositoryEntry> entries1 = repositoryManager.genericANDQueryWithRolesRestriction(params1, 0, -1, true);
    Assert.assertNotNull(entries1);
    Assert.assertFalse(entries1.contains(re1));
    Assert.assertFalse(entries1.contains(re2));
    for (RepositoryEntry entry : entries1) {
        Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS_GUESTS);
    }
    // check for identity 1 (participant re2 + re1 accessible to all users)
    SearchRepositoryEntryParameters params2 = new SearchRepositoryEntryParameters();
    params2.setIdentity(id1);
    params2.setRoles(new Roles(false, false, false, false, false, false, false));
    List<RepositoryEntry> entries2 = repositoryManager.genericANDQueryWithRolesRestriction(params2, 0, -1, true);
    Assert.assertNotNull(entries2);
    Assert.assertFalse(entries2.isEmpty());
    Assert.assertTrue(entries2.contains(re1));
    Assert.assertTrue(entries2.contains(re2));
    for (RepositoryEntry entry : entries2) {
        if (!entry.equals(re2)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
    // check for identity 1 (re1 accessible to all users)
    SearchRepositoryEntryParameters params3 = new SearchRepositoryEntryParameters();
    params3.setIdentity(id2);
    params3.setRoles(new Roles(false, false, false, false, false, false, false));
    List<RepositoryEntry> entries3 = repositoryManager.genericANDQueryWithRolesRestriction(params3, 0, -1, true);
    Assert.assertNotNull(entries3);
    Assert.assertFalse(entries3.isEmpty());
    Assert.assertTrue(entries3.contains(re1));
    Assert.assertFalse(entries3.contains(re2));
    for (RepositoryEntry entry : entries3) {
        Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) BusinessGroup(org.olat.group.BusinessGroup) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 40 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method genericANDQueryWithRoles_owned.

@Test
public void genericANDQueryWithRoles_owned() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("owned-re-");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    dbInstance.commitAndCloseSession();
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(new Roles(false, false, false, true, false, false, false));
    params.setOnlyOwnedResources(true);
    params.setIdentity(owner);
    List<RepositoryEntry> myEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    Assert.assertNotNull(myEntries);
    Assert.assertEquals(1, myEntries.size());
    Assert.assertTrue(myEntries.contains(re));
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)58 Roles (org.olat.core.id.Roles)54 RepositoryEntry (org.olat.repository.RepositoryEntry)38 Test (org.junit.Test)24 Identity (org.olat.core.id.Identity)24 GroupRoles (org.olat.basesecurity.GroupRoles)18 RepositoryManager (org.olat.repository.RepositoryManager)14 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)12 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)12 ArrayList (java.util.ArrayList)10 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)10 CorruptedCourseException (org.olat.course.CorruptedCourseException)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 ICourse (org.olat.course.ICourse)8 BusinessGroup (org.olat.group.BusinessGroup)6 URI (java.net.URI)4 CourseConfig (org.olat.course.config.CourseConfig)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2