ParamResourceModel rm = new ParamResourceModel("GWC.diskQuotaLoadFailed", null, provider.getException().getMessage());
error(rm.getString());
}
// use a dettached copy of dq config to support the tabbed pane
final DiskQuotaConfig diskQuotaConfig;
if (diskQuotaModuleDisabled) {
diskQuotaConfig = new DiskQuotaConfig(); // fake
diskQuotaConfig.setDefaults();
} else {
diskQuotaConfig = gwc.getDiskQuotaConfig().clone();
}
// same as above, but we don't need to create a copy of the JDBC quota config since
// that config is just used to instantiate the quota store, and then gets promptly discarted
final JDBCConfiguration jdbcQuotaConfiguration;
if(gwc.getJDBCDiskQuotaConfig() == null) {
jdbcQuotaConfiguration = new JDBCConfiguration();
JDBCConfiguration.ConnectionPoolConfiguration configuration = new JDBCConfiguration.ConnectionPoolConfiguration();
configuration.setMinConnections(1);
configuration.setMaxConnections(10);
configuration.setConnectionTimeout(10000);
configuration.setMaxOpenPreparedStatements(50);
jdbcQuotaConfiguration.setConnectionPool(configuration);
} else {
jdbcQuotaConfiguration = gwc.getJDBCDiskQuotaConfig();
}
final Form<Map<String, Serializable>> form;
form = new Form<Map<String, Serializable>>("form");
add(form);
final IModel<DiskQuotaConfig> diskQuotaModel = new Model<DiskQuotaConfig>(diskQuotaConfig);
final IModel<JDBCConfiguration> jdbcQuotaModel = new Model<JDBCConfiguration>(jdbcQuotaConfiguration);
final DiskQuotaConfigPanel diskQuotaConfigPanel = new DiskQuotaConfigPanel(
"diskQuotaPanel", diskQuotaModel, jdbcQuotaModel);
if (diskQuotaModuleDisabled) {
diskQuotaConfigPanel.setEnabled(false);
super.warn(new ResourceModel("DiskQuotaSettingsPage.disabledWarning").getObject());
}
form.add(diskQuotaConfigPanel);
form.add(new Button("submit") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
GWC gwc = getGWC();
if (!diskQuotaModuleDisabled) {
StorageUnit chosenUnit = diskQuotaConfigPanel.getStorageUnit();
// REVISIT: it seems Wicket is sending back a plain string instead of a
String chosenQuotaStr = String.valueOf(diskQuotaConfigPanel.getQuotaValue());
Double chosenQuota;
try {
chosenQuota = Double.valueOf(chosenQuotaStr);
} catch (NumberFormatException e) {
form.error(chosenQuotaStr + " is not a valid floating point number");// TODO:
// localize
return;
}
if (chosenQuota.doubleValue() <= 0D) {
form.error("Quota has to be > 0");
return;
}
DiskQuotaConfig dqConfig = diskQuotaModel.getObject();
JDBCConfiguration jdbcConfig = jdbcQuotaModel.getObject();
if(dqConfig.getQuotaStore() != null && dqConfig.getQuotaStore().equals("JDBC")) {
try {
gwc.testQuotaConfiguration(jdbcConfig);
} catch(Exception e) {
LOGGER.log(Level.SEVERE, "Error instantiating the JDBC configuration", e);
error("Failure occurred while saving the JDBC configuration"
+ e.getMessage() + " (see the logs for a full stack trace)");
return;
}
}
dqConfig.getGlobalQuota().setValue(chosenQuota.doubleValue(), chosenUnit);
try {
gwc.saveDiskQuotaConfig(dqConfig, jdbcConfig);
} catch(Exception e) {
LOGGER.log(Level.SEVERE, "Failed to save the JDBC configuration", e);
error("Failure occurred while saving the JDBC configuration"