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

org.killbill.billing.util.nodes.DefaultNodeInfo Maven / Gradle / Ivy

There is a newer version: 0.24.11
Show newest version
/*
 * Copyright 2014-2015 Groupon, Inc
 * Copyright 2014-2015 The Billing Project, LLC
 *
 * The Billing Project licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package org.killbill.billing.util.nodes;

import java.util.Set;
import java.util.stream.Collectors;

import org.joda.time.DateTime;
import org.killbill.billing.osgi.api.DefaultPluginsInfoApi.DefaultPluginInfo;
import org.killbill.billing.osgi.api.DefaultPluginsInfoApi.DefaultPluginServiceInfo;
import org.killbill.billing.osgi.api.PluginInfo;
import org.killbill.billing.osgi.api.PluginServiceInfo;
import org.killbill.commons.utils.collect.Iterables;
import org.killbill.billing.util.nodes.json.NodeInfoModelJson;
import org.killbill.billing.util.nodes.json.PluginInfoModelJson;
import org.killbill.billing.util.nodes.json.PluginServiceInfoModelJson;

public class DefaultNodeInfo implements NodeInfo {

    private final String nodeName;
    private final DateTime bootTime;
    private final DateTime lastUpdatedDate;
    private final String killbillVersion;
    private final String apiVersion;
    private final String platformVersion;
    private final String commonVersion;
    private final String pluginApiVersion;
    private final Iterable pluginInfo;

    public DefaultNodeInfo(final String nodeName,
                           final DateTime bootTime,
                           final DateTime lastUpdatedDate,
                           final String killbillVersion,
                           final String apiVersion,
                           final String platformVersion,
                           final String commonVersion,
                           final String pluginApiVersion,
                           final Iterable pluginInfo) {
        this.nodeName = nodeName;
        this.bootTime = bootTime;
        this.lastUpdatedDate = lastUpdatedDate;
        this.killbillVersion = killbillVersion;
        this.apiVersion = apiVersion;
        this.platformVersion = platformVersion;
        this.commonVersion = commonVersion;
        this.pluginApiVersion = pluginApiVersion;
        this.pluginInfo = pluginInfo;
    }

    public DefaultNodeInfo(final NodeInfoModelJson in) {
        this(in.getNodeName(),
             in.getBootTime(),
             in.getBootTime(),
             in.getKillbillVersion(),
             in.getApiVersion(),
             in.getPlatformVersion(),
             in.getCommonVersion(),
             in.getPluginApiVersion(),
             toPluginInfo(in.getPluginInfo()));
    }

    private static Set toPluginServiceInfo(final Set services) {
        return services.stream()
                .map(input -> new DefaultPluginServiceInfo(input.getServiceTypeName(), input.getRegistrationName()))
                .collect(Collectors.toUnmodifiableSet());
    }

    private static Iterable toPluginInfo(final Iterable plugins) {
        return Iterables.toStream(plugins)
                        .map(DefaultNodeInfo::newDefaultPluginInfo)
                        .collect(Collectors.toUnmodifiableList());
    }

    private static DefaultPluginInfo newDefaultPluginInfo(PluginInfoModelJson input) {
        return new DefaultPluginInfo(input.getPluginKey(), input.getBundleSymbolicName(), input.getPluginName(),
                                     input.getVersion(), input.getState(), input.isSelectedForStart(),
                                     toPluginServiceInfo(input.getServices()));
    }

    @Override
    public String getNodeName() {
        return nodeName;
    }

    @Override
    public DateTime getBootTime() {
        return bootTime;
    }

    @Override
    public DateTime getLastUpdatedDate() {
        return lastUpdatedDate;
    }

    @Override
    public String getKillbillVersion() {
        return killbillVersion;
    }

    @Override
    public String getApiVersion() {
        return apiVersion;
    }

    @Override
    public String getPlatformVersion() {
        return platformVersion;
    }

    @Override
    public String getCommonVersion() {
        return commonVersion;
    }

    @Override
    public String getPluginApiVersion() {
        return pluginApiVersion;
    }

    @Override
    public Iterable getPluginInfo() {
        return pluginInfo;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy