All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.graylog2.rest.models.alarmcallbacks.responses.AvailableAlarmCallbackSummaryResponse Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
package org.graylog2.rest.models.alarmcallbacks.responses;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import org.graylog2.rest.models.configuration.responses.BooleanField;
import org.graylog2.rest.models.configuration.responses.DropdownField;
import org.graylog2.rest.models.configuration.responses.NumberField;
import org.graylog2.rest.models.configuration.responses.RequestedConfigurationField;
import org.graylog2.rest.models.configuration.responses.TextField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

public class AvailableAlarmCallbackSummaryResponse {
    private static final Logger LOG = LoggerFactory.getLogger(AvailableAlarmCallbackSummaryResponse.class);

    public String name;
    public Map> requested_configuration;

    @JsonIgnore
    public List getRequestedConfiguration() {
        return extractRequestedConfiguration(requested_configuration);
    }

    public List extractRequestedConfiguration(Map> config) {
        List result = Lists.newArrayList();
        List booleanFields = Lists.newArrayList();

        for (Map.Entry> entry : config.entrySet()) {
            try {
                String fieldType = (String) entry.getValue().get("type");
                switch (fieldType) {
                    case "text":
                        result.add(new TextField(entry));
                        continue;
                    case "number":
                        result.add(new NumberField(entry));
                        continue;
                    case "boolean":
                        booleanFields.add(new BooleanField(entry));
                        continue;
                    case "dropdown":
                        result.add(new DropdownField(entry));
                        continue;
                    default:
                        LOG.info("Unknown field type [{}].", fieldType);
                }
            } catch (Exception e) {
                LOG.error("Skipping invalid configuration field [" + entry.getKey() + "]", e);
            }
        }

        result.addAll(booleanFields);

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy