Search in sources :

Example 1 with EnvironmentWarningConfiguration

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);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) EnvironmentWarningConfiguration(fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration)

Example 2 with EnvironmentWarningConfiguration

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);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) EnvironmentWarningConfiguration(fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)2 EnvironmentWarningConfiguration (fish.payara.appserver.environment.warning.config.EnvironmentWarningConfiguration)2 ActionReport (org.glassfish.api.ActionReport)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1