use of org.olat.core.commons.services.license.ResourceLicense 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);
}
use of org.olat.core.commons.services.license.ResourceLicense 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();
}
use of org.olat.core.commons.services.license.ResourceLicense 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();
}
use of org.olat.core.commons.services.license.ResourceLicense in project openolat by klemens.
the class LicenseServiceImpl method loadOrCreateLicense.
@Override
public ResourceLicense loadOrCreateLicense(OLATResourceable ores) {
ResourceLicense license = licenseDao.loadByResource(ores);
if (license == null) {
LicenseType licenseType = licenseTypeDao.loadNoLicenseType();
license = licenseDao.createAndPersist(ores, licenseType);
}
return license;
}
use of org.olat.core.commons.services.license.ResourceLicense in project openolat by klemens.
the class ResourceLicenseDAO method loadLicenses.
List<ResourceLicense> loadLicenses(Collection<? extends OLATResourceable> resources) {
if (resources == null || resources.isEmpty())
return new ArrayList<>();
Set<String> resNames = new HashSet<>();
Set<Long> resIds = new HashSet<>();
for (OLATResourceable resource : resources) {
resNames.add(resource.getResourceableTypeName());
resIds.add(resource.getResourceableId());
}
String query = new StringBuilder(256).append("select license").append(" from license license").append(" inner join fetch license.licenseType as licenseType").append(" where license.resName in (:resNames)").append(" and license.resId in (:resIds)").toString();
return dbInstance.getCurrentEntityManager().createQuery(query, ResourceLicense.class).setParameter("resNames", resNames).setParameter("resIds", resIds).getResultList();
}
Aggregations