Search in sources :

Example 56 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project openolat by klemens.

the class EfficiencyStatementManagerTest method testBigDatas.

@Test
public void testBigDatas() {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(new Roles(true, false, false, false, false, false, false));
    params.setResourceTypes(Collections.singletonList("CourseModule"));
    List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 10000);
    int count = 0;
    for (RepositoryEntry entry : entries) {
        Long resourceableId = entry.getOlatResource().getResourceableId();
        try {
            ICourse course = CourseFactory.loadCourse(resourceableId);
            boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
            if (!enabled) {
                course = CourseFactory.openCourseEditSession(entry.getOlatResource().getResourceableId());
                CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
                courseConfig.setEfficencyStatementIsEnabled(true);
                CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
                CourseFactory.saveCourse(course.getResourceableId());
                CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            }
            DBFactory.getInstance().commitAndCloseSession();
            try {
                int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
                if (fromIndex < 100) {
                    fromIndex = 100;
                }
                List<Identity> assessedIdentities = loadIdentities.subList(fromIndex - 100, fromIndex);
                // force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
                RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                efficiencyStatementManager.updateEfficiencyStatements(courseEntry, assessedIdentities);
            } catch (Exception e) {
                e.printStackTrace();
            }
            DBFactory.getInstance().commitAndCloseSession();
            DBFactory.getInstance().closeSession();
        } catch (CorruptedCourseException e) {
            System.out.println("Error");
        }
        if (count++ % 100 == 0) {
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseConfig(org.olat.course.config.CourseConfig) CorruptedCourseException(org.olat.course.CorruptedCourseException) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 57 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project openolat by klemens.

the class RepositoryEntriesResource method getEntries.

/**
 * List all entries in the OLAT repository
 * @response.representation.200.qname {http://www.example.com}repositoryEntryVO
 * @response.representation.200.mediaType text/plain, text/html, application/xml, application/json
 * @response.representation.200.doc List all entries in the repository
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVOes}
 * @param start (optional)
 * @param limit (optional)
 * @param managed (optional)
 * @param externalId External ID (optional)
 * @param externalRef External reference number (optional)
 * @param resourceType The resource type (CourseModule) (optional)
 * @param httpRequest The HTTP request
 * @param request The RESt request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getEntries(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("resourceType") String resourceType, @Context HttpServletRequest httpRequest, @Context Request request) {
    try {
        // list of courses open for everybody
        Roles roles = getRoles(httpRequest);
        Identity identity = getIdentity(httpRequest);
        RepositoryManager rm = RepositoryManager.getInstance();
        SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles);
        params.setManaged(managed);
        if (StringHelper.containsNonWhitespace(externalId)) {
            params.setExternalId(externalId);
        }
        if (StringHelper.containsNonWhitespace(externalRef)) {
            params.setExternalRef(externalRef);
        }
        if (StringHelper.containsNonWhitespace(resourceType)) {
            params.setResourceTypes(Collections.singletonList(resourceType));
        }
        if (MediaTypeVariants.isPaged(httpRequest, request)) {
            int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
            List<RepositoryEntry> res = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
            RepositoryEntryVOes voes = new RepositoryEntryVOes();
            voes.setRepositoryEntries(toArrayOfVOes(res));
            voes.setTotalCount(totalCount);
            return Response.ok(voes).build();
        } else {
            List<RepositoryEntry> res = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
            RepositoryEntryVO[] voes = toArrayOfVOes(res);
            return Response.ok(voes).build();
        }
    } catch (Exception e) {
        throw new WebApplicationException(e);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) RepositoryEntryVOes(org.olat.restapi.support.vo.RepositoryEntryVOes) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) WebApplicationException(javax.ws.rs.WebApplicationException) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) WebApplicationException(javax.ws.rs.WebApplicationException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 58 with SearchRepositoryEntryParameters

use of org.olat.repository.model.SearchRepositoryEntryParameters in project openolat by klemens.

the class UserCalendarWebService method getCalendars.

private void getCalendars(CalendarVisitor calVisitor, UserRequest ureq) {
    Roles roles = ureq.getUserSession().getRoles();
    Identity retrievedUser = ureq.getIdentity();
    CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
    if (calendarModule.isEnabled()) {
        if (calendarModule.isEnablePersonalCalendar()) {
            KalendarRenderWrapper personalWrapper = getPersonalCalendar(ureq.getIdentity());
            calVisitor.visit(personalWrapper);
        }
        if (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) {
            RepositoryManager rm = RepositoryManager.getInstance();
            ACService acManager = CoreSpringFactory.getImpl(ACService.class);
            SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
            repoParams.setOnlyExplicitMember(true);
            repoParams.setIdentity(retrievedUser);
            IdentityEnvironment ienv = new IdentityEnvironment();
            ienv.setIdentity(retrievedUser);
            ienv.setRoles(roles);
            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);
                        CourseConfig config = course.getCourseEnvironment().getCourseConfig();
                        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
                        if (config.isCalendarEnabled()) {
                            KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
                            calVisitor.visit(wrapper);
                        } else {
                            CalCourseNodeVisitor visitor = new CalCourseNodeVisitor();
                            new CourseTreeVisitor(course, ienv).visit(visitor, new VisibleTreeFilter());
                            if (visitor.isFound()) {
                                KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
                                calVisitor.visit(wrapper);
                            }
                        }
                    } catch (Exception e) {
                        log.error("", e);
                    }
                }
            }
        }
        if (calendarModule.isEnableGroupCalendar()) {
            CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
            // start found forums in groups
            BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class);
            SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
            params.addTools(CollaborationTools.TOOL_CALENDAR);
            List<BusinessGroup> groups = bgm.findBusinessGroups(params, null, 0, -1);
            for (BusinessGroup group : groups) {
                KalendarRenderWrapper wrapper = collaborationManager.getCalendar(group, ureq, false);
                calVisitor.visit(wrapper);
            }
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) WebApplicationException(javax.ws.rs.WebApplicationException) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) CourseConfig(org.olat.course.config.CourseConfig) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroupService(org.olat.group.BusinessGroupService) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CalendarModule(org.olat.commons.calendar.CalendarModule) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CollaborationManager(org.olat.collaboration.CollaborationManager)

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