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();
}
}
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();
}
}
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);
}
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());
}
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));
}
Aggregations