use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.
the class CatalogNodeManagerController method loadResources.
private void loadResources(UserRequest ureq) {
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
params.setParentEntry(catalogEntry);
List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
List<Long> resourceKeys = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
resourceKeys.add(entry.getOlatResource().getKey());
}
List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
List<CatalogEntryRow> items = new ArrayList<>();
List<CatalogEntryRow> closedItems = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
CatalogEntryRow row = new CatalogEntryRow(entry);
List<PriceMethod> types = new ArrayList<PriceMethod>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", 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(getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
if (entry.getRepositoryEntryStatus().isClosed()) {
closedItems.add(row);
} else {
items.add(row);
}
}
entriesModel.setObjects(items);
entriesEl.reset();
entriesEl.setVisible(entriesModel.getRowCount() > 0);
closedEntriesModel.setObjects(closedItems);
closedEntriesEl.reset();
closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.
the class DefaultRepositoryEntryDataSource method processViewModel.
private List<RepositoryEntryRow> processViewModel(List<RepositoryEntryMyView> repoEntries) {
List<Long> repoKeys = new ArrayList<>(repoEntries.size());
List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
for (RepositoryEntryMyView entry : repoEntries) {
repoKeys.add(entry.getKey());
if (entry.isValidOfferAvailable()) {
resourcesWithAC.add(entry.getOlatResource());
}
}
List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
repositoryService.filterMembership(searchParams.getIdentity(), repoKeys);
List<RepositoryEntryRow> items = new ArrayList<RepositoryEntryRow>();
for (RepositoryEntryMyView entry : repoEntries) {
RepositoryEntryRow row = new RepositoryEntryRow(entry);
VFSLeaf image = repositoryManager.getImage(entry);
if (image != null) {
row.setThumbnailRelPath(uifactory.getMapperThumbnailUrl() + "/" + image.getName());
}
List<PriceMethod> types = new ArrayList<PriceMethod>();
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));
}
}
}
}
row.setMember(repoKeys.contains(entry.getKey()));
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
uifactory.forgeMarkLink(row);
uifactory.forgeSelectLink(row);
uifactory.forgeStartLink(row);
uifactory.forgeDetails(row);
uifactory.forgeRatings(row);
uifactory.forgeComments(row);
items.add(row);
}
return items;
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.
the class DefaultRepositoryEntryDataSource method processViewModel.
private List<RepositoryEntryRow> processViewModel(List<RepositoryEntryMyView> repoEntries) {
List<Long> repoKeys = new ArrayList<>(repoEntries.size());
List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
for (RepositoryEntryMyView entry : repoEntries) {
repoKeys.add(entry.getKey());
if (entry.isValidOfferAvailable()) {
resourcesWithAC.add(entry.getOlatResource());
}
}
List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
repositoryService.filterMembership(searchParams.getIdentity(), repoKeys);
List<RepositoryEntryRow> items = new ArrayList<RepositoryEntryRow>();
for (RepositoryEntryMyView entry : repoEntries) {
RepositoryEntryRow row = new RepositoryEntryRow(entry);
VFSLeaf image = repositoryManager.getImage(entry);
if (image != null) {
row.setThumbnailRelPath(uifactory.getMapperThumbnailUrl() + "/" + image.getName());
}
List<PriceMethod> types = new ArrayList<PriceMethod>();
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));
}
}
}
}
row.setMember(repoKeys.contains(entry.getKey()));
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
uifactory.forgeMarkLink(row);
uifactory.forgeSelectLink(row);
uifactory.forgeStartLink(row);
uifactory.forgeDetails(row);
uifactory.forgeRatings(row);
uifactory.forgeComments(row);
items.add(row);
}
return items;
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.
the class CatalogNodeManagerController method loadResources.
private void loadResources(UserRequest ureq) {
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
params.setParentEntry(catalogEntry);
List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
List<Long> resourceKeys = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
resourceKeys.add(entry.getOlatResource().getKey());
}
List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
List<CatalogEntryRow> items = new ArrayList<>();
List<CatalogEntryRow> closedItems = new ArrayList<>();
for (RepositoryEntry entry : repoEntries) {
CatalogEntryRow row = new CatalogEntryRow(entry);
List<PriceMethod> types = new ArrayList<PriceMethod>();
if (entry.isMembersOnly()) {
// members only always show lock icon
types.add(new PriceMethod("", "o_ac_membersonly_icon", 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(getLocale());
types.add(new PriceMethod(price, type, displayName));
}
}
}
}
if (!types.isEmpty()) {
row.setAccessTypes(types);
}
if (entry.getRepositoryEntryStatus().isClosed()) {
closedItems.add(row);
} else {
items.add(row);
}
}
entriesModel.setObjects(items);
entriesEl.reset();
entriesEl.setVisible(entriesModel.getRowCount() > 0);
closedEntriesModel.setObjects(closedItems);
closedEntriesEl.reset();
closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
use of org.olat.resource.accesscontrol.model.PriceMethodBundle 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;
}
Aggregations