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