use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class UserCoursesWebService method getFavoritCourses.
/**
* Retrieves the list of my favorite courses.
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The courses
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param start The first result
* @param limit Max result
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of my favorite courses
*/
@GET
@Path("favorite")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFavoritCourses(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
List<String> courseType = Collections.singletonList("CourseModule");
RepositoryManager rm = RepositoryManager.getInstance();
if (MediaTypeVariants.isPaged(httpRequest, request)) {
List<RepositoryEntry> repoEntries = rm.getFavoritLearningResourcesAsTeacher(identity, courseType, start, limit, RepositoryEntryOrder.nameAsc);
int totalCount;
if (repoEntries.size() < limit) {
totalCount = repoEntries.size();
} else {
totalCount = rm.countFavoritLearningResourcesAsTeacher(identity, courseType);
}
CourseVO[] vos = toCourseVo(repoEntries);
CourseVOes voes = new CourseVOes();
voes.setCourses(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
List<RepositoryEntry> repoEntries = rm.getFavoritLearningResourcesAsTeacher(identity, courseType, 0, -1, RepositoryEntryOrder.nameAsc);
CourseVO[] vos = toCourseVo(repoEntries);
return Response.ok(vos).build();
}
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class SharedFolderWebDAVMergeSource method loadMergedContainers.
@Override
protected List<VFSContainer> loadMergedContainers() {
SharedFolderManager sfm = SharedFolderManager.getInstance();
RepositoryManager repoManager = RepositoryManager.getInstance();
List<VFSContainer> containers = new ArrayList<>();
Set<Long> addedEntries = new HashSet<>();
List<RepositoryEntry> ownerEntries = repoManager.queryByMembership(getIdentity(), true, true, false, SharedFolderFileResource.TYPE_NAME);
for (RepositoryEntry entry : ownerEntries) {
VFSContainer container = sfm.getNamedSharedFolder(entry, true);
if (container != null) {
addContainerToList(container, containers);
addedEntries.add(entry.getKey());
}
}
List<RepositoryEntry> participantEntries = repoManager.queryByMembership(getIdentity(), false, false, true, SharedFolderFileResource.TYPE_NAME);
for (RepositoryEntry entry : participantEntries) {
addReadonlyFolder(entry, sfm, addedEntries, containers);
}
// see /webapp/WEB-INF/classes/org/olat/core/commons/services/webdav/webdavContext.xml
if (publiclyReadableFolders != null && publiclyReadableFolders.size() > 0) {
// Temporarily save added entries. This is needed to make sure not to add an entry twice.
String firstItem = publiclyReadableFolders.get(0);
// If the first value in the list is '*', list all resource folders.
if (firstItem != null && firstItem.equals("*")) {
// fake role that represents normally logged in user
Roles registeredUserRole = new Roles(false, false, false, false, false, false, false);
List<String> types = Collections.singletonList(SharedFolderFileResource.TYPE_NAME);
List<RepositoryEntry> allEntries = repoManager.queryByTypeLimitAccess(getIdentity(), types, registeredUserRole);
for (RepositoryEntry entry : allEntries) {
addReadonlyFolder(entry, sfm, addedEntries, containers);
}
} else {
// only list the specified folders
List<Long> publiclyReadableFoldersKeys = getSharedKeys();
List<RepositoryEntry> entries = repoManager.lookupRepositoryEntries(publiclyReadableFoldersKeys);
for (RepositoryEntry entry : entries) {
if (entry.getAccess() >= RepositoryEntry.ACC_USERS || (entry.getAccess() == RepositoryEntry.ACC_OWNERS && entry.isMembersOnly())) {
// add folder (which is a repo entry) to root container if not present
addReadonlyFolder(entry, sfm, addedEntries, containers);
} else {
log.warn("Access denied on entry::" + entry.getKey(), null);
}
}
}
}
return containers;
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class WikisWebService method getAccessibleWikiRepositoryEntries.
/**
* returns all accessiblewikiRepositoryEntries of type wiki
*
* @param httpRequest
* @return
*/
private static List<RepositoryEntry> getAccessibleWikiRepositoryEntries(HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
RepositoryManager rm = RepositoryManager.getInstance();
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, new String[] { WikiResource.TYPE_NAME });
List<RepositoryEntry> res = rm.genericANDQueryWithRolesRestriction(params, 0, -1, true);
return res;
}
use of org.olat.repository.RepositoryManager 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);
}
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class CourseElementWebService method updateWiki.
/**
* Attaches an wiki building block.
* @response.representation.mediaType application/x-www-form-urlencoded
* @response.representation.doc The assessment node metadatas
* @response.representation.200.qname {http://www.example.com}courseNodeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id which of this wiki
* @param shortTitle The node short title
* @param longTitle The node long title
* @param objectives The node learning objectives
* @param visibilityExpertRules The rules to view the node (optional)
* @param accessExpertRules The rules to access the node (optional)
* @param wikiResourceableId The repository entry key of the wiki
* @param request The HTTP request
* @return
*/
@POST
@Path("wiki/{nodeId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public // fxdiff FXOLAT-122: course management
Response updateWiki(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @FormParam("shortTitle") @DefaultValue("undefined") String shortTitle, @FormParam("longTitle") @DefaultValue("undefined") String longTitle, @FormParam("objectives") @DefaultValue("undefined") String objectives, @FormParam("visibilityExpertRules") String visibilityExpertRules, @FormParam("accessExpertRules") String accessExpertRules, @FormParam("wikiResourceableId") Long wikiResourceableId, @Context HttpServletRequest request) {
RepositoryEntry wikiRepoEntry = null;
if (wikiResourceableId != null) {
RepositoryManager rm = RepositoryManager.getInstance();
wikiRepoEntry = rm.lookupRepositoryEntry(wikiResourceableId);
if (wikiRepoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
}
WikiCustomConfig config = new WikiCustomConfig(wikiRepoEntry);
return update(courseId, nodeId, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, request);
}
Aggregations