001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle-sdk.
005 *
006 * Dicoogle/dicoogle-sdk is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle-sdk is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.sdk.core;
020
021import java.net.URI;
022import java.util.Collection;
023import java.util.List;
024
025import pt.ua.dicoogle.sdk.IndexerInterface;
026import pt.ua.dicoogle.sdk.QueryInterface;
027import pt.ua.dicoogle.sdk.StorageInputStream;
028import pt.ua.dicoogle.sdk.StorageInterface;
029import pt.ua.dicoogle.sdk.datastructs.Report;
030import pt.ua.dicoogle.sdk.datastructs.SearchResult;
031import pt.ua.dicoogle.sdk.task.JointQueryTask;
032import pt.ua.dicoogle.sdk.task.Task;
033
034/**
035 * Interface for accessing external functionalities of the platform, including other plugins' interfaces.
036 * <p>
037 * For instance, if a graphical plugin needs to query, it will able to access query providers
038 * with this platform. </p>
039 * 
040 * @author: Luís A. Bastião Silva <bastiao@ua.pt>
041 * @author Carlos Ferreira
042 * @author Frederico Valente
043 * @see QueryInterface
044 * @see IndexerInterface
045 * @see StorageInterface
046 */
047public interface DicooglePlatformInterface {
048    
049    /**
050     * Gets an installed indexer plugin by name.
051     * @param name the name of the plugin 
052     * @return the plugin that implements this interface
053     */
054    public IndexerInterface requestIndexPlugin(String name);
055    
056    /**
057     * Gets an installed query plugin by name.
058     * @param name the name of the plugin 
059     * @return the plugin that implements this interface
060     */
061    public QueryInterface requestQueryPlugin(String name);
062    
063    /**
064     * Obtains a collection of all active index plugins.
065     * @return an unmodifiable collection of active instances of {@link IndexerInterface}
066     */
067    public Collection<IndexerInterface> getAllIndexPlugins();
068    
069    /**
070     * Obtains a collection of all active query plugins.
071     * @return an unmodifiable collection of active instances of {@link QueryInterface}
072     */
073    public Collection<QueryInterface> getAllQueryPlugins();
074    
075    /** Obtains the storage interface for handling storage of the given scheme.
076     * 
077     * @param scheme the storage scheme
078     * @return the storage interface capable of handling that content, or {@code null} if no storage plugin
079     * installed can.
080     */
081    public StorageInterface getStoragePluginForSchema(String scheme);
082    
083    /** Obtains the storage interface for handling content in the given location.
084     * 
085     * @param location the storage location to check
086     * @return the storage interface capable of handling that content, or {@code null} if no storage plugin
087     * installed can
088     */
089    public StorageInterface getStorageForSchema(URI location);
090    
091    /** Quickly obtains all storage elements at the given location.
092     * 
093     * @param location the location to retrieve
094     * @param args a variable list of extra parameters for the retrieve
095     * @return an iterable of storage input streams
096     */
097    public Iterable<StorageInputStream> resolveURI(URI location, Object ...args);
098    
099    /** Obtains all installed storage plugins.
100     * 
101     * @param onlyEnabled whether only enabled plugins should be retrieved (all are retrieved if {@code false})
102     * @return a collection of storage plugin interfaces
103     */
104    public Collection<StorageInterface> getStoragePlugins(boolean onlyEnabled);
105
106    /** Obtains the storage interface for handling storage of the given scheme.
107     * Same as {@link #getStoragePluginForSchema(java.lang.String)}.
108     * 
109     * @param scheme the storage scheme
110     * @return the storage interface capable of handling that content, or {@code null} if no storage plugin
111     * installed can
112     */
113        public StorageInterface getStorageForSchema(String scheme);
114
115    /** Obtains all installed query plugins.
116     * 
117     * @param onlyEnabled whether only enabled plugins should be retrieved (all are retrieved if {@code false})
118     * @return a collection of query plugin interfaces
119     */
120        public Collection<QueryInterface> getQueryPlugins(boolean onlyEnabled);
121
122    /** Gets the names of all query providers.
123     * 
124     * @param enabled whether only enabled plugins should be retrieved (all are retrieved if {@code false})
125     * @return a collection of unique query provider names
126     */
127        public List<String> getQueryProvidersName(boolean enabled);
128
129    /** Gets the query provider with the given name.
130     * 
131     * @param name the unique name of the provider
132     * @param onlyEnabled whether only enabled plugins should be retrieved (all are retrieved if {@code false})
133     * @return a collection of unique query provider names
134     */
135        public QueryInterface getQueryProviderByName(String name,
136                        boolean onlyEnabled);
137
138    /**
139     * Easily performs a query over all query providers. This operation is asynchronous and returns immediately.
140     * @param holder a query task holder containing callback methods
141     * @param query a string describing the query
142     * @param parameters a variable list of extra parameters for the query
143     * @return a join query task
144     */
145        public JointQueryTask queryAll(JointQueryTask holder, String query,
146                        Object... parameters) ;
147
148    /** Easily performs a query over a specific provider. This operation is asynchronous and returns immediately.
149     * 
150     * @param querySource the name of the query provider to issue
151     * @param query a string describing the query
152     * @param parameters a variable list of extra parameters for the query
153     * @return an asynchronous task containing the results
154     */
155        public Task<Iterable<SearchResult>> query(String querySource, String query,
156                        Object... parameters);
157
158    /** Easily performs a query over multiple providers. This operation is asynchronous and returns immediately.
159     * 
160     * @param holder a query task holder containing callback methods
161     * @param querySources a list of names of query providers to issue
162     * @param query a string describing the query
163     * @param parameters a variable list of extra parameters for the query
164     * @return an asynchronous task containing the results
165     */
166        public JointQueryTask query(JointQueryTask holder,
167                        List<String> querySources, String query, Object... parameters);
168
169    /** Easily performs an indexation procedure over all active indexers. This operation is asynchronous
170     * and returns immediately.
171     * 
172     * @param path the path to index
173     * @return a list of asynchronous tasks, one for each provider
174     */
175        public List<Task<Report>> index(URI path);
176
177    /** Easily performs an indexation procedure over all active indexers. This operation is synchronous
178     * and will wait until all providers have finished indexing.
179     * 
180     * @param path the path to index
181     * @return a list of reports, one for each provider
182     */
183        public List<Report> indexBlocking(URI path);
184    
185    /** Obtain access to the server's settings.
186     * @return an object for read-only access to the settings
187     */
188    public ServerSettingsReader getSettings();
189}