Search in sources :

Example 26 with LicenseType

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

the class LicenseTypeDAOTest method shouldCheckIfExists.

@Test
public void shouldCheckIfExists() {
    String name = UUID.randomUUID().toString();
    boolean exists = licenseTypeDao.exists(name);
    assertThat(exists).isFalse();
    LicenseType licenseType1 = licenseTypeDao.create(name);
    licenseType1 = licenseTypeDao.save(licenseType1);
    dbInstance.commitAndCloseSession();
    exists = licenseTypeDao.exists(name);
    assertThat(exists).isTrue();
}
Also used : LicenseType(org.olat.core.commons.services.license.LicenseType) Test(org.junit.Test)

Example 27 with LicenseType

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

the class ResourceLicenseDAOTest method shouldLoadLicenseForResources.

@Test
public void shouldLoadLicenseForResources() {
    String resName = "res";
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    OLATResourceable ores1 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license1 = licenseDao.createAndPersist(ores1, licenseType);
    OLATResourceable ores2 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license2 = licenseDao.createAndPersist(ores2, licenseType);
    OLATResourceable ores3 = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    ResourceLicense license3 = licenseDao.createAndPersist(ores3, licenseType);
    OLATResourceable oresSameName = OresHelper.createOLATResourceableInstance(resName, (new Random()).nextLong());
    licenseDao.createAndPersist(oresSameName, licenseType);
    OLATResourceable oresSameId = OresHelper.createOLATResourceableInstance("other", ores1.getResourceableId());
    licenseDao.createAndPersist(oresSameId, licenseType);
    dbInstance.commitAndCloseSession();
    List<ResourceLicense> loadedLicenses = licenseDao.loadLicenses(Arrays.asList(ores1, ores2, ores3));
    assertThat(loadedLicenses).containsExactly(license1, license2, license3);
}
Also used : Random(java.util.Random) OLATResourceable(org.olat.core.id.OLATResourceable) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 28 with LicenseType

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

the class ResourceLicenseDAOTest method shouldCreateAndPersistLicense.

@Test
public void shouldCreateAndPersistLicense() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    String licensor = "licensor";
    ResourceLicense license = licenseDao.createAndPersist(ores, licenseType, licensor);
    dbInstance.commitAndCloseSession();
    assertThat(license.getResName()).isEqualTo(ores.getResourceableTypeName());
    assertThat(license.getResId()).isEqualTo(ores.getResourceableId());
    assertThat(license.getLicenseType()).isEqualTo(licenseType);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    assertThat(license.getCreationDate()).isNotNull();
    assertThat(license.getLastModified()).isNotNull();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 29 with LicenseType

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

the class ResourceLicenseDAOTest method shoulDeleteLicenseOfResource.

@Test
public void shoulDeleteLicenseOfResource() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    licenseDao.createAndPersist(ores, licenseType);
    dbInstance.commitAndCloseSession();
    ResourceLicense loadedLicense = licenseDao.loadByResource(ores);
    assertThat(loadedLicense).isNotNull();
    licenseDao.delete(ores);
    dbInstance.commitAndCloseSession();
    loadedLicense = licenseDao.loadByResource(ores);
    assertThat(loadedLicense).isNull();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) Test(org.junit.Test)

Example 30 with LicenseType

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

the class LicenseAdminConfigController method doSetDefaultLicenceType.

private void doSetDefaultLicenceType(FormItem source, SingleSelection singleSelection) {
    if (singleSelection.isOneSelected()) {
        String selectedKey = singleSelection.getSelectedKey();
        LicenseHandler handler = (LicenseHandler) source.getUserObject();
        LicenseType licenseType = licenseService.loadLicenseTypeByKey(selectedKey);
        licenseModule.setDefaultLicenseTypeKey(handler, String.valueOf(licenseType.getKey()));
    }
}
Also used : LicenseHandler(org.olat.core.commons.services.license.LicenseHandler) 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