use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class CourseGlossaryFactory method createCourseGlossaryMainRunController.
/**
* The glossarymaincontroller allows browsing in the glossary. A flag enables
* the edit mode.
*
* @param windowControl
* @param ureq
* @param courseConfig use the glossary configuration from the given course
* configuration
* @param hasGlossaryEditRights
* @return
*/
public static GlossaryMainController createCourseGlossaryMainRunController(WindowControl lwControl, UserRequest lureq, CourseConfig cc, boolean hasGlossaryRights) {
if (cc.hasGlossary()) {
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
if (repoEntry == null) {
// seems to be removed
return null;
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
boolean owner = repositoryService.hasRole(lureq.getIdentity(), repoEntry, GroupRoles.owner.name());
VFSContainer glossaryFolder = GlossaryManager.getInstance().getGlossaryRootFolder(repoEntry.getOlatResource());
Properties glossProps = GlossaryItemManager.getInstance().getGlossaryConfig(glossaryFolder);
boolean editUsersEnabled = "true".equals(glossProps.getProperty(GlossaryItemManager.EDIT_USERS));
GlossarySecurityCallback secCallback;
if (lureq.getUserSession().getRoles().isGuestOnly()) {
secCallback = new GlossarySecurityCallbackImpl();
} else {
secCallback = new GlossarySecurityCallbackImpl(hasGlossaryRights, owner, editUsersEnabled, lureq.getIdentity().getKey());
}
return new GlossaryMainController(lwControl, lureq, glossaryFolder, repoEntry.getOlatResource(), secCallback, true);
}
return null;
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class CourseSite method createController.
@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
if (entry == null) {
return getAlternativeController(ureq, wControl, config);
}
MainLayoutController c;
ICourse course = CourseFactory.loadCourse(entry);
UserSession usess = ureq.getUserSession();
// course-launch-state depending course-settings
RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
boolean isAllowedToLaunch = reSecurity.canLaunch();
boolean hasAccess = false;
if (isAllowedToLaunch) {
// either check with securityCallback or use access-settings from course-nodes
if (siteSecCallback != null) {
hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
} else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
hasAccess = false;
} else {
// check within course: accessibility of course root node
CourseNode rootNode = course.getRunStructure().getRootNode();
UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
}
}
// load course (admins always see content) or alternative controller if course is not launchable
if (hasAccess || usess.getRoles().isOLATAdmin()) {
rs.incrementLaunchCounter(entry);
// build up the context path for linked course
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {
@Override
public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
}
}, false, true);
// Configure run controller
// a: don't show close link, is opened as site not tab
runCtr.setCourseCloseEnabled(false);
// b: don't show toolbar
if (!showToolController) {
runCtr.setToolControllerEnabled(false);
}
c = runCtr;
} else {
// access restricted (not in group / author) -> show controller
// defined in olat_extensions (type autoCreator)
c = getAlternativeController(ureq, wControl, config);
}
return c;
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class CourseSiteContextEntryControllerCreator method createLaunchController.
/**
* Create a launch controller used to launch the given repo entry.
* @param re
* @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
* @param ureq
* @param wControl
* @return null if no entry was found, a no access message controller if not allowed to launch or the launch
* controller if successful.
*/
private Controller createLaunchController(RepositoryEntry re, UserRequest ureq, WindowControl wControl) {
if (re == null) {
return messageController(ureq, wControl, "repositoryentry.not.existing");
}
UserSession usess = ureq.getUserSession();
if (re.getAccess() == RepositoryEntry.DELETED) {
Roles roles = usess.getRoles();
if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
return messageController(ureq, wControl, "repositoryentry.deleted");
}
}
if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(re.getOlatResource())) {
return null;
}
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, re);
if (!reSecurity.canLaunch()) {
return messageController(ureq, wControl, "launch.noaccess");
}
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
rs.incrementLaunchCounter(re);
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
WindowControl bwControl;
OLATResourceable businessOres = re;
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
if (ce.equals(wControl.getBusinessControl().getCurrentContextEntry())) {
bwControl = wControl;
} else {
bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
}
MainLayoutController ctrl = handler.createLaunchController(re, reSecurity, ureq, bwControl);
if (ctrl == null) {
throw new AssertException("could not create controller for repositoryEntry " + re);
}
return ctrl;
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class QTIHandler method createResource.
protected RepositoryEntry createResource(String type, FileResource ores, Identity initialAuthor, String displayname, String description, Object object, Locale locale) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
File fRepositoryQTI = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), "qti.zip");
QTIEditorPackageImpl qtiPackage = new QTIEditorPackageImpl(displayname, type, locale);
if (object instanceof QItemList) {
QItemList itemToImport = (QItemList) object;
QTIQPoolServiceProvider provider = (QTIQPoolServiceProvider) CoreSpringFactory.getBean("qtiPoolServiceProvider");
provider.exportToEditorPackage(qtiPackage, itemToImport.getItems(), true);
}
qtiPackage.savePackageTo(fRepositoryQTI);
return re;
}
use of org.olat.repository.RepositoryService in project OpenOLAT by OpenOLAT.
the class BinderTemplateHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
try {
// create resource
OLATResource resource = portfolioService.createBinderTemplateResource();
OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
File fResourceFileroot = fResourceRootContainer.getBasefile();
File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
FileResource.copyResource(file, filename, zipRoot);
// create repository entry
RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
// import binder
File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
File posterImage = null;
if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
posterImage = new File(zipRoot, transientBinder.getImagePath());
}
portfolioService.importBinder(transientBinder, re, posterImage);
RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
if (rei.anyExportedPropertiesAvailable()) {
re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
}
// delete the imported files
FileUtils.deleteDirsAndFiles(zipRoot, true, true);
return re;
} catch (IOException e) {
log.error("", e);
return null;
}
}
Aggregations