Search in sources :

Example 41 with LicenseType

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

the class MetadataBulkChangeController method updateLicenseVisibility.

void updateLicenseVisibility() {
    boolean freetextSelected = false;
    if (licenseEl != null && licenseEl.isOneSelected()) {
        String selectedKey = licenseEl.getSelectedKey();
        LicenseType licenseType = licenseService.loadLicenseTypeByKey(selectedKey);
        freetextSelected = licenseService.isFreetext(licenseType);
    }
    licenseFreetextEl.setVisible(freetextSelected);
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 42 with LicenseType

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

the class RightsMetadataEditController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.UPDATE_QUESTION_ITEM_METADATA);
        builder.withBefore(itemImpl);
        if (licenseModule.isEnabled(licenseHandler)) {
            if (licenseEl != null && licenseEl.isOneSelected()) {
                String licenseTypeKey = licenseEl.getSelectedKey();
                LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
                license.setLicenseType(licneseType);
            }
            String licensor = null;
            String freetext = null;
            if (licensorEl != null && licensorEl.isVisible()) {
                licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
            }
            if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
                freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
            }
            license.setLicensor(licensor);
            license.setFreetext(freetext);
            license = licenseService.update(license);
            licensorEl.setValue(license.getLicensor());
            licenseFreetextEl.setValue(license.getFreetext());
        }
        item = qpoolService.updateItem(item);
        builder.withAfter(itemImpl);
        qpoolService.persist(builder.create());
        fireEvent(ureq, new QItemEdited(item));
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QItemEdited(org.olat.modules.qpool.ui.events.QItemEdited) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) LicenseType(org.olat.core.commons.services.license.LicenseType)

Example 43 with LicenseType

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

the class RepositoryEntryImportExport method importLicense.

private void importLicense(RepositoryEntry newEntry) {
    if (!propertiesLoaded) {
        loadConfiguration();
    }
    LicenseService licenseService = CoreSpringFactory.getImpl(LicenseService.class);
    boolean hasLicense = StringHelper.containsNonWhitespace(repositoryProperties.getLicenseTypeName());
    if (hasLicense) {
        String licenseTypeName = repositoryProperties.getLicenseTypeName();
        LicenseType licenseType = licenseService.loadLicenseTypeByName(licenseTypeName);
        if (licenseType == null) {
            licenseType = licenseService.createLicenseType(licenseTypeName);
            licenseType.setText(repositoryProperties.getLicenseText());
            licenseService.saveLicenseType(licenseType);
        }
        ResourceLicense license = licenseService.loadOrCreateLicense(newEntry.getOlatResource());
        license.setLicenseType(licenseType);
        license.setLicensor(repositoryProperties.getLicensor());
        if (licenseService.isFreetext(licenseType)) {
            license.setFreetext(repositoryProperties.getLicenseText());
        }
        licenseService.update(license);
    }
}
Also used : LicenseService(org.olat.core.commons.services.license.LicenseService) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 44 with LicenseType

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

the class MetaInfoFactoryTest method shouldCreateNonExistingLicenseType.

@Test
public void shouldCreateNonExistingLicenseType() {
    String typeName = "name";
    LicenseType licenseType = licenseService.createLicenseType(typeName);
    licenseType = licenseService.saveLicenseType(licenseType);
    dbInstance.commitAndCloseSession();
    String licensor = "licensor";
    String name = "new";
    String text = "text";
    File file = new File("");
    MetaInfo meta = new MetaInfoFileImpl(file);
    meta.setLicenseTypeName(name);
    meta.setLicensor(licensor);
    meta.setLicenseText(text);
    License license = metaInfoFactory.getLicense(meta);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    LicenseType loadedLicenseType = license.getLicenseType();
    assertThat(loadedLicenseType.getName()).isEqualTo(name);
    assertThat(loadedLicenseType.getText()).isEqualTo(text);
    LicenseType createdLicenseType = licenseService.loadLicenseTypeByName(name);
    assertThat(createdLicenseType).isNotNull();
}
Also used : License(org.olat.core.commons.services.license.License) File(java.io.File) LicenseType(org.olat.core.commons.services.license.LicenseType) Test(org.junit.Test)

Example 45 with LicenseType

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

the class MetaInfoFactoryTest method shouldLoadExistingLicenseType.

@Test
public void shouldLoadExistingLicenseType() {
    String typeName = "name";
    LicenseType licenseType = licenseService.createLicenseType(typeName);
    licenseType = licenseService.saveLicenseType(licenseType);
    dbInstance.commitAndCloseSession();
    String licensor = "licensor";
    String name = licenseType.getName();
    File file = new File("");
    MetaInfo meta = new MetaInfoFileImpl(file);
    meta.setLicenseTypeName(name);
    meta.setLicensor(licensor);
    License license = metaInfoFactory.getLicense(meta);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    LicenseType loadedLicenseType = license.getLicenseType();
    assertThat(loadedLicenseType).isEqualTo(licenseType);
}
Also used : License(org.olat.core.commons.services.license.License) File(java.io.File) LicenseType(org.olat.core.commons.services.license.LicenseType) Test(org.junit.Test)

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