Search in sources :

Example 96 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MultiEvaluationFormController method initSegmentView.

private void initSegmentView(UserRequest ureq, List<Identity> otherEvaluators, boolean anonym) {
    mainVC = createVelocityContainer("multi_evaluation_form");
    segmentView = SegmentViewFactory.createSegmentView("segments", mainVC, this);
    boolean viewOthers = isViewOthers();
    if (owner != null) {
        String ownerFullname = userManager.getUserDisplayName(owner);
        evaluators.add(new Evaluator(owner, ownerFullname));
        String id = "eva-" + (count++);
        ownerLink = LinkFactory.createCustomLink(id, id, ownerFullname, Link.BUTTON | Link.NONTRANSLATED, mainVC, this);
        ownerLink.setUserObject(owner);
        boolean me = owner.equals(ureq.getIdentity());
        segmentView.addSegment(ownerLink, me);
        if (me) {
            doOpenEvalutationForm(ureq, owner);
        }
    }
    if (otherEvaluators != null && otherEvaluators.size() > 0) {
        int countEva = 1;
        for (Identity evaluator : otherEvaluators) {
            boolean me = evaluator.equals(ureq.getIdentity());
            String evaluatorFullname;
            if (!me && anonym) {
                evaluatorFullname = translate("anonym.evaluator", new String[] { Integer.toString(countEva++) });
            } else {
                evaluatorFullname = userManager.getUserDisplayName(evaluator);
            }
            evaluators.add(new Evaluator(evaluator, evaluatorFullname));
            String id = "eva-" + (count++);
            Link evaluatorLink = LinkFactory.createCustomLink(id, id, evaluatorFullname, Link.BUTTON | Link.NONTRANSLATED, mainVC, this);
            evaluatorLink.setUserObject(evaluator);
            otherEvaluatorLinks.add(evaluatorLink);
            segmentView.addSegment(evaluatorLink, me);
            if (me) {
                doOpenEvalutationForm(ureq, evaluator);
            }
        }
    }
    if ((owner != null && otherEvaluators != null && otherEvaluators.size() > 0) || (otherEvaluators != null && otherEvaluators.size() > 1)) {
        compareLink = LinkFactory.createLink("compare.evaluations", mainVC, this);
        compareLink.setUserObject(owner);
        segmentView.addSegment(compareLink, false);
    }
    segmentView.setVisible(viewOthers);
    mainVC.put("segments", segmentView);
}
Also used : Evaluator(org.olat.modules.forms.ui.model.Evaluator) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link)

Example 97 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MultiEvaluationFormController method initOnePageView.

private void initOnePageView(UserRequest ureq, List<Identity> otherEvaluators, boolean anonym) {
    mainVC = createVelocityContainer("multi_evaluation_one_page");
    List<EvaluatorPanel> panels = new ArrayList<>();
    mainVC.contextPut("panels", panels);
    boolean viewOthers = isViewOthers();
    if (owner != null) {
        String ownerFullname = userManager.getUserDisplayName(owner);
        Evaluator evaluator = new Evaluator(owner, ownerFullname);
        evaluators.add(evaluator);
        boolean me = owner.equals(getIdentity());
        if (me || viewOthers) {
            Controller ctrl = createEvalutationForm(ureq, owner);
            String componentName = "panel_" + (++count);
            panels.add(new EvaluatorPanel(evaluator, componentName, ctrl.getInitialComponent()));
            mainVC.put(componentName, ctrl.getInitialComponent());
        }
    }
    if (otherEvaluators != null && otherEvaluators.size() > 0) {
        int countEva = 1;
        for (Identity evaluator : otherEvaluators) {
            boolean me = evaluator.equals(ureq.getIdentity());
            String evaluatorFullname;
            if (!me && anonym) {
                evaluatorFullname = translate("anonym.evaluator", new String[] { Integer.toString(countEva++) });
            } else {
                evaluatorFullname = userManager.getUserDisplayName(evaluator);
            }
            Evaluator eval = new Evaluator(evaluator, evaluatorFullname);
            evaluators.add(eval);
            if (me || viewOthers) {
                Controller ctrl = createEvalutationForm(ureq, evaluator);
                String componentName = "panel_" + (++count);
                panels.add(new EvaluatorPanel(eval, componentName, ctrl.getInitialComponent()));
                mainVC.put(componentName, ctrl.getInitialComponent());
            }
        }
    }
    if (viewOthers && (owner != null && otherEvaluators != null && otherEvaluators.size() > 0) || (otherEvaluators != null && otherEvaluators.size() > 1)) {
        removeAsListenerAndDispose(compareEvaluationCtrl);
        CompareEvaluationsFormController ctrl = new CompareEvaluationsFormController(ureq, getWindowControl(), evaluators, anchor, formEntry);
        listenTo(ctrl);
        Evaluator eval = new Evaluator(null, translate("compare.evaluations"));
        String componentName = "panel_" + (++count);
        panels.add(new EvaluatorPanel(eval, componentName, ctrl.getInitialComponent()));
        mainVC.put(componentName, ctrl.getInitialComponent());
    }
}
Also used : CompareEvaluationsFormController(org.olat.modules.forms.ui.CompareEvaluationsFormController) ArrayList(java.util.ArrayList) Evaluator(org.olat.modules.forms.ui.model.Evaluator) CompareEvaluationsFormController(org.olat.modules.forms.ui.CompareEvaluationsFormController) Controller(org.olat.core.gui.control.Controller) EvaluationFormController(org.olat.modules.forms.ui.EvaluationFormController) BasicController(org.olat.core.gui.control.controller.BasicController) Identity(org.olat.core.id.Identity)

Example 98 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class PortfolioServiceImpl method updateAssessmentEntryLastModification.

private void updateAssessmentEntryLastModification(Binder binder, Identity doer, Role by) {
    if (binder.getEntry() == null)
        return;
    RepositoryEntry entry = binder.getEntry();
    List<Identity> assessedIdentities = getMembers(binder, PortfolioRoles.owner.name());
    // order status from the entry / section
    if ("CourseModule".equals(entry.getOlatResource().getResourceableTypeName())) {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(binder.getSubIdent());
        if (courseNode instanceof PortfolioCourseNode) {
            PortfolioCourseNode pfNode = (PortfolioCourseNode) courseNode;
            for (Identity assessedIdentity : assessedIdentities) {
                UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
                pfNode.updateLastModifications(userCourseEnv, doer, by);
            }
        }
    } else {
        OLATResource resource = ((BinderImpl) binder.getTemplate()).getOlatResource();
        RepositoryEntry referenceEntry = repositoryService.loadByResourceKey(resource.getKey());
        for (Identity assessedIdentity : assessedIdentities) {
            AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, null, binder.getEntry(), binder.getSubIdent(), referenceEntry);
            if (by == Role.coach) {
                assessmentEntry.setLastCoachModified(new Date());
            } else if (by == Role.user) {
                assessmentEntry.setLastUserModified(new Date());
            }
            assessmentService.updateAssessmentEntry(assessmentEntry);
        }
    }
}
Also used : PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) BinderImpl(org.olat.modules.portfolio.model.BinderImpl) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) Identity(org.olat.core.id.Identity) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date)

Example 99 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class SharedWithMeQueries method searchSharedBindersTwo.

