Search in sources :

Example 1 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project OpenOLAT by OpenOLAT.

the class MetaInfoFactory method getLicense.

/**
 * Get the license of the MetaInfo
 *
 * @param meta
 * @return the license or null if no license is stored in the MetaInfo
 */
public License getLicense(MetaInfo meta) {
    LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
    License license = null;
    boolean hasLicense = meta != null && StringHelper.containsNonWhitespace(meta.getLicenseTypeName());
    if (hasLicense) {
        String licenseTypeName = meta.getLicenseTypeName();
        LicenseType licenseType = licenseService.loadLicenseTypeByName(licenseTypeName);
        if (licenseType == null) {
            licenseType = licenseService.createLicenseType(licenseTypeName);
            licenseType.setText(meta.getLicenseText());
            licenseService.saveLicenseType(licenseType);
        }
        license = licenseService.createLicense(licenseType);
        license.setLicensor(meta.getLicensor());
        if (licenseService.isFreetext(licenseType)) {
            license.setFreetext(meta.getLicenseText());
        }
    }
    return license;
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) License(org.olat.core.commons.services.license.License) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 2 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project OpenOLAT by OpenOLAT.

the class MetaInfoFormController method getLicenseFromFormItems.

private License getLicenseFromFormItems() {
    License license = licenseService.createLicense(null);
    String licensor = "";
    String freetext = "";
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        if (licensorEl != null && licensorEl.isVisible() && StringHelper.containsNonWhitespace(licensorEl.getValue())) {
            licensor = licensorEl.getValue();
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible() && StringHelper.containsNonWhitespace(licenseFreetextEl.getValue())) {
            freetext = licenseFreetextEl.getValue();
        }
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    license.setLicensor(licensor);
    license.setFreetext(freetext);
    return license;
}
Also used : License(org.olat.core.commons.services.license.License) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 3 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project OpenOLAT by OpenOLAT.

the class LicenseAdminConfigController method getLicenseTypeValues.

private String[] getLicenseTypeValues(List<LicenseType> licenseTypes) {
    String[] handlerNames = new String[licenseTypes.size()];
    int count = 0;
    for (LicenseType licenseType : licenseTypes) {
        handlerNames[count++] = LicenseUIFactory.translate(licenseType, getLocale());
    }
    return handlerNames;
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 4 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project OpenOLAT by OpenOLAT.

the class LicenseAdminConfigController method reloadDefaultLicenseTypeEl.

private void reloadDefaultLicenseTypeEl(LicenseHandler handler) {
    SingleSelection defaultLicenseTypeEl = defaultLicenseTypeEls.get(handler.getType());
    if (defaultLicenseTypeEl != null) {
        List<LicenseType> activatedLicenseTypes = licenseService.loadActiveLicenseTypes(handler);
        Collections.sort(activatedLicenseTypes);
        String[] licenseTypeKeys = getLicenseTypeKeys(activatedLicenseTypes);
        String[] licenseTypeValues = getLicenseTypeValues(activatedLicenseTypes);
        defaultLicenseTypeEl.setKeysAndValues(licenseTypeKeys, licenseTypeValues, null);
        String defaultLicenseTypeKey = licenseModule.getDefaultLicenseTypeKey(handler);
        if (Arrays.asList(licenseTypeKeys).contains(defaultLicenseTypeKey)) {
            defaultLicenseTypeEl.select(defaultLicenseTypeKey, true);
        }
    }
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 5 with LicenseType

use of org.olat.core.commons.services.license.LicenseType in project OpenOLAT by OpenOLAT.

the class LicenseSelectionConfig method getLicenseTypeValues.

public String[] getLicenseTypeValues(Locale locale) {
    String[] values = new String[selectableLicenseTypes.size()];
    int count = 0;
    for (LicenseType licenseType : selectableLicenseTypes) {
        String translation = LicenseUIFactory.translate(licenseType, locale);
        translation = setSpecialTranslation(translation, licenseType, locale);
        values[count++] = translation;
    }
    return values;
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType)

Aggregations

LicenseType (org.olat.core.commons.services.license.LicenseType)106 Test (org.junit.Test)40 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)28 LicenseService (org.olat.core.commons.services.license.LicenseService)14 License (org.olat.core.commons.services.license.License)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 File (java.io.File)6 ArrayList (java.util.ArrayList)4 LicenseHandler (org.olat.core.commons.services.license.LicenseHandler)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 QLicense (org.olat.modules.qpool.model.QLicense)4 Date (java.util.Date)2 Random (java.util.Random)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 LicenseImpl (org.olat.core.commons.services.license.model.LicenseImpl)2 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 Translator (org.olat.core.gui.translator.Translator)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2