Search in sources :

Example 6 with SearchRepositoryEntryParameters

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

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 7 with SearchRepositoryEntryParameters

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

the class OLATUpgrade_11_0_0 method upgradeEfficiencyStatementTable.

private boolean upgradeEfficiencyStatementTable(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    boolean allOk = true;
    if (!uhd.getBooleanDataValue(EFFICIENCY_STATEMENT_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 {
                    convertUserEfficiencyStatemen(course);
                } catch (CorruptedCourseException e) {
                    log.error("Corrupted course: " + course.getKey(), e);
                }
            }
            counter += courses.size();
            log.audit("Efficiency statement data migration processed: " + courses.size() + ", total courses processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(EFFICIENCY_STATEMENT_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 8 with SearchRepositoryEntryParameters

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

the class OLATUpgrade_12_0_0 method upgradeLastModified.

private boolean upgradeLastModified(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    boolean allOk = true;
    if (!uhd.getBooleanDataValue(LAST_USER_MODIFICATION)) {
        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 &= processCourseAssessmentLastModified(course);
                } catch (CorruptedCourseException e) {
                    log.error("Corrupted course: " + course.getKey(), e);
                }
            }
            counter += courses.size();
            log.audit("Last modifications migration processed: " + courses.size() + ", total courses processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(LAST_USER_MODIFICATION, allOk);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return allOk;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CorruptedCourseException(org.olat.course.CorruptedCourseException) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 9 with SearchRepositoryEntryParameters

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

the class OLATUpgrade_11_2_1 method upgradeStatus.

private boolean upgradeStatus(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    boolean allOk = true;
    if (!uhd.getBooleanDataValue(STATUS_OLD_TASK_ELEMENT)) {
        int counter = 0;
        final Roles roles = new Roles(true, false, false, false, false, false, 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) {
                processCourse(course);
            }
            counter += courses.size();
            log.audit("Course for checklist and deprecated tasks migration processed: " + courses.size() + ", total courses processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(STATUS_OLD_TASK_ELEMENT, allOk);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return allOk;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 10 with SearchRepositoryEntryParameters

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

the class BusinessGroupServiceImpl method dedupMembers.

@Override
public void dedupMembers(Identity ureqIdentity, boolean coaches, boolean participants, ProgressDelegate delegate) {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(new Roles(true, false, false, false, false, false, false));
    params.setResourceTypes(Collections.singletonList("CourseModule"));
    float ratio = -1.0f;
    if (delegate != null) {
        int numOfEntries = repositoryManager.countGenericANDQueryWithRolesRestriction(params);
        ratio = 100.0f / numOfEntries;
    }
    int counter = 0;
    int countForCommit = 0;
    float actual = 100.0f;
    int batch = 25;
    List<RepositoryEntry> entries;
    do {
        entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, batch, true);
        for (RepositoryEntry re : entries) {
            countForCommit += 2 + dedupSingleRepositoryentry(ureqIdentity, re, coaches, participants, false);
            if (countForCommit > 25) {
                dbInstance.intermediateCommit();
                countForCommit = 0;
            }
        }
        counter += entries.size();
        if (delegate != null) {
            actual -= (entries.size() * ratio);
            delegate.setActual(actual);
        }
    } while (entries.size() == batch);
    if (delegate != null) {
        delegate.finished();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

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