private void searchSharedBindersTwo(Identity member, List<AssessedBinder> binders) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select binder.key,").append("  section.key, section.status, section.title, section.pos, section.endDate,").append("  page.key, page.status, page.lastModified, page.lastPublicationDate,").append("  body.lastModified, max(parts.lastModified), infos.recentLaunch").append(" from pfbinder as binder").append(" inner join binder.sections as section").append(" inner join section.pages as page").append(" inner join page.body as body").append(" left join body.parts as parts").append(" left join pfbinderuserinfos as infos on (infos.binder.key=binder.key and infos.identity.key=:identityKey)").append(" where exists (select membership.key from bgroupmember as membership").append("   where membership.group.key=binder.baseGroup.key and membership.identity.key=:identityKey and membership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select sectionMembership.key from bgroupmember as sectionMembership").append("   where sectionMembership.group.key=section.baseGroup.key and sectionMembership.identity.key=:identityKey and sectionMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select page.key from pfpage as coachedPage").append("   inner join coachedPage.baseGroup as pageGroup").append("   inner join pageGroup.members as pageMembership on (pageMembership.identity.key=:identityKey and pageMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("'))").append("   where coachedPage.key=page.key").append(" ) group by binder.key, section.key, section.status, section.title, section.pos, section.endDate,").append("    page.key, page.status, page.lastModified, page.lastPublicationDate, body.lastModified, infos.recentLaunch");
    Date now = new Date();
    List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", member.getKey()).getResultList();
    if (objects.size() > 0) {
        Set<Long> sectionKeys = new HashSet<>();
        Map<Long, AssessedBinder> keyToBinder = binders.stream().collect(Collectors.toMap(b -> b.getBinderKey(), b -> b));
        for (Object[] object : objects) {
            int pos = 0;
            Long binderKey = (Long) object[pos++];
            AssessedBinder binder = keyToBinder.get(binderKey);
            if (binder == null) {
                continue;
            }
            Long sectionKey = (Long) object[pos++];
            String sectionStatus = (String) object[pos++];
            String sectionTitle = (String) object[pos++];
            Number sectionPosNumber = (Number) object[pos++];
            Date sectionEndDate = (Date) object[pos++];
            ;
            Long pageKey = (Long) object[pos++];
            String pageStatus = (String) object[pos++];
            Date pageLastModified = (Date) object[pos++];
            Date pageLastPublication = (Date) object[pos++];
            Date bodyLastModified = (Date) object[pos++];
            Date partLastModified = (Date) object[pos++];
            Date recentLaunch = (Date) object[pos++];
            Date lastModified = pageLastModified;
            if (lastModified == null || (lastModified != null && partLastModified != null && partLastModified.after(lastModified))) {
                lastModified = partLastModified;
            }
            if (lastModified == null || (lastModified != null && bodyLastModified != null && bodyLastModified.after(lastModified))) {
                lastModified = bodyLastModified;
            }
            if (lastModified != null && (binder.getLastModified() == null || binder.getLastModified().before(lastModified))) {
                binder.setLastModified(lastModified);
            }
            if (binder.getRecentLaunch() == null) {
                binder.setRecentLaunch(recentLaunch);
            }
            if (pageKey != null && pageStatus == null) {
                binder.incrementNumOfDraftPages();
            } else if (StringHelper.containsNonWhitespace(pageStatus)) {
                PageStatus status = PageStatus.valueOf(pageStatus);
                if (PageStatus.isClosed(status, sectionEndDate, now)) {
                    binder.incrementNumOfClosedPages();
                } else if (PageStatus.draft.name().equals(pageStatus)) {
                    binder.incrementNumOfDraftPages();
                } else if (PageStatus.inRevision.name().equals(pageStatus)) {
                    binder.incrementNumOfInRevisionPages();
                }
            }
            if (recentLaunch == null && pageLastPublication != null) {
                binder.incrementNumOfNewlyPublishedPages();
            } else if (recentLaunch != null && pageLastPublication != null && recentLaunch.before(pageLastPublication)) {
                binder.incrementNumOfNewlyPublishedPages();
            }
            if (!sectionKeys.contains(sectionKey)) {
                SectionStatus status = SectionStatus.notStarted;
                if (StringHelper.containsNonWhitespace(sectionStatus)) {
                    status = SectionStatus.valueOf(sectionStatus);
                }
                if (status == SectionStatus.notStarted || status == SectionStatus.inProgress) {
                    binder.setNumOfOpenSections(binder.getNumOfOpenSections() + 1);
                }
                if (status == SectionStatus.inProgress || status == SectionStatus.submitted || status == SectionStatus.closed) {
                    if (binder.getSections() == null) {
                        binder.setSections(new ArrayList<>());
                    }
                    int sectionPos = sectionPosNumber == null ? -1 : sectionPosNumber.intValue();
                    binder.getSections().add(new AssessedBinderSection(sectionKey, sectionTitle, sectionPos));
                    sectionKeys.add(sectionKey);
                }
            }
        }
    }
}
Also used : PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) SearchSharePagesParameters(org.olat.modules.portfolio.model.SearchSharePagesParameters) AssessedBinderSection(org.olat.modules.portfolio.model.AssessedBinderSection) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) Service(org.springframework.stereotype.Service) Map(java.util.Map) SectionStatus(org.olat.modules.portfolio.SectionStatus) StringHelper(org.olat.core.util.StringHelper) PersistenceHelper.appendFuzzyLike(org.olat.core.commons.persistence.PersistenceHelper.appendFuzzyLike) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) Set(java.util.Set) BinderStatus(org.olat.modules.portfolio.BinderStatus) Collectors(java.util.stream.Collectors) List(java.util.List) DB(org.olat.core.commons.persistence.DB) Identity(org.olat.core.id.Identity) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) PortfolioRoles(org.olat.modules.portfolio.PortfolioRoles) PageStatus(org.olat.modules.portfolio.PageStatus) PageStatus(org.olat.modules.portfolio.PageStatus) SectionStatus(org.olat.modules.portfolio.SectionStatus) AssessedBinderSection(org.olat.modules.portfolio.model.AssessedBinderSection) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) Date(java.util.Date) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) HashSet(java.util.HashSet)

Example 100 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class SharedWithMeQueries method searchSharedPagesEntries.

