CCM NG: Some more things for the PrimeFaces prototype

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4213 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-08-05 18:30:14 +00:00
parent 4820bc7f03
commit 613205fe39
6 changed files with 202 additions and 41 deletions

View File

@ -62,13 +62,28 @@ import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "Role.findByName", @NamedQuery(name = "Role.findByName",
query = "SELECT r FROM Role r " 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"),
@NamedQuery( @NamedQuery(
name = "Role.findAllOrderedByRoleName", name = "Role.findAllOrderedByRoleName",
query = "SELECT r FROM Role r ORDER BY r.name"), 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( @NamedQuery(
name = "Role.searchByName", name = "Role.searchByName",
query query = "SELECT r FROM Role r "
= "SELECT r FROM Role r WHERE LOWER(r.name) LIKE CONCAT(LOWER(:name), '%') " + "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 ") + "ORDER BY r.name ")
}) })
@NamedEntityGraphs({ @NamedEntityGraphs({

View File

@ -26,6 +26,7 @@ import javax.persistence.TypedQuery;
import org.libreccm.core.AbstractEntityRepository; import org.libreccm.core.AbstractEntityRepository;
import org.libreccm.core.CoreConstants; import org.libreccm.core.CoreConstants;
import javax.persistence.NoResultException;
import javax.transaction.Transactional; import javax.transaction.Transactional;
/** /**
@ -49,6 +50,12 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
return entity.getRoleId() == 0; 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. * Finds a role a its name.
* *
@ -75,6 +82,15 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
return query.getResultList(); 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) { public List<Role> searchByName(final String name) {
final TypedQuery<Role> query = getEntityManager().createNamedQuery( final TypedQuery<Role> query = getEntityManager().createNamedQuery(
"Role.searchByName", Role.class); "Role.searchByName", Role.class);
@ -82,6 +98,28 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
return query.getResultList(); 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 @AuthorizationRequired
@RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE) @RequiresPrivilege(CoreConstants.ADMIN_PRIVILEGE)
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)

View File

@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
package org.libreccm.ui.admin; package org.libreccm.ui.admin.sysinfo;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -43,9 +43,9 @@ import javax.xml.transform.TransformerFactory;
*/ */
@RequestScoped @RequestScoped
@Named @Named
public class ConfigurationController { public class SysInfoController {
public List<ConfProperty> getSystemInformation() { public List<SysInfoProperty> getSystemInformation() {
final Properties properties = new Properties(); final Properties properties = new Properties();
try (final InputStream stream = getClass().getResourceAsStream( try (final InputStream stream = getClass().getResourceAsStream(
@ -61,67 +61,67 @@ public class ConfigurationController {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
final List<ConfProperty> sysInfo = new ArrayList<>(); final List<SysInfoProperty> sysInfo = new ArrayList<>();
properties.stringPropertyNames().forEach(propName -> sysInfo.add( properties.stringPropertyNames().forEach(propName -> sysInfo.add(
new ConfProperty(propName, new SysInfoProperty(propName,
properties.getProperty(propName)))); properties.getProperty(propName))));
return sysInfo; return sysInfo;
} }
public List<ConfProperty> getJavaSystemProperties() { public List<SysInfoProperty> getJavaSystemProperties() {
final Properties systemProperties = System.getProperties(); final Properties systemProperties = System.getProperties();
final List<ConfProperty> javaSysProps = new ArrayList<>(); final List<SysInfoProperty> javaSysProps = new ArrayList<>();
systemProperties.stringPropertyNames().forEach(propName -> javaSysProps systemProperties.stringPropertyNames().forEach(propName -> javaSysProps
.add(new ConfProperty(propName, systemProperties.getProperty( .add(new SysInfoProperty(propName, systemProperties.getProperty(
propName)))); propName))));
return javaSysProps; return javaSysProps;
} }
public List<ConfProperty> getXmlConfig() { public List<SysInfoProperty> getXmlConfig() {
final List<ConfProperty> xmlProps = new ArrayList<>(); final List<SysInfoProperty> xmlProps = new ArrayList<>();
final ResourceBundle texts = ResourceBundle.getBundle( final ResourceBundle texts = ResourceBundle.getBundle(
"com.arsdigita.ui.admin.AdminResources"); "com.arsdigita.ui.admin.AdminResources");
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer_factory"), texts.getString("ui.admin.sysinfo.xml_transformer_factory"),
TransformerFactory.newInstance().getClass().getName())); TransformerFactory.newInstance().getClass().getName()));
try { try {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"), texts.getString("ui.admin.sysinfo.xml_transformer"),
TransformerFactory.newInstance().newTransformer().getClass() TransformerFactory.newInstance().newTransformer().getClass()
.getName())); .getName()));
} catch (TransformerConfigurationException ex) { } catch (TransformerConfigurationException ex) {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"), "???")); texts.getString("ui.admin.sysinfo.xml_transformer"), "???"));
} }
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder_factory"), texts.getString("ui.admin.sysinfo.xml_document_builder_factory"),
DocumentBuilderFactory.newInstance().getClass().getName())); DocumentBuilderFactory.newInstance().getClass().getName()));
try { try {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"), texts.getString("ui.admin.sysinfo.xml_document_builder"),
DocumentBuilderFactory.newInstance().newDocumentBuilder() DocumentBuilderFactory.newInstance().newDocumentBuilder()
.getClass().getName())); .getClass().getName()));
} catch (ParserConfigurationException ex) { } catch (ParserConfigurationException ex) {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"), texts.getString("ui.admin.sysinfo.xml_document_builder"),
"???")); "???"));
} }
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser_factory"), texts.getString("ui.admin.sysinfo.sax_parser_factory"),
SAXParserFactory.newInstance().getClass().getName())); SAXParserFactory.newInstance().getClass().getName()));
try { try {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"), texts.getString("ui.admin.sysinfo.sax_parser"),
SAXParserFactory.newInstance().newSAXParser().getClass() SAXParserFactory.newInstance().newSAXParser().getClass()
.getName())); .getName()));
} catch (ParserConfigurationException | SAXException ex) { } catch (ParserConfigurationException | SAXException ex) {
xmlProps.add(new ConfProperty( xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"), "???")); texts.getString("ui.admin.sysinfo.sax_parser"), "???"));
} }

View File

@ -16,18 +16,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA * 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> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
public class ConfProperty { public class SysInfoProperty {
private final String name; private final String name;
private final String value; private final String value;
public ConfProperty(final String name, final String value) { public SysInfoProperty(final String name, final String value) {
this.name = name; this.name = name;
this.value = value; this.value = value;
} }

View File

@ -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;
}
}
}

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui" xmlns:p="http://primefaces.org/ui"
@ -46,12 +47,14 @@
</h:form> </h:form>
</div> </div>
<p:tabView id="admin-tabs" dynamic="true"> <p:tabView dynamic="true" id="admin-tabs">
<p:tab title="#{texts['ui.admin.tab.applications']}"> <p:tab title="#{texts['ui.admin.tab.applications']}">
<h:outputText value="Applications Placeholder" /> <h:outputText value="Applications Placeholder" />
</p:tab> </p:tab>
<p:tab title="#{texts['ui.admin.tab.users_groups_roles.title']}"> <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"> <p:tab title="Users">
<h:outputText value="Users Placeholder" /> <h:outputText value="Users Placeholder" />
</p:tab> </p:tab>
@ -59,7 +62,29 @@
<h:outputText value="Groups Placeholder" /> <h:outputText value="Groups Placeholder" />
</p:tab> </p:tab>
<p:tab title="Roles"> <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:tab>
</p:tabView> </p:tabView>
@ -74,7 +99,7 @@
<h:outputText value="Workflows Placeholder" /> <h:outputText value="Workflows Placeholder" />
</p:tab> </p:tab>
<p:tab title="#{texts['ui.admin.tab.sysinfo.title']}"> <p:tab title="#{texts['ui.admin.tab.sysinfo.title']}">
<p:dataTable value="#{configurationController.systemInformation}" <p:dataTable value="#{sysInfoController.systemInformation}"
var="prop"> var="prop">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{texts['ui.admin.sysinfo.appinfo']}" /> <h:outputText value="#{texts['ui.admin.sysinfo.appinfo']}" />
@ -87,7 +112,7 @@
</p:column> </p:column>
</p:dataTable> </p:dataTable>
<p:dataTable value="#{configurationController.javaSystemProperties}" <p:dataTable value="#{sysInfoController.javaSystemProperties}"
var="prop"> var="prop">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{texts['ui.admin.sysinfo.java_system_properties']}" /> <h:outputText value="#{texts['ui.admin.sysinfo.java_system_properties']}" />
@ -100,7 +125,7 @@
</p:column> </p:column>
</p:dataTable> </p:dataTable>
<p:dataTable value="#{configurationController.xmlConfig}" <p:dataTable value="#{sysInfoController.xmlConfig}"
var="prop"> var="prop">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{texts['ui.admin.sysinfo.xml_config']}" /> <h:outputText value="#{texts['ui.admin.sysinfo.xml_config']}" />