CCM NG: Some more things for the PrimeFaces prototype
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4213 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
4820bc7f03
commit
613205fe39
|
|
@ -62,14 +62,29 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
@NamedQuery(name = "Role.findByName",
|
||||
query = "SELECT r FROM Role r "
|
||||
+ "WHERE r.name = :name"),
|
||||
@NamedQuery(
|
||||
name = "Role.count",
|
||||
query = "SELECT COUNT(r) FROM Role r"),
|
||||
@NamedQuery(
|
||||
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 "),
|
||||
@NamedQuery(
|
||||
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), '%') "
|
||||
+ "ORDER BY r.name ")
|
||||
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), '%') "
|
||||
+ "GROUP BY r.name "
|
||||
+ "ORDER BY r.name ")
|
||||
})
|
||||
@NamedEntityGraphs({
|
||||
@NamedEntityGraph(
|
||||
|
|
@ -91,9 +106,9 @@ public class Role implements Serializable {
|
|||
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")
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import javax.persistence.TypedQuery;
|
|||
import org.libreccm.core.AbstractEntityRepository;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -49,6 +50,12 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
|
|||
return entity.getRoleId() == 0;
|
||||
}
|
||||
|
||||
public long count() {
|
||||
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
|
||||
"Role.count", Long.class);
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a role a its name.
|
||||
*
|
||||
|
|
@ -75,6 +82,15 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Role> findAllOrderedByRole(final int maxResults,
|
||||
final int firstResult) {
|
||||
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
|
||||
"Role.findAllOrderedByRoleName", Role.class);
|
||||
query.setMaxResults(maxResults);
|
||||
query.setFirstResult(firstResult);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Role> searchByName(final String name) {
|
||||
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
|
||||
"Role.searchByName", Role.class);
|
||||
|
|
@ -82,6 +98,28 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<Role> searchByName(final String name,
|
||||
final int maxResults,
|
||||
final int firstResult) {
|
||||
final TypedQuery<Role> query = getEntityManager().createNamedQuery(
|
||||
"Role.searchByName", Role.class);
|
||||
query.setParameter("name", name);
|
||||
query.setFirstResult(firstResult);
|
||||
query.setMaxResults(maxResults);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public long searchByNameCount(final String name) {
|
||||
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
|
||||
"Role.searchByNameCount", Long.class);
|
||||
query.setParameter("name", name);
|
||||
try {
|
||||
return query.getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin;
|
||||
package org.libreccm.ui.admin.sysinfo;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
|
@ -43,9 +43,9 @@ import javax.xml.transform.TransformerFactory;
|
|||
*/
|
||||
@RequestScoped
|
||||
@Named
|
||||
public class ConfigurationController {
|
||||
public class SysInfoController {
|
||||
|
||||
public List<ConfProperty> getSystemInformation() {
|
||||
public List<SysInfoProperty> getSystemInformation() {
|
||||
final Properties properties = new Properties();
|
||||
|
||||
try (final InputStream stream = getClass().getResourceAsStream(
|
||||
|
|
@ -61,67 +61,67 @@ public class ConfigurationController {
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
final List<ConfProperty> sysInfo = new ArrayList<>();
|
||||
final List<SysInfoProperty> sysInfo = new ArrayList<>();
|
||||
properties.stringPropertyNames().forEach(propName -> sysInfo.add(
|
||||
new ConfProperty(propName,
|
||||
new SysInfoProperty(propName,
|
||||
properties.getProperty(propName))));
|
||||
return sysInfo;
|
||||
}
|
||||
|
||||
public List<ConfProperty> getJavaSystemProperties() {
|
||||
public List<SysInfoProperty> getJavaSystemProperties() {
|
||||
final Properties systemProperties = System.getProperties();
|
||||
final List<ConfProperty> javaSysProps = new ArrayList<>();
|
||||
final List<SysInfoProperty> javaSysProps = new ArrayList<>();
|
||||
systemProperties.stringPropertyNames().forEach(propName -> javaSysProps
|
||||
.add(new ConfProperty(propName, systemProperties.getProperty(
|
||||
.add(new SysInfoProperty(propName, systemProperties.getProperty(
|
||||
propName))));
|
||||
return javaSysProps;
|
||||
}
|
||||
|
||||
public List<ConfProperty> getXmlConfig() {
|
||||
final List<ConfProperty> xmlProps = new ArrayList<>();
|
||||
public List<SysInfoProperty> getXmlConfig() {
|
||||
final List<SysInfoProperty> xmlProps = new ArrayList<>();
|
||||
|
||||
final ResourceBundle texts = ResourceBundle.getBundle(
|
||||
"com.arsdigita.ui.admin.AdminResources");
|
||||
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_transformer_factory"),
|
||||
TransformerFactory.newInstance().getClass().getName()));
|
||||
try {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_transformer"),
|
||||
TransformerFactory.newInstance().newTransformer().getClass()
|
||||
.getName()));
|
||||
} catch (TransformerConfigurationException ex) {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_transformer"), "???"));
|
||||
}
|
||||
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_document_builder_factory"),
|
||||
DocumentBuilderFactory.newInstance().getClass().getName()));
|
||||
|
||||
try {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_document_builder"),
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.getClass().getName()));
|
||||
} catch (ParserConfigurationException ex) {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.xml_document_builder"),
|
||||
"???"));
|
||||
}
|
||||
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.sax_parser_factory"),
|
||||
SAXParserFactory.newInstance().getClass().getName()));
|
||||
|
||||
try {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.sax_parser"),
|
||||
SAXParserFactory.newInstance().newSAXParser().getClass()
|
||||
.getName()));
|
||||
} catch (ParserConfigurationException | SAXException ex) {
|
||||
xmlProps.add(new ConfProperty(
|
||||
xmlProps.add(new SysInfoProperty(
|
||||
texts.getString("ui.admin.sysinfo.sax_parser"), "???"));
|
||||
}
|
||||
|
||||
|
|
@ -16,18 +16,18 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin;
|
||||
package org.libreccm.ui.admin.sysinfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ConfProperty {
|
||||
public class SysInfoProperty {
|
||||
|
||||
private final String name;
|
||||
private final String value;
|
||||
|
||||
public ConfProperty(final String name, final String value) {
|
||||
public SysInfoProperty(final String name, final String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.ui.admin.usersgroupsroles;
|
||||
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.primefaces.model.LazyDataModel;
|
||||
import org.primefaces.model.SortOrder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Named
|
||||
public class RolesController {
|
||||
|
||||
@Inject
|
||||
private RoleRepository roleRepo;
|
||||
|
||||
private final LazyDataModel<Role> tableModel;
|
||||
|
||||
public RolesController() {
|
||||
tableModel = new RolesTableModel();
|
||||
}
|
||||
|
||||
public LazyDataModel<Role> getTableModel() {
|
||||
return tableModel;
|
||||
}
|
||||
|
||||
public List<Role> getRoles() {
|
||||
return roleRepo.findAll();
|
||||
}
|
||||
|
||||
private class RolesTableModel extends LazyDataModel<Role> {
|
||||
|
||||
private static final long serialVersionUID = 8878060757439667086L;
|
||||
|
||||
@Override
|
||||
public List<Role> load(final int first,
|
||||
final int pageSize,
|
||||
final String sortField,
|
||||
final SortOrder sortOrder,
|
||||
final Map<String, Object> filters) {
|
||||
final List<Role> roles;
|
||||
if (filters.containsKey("name")) {
|
||||
final String name = (String) filters.get("name");
|
||||
roles = roleRepo.searchByName(name, pageSize, first);
|
||||
setRowCount((int) roleRepo.searchByNameCount(name));
|
||||
} else {
|
||||
roles = roleRepo.findAllOrderedByRole(pageSize, first);
|
||||
setRowCount((int) roleRepo.count());
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||
xmlns:p="http://primefaces.org/ui"
|
||||
|
|
@ -46,12 +47,14 @@
|
|||
</h:form>
|
||||
</div>
|
||||
|
||||
<p:tabView id="admin-tabs" dynamic="true">
|
||||
<p:tabView dynamic="true" id="admin-tabs">
|
||||
<p:tab title="#{texts['ui.admin.tab.applications']}">
|
||||
<h:outputText value="Applications Placeholder" />
|
||||
</p:tab>
|
||||
<p:tab title="#{texts['ui.admin.tab.users_groups_roles.title']}">
|
||||
<p:tabView id="user-groups-roles-tabs" orientation="left">
|
||||
<p:tabView dynamic="true"
|
||||
id="user-groups-roles-tabs"
|
||||
orientation="left">
|
||||
<p:tab title="Users">
|
||||
<h:outputText value="Users Placeholder" />
|
||||
</p:tab>
|
||||
|
|
@ -59,7 +62,29 @@
|
|||
<h:outputText value="Groups Placeholder" />
|
||||
</p:tab>
|
||||
<p:tab title="Roles">
|
||||
<h:outputText value="Roles Placeholder" />
|
||||
<!--<h:outputText value="Roles Placeholder" />-->
|
||||
<!--<p:panel header="#{texts['ui.admin.tab.users_groups_roles.title']}">-->
|
||||
<h:form>
|
||||
<p:dataTable id="rolesTable"
|
||||
lazy="true"
|
||||
paginator="true"
|
||||
rows="20"
|
||||
rowsPerPageTemplate="20,50"
|
||||
scrollable="true"
|
||||
value="#{rolesController.tableModel}"
|
||||
var="role">
|
||||
<f:facet name="header">
|
||||
<h:outputText value="#{texts['ui.admin.tab.users_groups_roles.title']}" />
|
||||
</f:facet>
|
||||
|
||||
<p:column filterBy="#{role.name}"
|
||||
headerText="#{texts['ui.admin.roles.table.name']}"
|
||||
id="role-name">
|
||||
<h:outputText value="#{role.name}" />
|
||||
</p:column>
|
||||
</p:dataTable>
|
||||
</h:form>
|
||||
<!--</p:panel>-->
|
||||
</p:tab>
|
||||
</p:tabView>
|
||||
|
||||
|
|
@ -74,7 +99,7 @@
|
|||
<h:outputText value="Workflows Placeholder" />
|
||||
</p:tab>
|
||||
<p:tab title="#{texts['ui.admin.tab.sysinfo.title']}">
|
||||
<p:dataTable value="#{configurationController.systemInformation}"
|
||||
<p:dataTable value="#{sysInfoController.systemInformation}"
|
||||
var="prop">
|
||||
<f:facet name="header">
|
||||
<h:outputText value="#{texts['ui.admin.sysinfo.appinfo']}" />
|
||||
|
|
@ -87,7 +112,7 @@
|
|||
</p:column>
|
||||
</p:dataTable>
|
||||
|
||||
<p:dataTable value="#{configurationController.javaSystemProperties}"
|
||||
<p:dataTable value="#{sysInfoController.javaSystemProperties}"
|
||||
var="prop">
|
||||
<f:facet name="header">
|
||||
<h:outputText value="#{texts['ui.admin.sysinfo.java_system_properties']}" />
|
||||
|
|
@ -100,7 +125,7 @@
|
|||
</p:column>
|
||||
</p:dataTable>
|
||||
|
||||
<p:dataTable value="#{configurationController.xmlConfig}"
|
||||
<p:dataTable value="#{sysInfoController.xmlConfig}"
|
||||
var="prop">
|
||||
<f:facet name="header">
|
||||
<h:outputText value="#{texts['ui.admin.sysinfo.xml_config']}" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue