Search in sources :

Example 11 with CPPackageConfig

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

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 12 with CPPackageConfig

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

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)

Example 13 with CPPackageConfig

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

the class CPManagerImpl method createNewCP.

/**
 * @see org.olat.ims.cp.CPManager#createNewCP(org.olat.core.id.OLATResourceable)
 */
public ContentPackage createNewCP(OLATResourceable ores, String initalPageTitle) {
    // copy template cp to new repo-location
    if (copyTemplCP(ores)) {
        File cpRoot = FileResourceManager.getInstance().unzipFileResource(ores);
        logDebug("createNewCP: cpRoot=" + cpRoot);
        logDebug("createNewCP: cpRoot.getAbsolutePath()=" + cpRoot.getAbsolutePath());
        LocalFolderImpl vfsWrapper = new LocalFolderImpl(cpRoot);
        ContentPackage cp = load(vfsWrapper, ores);
        // Modify the copy of the template to get a unique identifier
        CPOrganization orga = setUniqueOrgaIdentifier(cp);
        setOrgaTitleToRepoEntryTitle(ores, orga);
        // Also set the translated title of the inital page.
        orga.getItems().get(0).setTitle(initalPageTitle);
        writeToFile(cp);
        // set the default settings for file delivery
        DeliveryOptions defOptions = DeliveryOptions.defaultWithGlossary();
        CPPackageConfig config = new CPPackageConfig();
        config.setDeliveryOptions(defOptions);
        setCPPackageConfig(ores, config);
        return cp;
    } else {
        logError("CP couldn't be created. Error when copying template. Ores: " + ores.getResourceableId(), null);
        throw new OLATRuntimeException("ERROR while creating new empty cp. an error occured while trying to copy template CP", null);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) File(java.io.File) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions) CPOrganization(org.olat.ims.cp.objects.CPOrganization) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 14 with CPPackageConfig

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

the class CPManagerImpl method getCPPackageConfig.

@Override
public CPPackageConfig getCPPackageConfig(OLATResourceable ores) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File reFolder = frm.getFileResourceRoot(ores);
    File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
    CPPackageConfig config;
    if (configXml.exists()) {
        config = (CPPackageConfig) configXstream.fromXML(configXml);
    } else {
        // set default config
        config = new CPPackageConfig();
        config.setDeliveryOptions(DeliveryOptions.defaultWithGlossary());
        setCPPackageConfig(ores, config);
    }
    return config;
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) CPPackageConfig(org.olat.ims.cp.ui.CPPackageConfig) File(java.io.File)

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