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

io.inugami.configuration.models.plugins.Plugin Maven / Gradle / Ivy

/* --------------------------------------------------------------------
 *  Inugami
 * --------------------------------------------------------------------
 *
 * This program 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, version 3.
 *
 * 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 GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see .
 */
package io.inugami.configuration.models.plugins;

import io.inugami.api.alertings.AlertingProvider;
import io.inugami.api.exceptions.Asserts;
import io.inugami.api.handlers.Handler;
import io.inugami.api.listeners.EngineListener;
import io.inugami.api.models.Gav;
import io.inugami.api.models.plugins.ManifestInfo;
import io.inugami.api.processors.Processor;
import io.inugami.api.providers.Provider;
import io.inugami.configuration.models.EventConfig;
import io.inugami.configuration.models.plugins.front.PluginFrontConfig;
import lombok.*;

import java.io.File;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * Plugin
 *
 * @author patrick_guillerm
 * @since 27 déc. 2016
 */
@ToString(onlyExplicitlyIncluded = true)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@SuppressWarnings({"java:S3655", "java:S107"})
public final class Plugin implements Serializable {

    // =========================================================================
    // ATTRIBUTES
    // =========================================================================
    /**
     * The Constant serialVersionUID.
     */
    private static final long serialVersionUID = 1620535173987042446L;

    private           boolean                          enabled = true;
    private           PluginConfiguration              config;
    private           List                events;
    private           boolean                          eventConfigPresent;
    private           ManifestInfo                     manifest;
    private           Map> properties;
    private transient List             listeners;
    private transient List                  processors;
    private transient List                   providers;
    private transient List                    handlers;
    private transient List           alertingProviders;
    @ToString.Include
    @EqualsAndHashCode.Include
    private           Gav                              gav;

    // =========================================================================
    // CONSTRUCTORS
    // =========================================================================

    //@formatter:off
    public Plugin(final PluginConfiguration config,
                  final List events,
                  final List listeners,
                  final List processors,
                  final List handlers,
                  final List providers,
                  final List alertingProviders,
                  final ManifestInfo manifest,
                  final Map> propertiesPaths) {
        //@formatter:on
        Asserts.assertNotNull(config);
        Asserts.assertNotNull(config.getGav());
        this.gav = config.getGav();
        this.enabled = config.isEnable();
        this.config = config;
        this.eventConfigPresent = (events != null) && !events.isEmpty();
        this.manifest = manifest;
        this.properties = propertiesPaths;

        //@formatter:off
        this.events = events == null ? null : Collections.unmodifiableList(events);
        this.listeners = listeners == null ? null : Collections.unmodifiableList(listeners);
        this.processors = processors == null ? null : Collections.unmodifiableList(processors);
        this.handlers = handlers == null ? null : Collections.unmodifiableList(handlers);
        this.providers = providers == null ? null : Collections.unmodifiableList(providers);
        this.alertingProviders = alertingProviders == null ? null : Collections.unmodifiableList(alertingProviders);
        //@formatter:on

    }

    public Plugin(final String groupId, final String artifactId) {
        gav = Gav.builder()
                 .groupId(groupId)
                 .artifactId(artifactId)
                 .build();
        config = null;
        events = null;
        eventConfigPresent = false;
        manifest = null;
        properties = null;
        listeners = null;
        processors = null;
        providers = null;
        handlers = null;
        alertingProviders = null;

    }

    // =========================================================================
    // DELEGATES
    // =========================================================================


    public List getResources() {
        return config.getResources();
    }

    // =========================================================================
    // GETTERS & SETTERS
    // =========================================================================
    public String buildChannelName() {
        String result = null;
        if (getFrontConfig().isPresent()) {
            result = getFrontConfig().get().getPluginBaseName();
        } else {
            //@formatter:off
            result = String.join(":", getGav().getGroupId(), getGav().getArtifactId());
            //@formatter:on
        }
        return result;
    }


    public void enablePlugin() {
        this.enabled = true;
    }

    public void disablePlugin() {
        this.enabled = false;
    }

    public Optional> getEvents() {
        return events == null ? Optional.empty() : Optional.of(events);
    }

    public Optional> getListeners() {
        return listeners == null ? Optional.empty() : Optional.of(listeners);
    }

    public Optional> getProcessors() {
        return processors == null ? Optional.empty() : Optional.of(processors);
    }

    public Optional> getProviders() {
        return providers == null ? Optional.empty() : Optional.of(providers);
    }


    public Optional getFrontConfig() {
        return config.getFrontConfig();
    }

    public Optional getTimeout() {
        return Optional.ofNullable(config.getTimeout());
    }


    public File getWorkspace() {
        return manifest == null ? null : manifest.getWorkspace();
    }

    public Optional> getAlertingProviders() {
        return Optional.ofNullable(alertingProviders);
    }

    public Optional>> getProperties() {
        return Optional.ofNullable(properties);
    }

    public Optional> getHandlers() {
        return handlers == null ? Optional.empty() : Optional.of(handlers);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy