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);
}
}
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);
}
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);
}
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();
}
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);
}
Aggregations