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

org.graylog.plugins.sidecar.rest.models.Configuration Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show newest version
/*
 * Copyright (C) 2020 Graylog, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program 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
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program. If not, see
 * .
 */
package org.graylog.plugins.sidecar.rest.models;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import org.graylog.autovalue.WithBeanGetter;
import org.mongojack.Id;
import org.mongojack.ObjectId;

import javax.annotation.Nullable;
import java.util.Set;

@AutoValue
@WithBeanGetter
@JsonAutoDetect
public abstract class Configuration {
    public static final String FIELD_ID = "id";
    public static final String FIELD_COLLECTOR_ID = "collector_id";
    public static final String FIELD_NAME = "name";
    public static final String FIELD_COLOR = "color";
    public static final String FIELD_TEMPLATE = "template";
    public static final String FIELD_TAGS = "tags";

    @Id
    @ObjectId
    @Nullable
    @JsonProperty(FIELD_ID)
    public abstract String id();

    @JsonProperty(FIELD_COLLECTOR_ID)
    public abstract String collectorId();

    @JsonProperty(FIELD_NAME)
    public abstract String name();

    @JsonProperty(FIELD_COLOR)
    public abstract String color();

    @JsonProperty(FIELD_TEMPLATE)
    public abstract String template();

    @JsonProperty(FIELD_TAGS)
    public abstract Set tags();

    @JsonCreator
    public static Configuration create(@JsonProperty(FIELD_ID) String id,
                                       @JsonProperty(FIELD_COLLECTOR_ID) String collectorId,
                                       @JsonProperty(FIELD_NAME) String name,
                                       @JsonProperty(FIELD_COLOR) String color,
                                       @JsonProperty(FIELD_TEMPLATE) String template,
                                       @JsonProperty(FIELD_TAGS) @Nullable Set tags) {
        return builder()
                .id(id)
                .collectorId(collectorId)
                .name(name)
                .color(color)
                .template(template)
                .tags(tags == null ? Set.of() : tags)
                .build();
    }

    public static Configuration createWithoutId(String collectorId,
                                                String name,
                                                String color,
                                                String template,
                                                Set tags) {
        return create(new org.bson.types.ObjectId().toHexString(),
                collectorId,
                name,
                color,
                template,
                tags);
    }

    public static Builder builder() {
        return new AutoValue_Configuration.Builder();
    }

    public abstract Builder toBuilder();

    @AutoValue.Builder
    public abstract static class Builder {
        public abstract Builder id(String id);

        public abstract Builder collectorId(String collectorId);

        public abstract Builder name(String name);

        public abstract Builder color(String color);

        public abstract Builder template(String template);

        public abstract Builder tags(Set tags);

        public abstract Configuration build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy