Search in sources :

Example 16 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project openolat by klemens.

the class ACFrontendManager method denyAccesToResource.

@Override
public boolean denyAccesToResource(Identity identity, Offer offer) {
    // check if offer is ok: key is stupid but further check as date, validity...
    if (offer.getKey() == null) {
        return false;
    }
    // check the resource
    OLATResource resource = offer.getResource();
    if (resource == null || resource.getKey() == null || resource.getResourceableId() == null || resource.getResourceableTypeName() == null) {
        return false;
    }
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        BusinessGroup group = businessGroupService.loadBusinessGroup(resource);
        if (group != null) {
            if (businessGroupService.hasRoles(identity, group, GroupRoles.participant.name())) {
                businessGroupRelationDao.removeRole(identity, group, GroupRoles.participant.name());
            }
            return true;
        }
    } else {
        RepositoryEntryRef entry = repositoryManager.lookupRepositoryEntry(resource, false);
        if (entry != null) {
            if (repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.participant.name())) {
                repositoryEntryRelationDao.removeRole(identity, entry, GroupRoles.participant.name());
            }
            return true;
        }
    }
    return false;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 17 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project openolat by klemens.

the class RepositoryEntryRelationDAO method countMembers.

public int countMembers(List<? extends RepositoryEntryRef> res, Identity excludeMe) {
    if (res == null || res.isEmpty())
        return 0;
    List<Long> repoKeys = new ArrayList<>(res.size());
    for (RepositoryEntryRef re : res) {
        repoKeys.add(re.getKey());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select count(distinct members.identity.key) from ").append(RepositoryEntry.class.getName()).append(" as v").append(" inner join v.groups as relGroup").append(" inner join relGroup.group as baseGroup").append(" inner join baseGroup.members as members").append(" where v.key in (:repoKeys)");
    if (excludeMe != null) {
        sb.append(" and not(members.identity.key=:identityKey)");
    }
    TypedQuery<Number> countQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class).setParameter("repoKeys", repoKeys);
    if (excludeMe != null) {
        countQuery.setParameter("identityKey", excludeMe.getKey());
    }
    Number count = countQuery.getSingleResult();
    return count == null ? 0 : count.intValue();
}
Also used : ArrayList(java.util.ArrayList) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 18 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project openolat by klemens.

the class RepositoryEntryRuntimeController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (cmc == source) {
        cleanUp();
    } else if (source == accessController) {
        if (event.equals(AccessEvent.ACCESS_OK_EVENT)) {
            doPostSuccessfullAccess(ureq);
        } else if (event.equals(AccessEvent.ACCESS_FAILED_EVENT)) {
            String msg = ((AccessEvent) event).getMessage();
            if (StringHelper.containsNonWhitespace(msg)) {
                getWindowControl().setError(msg);
            } else {
                showError("error.accesscontrol");
            }
        }
    } else if (accessCtrl == source) {
        if (event == Event.CHANGED_EVENT) {
            refreshRepositoryEntry(accessCtrl.getEntry());
            if (ordersLink != null) {
                boolean booking = acService.isResourceAccessControled(re.getOlatResource(), null);
                ordersLink.setVisible(!corrupted && booking);
            }
        } else if (event == Event.CLOSE_EVENT) {
            doClose(ureq);
        }
    } else if (descriptionCtrl == source) {
        if (event == Event.CHANGED_EVENT) {
            RepositoryEntry entry = descriptionCtrl.getEntry();
            refreshRepositoryEntry(entry);
            handler.onDescriptionChanged(entry);
            // update name of root bread crumb and opened tabs in top nav in case the title has been modified
            if (toolbarPanel.getBreadCrumbs().size() > 0) {
                String newTitle = entry.getDisplayname();
                String oldTitle = toolbarPanel.getBreadCrumbs().get(0).getCustomDisplayText();
                if (!newTitle.equals(oldTitle)) {
                    // 1: update breadcrumb in toolbar
                    toolbarPanel.getBreadCrumbs().get(0).setCustomDisplayText(newTitle);
                    // 2: update dynamic tab in topnav
                    OLATResourceable reOres = OresHelper.clone(entry);
                    getWindowControl().getWindowBackOffice().getWindow().getDTabs().updateDTabTitle(reOres, newTitle);
                }
            }
        } else if (event == Event.CLOSE_EVENT) {
            doClose(ureq);
        }
    } else if (detailsCtrl == source) {
        if (event instanceof LeavingEvent) {
            doClose(ureq);
        } else if (event == Event.DONE_EVENT) {
            popToRoot(ureq);
            cleanUp();
            if (getRuntimeController() == null) {
                doRun(ureq, reSecurity);
            }
        }
    } else if (confirmDeleteCtrl == source) {
        if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
            removeAsListenerAndDispose(confirmDeleteCtrl);
            removeAsListenerAndDispose(cmc);
            confirmDeleteCtrl = null;
            cmc = null;
        } else if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            cmc.deactivate();
            EntryChangedEvent e = new EntryChangedEvent(getRepositoryEntry(), getIdentity(), Change.deleted, "runtime");
            ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, RepositoryService.REPOSITORY_EVENT_ORES);
            doClose(ureq);
            cleanUp();
        }
    } else if (copyCtrl == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            RepositoryEntryRef copy = copyCtrl.getCopiedEntry();
            String businessPath = "[RepositoryEntry:" + copy.getKey() + "][EditDescription:0]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
            EntryChangedEvent e = new EntryChangedEvent(getRepositoryEntry(), getIdentity(), Change.added, "runtime");
            ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, RepositoryService.REPOSITORY_EVENT_ORES);
        }
        cleanUp();
    }
}
Also used : LeavingEvent(org.olat.repository.ui.list.LeavingEvent) AccessEvent(org.olat.resource.accesscontrol.ui.AccessEvent) OLATResourceable(org.olat.core.id.OLATResourceable) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 19 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project openolat by klemens.

