use of org.olat.repository.RepositoryEntryAuthorView in project openolat by klemens.
the class RepositoryEntryAuthorQueriesTest method searchViews.
@Test
public void searchViews() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("view-");
dbInstance.commit();
Roles roles = securityManager.getRoles(id);
SearchAuthorRepositoryEntryViewParams params = new SearchAuthorRepositoryEntryViewParams(id, roles);
params.setMarked(Boolean.TRUE);
List<RepositoryEntryAuthorView> views = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
Assert.assertNotNull(views);
}
use of org.olat.repository.RepositoryEntryAuthorView in project openolat by klemens.
the class AuthoringEntryDataSource method getRows.
@Override
public final ResultInfos<AuthoringEntryRow> getRows(String query, List<FlexiTableFilter> filters, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
if (filters != null && filters.size() > 0) {
String filter = filters.get(0).getFilter();
if (StringHelper.containsNonWhitespace(filter)) {
searchParams.setResourceTypes(Collections.singletonList(filter));
} else {
searchParams.setResourceTypes(null);
}
} else if (useFilters) {
searchParams.setResourceTypes(null);
}
if (orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
OrderBy o = OrderBy.valueOf(orderBy[0].getKey());
searchParams.setOrderBy(o);
searchParams.setOrderByAsc(orderBy[0].isAsc());
}
if (StringHelper.containsNonWhitespace(query)) {
searchParams.setIdRefsAndTitle(query);
} else {
searchParams.setIdRefsAndTitle(null);
}
List<RepositoryEntryAuthorView> views = repositoryService.searchAuthorView(searchParams, firstResult, maxResults);
List<AuthoringEntryRow> rows = processViewModel(views);
ResultInfos<AuthoringEntryRow> results = new DefaultResultInfos<>(firstResult + rows.size(), -1, rows);
if (firstResult == 0 && views.size() < maxResults) {
count = new Integer(views.size());
}
return results;
}
use of org.olat.repository.RepositoryEntryAuthorView in project openolat by klemens.
the class RepositoryEntryAuthorQueries method searchViews.
public List<RepositoryEntryAuthorView> searchViews(SearchAuthorRepositoryEntryViewParams params, int firstResult, int maxResults) {
if (params.getIdentity() == null) {
log.error("No identity defined for query");
return Collections.emptyList();
}
TypedQuery<Object[]> query = createViewQuery(params, Object[].class);
query.setFirstResult(firstResult);
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
List<Object[]> objects = query.getResultList();
List<RepositoryEntryAuthorView> views = new ArrayList<>(objects.size());
for (Object[] object : objects) {
RepositoryEntry re = (RepositoryEntry) object[0];
Number numOfMarks = (Number) object[1];
boolean hasMarks = numOfMarks == null ? false : numOfMarks.longValue() > 0;
Number numOffers = (Number) object[2];
long offers = numOffers == null ? 0l : numOffers.longValue();
Number numOfReferences = (Number) object[3];
int references = numOfReferences == null ? 0 : numOfReferences.intValue();
String deletedByName = null;
if (params.isDeleted()) {
Identity deletedBy = re.getDeletedBy();
if (deletedBy != null) {
deletedByName = userManager.getUserDisplayName(deletedBy);
}
}
views.add(new RepositoryEntryAuthorImpl(re, hasMarks, offers, references, deletedByName));
}
return views;
}
use of org.olat.repository.RepositoryEntryAuthorView in project openolat by klemens.
the class RepositoryEntryAuthorQueriesTest method searchViews_orderBy.
@Test
public void searchViews_orderBy() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("view-");
dbInstance.commit();
Roles roles = securityManager.getRoles(id);
SearchAuthorRepositoryEntryViewParams params = new SearchAuthorRepositoryEntryViewParams(id, roles);
params.setMarked(Boolean.TRUE);
for (OrderBy orderBy : OrderBy.values()) {
params.setOrderBy(orderBy);
params.setOrderByAsc(true);
List<RepositoryEntryAuthorView> viewAsc = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
Assert.assertNotNull(viewAsc);
params.setOrderByAsc(false);
List<RepositoryEntryAuthorView> viewDesc = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
Assert.assertNotNull(viewDesc);
}
}
use of org.olat.repository.RepositoryEntryAuthorView 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