use of fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration in project Payara by payara.
the class SetEnvironmentWarningConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config config = targetUtil.getConfig(target);
ActionReport actionReport = acc.getActionReport();
EnvironmentWarningConfiguration environmentWarningConfiguration = config.getExtensionByType(EnvironmentWarningConfiguration.class);
if (environmentWarningConfiguration != null) {
try {
ConfigSupport.apply(new SingleConfigCode<EnvironmentWarningConfiguration>() {
@Override
public Object run(EnvironmentWarningConfiguration config) throws PropertyVetoException {
if (enabled != null) {
config.setEnabled(enabled);
}
if (message != null) {
config.setMessage(message);
}
if (backgroundColour != null) {
if (backgroundColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
config.setBackgroundColour(backgroundColour);
} else {
throw new PropertyVetoException("Invalid data for background colour, must be a hex value.", new PropertyChangeEvent(config, "backgroundColour", config.getBackgroundColour(), backgroundColour));
}
}
if (textColour != null) {
if (textColour.matches("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")) {
config.setTextColour(textColour);
} else {
throw new PropertyVetoException("Invalid data for text colour, must be a hex value.", new PropertyChangeEvent(config, "textColour", config.getTextColour(), textColour));
}
}
return null;
}
}, environmentWarningConfiguration);
} catch (TransactionFailure ex) {
// Set failure
actionReport.failure(Logger.getLogger(SetEnvironmentWarningConfigurationCommand.class.getName()), "Failed to update configuration", ex);
}
}
}
use of fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration in project Payara by payara.
the class GetEnvironmentWarningConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config configNode = targetUtil.getConfig(config);
EnvironmentWarningConfiguration environmentWarningConfiguration = configNode.getExtensionByType(EnvironmentWarningConfiguration.class);
ActionReport actionReport = acc.getActionReport();
final String[] outputHeaders = { "Enabled", "Message", "Background Colour", "Text Colour" };
ColumnFormatter columnFormatter = new ColumnFormatter(outputHeaders);
Object[] outputValues = { environmentWarningConfiguration.isEnabled(), environmentWarningConfiguration.getMessage(), environmentWarningConfiguration.getBackgroundColour(), environmentWarningConfiguration.getTextColour() };
columnFormatter.addRow(outputValues);
actionReport.appendMessage(columnFormatter.toString());
Map<String, Object> extraPropsMap = new HashMap<>();
extraPropsMap.put("enabled", environmentWarningConfiguration.isEnabled());
extraPropsMap.put("message", environmentWarningConfiguration.getMessage());
extraPropsMap.put("backgroundColour", environmentWarningConfiguration.getBackgroundColour());
extraPropsMap.put("textColour", environmentWarningConfiguration.getTextColour());
Properties extraProps = new Properties();
extraProps.put("environmentWarningConfiguration", extraPropsMap);
actionReport.setExtraProperties(extraProps);
}
Aggregations