CCM NG/ccm-core: Some things for the Vaadin prototype

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4829 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-07-01 09:54:55 +00:00
parent b53e2b6fb4
commit f26166ce41
8 changed files with 136 additions and 88 deletions

View File

@ -219,10 +219,10 @@ public class GroupDetails extends Window {
membersGridHeaderCell
.setComponent(new HorizontalLayout(addMemberButton));
final GroupMembersTableDataProvider dataProvider = cdiUtil
final GroupMembersTableDataProvider usersDataProvider = cdiUtil
.findBean(GroupMembersTableDataProvider.class);
dataProvider.setGroup(group);
membersGrid.setDataProvider(dataProvider);
usersDataProvider.setGroup(group);
membersGrid.setDataProvider(usersDataProvider);
final GroupRolesController rolesController = cdiUtil
.findBean(GroupRolesController.class);
@ -240,24 +240,46 @@ public class GroupDetails extends Window {
rolesGrid.getDataProvider().refreshAll();
}))
.setId(COL_ROLE_REMOVE);
rolesGrid.setWidth("100%");
final RoleRepository roleRepository = cdiUtil
.findBean(RoleRepository.class);
final HeaderRow rolesGridHeader = rolesGrid.prependHeaderRow();
final Button addRoleButton = new Button("Add role");
addRoleButton.setIcon(VaadinIcons.PLUS);
addRoleButton.setStyleName(ValoTheme.BUTTON_TINY);
addRoleButton.addClickListener(event -> {
final RoleSelector roleSelector = new RoleSelector(
"Select role(s) to add to group",
"Add selected role(s) to group",
usersGroupsRoles,
roleRepository.findByParty(group),
(selectedRoles -> {
selectedRoles.forEach(role -> {
rolesController.assignRoleToGroup(role, group);
rolesGrid.getDataProvider().refreshAll();
});
}));
roleSelector.center();
roleSelector.setWidth("80%");
UI.getCurrent().addWindow(roleSelector);
});
//ToDo Add roles grid
final HeaderCell rolesGridHeaderCell = rolesGridHeader
.join(COL_ROLE_NAME,
COL_ROLE_REMOVE);
rolesGridHeaderCell
.setComponent(new HorizontalLayout(addRoleButton));
final GroupRolesTableDataProvider rolesDataProvider = cdiUtil
.findBean(GroupRolesTableDataProvider.class);
rolesDataProvider.setGroup(group);
rolesGrid.setDataProvider(rolesDataProvider);
final TabSheet tabs = new TabSheet();
tabs.addTab(membersGrid, "Members");
tabs.addTab(new Label("Roles Placeholder"), "Roles");
tabs.addTab(rolesGrid, "Roles");
final VerticalLayout windowLayout = new VerticalLayout(propertiesPanel,
tabs);

View File

@ -20,7 +20,6 @@ package org.libreccm.admin.ui.usersgroupsroles;
import com.arsdigita.ui.admin.AdminUiConstants;
import com.vaadin.cdi.CDIUI;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
@ -42,56 +41,61 @@ import java.util.ResourceBundle;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class RoleSelector extends Window {
private static final long serialVersionUID = -1437536052155383270L;
private static final String COL_NAME = "rolename";
private static final String COL_OTHER = "other";
private final RoleRepository roleRepo;
private final RoleSelectionAction roleSelectionAction;
public RoleSelector(final String caption,
final String actionLabel,
final UsersGroupsRoles usersGroupsRoles,
final List<Role> excludedRoles,
final RoleSelectionAction action) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
roleRepo = cdiUtil.findBean(RoleRepository.class);
this.roleSelectionAction = action;
addWidgets(caption, actionLabel, excludedRoles, action);
}
private void addWidgets(final String caption,
final String actionLabel,
final List<Role> excludedRoles,
final RoleSelectionAction action) {
setCaption(caption);
final ResourceBundle bundle = ResourceBundle
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
UI.getCurrent().getLocale());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Grid<Role> rolesGrid = new Grid<>();
rolesGrid
.addColumn(Role::getName)
.setId(COL_NAME)
.setCaption("Role");
rolesGrid
.addColumn(role -> " ")
.setId(COL_OTHER)
.setCaption(" ");
rolesGrid.setSelectionMode(Grid.SelectionMode.MULTI);
rolesGrid.setWidth("100%");
final Button actionButton = new Button(actionLabel);
actionButton.addClickListener(event -> {
action.action(rolesGrid.getSelectedItems());
close();
});
actionButton.setIcon(VaadinIcons.PLUS_CIRCLE_O);
actionButton.setStyleName(ValoTheme.BUTTON_TINY);
@ -101,9 +105,10 @@ public class RoleSelector extends Window {
});
clearButton.setIcon(VaadinIcons.BACKSPACE);
clearButton.setStyleName(ValoTheme.BUTTON_TINY);
final HeaderRow actions = rolesGrid.prependHeaderRow();
final HeaderCell actionsCell = actions.join(COL_NAME);
final HeaderCell actionsCell = actions.join(COL_NAME,
COL_OTHER);
actionsCell.setComponent(new HorizontalLayout(actionButton,
clearButton));
@ -116,4 +121,5 @@ public class RoleSelector extends Window {
setContent(rolesGrid);
}
}

View File

@ -70,66 +70,73 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA;
@NamedQueries({
@NamedQuery(name = "Role.findByName",
query = "SELECT r FROM Role r "
+ "WHERE r.name = :name")
+ "WHERE r.name = :name")
,
@NamedQuery(
name = "Role.count",
query = "SELECT COUNT(r) FROM Role r")
name = "Role.count",
query = "SELECT COUNT(r) FROM Role r")
,
@NamedQuery(
name = "Role.findAllOrderedByRoleName",
query = "SELECT r FROM Role r ORDER BY r.name")
name = "Role.findAllOrderedByRoleName",
query = "SELECT r FROM Role r ORDER BY r.name")
,
@NamedQuery(
name = "Role.findAllOrderedByRoleNameLimit",
query = "SELECT r FROM Role r ORDER BY r.name ")
name = "Role.findAllOrderedByRoleNameLimit",
query = "SELECT r FROM Role r ORDER BY r.name ")
,
@NamedQuery(
name = "Role.findAllOrderedByRoleNameDesc",
query = "SELECT r FROM Role r ORDER BY r.name DESC")
name = "Role.findAllOrderedByRoleNameDesc",
query = "SELECT r FROM Role r ORDER BY r.name DESC")
,
@NamedQuery(
name = "Role.searchByName",
query = "SELECT r FROM Role r "
+ "WHERE LOWER(r.name) LIKE CONCAT(LOWER(:name), '%') "
name = "Role.searchByName",
query = "SELECT r FROM Role r "
+ "WHERE LOWER(r.name) LIKE CONCAT(LOWER(:name), '%') "
+ "ORDER BY r.name ")
,
@NamedQuery(
name = "Role.searchByNameCount",
query = "SELECT COUNT(r.name) FROM Role r "
+ "WHERE LOWER(r.name) LIKE CONCAT(LOWER(:name), '%') "
name = "Role.searchByNameCount",
query = "SELECT COUNT(r.name) FROM Role r "
+ "WHERE LOWER(r.name) LIKE CONCAT(LOWER(:name), '%') "
+ "GROUP BY r.name "
+ "ORDER BY r.name ")
+ "ORDER BY r.name ")
,
@NamedQuery(
name = "Role.findByPrivilege",
query = "SELECT r FROM Role r JOIN r.permissions p "
+ "WHERE p.grantedPrivilege = :privilege "
+ "ORDER BY r.name")
name = "Role.findByPrivilege",
query = "SELECT r FROM Role r JOIN r.permissions p "
+ "WHERE p.grantedPrivilege = :privilege "
+ "ORDER BY r.name")
,
@NamedQuery(
name = "Role.findByPrivilegeAndObject",
query = "SELECT r FROM Role r JOIN r.permissions p "
+ "WHERE p.grantedPrivilege = :privilege "
+ "AND p.object = :object "
+ "ORDER BY r.name")
name = "Role.findByPrivilegeAndObject",
query = "SELECT r FROM Role r JOIN r.permissions p "
+ "WHERE p.grantedPrivilege = :privilege "
+ "AND p.object = :object "
+ "ORDER BY r.name")
,
@NamedQuery(
name = "Role.findRolesOfUser",
query = "SELECT r.role FROM RoleMembership r "
+ "WHERE r.member = :user")
name = "Role.findRolesOfUser",
query = "SELECT r.role FROM RoleMembership r "
+ "WHERE r.member = :user")
,
@NamedQuery(
name = "Role.findByParty",
query = "SELECT r FROM Role r "
+ "JOIN r.memberships m "
+ "WHERE m.member = :member"
)
})
@NamedEntityGraphs({
@NamedEntityGraph(
name = Role.ENTITY_GRPAH_WITH_MEMBERS,
attributeNodes = {
@NamedAttributeNode(value = "memberships"),})
name = Role.ENTITY_GRPAH_WITH_MEMBERS,
attributeNodes = {
@NamedAttributeNode(value = "memberships"),})
,
@NamedEntityGraph(
name = Role.ENTITY_GRPAH_WITH_PERMISSIONS,
attributeNodes = {
@NamedAttributeNode(value = "permissions")
})
name = Role.ENTITY_GRPAH_WITH_PERMISSIONS,
attributeNodes = {
@NamedAttributeNode(value = "permissions")
})
})
@XmlRootElement(name = "role", namespace = CORE_XML_NS)
@XmlAccessorType(XmlAccessType.FIELD)
@ -142,9 +149,9 @@ public class Role implements Serializable, Portable {
private static final long serialVersionUID = -7121296514181469687L;
public static final String ENTITY_GRPAH_WITH_MEMBERS
= "Role.withMembers";
= "Role.withMembers";
public static final String ENTITY_GRPAH_WITH_PERMISSIONS
= "Role.withPermissions";
= "Role.withPermissions";
@Id
@Column(name = "ROLE_ID")
@ -168,12 +175,12 @@ public class Role implements Serializable, Portable {
*/
@Embedded
@AssociationOverride(
name = "values",
joinTable = @JoinTable(name = "ROLE_DESCRIPTIONS",
schema = DB_SCHEMA,
joinColumns = {
@JoinColumn(name = "ROLE_ID")
}))
name = "values",
joinTable = @JoinTable(name = "ROLE_DESCRIPTIONS",
schema = DB_SCHEMA,
joinColumns = {
@JoinColumn(name = "ROLE_ID")
}))
@XmlElement(name = "description", namespace = CORE_XML_NS)
private LocalizedString description = new LocalizedString();
@ -334,9 +341,9 @@ public class Role implements Serializable, Portable {
// name,
// Objects.toString(permissions));
return String.format("%s{ "
+ "roldId = %d, "
+ "name = \"%s\", "
+ " }",
+ "roldId = %d, "
+ "name = \"%s\", "
+ " }",
super.toString(),
roleId,
name);

View File

@ -56,7 +56,7 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
public long count() {
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
"Role.count", Long.class);
"Role.count", Long.class);
return query.getSingleResult();
}
@ -66,11 +66,11 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
* @param name The name of the role to retrieve.
*
* @return The role identified by the provided {@code name} or {@code null}
* if there is no matching role.
* if there is no matching role.
*/
public Optional<Role> findByName(final String name) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findByName", Role.class);
"Role.findByName", Role.class);
query.setParameter("name", name);
final List<Role> result = query.getResultList();
if (result.isEmpty()) {
@ -82,42 +82,51 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
public List<Role> findAllOrderedByRoleName() {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findAllOrderedByRoleName", Role.class);
"Role.findAllOrderedByRoleName", Role.class);
return query.getResultList();
}
public List<Role> findAllOrderedByRole(final int maxResults,
final int firstResult) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findAllOrderedByRoleName", Role.class);
"Role.findAllOrderedByRoleName", Role.class);
query.setMaxResults(maxResults);
query.setFirstResult(firstResult);
return query.getResultList();
}
@Transactional(Transactional.TxType.REQUIRED)
public List<Role> findByPrivilege(final String privilege) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findByPrivilege", Role.class);
query.setParameter("privilege", privilege);
public List<Role> findByParty(final Party party) {
final TypedQuery<Role> query = getEntityManager()
.createNamedQuery("Role.findByParty", Role.class);
query.setParameter("member", party);
return query.getResultList();
}
@Transactional(Transactional.TxType.REQUIRED)
public List<Role> findByPrivilege(final String privilege) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findByPrivilege", Role.class);
query.setParameter("privilege", privilege);
return query.getResultList();
}
@Transactional(Transactional.TxType.REQUIRED)
public List<Role> findByPrivilege(final String privilege,
final CcmObject object) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.findByPrivilegeAndObject", Role.class);
"Role.findByPrivilegeAndObject", Role.class);
query.setParameter("privilege", privilege);
query.setParameter("object", object);
return query.getResultList();
}
public List<Role> searchByName(final String name) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.searchByName", Role.class);
"Role.searchByName", Role.class);
query.setParameter("name", name);
return query.getResultList();
}
@ -126,7 +135,7 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
final int maxResults,
final int firstResult) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.searchByName", Role.class);
"Role.searchByName", Role.class);
query.setParameter("name", name);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
@ -135,7 +144,7 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
public long searchByNameCount(final String name) {
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
"Role.searchByNameCount", Long.class);
"Role.searchByNameCount", Long.class);
query.setParameter("name", name);
try {
return query.getSingleResult();

View File

@ -610,3 +610,4 @@ ui.admin.importexport.import.status.import_active=An import process is active.
ui.admin.importexport.import.status.locked=This should not happen.
ui.admin.importexport.import.current_status=Import current status
ui.admin.importexport.import.report=Report from last import process
ui.groups.roles.remove=Remove

View File

@ -614,3 +614,4 @@ ui.admin.importexport.import.status.import_active=Ein Import-Prozess ist bereits
ui.admin.importexport.import.status.locked=This should not happen.
ui.admin.importexport.import.current_status=Aktueller Status des Import-Prozesses
ui.admin.importexport.import.report=Bericht des letzten Import-Prozesses
ui.groups.roles.remove=Entfernen

View File

@ -607,3 +607,4 @@ ui.admin.importexport.import.status.import_active=An import process is active.
ui.admin.importexport.import.status.locked=This should not happen.
ui.admin.importexport.import.current_status=Import current status
ui.admin.importexport.import.report=Report from last import process
ui.groups.roles.remove=Remove

View File

@ -598,3 +598,4 @@ ui.admin.importexport.import.status.import_active=An import process is active.
ui.admin.importexport.import.status.locked=This should not happen.
ui.admin.importexport.import.current_status=Import current status
ui.admin.importexport.import.report=Report from last import process
ui.groups.roles.remove=Remove