Search in sources :

Example 21 with SearchRepositoryEntryParameters

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

the class RepositoryEntriesResource method getEntriesText.

/**
 * 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 uriInfo The URI information
 * @param httpRequest The HTTP request
 * @return
 */
@GET
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
public Response getEntriesText(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
    try {
        // list of courses open for everybody
        Roles roles = getRoles(httpRequest);
        Identity identity = getIdentity(httpRequest);
        SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles);
        List<RepositoryEntry> coursRepos = RepositoryManager.getInstance().genericANDQueryWithRolesRestriction(params, 0, -1, false);
        StringBuilder sb = new StringBuilder();
        sb.append("Course List\n");
        for (RepositoryEntry repoE : coursRepos) {
            UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
            URI repoUri = baseUriBuilder.path(RepositoryEntriesResource.class).path(repoE.getKey().toString()).build();
            sb.append("<a href=\"").append(repoUri).append(">").append(repoE.getDisplayname()).append("(").append(repoE.getKey()).append(")").append("</a>").append("\n");
        }
        return Response.ok(sb.toString()).build();
    } catch (Exception e) {
        throw new WebApplicationException(e);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) WebApplicationException(javax.ws.rs.WebApplicationException) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) WebApplicationException(javax.ws.rs.WebApplicationException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with SearchRepositoryEntryParameters

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

the class RepositoryEntriesResource method searchEntries.

/**
 * Search for repository entries, possible search attributes are name, author and type
 * @response.representation.mediaType multipart/form-data
 * @response.representation.doc Search for repository entries
 * @response.representation.200.qname {http://www.example.com}repositoryEntryVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Search for repository entries
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param type Filter by the file resource type of the repository entry
 * @param author Filter by the author's username
 * @param name Filter by name of repository entry
 * @param myEntries Only search entries the requester owns
 * @param httpRequest The HTTP request
 * @return
 */
@GET
@Path("search")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response searchEntries(@QueryParam("type") String type, @QueryParam("author") @DefaultValue("*") String author, @QueryParam("name") @DefaultValue("*") String name, @QueryParam("myentries") @DefaultValue("false") boolean myEntries, @Context HttpServletRequest httpRequest) {
    RepositoryManager rm = RepositoryManager.getInstance();
    try {
        List<RepositoryEntry> reposFound = new ArrayList<RepositoryEntry>();
        Identity identity = getIdentity(httpRequest);
        boolean restrictedType = type != null && !type.isEmpty();
        // list of courses open for everybody
        Roles roles = getRoles(httpRequest);
        if (myEntries) {
            List<RepositoryEntry> lstRepos = rm.queryByOwner(identity, restrictedType ? new String[] { type } : null);
            boolean restrictedName = !name.equals("*");
            boolean restrictedAuthor = !author.equals("*");
            if (restrictedName | restrictedAuthor) {
                // filter by search conditions
                for (RepositoryEntry re : lstRepos) {
                    boolean nameOk = restrictedName ? re.getDisplayname().toLowerCase().contains(name.toLowerCase()) : true;
                    boolean authorOk = restrictedAuthor ? re.getInitialAuthor().toLowerCase().equals(author.toLowerCase()) : true;
                    if (nameOk & authorOk)
                        reposFound.add(re);
                }
            } else {
                if (!lstRepos.isEmpty())
                    reposFound.addAll(lstRepos);
            }
        } else {
            List<String> types = new ArrayList<String>(1);
            if (restrictedType)
                types.add(type);
            SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(name, author, null, restrictedType ? types : null, identity, roles, null);
            List<RepositoryEntry> lstRepos = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
            if (!lstRepos.isEmpty())
                reposFound.addAll(lstRepos);
        }
        int i = 0;
        RepositoryEntryVO[] reVOs = new RepositoryEntryVO[reposFound.size()];
        for (RepositoryEntry re : reposFound) {
            reVOs[i++] = ObjectFactory.get(re);
        }
        return Response.ok(reVOs).build();
    } catch (Exception e) {
        throw new WebApplicationException(e);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryManager(org.olat.repository.RepositoryManager) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with SearchRepositoryEntryParameters

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

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

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

the class OLATUpgrade_8_2_0 method upgradeCourseConditions.

private boolean upgradeCourseConditions(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CONDITIONS)) {
        int counter = 0;
        List<RepositoryEntry> entries;
        SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
        params.setRoles(new Roles(true, false, false, false, false, false, false));
        params.addResourceTypes("CourseModule");
        do {
            entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, REPO_ENTRIES_BATCH_SIZE, true);
            for (RepositoryEntry entry : entries) {
                try {
                    ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
                    CourseEnvironmentMapper envMapper = getCourseEnvironmentMapper(entry);
                    course.postImport(null, envMapper);
                } catch (CorruptedCourseException e) {
                    log.error("Course seems corrupt: " + entry.getOlatResource().getResourceableId());
                } catch (Exception e) {
                    log.error("Course seems highly corrupt: " + entry.getOlatResource().getResourceableId());
                }
            }
            dbInstance.intermediateCommit();
            counter += entries.size();
            log.audit("Processed repository entries: " + entries.size());
        } while (entries.size() == REPO_ENTRIES_BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_CONDITIONS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CorruptedCourseException(org.olat.course.CorruptedCourseException) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) CorruptedCourseException(org.olat.course.CorruptedCourseException)

Example 25 with SearchRepositoryEntryParameters

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

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