Search in sources :

Example 46 with SearchRepositoryEntryParameters

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

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

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

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

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

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

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

the class RepositoryManagerQueryTest method testOneShootQueryWithAuthorRole.

@Test
public void testOneShootQueryWithAuthorRole() {
    List<String> types = Collections.singletonList(TEST_RES_NAME);
    // roles: author + institution manager
    Roles role2 = new Roles(false, false, false, true, false, false, false);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(null, null, null, types, null, role2, null);
    List<RepositoryEntry> resultOneShoot = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    assertNotNull(resultOneShoot);
    assertFalse(resultOneShoot.isEmpty());
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) Test(org.junit.Test)

Example 50 with SearchRepositoryEntryParameters

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

the class RepositoryManagerTest method genericANDQueryWithRoles_managed.

@Test
public void genericANDQueryWithRoles_managed() {
    RepositoryEntry managedRe = JunitTestHelper.createAndPersistRepositoryEntry();
    managedRe.setManagedFlagsString("all");
    managedRe = dbInstance.getCurrentEntityManager().merge(managedRe);
    RepositoryEntry freeRe = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    // search managed
    SearchRepositoryEntryParameters paramsManaged = new SearchRepositoryEntryParameters();
    paramsManaged.setRoles(new Roles(true, false, false, false, false, false, false));
    paramsManaged.setManaged(Boolean.TRUE);
    List<RepositoryEntry> managedEntries = repositoryManager.genericANDQueryWithRolesRestriction(paramsManaged, 0, -1, true);
    Assert.assertNotNull(managedEntries);
    Assert.assertTrue(managedEntries.size() > 0);
    Assert.assertTrue(managedEntries.contains(managedRe));
    Assert.assertFalse(managedEntries.contains(freeRe));
    // search unmanaged
    SearchRepositoryEntryParameters paramsFree = new SearchRepositoryEntryParameters();
    paramsFree.setRoles(new Roles(true, false, false, false, false, false, false));
    paramsFree.setManaged(Boolean.FALSE);
    List<RepositoryEntry> freeEntries = repositoryManager.genericANDQueryWithRolesRestriction(paramsFree, 0, -1, true);
    Assert.assertNotNull(freeEntries);
    Assert.assertTrue(freeEntries.size() > 0);
    Assert.assertFalse(freeEntries.contains(managedRe));
    Assert.assertTrue(freeEntries.contains(freeRe));
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) 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