public List<AssessedPage> searchSharedPagesEntries(Identity member, SearchSharePagesParameters params) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select binder.key,").append("  section.key, section.endDate,").append("  page.key, page.title, page.status, page.lastModified,").append("  body.lastModified,").append("  (select max(part.lastModified) from pfpagepart as part").append("   where part.body.key=body.key").append("  ) as partLastModified,").append("  uinfos.userStatus, uinfos.mark,").append("  owner").append(" from pfbinder as binder").append(" inner join binder.baseGroup as baseGroup").append(" inner join baseGroup.members as ownership on (ownership.role='").append(PortfolioRoles.owner.name()).append("')").append(" inner join ownership.identity as owner").append(" inner join fetch owner.user as owneruser").append(" inner join binder.sections as section").append(" inner join section.pages as page").append(" inner join page.body as body").append(params.isBookmarkOnly() ? " inner" : " left").append(" join pfpageuserinfos as uinfos on (uinfos.page.key=page.key and uinfos.identity.key=:identityKey)").append(" where ");
    if (params.isBookmarkOnly()) {
        sb.append(" uinfos.mark=true and");
    }
    String searchString = params.getSearchString();
    if (StringHelper.containsNonWhitespace(searchString)) {
        searchString = makeFuzzyQueryString(searchString);
        sb.append(" (");
        appendFuzzyLike(sb, "page.title", "searchString", dbInstance.getDbVendor());
        sb.append(") and");
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        sb.append(" (page.status is null or page.status not in (:excludedPageStatus)) and");
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        sb.append(" (uinfos.userStatus is null or uinfos.userStatus not in (:excludedPageUserStatus)) and");
    }
    sb.append(" (exists (select membership.key from bgroupmember as membership").append("   where membership.group.key=binder.baseGroup.key and membership.identity.key=:identityKey and membership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select sectionMembership.key from bgroupmember as sectionMembership").append("   where sectionMembership.group.key=section.baseGroup.key and sectionMembership.identity.key=:identityKey and sectionMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select page.key from pfpage as coachedPage").append("   inner join coachedPage.baseGroup as pageGroup").append("   inner join pageGroup.members as pageMembership on (pageMembership.identity.key=:identityKey and pageMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("'))").append("   where coachedPage.key=page.key").append(" ))");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", member.getKey());
    if (StringHelper.containsNonWhitespace(searchString)) {
        query.setParameter("searchString", searchString.toLowerCase());
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        List<String> excludedPageStatus = params.getExcludedPageStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageStatus", excludedPageStatus);
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        List<String> excludedPageUserStatus = params.getExcludedPageUserStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageUserStatus", excludedPageUserStatus);
    }
    List<Object[]> objects = query.getResultList();
    List<AssessedPage> items = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        int pos = 0;
        Long binderKey = (Long) object[pos++];
        // Section key
        pos++;
        Date sectionDate = (Date) object[pos++];
        Long pageKey = (Long) object[pos++];
        String pageTitle = (String) object[pos++];
        PageStatus pageStatus = PageStatus.valueOfOrNull((String) object[pos++]);
        Date pageLastModified = (Date) object[pos++];
        Date bodyLastModified = (Date) object[pos++];
        Date partLastModified = (Date) object[pos++];
        PageUserStatus userStatus = PageUserStatus.valueOfWithDefault((String) object[pos++]);
        Boolean mark = (Boolean) object[pos++];
        Identity owner = (Identity) object[pos++];
        Date lastModified = pageLastModified;
        if (lastModified == null || (lastModified != null && partLastModified != null && partLastModified.after(lastModified))) {
            lastModified = partLastModified;
        }
        if (lastModified == null || (lastModified != null && bodyLastModified != null && bodyLastModified.after(lastModified))) {
            lastModified = bodyLastModified;
        }
        items.add(new AssessedPage(binderKey, sectionDate, pageKey, pageTitle, pageStatus, lastModified, mark, userStatus, owner));
    }
    return items;
}
Also used : PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) SearchSharePagesParameters(org.olat.modules.portfolio.model.SearchSharePagesParameters) AssessedBinderSection(org.olat.modules.portfolio.model.AssessedBinderSection) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) Service(org.springframework.stereotype.Service) Map(java.util.Map) SectionStatus(org.olat.modules.portfolio.SectionStatus) StringHelper(org.olat.core.util.StringHelper) PersistenceHelper.appendFuzzyLike(org.olat.core.commons.persistence.PersistenceHelper.appendFuzzyLike) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) Set(java.util.Set) BinderStatus(org.olat.modules.portfolio.BinderStatus) Collectors(java.util.stream.Collectors) List(java.util.List) DB(org.olat.core.commons.persistence.DB) Identity(org.olat.core.id.Identity) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) PortfolioRoles(org.olat.modules.portfolio.PortfolioRoles) PageStatus(org.olat.modules.portfolio.PageStatus) PageStatus(org.olat.modules.portfolio.PageStatus) ArrayList(java.util.ArrayList) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) Date(java.util.Date) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) Identity(org.olat.core.id.Identity)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130