CCM NG/ccm-core: Some work for the Vaadin prototype
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4821 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: c101563f80
pull/2/head
parent
93ec4021ae
commit
ba5e114ffe
|
|
@ -48,10 +48,7 @@ import org.libreccm.security.GroupRepository;
|
|||
import org.libreccm.security.User;
|
||||
import org.libreccm.security.UserRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -220,14 +217,12 @@ public class GroupDetails extends Window {
|
|||
dataProvider.setGroup(group);
|
||||
membersGrid.setDataProvider(dataProvider);
|
||||
|
||||
//ToDo Add roles grid
|
||||
|
||||
final TabSheet tabs = new TabSheet();
|
||||
tabs.addTab(membersGrid, "Members");
|
||||
tabs.addTab(new Label("Roles Placeholder"), "Roles");
|
||||
|
||||
// final Panel membersPanel = new Panel("Members");
|
||||
// membersPanel.setContent(membersGrid);
|
||||
// final VerticalLayout windowLayout = new VerticalLayout(propertiesPanel,
|
||||
// membersPanel);
|
||||
final VerticalLayout windowLayout = new VerticalLayout(propertiesPanel,
|
||||
tabs);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,20 +47,20 @@ class GroupMembersController {
|
|||
private GroupManager groupManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addMembersToGroup(final Set<User> users, final Group group) {
|
||||
protected void addMembersToGroup(final Set<User> users, final Group group) {
|
||||
|
||||
users.forEach(user -> addMemberToGroup(user, group));
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addMemberToGroup(final User user, final Group group) {
|
||||
protected void addMemberToGroup(final User user, final Group group) {
|
||||
|
||||
final User theUser = userRepo
|
||||
.findById(user.getPartyId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No user with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
user.getPartyId())));
|
||||
.orElseThrow(() -> new IllegalArgumentException(
|
||||
String.format("No user with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
user.getPartyId())));
|
||||
|
||||
final Group theGroup = groupRepo
|
||||
.findById(group.getPartyId())
|
||||
|
|
@ -71,10 +71,10 @@ class GroupMembersController {
|
|||
|
||||
groupManager.addMemberToGroup(theUser, theGroup);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void removeMemberFromGroup(final User member, final Group group) {
|
||||
|
||||
protected void removeMemberFromGroup(final User member, final Group group) {
|
||||
|
||||
final User theMember = userRepo
|
||||
.findById(member.getPartyId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
|
|
@ -88,9 +88,8 @@ class GroupMembersController {
|
|||
.format("No group with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
group.getPartyId())));
|
||||
|
||||
|
||||
groupManager.removeMemberFromGroup(theMember, theGroup);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ViewScoped
|
||||
public class GroupMembersTableDataProvider
|
||||
class GroupMembersTableDataProvider
|
||||
extends AbstractDataProvider<User, String> {
|
||||
|
||||
private static final long serialVersionUID = -1924910843845830008L;
|
||||
|
|
@ -56,8 +56,9 @@ public class GroupMembersTableDataProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public int size(Query<User, String> query) {
|
||||
public int size(final Query<User, String> query) {
|
||||
|
||||
Objects.requireNonNull(group,
|
||||
"This data provider needs to be initalized "
|
||||
|
|
@ -81,7 +82,7 @@ public class GroupMembersTableDataProvider
|
|||
|
||||
final Root<GroupMembership> from = criteriaQuery
|
||||
.from(GroupMembership.class);
|
||||
|
||||
|
||||
criteriaQuery = criteriaQuery.select(builder.count(from));
|
||||
criteriaQuery.where(builder.equal(from.get("group"), group));
|
||||
|
||||
|
|
@ -118,21 +119,21 @@ public class GroupMembersTableDataProvider
|
|||
// .stream();
|
||||
|
||||
final CriteriaQuery<GroupMembership> criteriaQuery = builder
|
||||
.createQuery(GroupMembership.class);
|
||||
final Root<GroupMembership> from = criteriaQuery
|
||||
.createQuery(GroupMembership.class);
|
||||
final Root<GroupMembership> from = criteriaQuery
|
||||
.from(GroupMembership.class);
|
||||
final Join<?, ?> join = from.join("member");
|
||||
criteriaQuery
|
||||
.where(builder.equal(from.get("group"), group))
|
||||
.orderBy(builder.asc(join.get("name")));
|
||||
|
||||
return entityManager
|
||||
.createQuery(criteriaQuery)
|
||||
.setMaxResults(query.getLimit())
|
||||
.setFirstResult(query.getOffset())
|
||||
.getResultList()
|
||||
.stream()
|
||||
.map(membership -> membership.getMember());
|
||||
final Join<?, ?> join = from.join("member");
|
||||
criteriaQuery
|
||||
.where(builder.equal(from.get("group"), group))
|
||||
.orderBy(builder.asc(join.get("name")));
|
||||
|
||||
return entityManager
|
||||
.createQuery(criteriaQuery)
|
||||
.setMaxResults(query.getLimit())
|
||||
.setFirstResult(query.getOffset())
|
||||
.getResultList()
|
||||
.stream()
|
||||
.map(GroupMembership::getMember);
|
||||
}
|
||||
|
||||
public void setGroup(final Group group) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.admin.ui.usersgroupsroles;
|
||||
|
||||
import org.libreccm.security.Group;
|
||||
import org.libreccm.security.GroupManager;
|
||||
import org.libreccm.security.GroupRepository;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleManager;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class GroupRolesController {
|
||||
|
||||
@Inject
|
||||
private RoleRepository roleRepo;
|
||||
|
||||
@Inject
|
||||
private RoleManager roleManager;
|
||||
|
||||
@Inject
|
||||
private GroupRepository groupRepo;
|
||||
|
||||
@Inject
|
||||
private GroupManager groupManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void assignRolesToGroup(final Set<Role> roles, final Group group) {
|
||||
|
||||
roles.forEach(role -> assignRoleToGroup(role, group));
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void assignRoleToGroup(final Role role, final Group group) {
|
||||
|
||||
final Role theRole = roleRepo
|
||||
.findById(role.getRoleId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Role with ID %d in the database.",
|
||||
role.getRoleId())));
|
||||
|
||||
final Group theGroup = groupRepo
|
||||
.findById(group.getPartyId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No group with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
group.getPartyId())));
|
||||
|
||||
roleManager.assignRoleToParty(theRole, theGroup);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void removeRoleFromGroup(final Role role, final Group group) {
|
||||
|
||||
final Role theRole = roleRepo
|
||||
.findById(role.getRoleId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Role with ID %d in the database.",
|
||||
role.getRoleId())));
|
||||
|
||||
final Group theGroup = groupRepo
|
||||
.findById(group.getPartyId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No group with id %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
group.getPartyId())));
|
||||
|
||||
roleManager.removeRoleFromParty(theRole, theGroup);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.admin.ui.usersgroupsroles;
|
||||
|
||||
import com.vaadin.cdi.ViewScoped;
|
||||
import com.vaadin.data.provider.AbstractDataProvider;
|
||||
import com.vaadin.data.provider.Query;
|
||||
import org.libreccm.security.Group;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleMembership;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ViewScoped
|
||||
class GroupRolesTableDataProvider
|
||||
extends AbstractDataProvider<Role, String> {
|
||||
|
||||
private static final long serialVersionUID = 7981493169013788121L;
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
private Group group;
|
||||
|
||||
@Override
|
||||
public boolean isInMemory() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public int size(Query<Role, String> query) {
|
||||
|
||||
Objects.requireNonNull(group,
|
||||
"This data provider needs to be initalized "
|
||||
+ "by calling setGroup(Group) before calling "
|
||||
+ "the count method.");
|
||||
|
||||
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Long> criteriaQuery = builder
|
||||
.createQuery(Long.class);
|
||||
|
||||
final Root<RoleMembership> from = criteriaQuery
|
||||
.from(RoleMembership.class);
|
||||
|
||||
criteriaQuery
|
||||
.select(builder.count(from))
|
||||
.where(builder.equal(from.get("member"), group));
|
||||
|
||||
return entityManager
|
||||
.createQuery(criteriaQuery)
|
||||
.getSingleResult()
|
||||
.intValue();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public Stream<Role> fetch(Query<Role, String> query) {
|
||||
|
||||
Objects.requireNonNull(group,
|
||||
"This data provider needs to be initalized "
|
||||
+ "by calling setGroup(Group) before calling "
|
||||
+ "the fetch method.");
|
||||
|
||||
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
|
||||
final CriteriaQuery<RoleMembership> criteriaQuery = builder
|
||||
.createQuery(RoleMembership.class);
|
||||
final Root<RoleMembership> from = criteriaQuery
|
||||
.from(RoleMembership.class);
|
||||
final Join<?, ?> join = from.join("role");
|
||||
criteriaQuery
|
||||
.where(builder.equal(from.get("member"), group))
|
||||
.orderBy(builder.asc(join.get("name")));
|
||||
|
||||
return entityManager
|
||||
.createQuery(criteriaQuery)
|
||||
.setMaxResults(query.getLimit())
|
||||
.setFirstResult(query.getOffset())
|
||||
.getResultList()
|
||||
.stream()
|
||||
.map(RoleMembership::getRole);
|
||||
}
|
||||
|
||||
public void setGroup(final Group group) {
|
||||
Objects.requireNonNull(group);
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -131,9 +131,16 @@ public class RoleEditor extends Window {
|
|||
// }
|
||||
if (role != null) {
|
||||
roleName.setValue(role.getName());
|
||||
roleDescription.setValue(role
|
||||
final String description = role
|
||||
.getDescription()
|
||||
.getValue(UI.getCurrent().getLocale()));
|
||||
.getValue(UI.getCurrent().getLocale());
|
||||
if (description == null) {
|
||||
roleDescription.setValue("");
|
||||
} else {
|
||||
roleDescription.setValue(role
|
||||
.getDescription()
|
||||
.getValue(UI.getCurrent().getLocale()));
|
||||
}
|
||||
}
|
||||
|
||||
setContent(layout);
|
||||
|
|
|
|||
Loading…
Reference in New Issue