Project

General

Profile

1
/**
2
 *  Copyright: 2013 Regents of the University of California and the
3
 *             National Center for Ecological Analysis and Synthesis
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
package edu.ucsb.nceas.metacat.common.query;
20

    
21
import java.util.List;
22

    
23
import org.dataone.configuration.Settings;
24

    
25
/**
26
 * A class represents the enable query engine type in the metacat
27
 * @author tao
28
 *
29
 */
30
public class EnabledQueryEngines {
31
    
32
    public static final String PATHQUERYENGINE = "pathquery";
33
    public static final String SOLRENGINE = "solr";
34
    private static final String ENABLED_ENGINES_PATH = "dbquery.enabledEngines";
35
    private static EnabledQueryEngines enabledEnginesObj = null;
36
    private List<String> enabledEngines = null;
37
    
38
    
39
    
40
    /*
41
     * Constructor. Read the enabled engines from the property file
42
     */
43
    private EnabledQueryEngines() {
44
        enabledEngines = Settings.getConfiguration().getList(ENABLED_ENGINES_PATH);
45
    }
46
    
47
    /**
48
     * Get the singleton instance
49
     * @return
50
     */
51
    public static EnabledQueryEngines getInstance() {
52
        if(enabledEnginesObj ==null) {
53
            enabledEnginesObj = new EnabledQueryEngines();
54
        }
55
        return enabledEnginesObj;
56
    }
57
    
58
    
59
    /**
60
     * Get the list of enabled engines. 
61
     * @return an empty list will be returned if there are no enabled engines.
62
     */
63
    public List<String> getEnabled() {
64
        return this.enabledEngines;
65
    }
66
    
67
    /**
68
     * If the the specified engine name is enabled. The name is not case sensitive.
69
     * @param engine  the specified engine name.
70
     * @return true if the specified name is enabled.
71
     */
72
    public boolean isEnabled(String engine) {
73
        boolean enabled = false;
74
        if(engine != null && !engine.trim().equals("") && enabledEngines != null) {
75
            for(String name : enabledEngines) {
76
                if(name != null && name.equalsIgnoreCase(engine)) {
77
                    enabled = true;
78
                    break;
79
                }
80
            }
81
        }
82
        return enabled;
83
    }
84
}
(2-2/7)