use of org.olat.repository.RepositoryManager 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);
}
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class FeedViewHelper method getJumpInLink.
/**
* @param feed
* the target feed for the jumpInLink
* @param item
* the target item for the jumpInLink or null if not want to
* refer to a specific item
* @return the jump in link
*/
public String getJumpInLink(Feed feed, Item item) {
String jumpInLink = null;
RepositoryManager resMgr = RepositoryManager.getInstance();
if (courseId != null && nodeId != null) {
OLATResourceable oresCourse = OLATResourceManager.getInstance().findResourceable(courseId, CourseModule.getCourseTypeName());
OLATResourceable oresNode = OresHelper.createOLATResourceableInstance("CourseNode", Long.valueOf(nodeId));
RepositoryEntry repositoryEntry = resMgr.lookupRepositoryEntry(oresCourse, false);
List<ContextEntry> ces = new ArrayList<>();
ces.add(BusinessControlFactory.getInstance().createContextEntry(repositoryEntry));
ces.add(BusinessControlFactory.getInstance().createContextEntry(oresNode));
jumpInLink = BusinessControlFactory.getInstance().getAsURIString(ces, false);
} else {
RepositoryEntry repositoryEntry = resMgr.lookupRepositoryEntry(feed, false);
if (repositoryEntry != null) {
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(repositoryEntry);
jumpInLink = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
} else {
// its a liveblog-helperFeed
final BusinessControlFactory bCF = BusinessControlFactory.getInstance();
String feedBP = LiveBlogArtefactHandler.LIVEBLOG + feed.getResourceableId() + "]";
final List<ContextEntry> ceList = bCF.createCEListFromString(feedBP);
jumpInLink = bCF.getAsURIString(ceList, true);
}
}
if (item != null && jumpInLink != null) {
jumpInLink += "/item=" + item.getKey() + "/0";
}
return jumpInLink;
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class FeedMediaDispatcher method hasAccess.
/**
* Verifies the access of an identity to a course node.
*
* @param identity
* @param token
* @param course
* @param node
* @return True if the identity has access to the node in the given course.
* False otherwise.
*/
private boolean hasAccess(Identity identity, String token, ICourse course, CourseNode node) {
boolean hasAccess = false;
final RepositoryManager resMgr = RepositoryManager.getInstance();
final RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(course, false);
if (allowsGuestAccess(repoEntry)) {
hasAccess = true;
} else {
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(identity);
Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
ienv.setRoles(roles);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
// Build an evaluation tree
TreeEvaluation treeEval = new TreeEvaluation();
NodeEvaluation nodeEval = node.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
if (nodeEval.isVisible() && validAuthentication(identity, token)) {
hasAccess = true;
}
}
return hasAccess;
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class IQEditController method getIQReference.
/**
* Ge the qti file soft key repository reference
* @param config
* @param strict
* @return RepositoryEntry
*/
public static RepositoryEntry getIQReference(ModuleConfiguration config, boolean strict) {
if (config == null) {
if (strict) {
throw new AssertException("missing config in IQ");
} else {
return null;
}
}
String repoSoftkey = (String) config.get(CONFIG_KEY_REPOSITORY_SOFTKEY);
if (repoSoftkey == null) {
if (strict) {
throw new AssertException("invalid config when being asked for references");
} else {
return null;
}
}
RepositoryManager rm = RepositoryManager.getInstance();
return rm.lookupRepositoryEntryBySoftkey(repoSoftkey, strict);
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class UserCalendarWebService method getCalendars.
private void getCalendars(CalendarVisitor calVisitor, UserRequest ureq) {
Roles roles = ureq.getUserSession().getRoles();
Identity retrievedUser = ureq.getIdentity();
CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
if (calendarModule.isEnabled()) {
if (calendarModule.isEnablePersonalCalendar()) {
KalendarRenderWrapper personalWrapper = getPersonalCalendar(ureq.getIdentity());
calVisitor.visit(personalWrapper);
}
if (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) {
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
repoParams.setIdentity(retrievedUser);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(retrievedUser);
ienv.setRoles(roles);
List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
for (RepositoryEntry entry : entries) {
AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
if (result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry);
CourseConfig config = course.getCourseEnvironment().getCourseConfig();
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
if (config.isCalendarEnabled()) {
KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
calVisitor.visit(wrapper);
} else {
CalCourseNodeVisitor visitor = new CalCourseNodeVisitor();
new CourseTreeVisitor(course, ienv).visit(visitor, new VisibleTreeFilter());
if (visitor.isFound()) {
KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
calVisitor.visit(wrapper);
}
}
} catch (Exception e) {
log.error("", e);
}
}
}
}
if (calendarModule.isEnableGroupCalendar()) {
CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
// start found forums in groups
BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
params.addTools(CollaborationTools.TOOL_CALENDAR);
List<BusinessGroup> groups = bgm.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : groups) {
KalendarRenderWrapper wrapper = collaborationManager.getCalendar(group, ureq, false);
calVisitor.visit(wrapper);
}
}
}
}
Aggregations