Search in sources :

Example 6 with CPPackageConfig

use of org.olat.ims.cp.ui.CPPackageConfig in project openolat by klemens.

the class ImsCPHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    final CPManager cpManager = CPManager.getInstance();
    OLATResource sourceResource = source.getOlatResource();
    OLATResource targetResource = target.getOlatResource();
    File sourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(sourceResource).getBasefile();
    File zipRoot = new File(sourceFileroot, FileResourceManager.ZIPDIR);
    File targetFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(targetResource).getBasefile();
    FileUtils.copyFileToDir(zipRoot, targetFileroot, "add file resource");
    // copy packaging info
    CPPackageConfig cpConfig = cpManager.getCPPackageConfig(sourceResource);
    if (cpConfig != null) {
        cpManager.setCPPackageConfig(targetResource, cpConfig);
    }
    CPOfflineReadableManager.getInstance().makeCPOfflineReadable(targetResource, target.getDisplayname() + ".zip");
    return target;
}
Also used : CPManager(org.olat.ims.cp.CPManager) OLATResource(org.olat.resource.OLATResource) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) File(java.io.File)

Example 7 with CPPackageConfig

use of org.olat.ims.cp.ui.CPPackageConfig in project openolat by klemens.

the class CPCourseNode method updateModuleConfigDefaults.

/**
 * Update the module configuration to have all mandatory configuration flags
 * set to usefull default values
 *
 * @param isNewNode true: an initial configuration is set; false: upgrading
 *          from previous node configuration version, set default to maintain
 *          previous behaviour
 */
@Override
public void updateModuleConfigDefaults(boolean isNewNode) {
    int CURRENTVERSION = 7;
    ModuleConfiguration config = getModuleConfiguration();
    if (isNewNode) {
        // use defaults for new course building blocks
        config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.FALSE.booleanValue());
        config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, Boolean.TRUE.booleanValue());
        // how to render files (include jquery etc)
        DeliveryOptions nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
        nodeDeliveryOptions.setInherit(Boolean.TRUE);
        config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
        config.setConfigurationVersion(CURRENTVERSION);
    } else {
        config.remove(NodeEditController.CONFIG_INTEGRATION);
        if (config.getConfigurationVersion() < 2) {
            // update new configuration options using default values for existing
            // nodes
            config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.TRUE.booleanValue());
            Boolean componentMenu = config.getBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU);
            if (componentMenu == null) {
                config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, Boolean.TRUE.booleanValue());
            }
            config.setConfigurationVersion(2);
        }
        if (config.getConfigurationVersion() < 3) {
            config.set(NodeEditController.CONFIG_CONTENT_ENCODING, NodeEditController.CONFIG_CONTENT_ENCODING_AUTO);
            config.set(NodeEditController.CONFIG_JS_ENCODING, NodeEditController.CONFIG_JS_ENCODING_AUTO);
            config.setConfigurationVersion(3);
        }
        // save it as version 6
        if (config.getConfigurationVersion() < 7) {
            String contentEncoding = (String) config.get(NodeEditController.CONFIG_CONTENT_ENCODING);
            if (contentEncoding != null && contentEncoding.equals("auto")) {
                // new style for auto
                contentEncoding = null;
            }
            String jsEncoding = (String) config.get(NodeEditController.CONFIG_JS_ENCODING);
            if (jsEncoding != null && jsEncoding.equals("auto")) {
                // new style for auto
                jsEncoding = null;
            }
            CPPackageConfig reConfig = null;
            DeliveryOptions nodeDeliveryOptions = (DeliveryOptions) config.get(CPEditController.CONFIG_DELIVERYOPTIONS);
            if (nodeDeliveryOptions == null) {
                // Update missing delivery options now, inherit from repo by default
                nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
                nodeDeliveryOptions.setInherit(Boolean.TRUE);
                RepositoryEntry re = getReferencedRepositoryEntry();
                // Check if delivery options are set for repo entry, if not create default
                if (re != null) {
                    reConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
                    if (reConfig == null) {
                        reConfig = new CPPackageConfig();
                    }
                    DeliveryOptions repoDeliveryOptions = reConfig.getDeliveryOptions();
                    if (repoDeliveryOptions == null) {
                        // migrate existing config back to repo entry using the default as a base
                        repoDeliveryOptions = DeliveryOptions.defaultWithGlossary();
                        reConfig.setDeliveryOptions(repoDeliveryOptions);
                        repoDeliveryOptions.setContentEncoding(contentEncoding);
                        repoDeliveryOptions.setJavascriptEncoding(jsEncoding);
                        CPManager.getInstance().setCPPackageConfig(re.getOlatResource(), reConfig);
                    } else {
                        // see if we have any different settings than the repo. if so, don't use inherit mode
                        if (contentEncoding != repoDeliveryOptions.getContentEncoding() || jsEncoding != repoDeliveryOptions.getJavascriptEncoding()) {
                            nodeDeliveryOptions.setInherit(Boolean.FALSE);
                            nodeDeliveryOptions.setContentEncoding(contentEncoding);
                            nodeDeliveryOptions.setJavascriptEncoding(jsEncoding);
                        }
                    }
                }
                // remove old config parameters
                config.remove(NodeEditController.CONFIG_CONTENT_ENCODING);
                config.remove(NodeEditController.CONFIG_JS_ENCODING);
                // replace with new delivery options
                config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
            }
            config.setConfigurationVersion(7);
        }
    // else node is up-to-date - nothing to do
    }
    if (config.getConfigurationVersion() != CURRENTVERSION) {
        OLog logger = Tracing.createLoggerFor(CPCourseNode.class);
        logger.error("CP course node version not updated to lastest version::" + CURRENTVERSION + ", was::" + config.getConfigurationVersion() + ". Check the code, programming error.");
    }
}
Also used : OLog(org.olat.core.logging.OLog) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) RepositoryEntry(org.olat.repository.RepositoryEntry) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions)

Example 8 with CPPackageConfig

use of org.olat.ims.cp.ui.CPPackageConfig in project OpenOLAT by OpenOLAT.

the class ImsCPHandler method createLaunchController.

@Override
public MainLayoutController createLaunchController(RepositoryEntry re, RepositoryEntrySecurity reSecurity, UserRequest ureq, WindowControl wControl) {
    OLATResource res = re.getOlatResource();
    File cpRoot = FileResourceManager.getInstance().unzipFileResource(res);
    final LocalFolderImpl vfsWrapper = new LocalFolderImpl(cpRoot);
    CPPackageConfig packageConfig = CPManager.getInstance().getCPPackageConfig(res);
    final DeliveryOptions deliveryOptions = (packageConfig == null ? null : packageConfig.getDeliveryOptions());
    return new CPRuntimeController(ureq, wControl, re, reSecurity, new RuntimeControllerCreator() {

        @Override
        public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry entry, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
            boolean activateFirstPage = true;
            String initialUri = null;
            CoreSpringFactory.getImpl(UserCourseInformationsManager.class).updateUserCourseInformations(entry.getOlatResource(), uureq.getIdentity());
            CPDisplayController cpCtr = new CPDisplayController(uureq, wwControl, vfsWrapper, true, true, activateFirstPage, true, deliveryOptions, initialUri, entry.getOlatResource(), "", false);
            MainLayout3ColumnsController ctr = new LayoutMain3ColsController(uureq, wwControl, cpCtr.getMenuComponent(), cpCtr.getInitialComponent(), vfsWrapper.getName());
            ctr.addDisposableChildController(cpCtr);
            return ctr;
        }
    });
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) MainLayout3ColumnsController(org.olat.core.gui.control.generic.layout.MainLayout3ColumnsController) CPDisplayController(org.olat.modules.cp.CPDisplayController) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayout3ColumnsController(org.olat.core.gui.control.generic.layout.MainLayout3ColumnsController) CPContentController(org.olat.ims.cp.ui.CPContentController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) CPDisplayController(org.olat.modules.cp.CPDisplayController) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) CPRuntimeController(org.olat.ims.cp.ui.CPRuntimeController) CPEditMainController(org.olat.ims.cp.ui.CPEditMainController) Controller(org.olat.core.gui.control.Controller) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) CPRuntimeController(org.olat.ims.cp.ui.CPRuntimeController) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) File(java.io.File) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions) UserRequest(org.olat.core.gui.UserRequest)

Example 9 with CPPackageConfig

use of org.olat.ims.cp.ui.CPPackageConfig in project OpenOLAT by OpenOLAT.

the class CPRunController method doLaunch.

private void doLaunch(UserRequest ureq) {
    DeliveryOptions deliveryOptions = (DeliveryOptions) config.get(CPEditController.CONFIG_DELIVERYOPTIONS);
    if (cpRoot == null) {
        // it is the first time we start the contentpackaging from this instance
        // of this controller.
        // need to be strict when launching -> "true"
        RepositoryEntry re = CPEditController.getCPReference(config, false);
        if (re == null) {
            showError(CPEditController.NLS_ERROR_CPREPOENTRYMISSING);
            return;
        }
        cpRoot = FileResourceManager.getInstance().unzipFileResource(re.getOlatResource());
        // nodes reference them
        if (cpRoot == null) {
            showError(CPEditController.NLS_ERROR_CPREPOENTRYMISSING);
            return;
        }
        if (deliveryOptions != null && deliveryOptions.getInherit() != null && deliveryOptions.getInherit().booleanValue()) {
            CPPackageConfig packageConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
            if (packageConfig != null && packageConfig.getDeliveryOptions() != null) {
                deliveryOptions = packageConfig.getDeliveryOptions();
            }
        }
    }
    // else cpRoot is already set (save some db access if the user opens /
    // closes / reopens the cp from the same CPRuncontroller instance)
    boolean activateFirstPage = true;
    if ((nodecmd != null) && !nodecmd.equals("")) {
        activateFirstPage = false;
    }
    boolean showNavigation = !config.getBooleanSafe(NodeEditController.CONFIG_COMPONENT_MENU);
    cpDispC = CPUIFactory.getInstance().createContentOnlyCPDisplayController(ureq, getWindowControl(), new LocalFolderImpl(cpRoot), activateFirstPage, showNavigation, deliveryOptions, nodecmd, courseResource, cpNode.getIdent(), preview);
    cpDispC.setContentEncoding(deliveryOptions.getContentEncoding());
    cpDispC.setJSEncoding(deliveryOptions.getJavascriptEncoding());
    cpDispC.addControllerListener(this);
    main.setContent(cpDispC.getInitialComponent());
    if (isExternalMenuConfigured()) {
        treeModel = cpDispC.getTreeModel();
        treeNodeClickListener = this;
        if (activateFirstPage) {
            selNodeId = cpDispC.getInitialSelectedNodeId();
        } else {
            String uri = nodecmd;
            if (uri.startsWith("/")) {
                uri = uri.substring(1, uri.length());
            }
            selNodeId = cpDispC.getNodeByUri(uri);
        }
    }
}
Also used : CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) RepositoryEntry(org.olat.repository.RepositoryEntry) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 10 with CPPackageConfig

use of org.olat.ims.cp.ui.CPPackageConfig in project OpenOLAT by OpenOLAT.

the class CompMenuForm method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest urequest, Controller source, Event event) {
    if (source == searchController) {
        if (event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) {
            // search controller done
            // -> close closeable modal controller
            cmc.deactivate();
            RepositoryEntry re = searchController.getSelectedEntry();
            if (re != null) {
                setCPReference(re, config);
                cpConfigurationVc.contextPut("showPreviewButton", Boolean.TRUE);
                String displayname = StringHelper.escapeHtml(re.getDisplayname());
                previewLink = LinkFactory.createCustomLink("command.preview", "command.preview", displayname, Link.NONTRANSLATED, cpConfigurationVc, this);
                previewLink.setCustomEnabledLinkCSS("o_preview");
                previewLink.setTitle(getTranslator().translate("command.preview"));
                // remove existing edit link, add new one if user is allowed to edit this CP
                if (editLink != null) {
                    cpConfigurationVc.remove(editLink);
                    editLink = null;
                }
                if (isEditable(urequest.getIdentity(), urequest.getUserSession().getRoles(), re)) {
                    editLink = LinkFactory.createButtonSmall("edit", cpConfigurationVc, this);
                }
                // fire event so the updated config is saved by the editormaincontroller
                fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
                CPPackageConfig cpConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
                if (cpConfig != null && cpConfig.getDeliveryOptions() != null) {
                    deliveryOptionsCtrl.setParentDeliveryOptions(cpConfig.getDeliveryOptions());
                }
            }
        }
    // else cancelled repo search
    } else if (source == accessibilityCondContr) {
        if (event == Event.CHANGED_EVENT) {
            Condition cond = accessibilityCondContr.getCondition();
            cpNode.setPreConditionAccess(cond);
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == cpMenuForm) {
        if (event == Event.DONE_EVENT) {
            config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, cpMenuForm.isCpMenu());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    } else if (source == deliveryOptionsCtrl) {
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            config.set(CPEditController.CONFIG_DELIVERYOPTIONS, deliveryOptionsCtrl.getDeliveryOptions());
            fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
        }
    }
}
Also used : Condition(org.olat.course.condition.Condition) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) RepositoryEntry(org.olat.repository.RepositoryEntry)

Aggregations

CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)14 File (java.io.File)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)6 OLATResource (org.olat.resource.OLATResource)4 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)2 UserRequest (org.olat.core.gui.UserRequest)2 TooledStackedPanel (org.olat.core.gui.components.stack.TooledStackedPanel)2 Controller (org.olat.core.gui.control.Controller)2 WindowControl (org.olat.core.gui.control.WindowControl)2 MainLayout3ColumnsController (org.olat.core.gui.control.generic.layout.MainLayout3ColumnsController)2 MainLayoutController (org.olat.core.gui.control.generic.layout.MainLayoutController)2 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 OLog (org.olat.core.logging.OLog)2 AssessmentMode (org.olat.course.assessment.AssessmentMode)2 Condition (org.olat.course.condition.Condition)2 FileResourceManager (org.olat.fileresource.FileResourceManager)2 CPManager (org.olat.ims.cp.CPManager)2