the class EfficiencyStatementManager method deleteEfficiencyStatement.

/**
 * Delete the given efficiency statement for this person
 * @param identity
 * @param efficiencyStatement
 */
protected void deleteEfficiencyStatement(Identity identity, EfficiencyStatement efficiencyStatement) {
    RepositoryEntryRef ref = new RepositoryEntryRefImpl(efficiencyStatement.getCourseRepoEntryKey());
    UserEfficiencyStatement s = getUserEfficiencyStatementLightByRepositoryEntry(ref, identity);
    if (s != null) {
        dbInstance.getCurrentEntityManager().remove(s);
    }
}
Also used : UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 20 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project openolat by klemens.

the class GetScoreWithCourseIdFunction method call.

/**
 * @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
 */
public Object call(Object[] inStack) {
    if (inStack.length > 2) {
        // need > 2 for compatibility reason
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.nodereference"));
    } else if (inStack.length < 1) {
        return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.nodereference"));
    }
    Long courseRepoEntryKey;
    try {
        courseRepoEntryKey = Long.decode((String) inStack[0]);
    } catch (NumberFormatException nfe) {
        return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.coursnodeidexpeted", "solution.example.node.infunction"));
    }
    // no integrity check can be done - other course might not exist anymore
    CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
    if (cev != null) {
        return defaultValue();
    }
    // the real function evaluation which is used during run time
    EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
    RepositoryEntryRef courseRef = new RepositoryEntryRefImpl(courseRepoEntryKey);
    UserEfficiencyStatement es = esm.getUserEfficiencyStatementLightByRepositoryEntry(courseRef, getUserCourseEnv().getIdentityEnvironment().getIdentity());
    if (es == null)
        return defaultValue();
    Float score = es.getScore();
    if (score == null)
        return defaultValue();
    // finally check existing value
    return new Double(score.doubleValue());
}
Also used : CourseEditorEnv(org.olat.course.editor.CourseEditorEnv) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) ArgumentParseException(org.olat.course.condition.interpreter.ArgumentParseException) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Aggregations

RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)22 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)12 OLATResource (org.olat.resource.OLATResource)10 IdentityRef (org.olat.basesecurity.IdentityRef)6 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)6 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)6 ArrayList (java.util.ArrayList)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)4 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupRef (org.olat.group.BusinessGroupRef)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 BGRepositoryEntryRelation (org.olat.group.model.BGRepositoryEntryRelation)2 BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2