use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class NewControllerFactory method launch.
/**
* Launch a controller in a tab or site in the given window from a user
* request url
*
* @param ureq
* @param wControl
*/
public boolean launch(UserRequest ureq, WindowControl wControl) {
BusinessControl bc = wControl.getBusinessControl();
ContextEntry mainCe = bc.popLauncherContextEntry();
if (mainCe == null) {
// nothing to launch
return false;
}
OLATResourceable ores = mainCe.getOLATResourceable();
// Check for RepositoryEntry resource
RepositoryEntry re = null;
if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(RepositoryEntry.class))) {
if (ores instanceof RepositoryEntry) {
re = (RepositoryEntry) ores;
ores = re.getOlatResource();
} else {
// It is a repository-entry => get OLATResourceable from RepositoryEntry
RepositoryManager repom = RepositoryManager.getInstance();
re = repom.lookupRepositoryEntry(ores.getResourceableId());
if (re != null) {
ores = re.getOlatResource();
mainCe.upgradeOLATResourceable(re);
}
}
}
// was brasato:: DTabs dts = wControl.getDTabs();
UserSession usess = ureq.getUserSession();
Window window = Windows.getWindows(usess).getWindow(ureq);
if (window == null) {
log.debug("Found no window for jumpin => take WindowBackOffice", null);
window = wControl.getWindowBackOffice().getWindow();
}
DTabs dts = window.getDTabs();
String firstType = mainCe.getOLATResourceable().getResourceableTypeName();
// String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup
ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType);
if (typeHandler == null) {
log.warn("Cannot found an handler for context entry: " + mainCe, null);
// simply return and don't throw a red screen
return false;
}
if (!typeHandler.validateContextEntryAndShowError(mainCe, ureq, wControl)) {
// simply return and don't throw a red screen
return false;
}
List<ContextEntry> entries = new ArrayList<ContextEntry>(5);
while (bc.hasContextEntry()) {
entries.add(bc.popLauncherContextEntry());
}
List<ContextEntry> ces = new ArrayList<ContextEntry>(entries.size() + 1);
ces.add(mainCe);
if (entries.size() > 0) {
ces.addAll(entries);
}
TabContext context = typeHandler.getTabContext(ureq, ores, mainCe, entries);
String siteClassName = typeHandler.getSiteClassName(ces, ureq);
// open in existing site
boolean launched = false;
boolean assessmentMode = usess.isInAssessmentModeProcess();
if (siteClassName != null) {
if (!assessmentMode) {
dts.activateStatic(ureq, siteClassName, context.getContext());
launched = true;
}
} else if (!assessmentMode || usess.matchLockResource(ores)) {
// get current tab or create new tab
DTab dt = dts.getDTab(ores);
if (dt == null) {
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, dts.getWindowControl());
usess.addToHistory(ureq, bc);
Controller launchC = typeHandler.createController(ces, ureq, bwControl);
if (launchC != null) {
dt = dts.createDTab(context.getTabResource(), re, launchC, context.getName());
if (dt == null) {
launched = false;
} else if (dts.addDTab(ureq, dt)) {
dts.activate(ureq, dt, context.getContext());
launched = true;
}
}
} else {
dts.activate(ureq, dt, context.getContext());
launched = true;
}
}
return launched;
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class CatalogHelper method addCourseToCatalogEntry.
/**
* Add a persisted course to the given catalog entry.
*
* @param course course object
* @param catEntry catalog entry
*/
public static final void addCourseToCatalogEntry(final ICourse course, final CatalogEntry catEntry) {
OLATResource ores = OLATResourceManager.getInstance().findResourceable(course.getResourceableId(), course.getResourceableTypeName());
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry re = rm.lookupRepositoryEntry(ores, true);
CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
CatalogEntry newLinkNotPersistedYet = cm.createCatalogEntry();
newLinkNotPersistedYet.setName(re.getDisplayname());
newLinkNotPersistedYet.setDescription(re.getDescription());
newLinkNotPersistedYet.setRepositoryEntry(re);
newLinkNotPersistedYet.setType(CatalogEntry.TYPE_LEAF);
newLinkNotPersistedYet.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
cm.addCatalogEntry(catEntry, newLinkNotPersistedYet);
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class CourseCreationHelper method finalizeWorkflow.
/**
* Finalizes the course creation workflow via wizard.
* @param ureq
*/
public void finalizeWorkflow(final UserRequest ureq) {
// --------------------------
// 1. insert the course nodes
// --------------------------
// single page node
CourseNode singlePageNode = null;
if (courseConfig.isCreateSinglePage()) {
singlePageNode = CourseExtensionHelper.createSinglePageNode(course, translator.translate("cce.informationpage"), translator.translate("cce.informationpage.descr"));
if (singlePageNode instanceof SPCourseNode) {
final String relPath = CourseEditorHelper.createUniqueRelFilePathFromShortTitle(singlePageNode, course.getCourseFolderContainer());
HTMLDocumentHelper.createHtmlDocument(course, relPath, courseConfig.getSinglePageText(translator));
((SPCourseNode) singlePageNode).getModuleConfiguration().set(SPEditController.CONFIG_KEY_FILE, relPath);
}
}
// enrollment node
CourseNode enCourseNode = null;
if (courseConfig.isCreateEnrollment()) {
enCourseNode = CourseExtensionHelper.createEnrollmentNode(course, translator.translate("cce.enrollment"), translator.translate("cce.enrollment.descr"));
}
// download folder node
CourseNode downloadFolderNode = null;
if (courseConfig.isCreateDownloadFolder()) {
downloadFolderNode = CourseExtensionHelper.createDownloadFolderNode(course, translator.translate("cce.downloadfolder"), translator.translate("cce.downloadfolder.descr"));
}
// forum node
CourseNode forumNode = null;
if (courseConfig.isCreateForum()) {
forumNode = CourseExtensionHelper.createForumNode(course, translator.translate("cce.forum"), translator.translate("cce.forum.descr"));
}
// contact form node
CourseNode contactNode = null;
if (courseConfig.isCreateContactForm()) {
contactNode = CourseExtensionHelper.createContactFormNode(course, translator.translate("cce.contactform"), translator.translate("cce.contactform.descr"));
if (contactNode instanceof COCourseNode) {
final List<String> emails = new ArrayList<String>();
String subject = translator.translate("cce.contactform.subject") + " " + courseConfig.getCourseTitle();
String email = ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());
if (StringHelper.containsNonWhitespace(email)) {
emails.add(email);
}
COCourseNode cocn = (COCourseNode) contactNode;
cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_EMAILTOADRESSES, emails);
cocn.getModuleConfiguration().set(COEditController.CONFIG_KEY_MSUBJECT_DEFAULT, subject);
}
}
// enrollment node
if (courseConfig.isCreateEnrollment()) {
// --------------------------
// 2. setup enrollment
// --------------------------
final String groupBaseName = createGroupBaseName();
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
// get default context for learning groups
// create n learning groups with m allowed members
String comma = "";
String tmpGroupList = "";
String groupNamesList = "";
for (int i = 0; i < courseConfig.getGroupCount(); i++) {
// create group
String name = groupBaseName + " " + (i + 1);
BusinessGroup learningGroup = bgs.createBusinessGroup(ureq.getIdentity(), name, null, 0, courseConfig.getSubscriberCount(), courseConfig.getEnableWaitlist(), courseConfig.getEnableFollowup(), addedEntry);
// enable the contact collaboration tool
CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(learningGroup);
ct.setToolEnabled(CollaborationTools.TOOL_CONTACT, true);
// append to current learning group list
groupNamesList = tmpGroupList + comma + learningGroup.getName();
enCourseNode.getModuleConfiguration().set(ENCourseNode.CONFIG_GROUPNAME, groupNamesList);
if (i == 0) {
comma = ",";
}
tmpGroupList = (String) enCourseNode.getModuleConfiguration().get(ENCourseNode.CONFIG_GROUPNAME);
}
// set signout property
enCourseNode.getModuleConfiguration().set(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED, courseConfig.getEnableSignout());
// access limits on chosen course elements
if (courseConfig.getEnableAccessLimit()) {
if (courseConfig.isEnableAclContactForm()) {
if (contactNode instanceof COCourseNode) {
Condition c = ((COCourseNode) contactNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((COCourseNode) contactNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclSinglePage()) {
if (singlePageNode instanceof SPCourseNode) {
Condition c = ((SPCourseNode) singlePageNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((SPCourseNode) singlePageNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclForum()) {
if (forumNode instanceof FOCourseNode) {
Condition c = ((FOCourseNode) forumNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((FOCourseNode) forumNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
if (courseConfig.isEnableAclDownloadFolder()) {
if (downloadFolderNode instanceof BCCourseNode) {
Condition c = ((BCCourseNode) downloadFolderNode).getPreConditionVisibility();
c.setEasyModeGroupAccess(groupNamesList);
((BCCourseNode) downloadFolderNode).setNoAccessExplanation(translator.translate("noaccessexplain"));
// calculate expression from easy mode form
String condString = c.getConditionFromEasyModeConfiguration();
c.setConditionExpression(condString);
c.setExpertMode(false);
}
}
}
}
// --------------------------
if (courseConfig.getPublish()) {
CourseAccessAndProperties accessAndProps = courseConfig.getAccessAndProperties();
RepositoryManager manager = RepositoryManager.getInstance();
addedEntry = manager.setAccessAndProperties(accessAndProps.getRepositoryEntry(), accessAndProps.getAccess(), accessAndProps.isMembersOnly(), accessAndProps.isCanCopy(), accessAndProps.isCanReference(), accessAndProps.isCanDownload());
addedEntry = manager.setLeaveSetting(addedEntry, accessAndProps.getSetting());
List<OfferAccess> offerAccess = accessAndProps.getOfferAccess();
ACService acService = CoreSpringFactory.getImpl(ACService.class);
for (OfferAccess newLink : offerAccess) {
acService.saveOfferAccess(newLink);
}
}
course = CourseFactory.openCourseEditSession(course.getResourceableId());
course.getRunStructure().getRootNode().setShortTitle(addedEntry.getDisplayname());
course.getRunStructure().getRootNode().setLongTitle(addedEntry.getDisplayname());
CourseFactory.saveCourse(course.getResourceableId());
final CourseEditorTreeModel cetm = course.getEditorTreeModel();
final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
rootNode.setShortTitle(addedEntry.getDisplayname());
rootNode.setLongTitle(addedEntry.getDisplayname());
course.getEditorTreeModel().nodeConfigChanged(course.getRunStructure().getRootNode());
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
// --------------------------
// 3.2 publish the course
// --------------------------
// fetch publish process
final PublishProcess pp = PublishProcess.getInstance(course, cetm, ureq.getLocale());
final StatusDescription[] sds;
// create publish node list
List<String> nodeIds = new ArrayList<String>();
nodeIds.add(cetm.getRootNode().getIdent());
for (int i = 0; i < cetm.getRootNode().getChildCount(); i++) {
nodeIds.add(cetm.getRootNode().getChildAt(i).getIdent());
}
pp.createPublishSetFor(nodeIds);
PublishSetInformations set = pp.testPublishSet(ureq.getLocale());
sds = set.getWarnings();
boolean isValid = sds.length == 0;
if (!isValid) {
// no error and no warnings -> return immediate
log.error("Course Publishing failed", new AssertionError());
}
pp.applyPublishSet(ureq.getIdentity(), ureq.getLocale(), true);
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
// save catalog entry
if (getConfiguration().getSelectedCatalogEntry() != null) {
CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
CatalogEntry newEntry = cm.createCatalogEntry();
newEntry.setRepositoryEntry(addedEntry);
newEntry.setName(addedEntry.getDisplayname());
newEntry.setDescription(addedEntry.getDescription());
newEntry.setType(CatalogEntry.TYPE_LEAF);
newEntry.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
// save entry
cm.addCatalogEntry(getConfiguration().getSelectedCatalogEntry(), newEntry);
}
}
use of org.olat.repository.RepositoryManager in project openolat by klemens.
the class VCCourseNode method createNodeRunConstructionResult.
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
updateModuleConfigDefaults(false);
// check if user is moderator of the virtual classroom
Roles roles = ureq.getUserSession().getRoles();
boolean moderator = roles.isOLATAdmin();
Long key = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
if (!moderator) {
if (roles.isInstitutionalResourceManager() | roles.isAuthor()) {
RepositoryManager rm = RepositoryManager.getInstance();
ICourse course = CourseFactory.loadCourse(key);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if (re != null) {
moderator = rm.isOwnerOfRepositoryEntry(ureq.getIdentity(), re);
if (!moderator) {
moderator = rm.isInstitutionalRessourceManagerFor(ureq.getIdentity(), ureq.getUserSession().getRoles(), re);
}
}
}
}
// load configuration
final String providerId = getModuleConfiguration().getStringValue(CONF_PROVIDER_ID);
VCProvider provider = providerId == null ? VCProviderFactory.createDefaultProvider() : VCProviderFactory.createProvider(providerId);
VCConfiguration config = handleConfig(provider);
// create run controller
Controller runCtr = new VCRunController(ureq, wControl, key + "_" + getIdent(), getShortName(), getLongTitle(), config, provider, moderator, userCourseEnv.isCourseReadOnly());
Controller controller = TitledWrapperHelper.getWrapper(ureq, wControl, runCtr, this, "o_vc_icon");
return new NodeRunConstructionResult(controller);
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class VideoHandler method getAsMediaResource.
@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
RepositoryManager repoManager = CoreSpringFactory.getImpl(RepositoryManager.class);
RepositoryEntry repoEntry = repoManager.lookupRepositoryEntry(res, false);
if (repoEntry == null) {
return new NotFoundMediaResource();
}
VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
VideoExportMediaResource exportResource = videoManager.getVideoExportMediaResource(repoEntry);
return exportResource;
}
Aggregations