use of org.olat.core.commons.services.license.ResourceLicense in project openolat by klemens.
the class AuthoringEntryDataSource method processViewModel.
private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) {
Set<String> newNames = new HashSet<>();
List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
for (RepositoryEntryAuthorView entry : repoEntries) {
if (entry.isOfferAvailable()) {
resourcesWithAC.add(entry.getOlatResource());
}
final String author = entry.getAuthor();
if (StringHelper.containsNonWhitespace(author)) {
newNames.add(author);
}
}
Map<String, String> fullNames = userManager.getUserDisplayNamesByUserName(newNames);
List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
Collection<OLATResourceable> resources = repoEntries.stream().map(RepositoryEntryAuthorView::getOlatResource).collect(Collectors.toList());
List<ResourceLicense> licenses = licenseService.loadLicenses(resources);
List<AuthoringEntryRow> items = new ArrayList<>();
for (RepositoryEntryAuthorView entry : repoEntries) {
String fullname = fullNames.get(entry.getAuthor());
if (fullname == null) {
fullname = entry.getAuthor();
}
AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname);
// bookmark
row.setMarked(entry.isMarked());
// access control
List<PriceMethod> types = new ArrayList<>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
} else {
// collect access control method icons
OLATResource resource = entry.getOlatResource();
for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
// license
for (ResourceLicense license : licenses) {
OLATResource resource = entry.getOlatResource();
if (license.getResId().equals(resource.getResourceableId()) && license.getResName().equals(resource.getResourceableTypeName())) {
row.setLicense(license);
}
}
uifactory.forgeLinks(row);
items.add(row);
}
return items;
}
use of org.olat.core.commons.services.license.ResourceLicense in project openolat by klemens.
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 klemens.
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 klemens.
the class LicenseServiceImpl method copy.
@Override
public ResourceLicense copy(OLATResourceable source, OLATResourceable target) {
if (source == null || target == null)
return null;
ResourceLicense targetLicense = null;
ResourceLicense sourceLicense = licenseDao.loadByResource(source);
if (sourceLicense != null) {
licenseDao.delete(target);
targetLicense = licenseDao.createAndPersist(target, sourceLicense);
}
return targetLicense;
}
use of org.olat.core.commons.services.license.ResourceLicense in project openolat by klemens.
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);
}
}
}
Aggregations