Search in sources :

Example 26 with SearchRepositoryEntryParameters

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

the class RepositorySearchController method doSearch.

private void doSearch(UserRequest ureq, String limitType, boolean onlyOwner, boolean updateFilters) {
    searchType = SearchType.searchForm;
    RepositoryManager rm = RepositoryManager.getInstance();
    Collection<String> s = searchForm.getRestrictedTypes();
    List<String> restrictedTypes;
    if (limitType != null) {
        restrictedTypes = Collections.singletonList(limitType);
    } else {
        restrictedTypes = (s == null) ? null : new ArrayList<String>(s);
    }
    String author = searchForm.getAuthor();
    String displayName = searchForm.getDisplayName();
    String description = searchForm.getDescription();
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(displayName, author, description, restrictedTypes, getIdentity(), ureq.getUserSession().getRoles(), getIdentity().getUser().getProperty(UserConstants.INSTITUTIONALNAME, null));
    params.setOnlyOwnedResources(onlyOwner);
    List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    filterRepositoryEntries(entries);
    repoTableModel.setObjects(entries);
    if (updateFilters) {
        updateFilters(entries, null);
    }
    tableCtr.modelChanged();
    displaySearchResults(ureq);
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) ArrayList(java.util.ArrayList) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 27 with SearchRepositoryEntryParameters

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

the class CoursesWebService method getCourseList.

/**
 * Get all courses viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
 * @response.representation.200.doc List of visible courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
 * @param start
 * @param limit
 * @param externalId Search with an external ID
 * @param externalRef Search with an external reference
 * @param managed (true / false) Search only managed / not managed groups
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseList(@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("repositoryEntryKey") String repositoryEntryKey, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
    params.setManaged(managed);
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    if (StringHelper.containsNonWhitespace(externalRef)) {
        params.setExternalRef(externalRef);
    }
    if (StringHelper.containsNonWhitespace(repositoryEntryKey) && StringHelper.isLong(repositoryEntryKey)) {
        try {
            params.setRepositoryEntryKeys(Collections.singletonList(new Long(repositoryEntryKey)));
        } catch (NumberFormatException e) {
            log.error("Cannot parse the following repository entry key: " + repositoryEntryKey);
        }
    }
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
        CourseVO[] vos = toCourseVo(repoEntries);
        CourseVOes voes = new CourseVOes();
        voes.setCourses(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
        CourseVO[] vos = toCourseVo(repoEntries);
        return Response.ok(vos).build();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CourseVO(org.olat.restapi.support.vo.CourseVO) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with SearchRepositoryEntryParameters

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

the class CoursesInfosWebService method getCourseInfoList.

/**
 * Get courses informations viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
 * @response.representation.200.doc List of visible courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVOes}
 * @param start
 * @param limit
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfoList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    // fxdiff VCRP-1,2: access control of resources
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
        List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>();
        final Set<Long> forumNotified = new HashSet<Long>();
        final Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
        collectSubscriptions(identity, forumNotified, courseNotified);
        for (RepositoryEntry entry : repoEntries) {
            CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
            if (info != null) {
                infos.add(info);
            }
        }
        CourseInfoVO[] vos = infos.toArray(new CourseInfoVO[infos.size()]);
        CourseInfoVOes voes = new CourseInfoVOes();
        voes.setInfos(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        return Response.serverError().status(Status.FORBIDDEN).build();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CourseInfoVOes(org.olat.restapi.support.vo.CourseInfoVOes) ArrayList(java.util.ArrayList) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 29 with SearchRepositoryEntryParameters

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

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

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

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)

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