CCM NG/ccm-core: Some JavaDoc for CategoryRepository and DomainRepository
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4702 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
66a6b22341
commit
35cffb28bb
|
|
@ -20,14 +20,19 @@ package org.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||||
|
|
||||||
|
import com.vaadin.ui.Button;
|
||||||
import com.vaadin.ui.CustomComponent;
|
import com.vaadin.ui.CustomComponent;
|
||||||
import com.vaadin.ui.Grid;
|
import com.vaadin.ui.Grid;
|
||||||
|
import com.vaadin.ui.HorizontalLayout;
|
||||||
import com.vaadin.ui.TabSheet;
|
import com.vaadin.ui.TabSheet;
|
||||||
|
import com.vaadin.ui.TextField;
|
||||||
import com.vaadin.ui.UI;
|
import com.vaadin.ui.UI;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderCell;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderRow;
|
||||||
|
import com.vaadin.ui.themes.ValoTheme;
|
||||||
import org.libreccm.admin.ui.AdminView;
|
import org.libreccm.admin.ui.AdminView;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,6 +54,7 @@ public class UsersGroupsRoles extends CustomComponent {
|
||||||
private final TabSheet tabSheet;
|
private final TabSheet tabSheet;
|
||||||
|
|
||||||
private final Grid<User> usersTable;
|
private final Grid<User> usersTable;
|
||||||
|
private UsersTableDataProvider usersTableDataProvider;
|
||||||
|
|
||||||
public UsersGroupsRoles(final AdminView view) {
|
public UsersGroupsRoles(final AdminView view) {
|
||||||
|
|
||||||
|
|
@ -87,6 +93,32 @@ public class UsersGroupsRoles extends CustomComponent {
|
||||||
.setId(COL_BANNED)
|
.setId(COL_BANNED)
|
||||||
.setCaption("Banned?");
|
.setCaption("Banned?");
|
||||||
|
|
||||||
|
final HeaderRow filterRow = usersTable.appendHeaderRow();
|
||||||
|
final HeaderCell userNameFilterCell = filterRow.getCell(COL_USER_NAME);
|
||||||
|
final TextField userNameFilter = new TextField();
|
||||||
|
userNameFilter.setPlaceholder("User name");
|
||||||
|
userNameFilter.setDescription("Filter users by username");
|
||||||
|
userNameFilter.addStyleName(ValoTheme.TEXTFIELD_TINY);
|
||||||
|
userNameFilter
|
||||||
|
.addValueChangeListener(event -> {
|
||||||
|
usersTableDataProvider
|
||||||
|
.setUserNameFilter(event.getValue().toLowerCase());
|
||||||
|
});
|
||||||
|
userNameFilterCell.setComponent(userNameFilter);
|
||||||
|
|
||||||
|
final HeaderRow actionsRow = usersTable.prependHeaderRow();
|
||||||
|
final HeaderCell actionsCell = actionsRow.join(COL_USER_NAME,
|
||||||
|
COL_GIVEN_NAME,
|
||||||
|
COL_FAMILY_NAME,
|
||||||
|
COL_EMAIL,
|
||||||
|
COL_BANNED);
|
||||||
|
final Button clearFiltersButton = new Button("Clear filters");
|
||||||
|
clearFiltersButton.addClickListener(event -> {
|
||||||
|
usersTableDataProvider.setUserNameFilter(null);
|
||||||
|
});
|
||||||
|
final HorizontalLayout actionsLayout = new HorizontalLayout(
|
||||||
|
clearFiltersButton);
|
||||||
|
actionsCell.setComponent(actionsLayout);
|
||||||
|
|
||||||
tabSheet.addTab(usersTable, "Users");
|
tabSheet.addTab(usersTable, "Users");
|
||||||
|
|
||||||
|
|
@ -97,8 +129,8 @@ public class UsersGroupsRoles extends CustomComponent {
|
||||||
// public void setUsers(final List<User> users) {
|
// public void setUsers(final List<User> users) {
|
||||||
// usersTable.setItems(users);
|
// usersTable.setItems(users);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void setDataProvider(final UsersTableDataProvider dataProvider) {
|
public void setDataProvider(final UsersTableDataProvider dataProvider) {
|
||||||
|
this.usersTableDataProvider = dataProvider;
|
||||||
usersTable.setDataProvider(dataProvider);
|
usersTable.setDataProvider(dataProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ public class UsersTableDataProvider extends AbstractDataProvider<User, String> {
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
private String userNameFilter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInMemory() {
|
public boolean isInMemory() {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -61,8 +63,6 @@ public class UsersTableDataProvider extends AbstractDataProvider<User, String> {
|
||||||
|
|
||||||
criteriaQuery = criteriaQuery.select(builder.count(from));
|
criteriaQuery = criteriaQuery.select(builder.count(from));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return entityManager
|
return entityManager
|
||||||
.createQuery(criteriaQuery)
|
.createQuery(criteriaQuery)
|
||||||
.getSingleResult()
|
.getSingleResult()
|
||||||
|
|
@ -78,6 +78,11 @@ public class UsersTableDataProvider extends AbstractDataProvider<User, String> {
|
||||||
.createQuery(User.class);
|
.createQuery(User.class);
|
||||||
final Root<User> from = criteriaQuery.from(User.class);
|
final Root<User> from = criteriaQuery.from(User.class);
|
||||||
|
|
||||||
|
if (userNameFilter != null && !userNameFilter.trim().isEmpty()) {
|
||||||
|
criteriaQuery
|
||||||
|
.where(builder.like(builder.lower(from.get("name")),
|
||||||
|
String.format("%s%%", userNameFilter)));
|
||||||
|
}
|
||||||
|
|
||||||
return entityManager
|
return entityManager
|
||||||
.createQuery(criteriaQuery)
|
.createQuery(criteriaQuery)
|
||||||
|
|
@ -87,4 +92,9 @@ public class UsersTableDataProvider extends AbstractDataProvider<User, String> {
|
||||||
.stream();
|
.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUserNameFilter(final String userNameFilter) {
|
||||||
|
this.userNameFilter = userNameFilter;
|
||||||
|
refreshAll();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ import javax.persistence.TypedQuery;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Provides CRUB operations for {@link Category} objects.
|
||||||
|
*
|
||||||
|
* Note: This repository class does no permission checks when retrieving
|
||||||
|
* categories. This is the responsibility of the application which uses the
|
||||||
|
* retrieved categories.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ import javax.transaction.Transactional;
|
||||||
/**
|
/**
|
||||||
* A repository for executing CRUD operations on {@link Domain} objects.
|
* A repository for executing CRUD operations on {@link Domain} objects.
|
||||||
*
|
*
|
||||||
|
* Note: This repository does the permission checks when retrieving
|
||||||
|
* {@link Domain}s from the database. This is the responsibility of the
|
||||||
|
* application using the {@link Domain}.
|
||||||
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
|
|
|
||||||
|
|
@ -136,12 +136,14 @@ public abstract class AbstractEntityRepository<K, E> {
|
||||||
*/
|
*/
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<E> findById(final K entityId) {
|
public Optional<E> findById(final K entityId) {
|
||||||
|
|
||||||
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
||||||
entityId));
|
entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<E> findById(final K entityId, final String entityGraphName) {
|
public Optional<E> findById(final K entityId, final String entityGraphName) {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager.
|
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager.
|
||||||
getEntityGraph(entityGraphName);
|
getEntityGraph(entityGraphName);
|
||||||
|
|
@ -151,6 +153,7 @@ public abstract class AbstractEntityRepository<K, E> {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<E> findById(final K entityId,
|
public Optional<E> findById(final K entityId,
|
||||||
final EntityGraph<E> entityGraph) {
|
final EntityGraph<E> entityGraph) {
|
||||||
|
|
||||||
final Map<String, Object> hints = new HashMap<>();
|
final Map<String, Object> hints = new HashMap<>();
|
||||||
hints.put(FETCH_GRAPH_HINT_KEY, entityGraph);
|
hints.put(FETCH_GRAPH_HINT_KEY, entityGraph);
|
||||||
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue