Search in sources :

Example 26 with ResourceLicense

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

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 27 with ResourceLicense

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

the class OLATUpgrade_12_4_0 method saveLicense.

private void saveLicense(QuestionItemImpl item) {
    QLicense qlicense = item.getLicense();
    String name = mapLicenseTypeName(qlicense.getLicenseKey());
    LicenseType licenseType = licenseService.loadLicenseTypeByName(name);
    ResourceLicense license = licenseService.loadOrCreateLicense(item);
    license.setLicenseType(licenseType);
    license.setFreetext(qlicense.getLicenseText());
    license.setLicensor(item.getCreator());
    licenseService.update(license);
}
Also used : QLicense(org.olat.modules.qpool.model.QLicense) LicenseType(org.olat.core.commons.services.license.LicenseType) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 28 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldUpdateLicense.

@Test
public void shouldUpdateLicense() {
    OLATResourceable ores = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    ResourceLicense license = licenseDao.createAndPersist(ores, licenseType);
    dbInstance.commitAndCloseSession();
    String freetext = "freetext";
    license.setFreetext(freetext);
    String licensor = "licensor";
    license.setLicensor(licensor);
    license = licenseDao.save(license);
    assertThat(license.getFreetext()).isEqualTo(freetext);
    assertThat(license.getLicensor()).isEqualTo(licensor);
    assertThat(license.getLicenseType()).isEqualTo(licenseType);
}
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 ResourceLicense

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

the class ResourceLicenseDAOTest method shouldCreateAndPersistRawLicense.

@Test
public void shouldCreateAndPersistRawLicense() {
    OLATResourceable oresTarget = JunitTestHelper.createRandomResource();
    OLATResourceable oresSource = JunitTestHelper.createRandomResource();
    LicenseType licenseType = licenseTypeDao.create("name");
    licenseType = licenseTypeDao.save(licenseType);
    String licensor = "licensor";
    String freetext = "freetext";
    ResourceLicense sourceLicense = licenseDao.createAndPersist(oresSource, licenseType, licensor);
    sourceLicense.setFreetext(freetext);
    sourceLicense = licenseDao.save(sourceLicense);
    dbInstance.commitAndCloseSession();
    ResourceLicense targetLicense = licenseDao.createAndPersist(oresTarget, sourceLicense);
    assertThat(targetLicense.getResName()).isEqualTo(oresTarget.getResourceableTypeName());
    assertThat(targetLicense.getResId()).isEqualTo(oresTarget.getResourceableId());
    assertThat(targetLicense.getLicenseType()).isEqualTo(sourceLicense.getLicenseType());
    assertThat(targetLicense.getLicensor()).isEqualTo(sourceLicense.getLicensor());
    assertThat(targetLicense.getFreetext()).isEqualTo(sourceLicense.getFreetext());
    assertThat(targetLicense.getCreationDate()).isNotNull();
    assertThat(targetLicense.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 30 with ResourceLicense

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

the class ResourceLicenseDAOTest method shouldLoadLicenseForResource.

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

Aggregations

ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)46 LicenseType (org.olat.core.commons.services.license.LicenseType)26 OLATResourceable (org.olat.core.id.OLATResourceable)16 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 LicenseService (org.olat.core.commons.services.license.LicenseService)8 HashSet (java.util.HashSet)4 Document (org.apache.lucene.document.Document)4 QuestionItemView (org.olat.modules.qpool.QuestionItemView)4 QLicense (org.olat.modules.qpool.model.QLicense)4 OLATResource (org.olat.resource.OLATResource)4 OlatDocument (org.olat.search.model.OlatDocument)4 Random (java.util.Random)2 StringTokenizer (java.util.StringTokenizer)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 DefaultResultInfos (org.olat.core.commons.persistence.DefaultResultInfos)2 License (org.olat.core.commons.services.license.License)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Identity (org.olat.core.id.Identity)2