use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class QTIMetadataConverter method addLicenseMetadataField.
private void addLicenseMetadataField(String label, QuestionItemFull fullItem, Element metadata) {
LicenseService lService = CoreSpringFactory.getImpl(LicenseService.class);
ResourceLicense license = lService.loadLicense(fullItem);
if (license != null) {
String licenseText = null;
LicenseType licenseType = license.getLicenseType();
if (lService.isFreetext(licenseType)) {
licenseText = license.getFreetext();
} else if (!lService.isNoLicense(licenseType)) {
licenseText = license.getLicenseType().getName();
}
if (StringHelper.containsNonWhitespace(licenseText)) {
addMetadataField(label, licenseText, metadata);
}
}
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class QTIMetadataConverter method createLicense.
public void createLicense(QuestionItemImpl poolItem, String licenseText, String licensor) {
ResourceLicense license = licenseService.loadOrCreateLicense(poolItem);
if (StringHelper.containsNonWhitespace(licenseText)) {
String mappedLicenseText = mapLicenseTypeName(licenseText);
LicenseType licenseType = licenseService.loadLicenseTypeByName(mappedLicenseText);
if (licenseType == null) {
licenseType = licenseService.loadFreetextLicenseType();
license.setFreetext(mappedLicenseText);
} else {
license.setFreetext(null);
}
license.setLicenseType(licenseType);
}
if (StringHelper.containsNonWhitespace(licensor)) {
license.setLicensor(licensor);
}
licenseService.update(license);
}
use of org.olat.core.commons.services.license.ResourceLicense in project OpenOLAT by OpenOLAT.
the class AbstractItemListController method reload.
@Override
public List<ItemRow> reload(List<ItemRow> rows) {
List<Long> itemToReload = new ArrayList<>();
for (ItemRow row : rows) {
itemToReload.add(row.getKey());
}
List<QuestionItemView> reloadedItems = itemsSource.getItems(itemToReload);
List<ItemRow> reloadedRows = new ArrayList<>(reloadedItems.size());
List<ResourceLicense> licenses = licenseService.loadLicenses(reloadedItems);
for (QuestionItemView item : reloadedItems) {
ItemRow reloadedRow = forgeRow(item, licenses);
reloadedRows.add(reloadedRow);
}
return reloadedRows;
}
Aggregations