CCM NG: Bug fixing for Configuration Admin UI

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4073 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-05-13 17:35:14 +00:00
parent 15571d4bbe
commit 6c89d10a80
8 changed files with 221 additions and 151 deletions

View File

@ -30,6 +30,7 @@ import com.arsdigita.templating.Templating;
import com.arsdigita.ui.SiteBanner;
import com.arsdigita.ui.UserBanner;
import com.arsdigita.ui.admin.categories.CategoriesTab;
import com.arsdigita.ui.admin.configuration.ConfigurationTab;
import com.arsdigita.web.BaseApplicationServlet;
import com.arsdigita.web.LoginSignal;
import com.arsdigita.xml.Document;
@ -131,7 +132,7 @@ public class AdminServlet
tabbedPane.addTab(
new Label(new GlobalizedMessage("ui.admin.tab.configuration.title",
BUNDLE_NAME)),
new RegistryAdminTab());
new ConfigurationTab());
tabbedPane.addTab(
new Label(new GlobalizedMessage("ui.admin.tab.workflows.title",

View File

@ -1,39 +0,0 @@
/*
* 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 com.arsdigita.ui.admin;
import com.arsdigita.bebop.Label;
import com.arsdigita.toolbox.ui.LayoutPanel;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class RegistryAdminTab extends LayoutPanel {
public RegistryAdminTab() {
super();
setLeft(new Label("Registry Admin Tab Left"));
setBody(new Label("Registry Admin Tab Body"));
}
}

View File

@ -163,7 +163,12 @@ public class ConfigurationsTable extends Table {
final ConfigurationInfo info = confManager
.getConfigurationInfo(c);
// return c.getName().startsWith(filterTerm);
return info.getTitle(negoiatedLocale).startsWith(filterTerm);
if (filterTerm == null || filterTerm.isEmpty()) {
return true;
} else {
return info.getTitle(negoiatedLocale).startsWith(
filterTerm);
}
})
.collect(Collectors.toCollection(ArrayList::new));
configurations.sort((c1, c2) -> {

View File

@ -18,8 +18,12 @@
*/
package org.libreccm.configuration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.ResourceBundle;
@ -32,6 +36,9 @@ import java.util.TreeMap;
*/
public final class ConfigurationInfo {
private final static Logger LOGGER = LogManager.getLogger(
ConfigurationInfo.class);
/**
* The fully qualified name of the configuration.
*/
@ -81,7 +88,15 @@ public final class ConfigurationInfo {
}
public ResourceBundle getDescriptionBundle(final Locale locale) {
try {
return ResourceBundle.getBundle(descBundle);
} catch (MissingResourceException ex) {
LOGGER.warn(
"Failed to find ResourceBundle for base name '{}' and "
+ "locale '{}'.",
descBundle, locale);
return null;
}
}
public String getTitleKey() {
@ -101,11 +116,41 @@ public final class ConfigurationInfo {
}
public String getTitle(final Locale locale) {
return getDescriptionBundle(locale).getString(titleKey);
final ResourceBundle bundle = getDescriptionBundle(locale);
if (bundle == null) {
return name;
} else {
try {
return bundle.getString(titleKey);
} catch (MissingResourceException ex) {
LOGGER.warn("Can't find resource for bundle '{}', "
+ "key '{}' and locale '{}'.",
descBundle,
titleKey,
locale);
return name;
}
}
}
public String getDescription(final Locale locale) {
return getDescriptionBundle(locale).getString(descKey);
final ResourceBundle bundle = getDescriptionBundle(locale);
if (bundle == null) {
return "";
} else {
try {
return bundle.getString(descKey);
} catch (MissingResourceException ex) {
LOGGER.warn("Can't find resource for bundle '{}', "
+ "key '{}' and locale '{}'.",
descBundle,
descKey,
locale);
return "";
}
}
}
public NavigableMap<String, SettingInfo> getSettings() {

View File

@ -114,11 +114,13 @@ public class ConfigurationManager {
* registry.
*
* @param configuration The configuration to save. The class of the provided
* object must be annotation with {@link Configuration}.
* object must be annotation with
* {@link Configuration}.
*
* @throws IllegalArgumentException If the {@code configuration} parameter
* is {@code null} or if the class of the provided object is not annotation
* with {@link Configuration}.
* is {@code null} or if the class of the
* provided object is not annotation with
* {@link Configuration}.
*/
public void saveConfiguration(final Object configuration) {
if (configuration == null) {
@ -197,12 +199,12 @@ public class ConfigurationManager {
Configuration.class);
final ConfigurationInfo confInfo = new ConfigurationInfo();
confInfo.setName(configuration.getClass().getName());
confInfo.setName(configuration.getName());
if (annotation.descBundle() == null
|| annotation.descBundle().isEmpty()) {
confInfo.setDescBundle(String.join("",
configuration.getClass()
.getName(),
confInfo.setDescBundle(
String.join("",
configuration.getName(),
"Description"));
} else {
confInfo.setDescBundle(annotation.descBundle());

View File

@ -18,8 +18,11 @@
*/
package org.libreccm.configuration;
import org.libreccm.configuration.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
@ -31,6 +34,8 @@ import java.util.ResourceBundle;
*/
public final class SettingInfo {
private static final Logger LOGGER = LogManager.getLogger(SettingInfo.class);
/**
* The fully qualified name of the setting.
*/
@ -104,7 +109,14 @@ public final class SettingInfo {
}
public ResourceBundle getDescriptionBundle(final Locale locale) {
try {
return ResourceBundle.getBundle(descBundle, locale);
} catch (MissingResourceException ex) {
LOGGER.warn("Failed to find bundle for base name '{}'"
+ " and locale '{}'.",
descBundle, locale);
return null;
}
}
public String getLabelKey() {
@ -116,7 +128,22 @@ public final class SettingInfo {
}
public String getLabel(final Locale locale) {
return getDescriptionBundle(locale).getString(labelKey);
final ResourceBundle bundle = getDescriptionBundle(locale);
if (bundle == null) {
return name;
} else {
try {
return bundle.getString(labelKey);
} catch (MissingResourceException ex) {
LOGGER.warn("Can't find resource for bundle '{}', "
+ "key '{}' and locale '{}'.",
descBundle,
labelKey,
locale);
return name;
}
}
}
public String getDescKey() {
@ -128,7 +155,22 @@ public final class SettingInfo {
}
public String getDescription(final Locale locale) {
return getDescriptionBundle(locale).getString(descKey);
final ResourceBundle bundle = getDescriptionBundle(locale);
if (bundle == null) {
return "";
} else {
try {
return bundle.getString(descKey);
} catch (MissingResourceException ex) {
LOGGER.warn("Can't find resource for bundle '{}', "
+ "key '{}' and locale '{}'.",
descBundle,
descKey,
locale);
return "";
}
}
}
@Override

View File

@ -32,6 +32,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import java.util.ArrayList;
import java.util.Objects;
/**
*
@ -131,6 +132,9 @@ public class SettingManager {
return null;
}
//Make the field accessible even if it has a private modifier
field.setAccessible(true);
if (field.getAnnotation(Setting.class) == null) {
return null;
}
@ -148,7 +152,7 @@ public class SettingManager {
try {
final Object conf = configuration.newInstance();
settingInfo.setDefaultValue(field.get(conf).toString());
settingInfo.setDefaultValue(Objects.toString(field.get(conf)));
} catch (InstantiationException | IllegalAccessException ex) {
LOGGER.warn(String.format("Failed to create instance of \"%s\" to "
+ "get default values.",

View File

@ -56,6 +56,13 @@ public class CcmIntegrator implements Integrator {
private static final Logger LOGGER = LogManager.getLogger(
CcmIntegrator.class);
/**
* Name of the property which is used to retrieve the data source in use
* from Hibernate.
*/
private static final String DATASOURCE_PROPERTY
= "hibernate.connection.datasource";
/**
* Service loader containing all modules. Initialised by the
* {@link #integrate(Configuration, SessionFactoryImplementor, SessionFactoryServiceRegistry)}
@ -91,10 +98,13 @@ public class CcmIntegrator implements Integrator {
final List<TreeNode> tree = treeManager.generateTree(modules);
final List<TreeNode> orderedNodes = treeManager.orderModules(tree);
//Get DataSource and Connection from the sessionFactory of
//Hibernate.
// //Get DataSource and Connection from the sessionFactory of
// //Hibernate.
final DataSource dataSource = (DataSource) sessionFactory.
getProperties().get("javax.persistence.jtaDataSource");
getProperties().get(DATASOURCE_PROPERTY);
if (dataSource == null) {
throw new IllegalStateException("No data source available.");
}
connection = dataSource.getConnection();
//Migrate tables and sequences which don't belong to a module
@ -312,7 +322,7 @@ public class CcmIntegrator implements Integrator {
//Get JDBC connection
final DataSource dataSource = (DataSource) sessionFactory
.getProperties().get("javax.persistence.jtaDataSource");
.getProperties().get(DATASOURCE_PROPERTY);
connection = dataSource.getConnection();
System.out.println("checking modules...");
LOGGER.info("Checking modules...");