Search in sources :

Example 86 with RepositoryManager

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);
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryManager(org.olat.repository.RepositoryManager) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 87 with RepositoryManager

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;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) RepositoryManager(org.olat.repository.RepositoryManager) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) RepositoryEntry(org.olat.repository.RepositoryEntry) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 88 with RepositoryManager

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;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 89 with RepositoryManager

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);
}
Also used : AssertException(org.olat.core.logging.AssertException) RepositoryManager(org.olat.repository.RepositoryManager)

Example 90 with RepositoryManager

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);
            }
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) WebApplicationException(javax.ws.rs.WebApplicationException) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) CourseConfig(org.olat.course.config.CourseConfig) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroupService(org.olat.group.BusinessGroupService) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CalendarModule(org.olat.commons.calendar.CalendarModule) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CollaborationManager(org.olat.collaboration.CollaborationManager)

Aggregations

RepositoryManager (org.olat.repository.RepositoryManager)136 RepositoryEntry (org.olat.repository.RepositoryEntry)122 Path (javax.ws.rs.Path)42 Identity (org.olat.core.id.Identity)32 Produces (javax.ws.rs.Produces)30 Roles (org.olat.core.id.Roles)30 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)26 ArrayList (java.util.ArrayList)20 Consumes (javax.ws.rs.Consumes)20 PUT (javax.ws.rs.PUT)18 MailPackage (org.olat.core.util.mail.MailPackage)16 GET (javax.ws.rs.GET)14 BaseSecurity (org.olat.basesecurity.BaseSecurity)14 AssertException (org.olat.core.logging.AssertException)14 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)14 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)12 Controller (org.olat.core.gui.control.Controller)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 UserRequest (org.olat.core.gui.UserRequest)10 WindowControl (org.olat.core.gui.control.WindowControl)10