// Path: grafana-dashboard-generator/src/main/java/uk/co/szmg/grafana/DashboardFactory.java
// public interface DashboardFactory {
// 
//     /**
//      * Creates dashboards.
//      * @return a list of dashboards created, should not be {@code null}
//      */
//     List<Dashboard> create();
// 
// }


import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static java.util.Collections.unmodifiableList;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import uk.co.szmg.grafana.DashboardFactory;
import uk.co.szmg.grafana.domain.Dashboard;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
package uk.co.szmg.grafana.stores;

/*-
 * #%L
 * grafana-dashboard-generator-cli
 * %%
 * Copyright (C) 2017 Mate Gabor Szvoboda
 * %%
 * Licensed 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.
 * #L%
 */




/**
 * Loads and provides dashboards.
 *
 * <p>First, an annotation based Spring context is built
 * in {@code rootPackage}. Then every {@link DashboardFactory}
 * beans are looked up and invoked to create dashboards.
 * Finally, all {@link Dashboard} beans are read.
 *
 * <p>This class can also return the duplicated dashboards.
 * Two dashboards are duplicated if their titles are equal.
 */
public class DashboardStore {

    private String rootPackage;

    private List<Dashboard> dashboards;

    /**
     * Creates a DashboardStore.
     * @param rootPackage root package of the annotation based spring context to be searched
     */
    public DashboardStore(String rootPackage) {
        this.rootPackage = rootPackage;
    }

    /**
     * Loads dashboards.
     *
     * <p>This will create the Spring context and look for
     * {@link DashboardFactory} and {@link Dashboard} implementations.
     */
    public void load() {
        List<Dashboard> dashboards = new ArrayList<>();
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(rootPackage);
// Path: grafana-dashboard-generator/src/main/java/uk/co/szmg/grafana/DashboardFactory.java
// public interface DashboardFactory {
// 
//     /**
//      * Creates dashboards.
//      * @return a list of dashboards created, should not be {@code null}
//      */
//     List<Dashboard> create();
// 
// }


// Path: grafana-dashboard-generator/src/main/java/uk/co/szmg/grafana/stores/DashboardStore.java
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static java.util.Collections.unmodifiableList;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import uk.co.szmg.grafana.DashboardFactory;
import uk.co.szmg.grafana.domain.Dashboard;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

package uk.co.szmg.grafana.stores;

/*-
 * #%L
 * grafana-dashboard-generator-cli
 * %%
 * Copyright (C) 2017 Mate Gabor Szvoboda
 * %%
 * Licensed 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.
 * #L%
 */




/**
 * Loads and provides dashboards.
 *
 * <p>First, an annotation based Spring context is built
 * in {@code rootPackage}. Then every {@link DashboardFactory}
 * beans are looked up and invoked to create dashboards.
 * Finally, all {@link Dashboard} beans are read.
 *
 * <p>This class can also return the duplicated dashboards.
 * Two dashboards are duplicated if their titles are equal.
 */
public class DashboardStore {

    private String rootPackage;

    private List<Dashboard> dashboards;

    /**
     * Creates a DashboardStore.
     * @param rootPackage root package of the annotation based spring context to be searched
     */
    public DashboardStore(String rootPackage) {
        this.rootPackage = rootPackage;
    }

    /**
     * Loads dashboards.
     *
     * <p>This will create the Spring context and look for
     * {@link DashboardFactory} and {@link Dashboard} implementations.
     */
    public void load() {
        List<Dashboard> dashboards = new ArrayList<>();
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(rootPackage);
        Map<String, DashboardFactory> factories = applicationContext.getBeansOfType(DashboardFactory.class);