Skip to content
Snippets Groups Projects
Commit 0d618451 authored by uhensler's avatar uhensler
Browse files

OO-3170: Default config values after registering a new license handler....

OO-3170: Default config values after registering a new license handler. License enabled checkbox has wrong state after deactivating a license type. Do not show licenses in folder course node, if licenses are disabled. Minor optimisations in display of licenses in learning resources.
parent 312023be
No related branches found
No related tags found
No related merge requests found
......@@ -33,11 +33,14 @@ import java.util.List;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.FileSelection;
import org.olat.core.commons.modules.bc.FolderConfig;
import org.olat.core.commons.modules.bc.FolderLicenseHandler;
import org.olat.core.commons.modules.bc.FolderManager;
import org.olat.core.commons.modules.bc.meta.MetaInfo;
import org.olat.core.commons.modules.bc.meta.MetaInfoFactory;
import org.olat.core.commons.modules.bc.meta.tagged.MetaTagged;
import org.olat.core.commons.services.license.License;
import org.olat.core.commons.services.license.LicenseHandler;
import org.olat.core.commons.services.license.LicenseModule;
import org.olat.core.commons.services.license.ui.LicenseRenderer;
import org.olat.core.gui.components.form.flexible.impl.NameValuePair;
import org.olat.core.gui.control.winmgr.AJAXFlags;
......@@ -89,6 +92,7 @@ public class ListRenderer {
private VFSLockManager lockManager;
private UserManager userManager;
boolean licensesEnabled ;
/**
* Default constructor.
......@@ -114,6 +118,9 @@ public class ListRenderer {
if(userManager == null) {
userManager = CoreSpringFactory.getImpl(UserManager.class);
}
LicenseModule licenseModule = CoreSpringFactory.getImpl(LicenseModule.class);
LicenseHandler licenseHandler = CoreSpringFactory.getImpl(FolderLicenseHandler.class);
licensesEnabled = licenseModule.isEnabled(licenseHandler);
List<VFSItem> children = fc.getCurrentContainerChildren();
// folder empty?
......@@ -133,7 +140,9 @@ public class ListRenderer {
.append("<thead><tr><th><a class='o_orderby ").append(sortCss,FolderComponent.SORT_NAME.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_NAME))
.append(">").append(translator.translate("header.Name")).append("</a>").append("</th>");
sb.append("<th>").append(translator.translate("header.license")).append("</th>");
if (licensesEnabled) {
sb.append("<th>").append(translator.translate("header.license")).append("</th>");
}
sb.append("<th><a class='o_orderby ").append(sortCss,FolderComponent.SORT_SIZE.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_SIZE))
.append(">").append(translator.translate("header.Size")).append("</a>")
......@@ -344,13 +353,15 @@ public class ListRenderer {
sb.append("</td><td>");
// license
MetaInfoFactory metaInfoFactory = CoreSpringFactory.getImpl(MetaInfoFactory.class);
License license = metaInfoFactory.getLicense(metaInfo);
if (license != null) {
LicenseRenderer licenseRenderer = new LicenseRenderer(translator.getLocale());
licenseRenderer.render(sb, license);
if (licensesEnabled) {
MetaInfoFactory metaInfoFactory = CoreSpringFactory.getImpl(MetaInfoFactory.class);
License license = metaInfoFactory.getLicense(metaInfo);
if (license != null) {
LicenseRenderer licenseRenderer = new LicenseRenderer(translator.getLocale());
licenseRenderer.render(sb, license);
}
sb.append("</td><td>");
}
sb.append("</td><td>");
// filesize
if (!isContainer) {
......
......@@ -66,7 +66,10 @@ public class LicenseModule extends AbstractSpringModule {
String handlerType = handler.getType();
String enabledObj = getStringPropertyValue(ENABLED_HANDLERS + handlerType, true);
Boolean enabled = Boolean.valueOf(enabledObj);
Boolean enabled = Boolean.FALSE;
if (StringHelper.containsNonWhitespace(enabledObj)) {
enabled = Boolean.valueOf(enabledObj);
}
enabledHandlers.put(handlerType, enabled);
String defaultLicenseTypeKey = getStringPropertyValue(DEFAULT_LICENSE_TYPE + handlerType, true);
......
......@@ -59,6 +59,7 @@ import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController;
import org.olat.core.gui.translator.Translator;
import org.olat.core.util.StringHelper;
import org.olat.core.util.Util;
import org.olat.core.util.i18n.ui.SingleKeyTranslatorController;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -446,6 +447,7 @@ public class LicenseAdminConfigController extends FormBasicController {
LicenseType licenseType = handlerLicenseType.getLicenseType();
if (active) {
licenseService.activate(handler, licenseType);
initDefaultLicenseType(handler, licenseType);
reloadDefaultLicenseTypeEl(handler);
} else {
if (isDefaultLicenseType(handler, licenseType)) {
......@@ -456,8 +458,24 @@ public class LicenseAdminConfigController extends FormBasicController {
reloadDefaultLicenseTypeEl(handler);
}
}
// checkboxes of enabled handlers was deactivated after deactivating a license type.
initGeneralElements();
}
/**
* Init the default license type of a new license handler, when the first
* license type if activated for the handler.
*
* @param handler
* @param licenseType
*/
private void initDefaultLicenseType(LicenseHandler handler, LicenseType licenseType) {
String defaultLicenseTypeKey = licenseModule.getDefaultLicenseTypeKey(handler);
if (!StringHelper.containsNonWhitespace(defaultLicenseTypeKey)) {
licenseModule.setDefaultLicenseTypeKey(handler, String.valueOf(licenseType.getKey()));
}
}
private boolean isDefaultLicenseType(LicenseHandler handler, LicenseType licenseType) {
String defaultLicenseTypeKey = licenseModule.getDefaultLicenseTypeKey(handler);
String licenseTypeKey = String.valueOf(licenseType.getKey());
......
......@@ -36,10 +36,10 @@ import java.util.Set;
import java.util.UUID;
import org.olat.NewControllerFactory;
import org.olat.core.commons.services.license.ResourceLicense;
import org.olat.core.commons.services.license.LicenseModule;
import org.olat.core.commons.services.license.LicenseService;
import org.olat.core.commons.services.license.LicenseType;
import org.olat.core.commons.services.license.ResourceLicense;
import org.olat.core.commons.services.license.ui.LicenseSelectionConfig;
import org.olat.core.commons.services.license.ui.LicenseUIFactory;
import org.olat.core.gui.UserRequest;
......@@ -404,8 +404,12 @@ public class RepositoryEditDescriptionController extends FormBasicController {
licenseSelected = !licenseService.isNoLicense(licenseType);
freetextSelected = licenseService.isFreetext(licenseType);
}
licensorEl.setVisible(licenseSelected);
licenseFreetextEl.setVisible(freetextSelected);
if (licensorEl != null) {
licensorEl.setVisible(licenseSelected);
}
if (licenseFreetextEl != null) {
licenseFreetextEl.setVisible(freetextSelected);
}
}
private void updateDatesVisibility() {
......@@ -477,7 +481,7 @@ public class RepositoryEditDescriptionController extends FormBasicController {
LicenseType selectedLicenseType = licenseService.loadLicenseTypeByKey(selectedKey);
isNoLicenseSelected = licenseService.isNoLicense(selectedLicenseType);
}
return !isNoLicenseSelected;
return isNoLicenseSelected;
}
private boolean validateTextElement(TextElement el, int maxLength) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment